Comparing version 0.0.1 to 0.0.2
17
num.js
@@ -178,6 +178,17 @@ var int = require('int'); | ||
Num.cmp = function(a, b) { | ||
a = ensure_num(a); | ||
b = ensure_num(b); | ||
return a.sub(b).toNumber(); | ||
// make copies cause we modify precision | ||
var a = Num(a); | ||
var b = Num(b); | ||
if (a._int._s != b._int._s) { | ||
return a._int._s ? -1 : 1; | ||
} | ||
// normalize the two numbers | ||
var precision = Math.max(a._precision, b._precision); | ||
a.set_precision(precision); | ||
b.set_precision(precision); | ||
return a._int.cmp(b._int); | ||
}; | ||
@@ -184,0 +195,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "arbitrary precision integer and decimal library in pure javascript", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"repository": { | ||
@@ -11,5 +11,11 @@ "type": "git", | ||
}, | ||
"keywords": [ | ||
"decimal", | ||
"num", | ||
"arithmatic", | ||
"precision" | ||
], | ||
"main": "num.js", | ||
"dependencies": { | ||
"int": "0.0.3" | ||
"int": "0.1.0" | ||
}, | ||
@@ -22,3 +28,6 @@ "devDependencies": { | ||
"node": "*" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
} | ||
} |
@@ -7,3 +7,3 @@ [![Build Status](https://secure.travis-ci.org/shtylman/node-num.png)](http://travis-ci.org/shtylman/node-num) | ||
Looking for just integers? Check out **int** at shtylman/node-int | ||
Looking for just integers? Check out [int](https://github.com/shtylman/node-int) | ||
@@ -10,0 +10,0 @@ ## quick and dirty ## |
@@ -38,1 +38,7 @@ | ||
test('build#precision', function() { | ||
assert.equal(num(15, 1), '1.5'); | ||
assert.equal(num(1234567890, 5), '12345.67890'); | ||
assert.equal(num(-122, 4), '-0.0122'); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13183
15
321