cuint
Advanced tools
Comparing version 0.0.0 to 0.0.1
@@ -0,1 +1,9 @@ | ||
0.0.1 / 2014-01-01 | ||
================== | ||
* toString() fix for uint < radix | ||
* toString() no longer alters the unsigned integer | ||
* fixed shiftLeft() not applying mask properly, affecting toString() and div() | ||
* added examples | ||
0.0.0 / 2013-12-31 | ||
@@ -2,0 +10,0 @@ ================== |
@@ -116,14 +116,15 @@ /** | ||
UINT32.prototype.toString = function (radix) { | ||
if (this._low == 0 && this._high == 0) return '0' | ||
radix = radix || 10 | ||
var radixUint = radixCache[radix] || new UINT32(radix) | ||
if ( this.lt(radixUint) ) return this.toNumber().toString(radix) | ||
var self = this.clone() | ||
var res = new Array(32) | ||
for (var i = 31; i >= 0; i--) { | ||
this.div(radixUint, true) | ||
res[i] = this.remainder.toNumber().toString(radix) | ||
if ( !this.gt(radixUint) ) break | ||
self.div(radixUint, true) | ||
res[i] = self.remainder.toNumber().toString(radix) | ||
if ( !self.gt(radixUint) ) break | ||
} | ||
res[i-1] = this.toNumber().toString(radix) | ||
res[i-1] = self.toNumber().toString(radix) | ||
@@ -391,5 +392,5 @@ return res.join('') | ||
this._high = (this._high << n) | (this._low >>> (16-n)) | ||
this._low = this._low << n | ||
this._low = (this._low << n) & 0xFFFF | ||
if (!allowOverflow) { | ||
this._low &= 0xFFFF | ||
// Overflow only allowed on the high bits... | ||
this._high &= 0xFFFF | ||
@@ -396,0 +397,0 @@ } |
{ | ||
"name": "cuint", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Unsigned integers for Javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -31,10 +31,10 @@ # C-like unsigned integers for Javascript | ||
In the browser, include the following, and access the constructor with _UINT32_: | ||
In the browser, include the following (file is located in the _build_ directory), and access the constructor with _UINT32_: | ||
`<script src="/your/path/to/uint32.js"></script> | ||
`<script src="/your/path/to/uint32.lmd.js"></script> | ||
... | ||
<script type="text/javascript"> | ||
var prime1 = UINT32('3266489917'); | ||
var prime2 = UINT32('2654435761'); | ||
var prime1plus2 = prime1.add(prime2) | ||
var v1 = UINT32('326648991'); | ||
var v2 = UINT32('265443576'); | ||
var v1plus2 = v1.add(v2) // 592092567 | ||
</script>` | ||
@@ -41,0 +41,0 @@ |
@@ -98,2 +98,13 @@ var assert = require('assert') | ||
describe('high bit+high bit 2', function () { | ||
it('should return n', function (done) { | ||
var u = UINT32('326648991').add( UINT32('265443576') ) | ||
assert.equal( u.toNumber(), 592092567 ) | ||
done() | ||
}) | ||
}) | ||
}) |
@@ -72,2 +72,13 @@ var assert = require('assert') | ||
describe('high bit/high bit 2', function () { | ||
it('should return n', function (done) { | ||
var u = UINT32('3266489917').div( UINT32('668265263') ) | ||
assert.equal( u.toNumber(), 4 ) | ||
done() | ||
}) | ||
}) | ||
}) |
@@ -52,2 +52,13 @@ var assert = require('assert') | ||
describe('< radix', function () { | ||
it('should return the number', function (done) { | ||
var u = UINT32(4).toString() | ||
assert.equal( u, '4' ) | ||
done() | ||
}) | ||
}) | ||
}) |
56763
29
1856