Comparing version 0.1.1 to 0.1.2
@@ -21,2 +21,10 @@ 'use strict'; | ||
ArchiNumber.prototype.mod = function (num) { | ||
var num1 = +this; | ||
var num2 = +num; | ||
var factor = getMaxFactor(num1, num2); | ||
return new ArchiNumber((num1 * factor) % (num2 * factor)); | ||
}; | ||
function getMaxFactor(num1, num2) { | ||
@@ -23,0 +31,0 @@ return Math.max(getFactor(num1), getFactor(num2)); |
{ | ||
"name": "archi", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Easy math with decimals for Javascript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -42,2 +42,3 @@ # +archi | ||
- `.minus(num)`: current num - other num | ||
- `.mod(num)`: current num % other num | ||
@@ -44,0 +45,0 @@ ## License |
@@ -23,7 +23,17 @@ 'use strict'; | ||
test('mod', function (t) { | ||
t.equal(+calc(2).mod(2), 0); | ||
t.equal(+calc(3).mod(2), 1); | ||
t.equal(+calc(0.3).mod(0.2), 1); | ||
t.equal(+calc(0.3).mod(0.1), 0); | ||
t.end(); | ||
}); | ||
test('composed calc', function (t) { | ||
t.equal(+calc(0.1).plus(0.2).minus(0.1), 0.2); | ||
t.equal(+calc(0.1).plus(0.1).plus(0.1), 0.3); | ||
t.equal(+calc(0.1).plus(0.1).mod(0.1), 0); | ||
t.end(); | ||
}); |
5994
68
47