diff --git a/build/Big.js b/build/Big.js index cea77eb..43ccafd 100644 --- a/build/Big.js +++ b/build/Big.js @@ -1,11 +1,11 @@ /////////////////////////////////////////////////////////////// // Big.js -// v0.9.0 (beta) +// v0.10.0 (beta) /////////////////////////////////////////////////////////////// // http://github.com/whatgoodisaroad/Big-js // By Wyatt Allen // MIT Licensed -// 2011-09-19 (Monday, 19 September 2011) +// 2013-02-11 (Monday, 11 February 2013) /////////////////////////////////////////////////////////////// var Big; @@ -164,8 +164,22 @@ function compare(bl, br) { bl = bl.clone(); br = br.clone(); - if (bl.sign != br.sign) { - if (bl.sign == POSITIVE) { return GT; } + if (bl.isZero() || br.isZero()) { + if (bl.isZero() && br.isZero()) { return EQ; } + + else if (bl.isZero()) { + if (br.sign == POSITIVE) { return LT; } + else /* (br.sign == POSITIVE) */ { return GT; } + } + + else /* (br.isZero()) */ { + if (bl.sign == POSITIVE) { return GT; } + else /* (bl.sign == POSITIVE) */ { return LT; } + } + } + + else if (bl.sign != br.sign) { + if (bl.sign == POSITIVE) { return GT; } else /* (bl.sign == NEGATIVE) */ { return LT; } } @@ -535,7 +549,7 @@ function subtract(l, r) { r = normalize(r); if (l.isZero()) { - return negate(l); + return negate(r); } if (r.isZero()) { @@ -610,7 +624,8 @@ function borrowFromMantissa(m) { -//// Basic, O(n^2) multiplication algorithm: +// +// Basic, O(n^2) multiplication algorithm: function multiply(l, r) { var same = preProcess(l, r), diff --git a/build/Big.min.js b/build/Big.min.js index 4b9e694..8e45610 100644 --- a/build/Big.min.js +++ b/build/Big.min.js @@ -1,22 +1,22 @@ /////////////////////////////////////////////////////////////// // Big.js -// v0.9.0 (beta) +// v0.10.0 (beta) /////////////////////////////////////////////////////////////// // http://github.com/whatgoodisaroad/Big-js // By Wyatt Allen // MIT Licensed -// 2011-09-19 (Monday, 19 September 2011) +// 2013-02-11 (Monday, 11 February 2013) /////////////////////////////////////////////////////////////// var Big; -(function(){function p(a,b){a=a.clone();b=b.clone();if(a.sign!=b.sign)return a.sign==k?n:g;else if(a.exponent!=b.exponent)return a.sign==k?a.exponent>b.exponent?n:g:a.exponent>b.exponent?g:n;else{var c=r(a,b);return a.sign==k?u(c.l.mantissa,c.r.mantissa):u(c.r.mantissa,c.l.mantissa)}}function u(a,b){a=a.slice();b=b.slice();if(b.length){if(!a.length)return h(b)?o:g}else return h(a)?o:n;if(a[0]>b[0])return n;else if(a[0]=0;--h)j=j+i[h]+c[h],g[h+1]=j%10,j=j>9?1:0;g[0]=j;return new d(f,e,g)}else return u(c.l.mantissa,c.r.mantissa)==o?x:a.sign==k?t(c.l,l(c.r)):t(c.r,l(c.l))}function t(a,b){a=m(a);b=m(b);if(a.isZero())return l(a);if(b.isZero())return a.clone();var c=p(a,b);if(c==o)return x;if(a.sign==b.sign){if(a.sign==q)return t(l(b),l(a));if(c==g)return l(t(b,a));c=r(a,b);c=y(c.l,c.r);return new Big(a.sign,c.l.exponent,A(c.l.mantissa,c.r.mantissa))}else return a.sign==k?z(a,l(b)):l(z(l(a),b))}function A(a,b){if(a.length== -0)return[];var c=a.slice(0,a.length-1),d=b.slice(0,b.length-1),f=a[a.length-1],e=b[b.length-1];return f=Big.precision)return f.DIVISION_ROUNDOFF=!0,f.DIVISION_REMAINDER=c.toString(),[];if(!a.length&&h(c.mantissa))return f.DIVISION_ROUNDOFF=!1,[];var e;if(a.length){var i={x:a[0],xs:a.slice(1)},a=i.x; -e=i.xs}else a=0,e=[];for(var g,j,i=9;i>=0;--i)if(j=b.times(new Big(i)),i==0||j.lessThanOrEqualTo(c))break;g={q:i,prod_bn:j};j=g.q;i=D;c=c.minus(g.prod_bn);c=c.times(new Big(10)).plus(new Big(a));b=i(e,b,c,d==0&&j==0?0:d+1,f);return[j].concat(b)}var k=!1,q=!0,n=0,g=1,o=2;Big=function(a,b,c,d){typeof a=="number"&&(a=""+a);if(a.substring)return a=a.replace(/(^\s+)|(\s+$)/g,""),b=/^[+-]/.test(a),c=/^[+-]?\d*\.\d*$/.test(a),d=b?a.slice(1):a,m(new Big(b&&a[0]=="-"?q:k,c?d.indexOf(".")-1:d.length-1,B(d.replace(".", -""))));else this.sign=a,this.exponent=b,this.mantissa=c,this.flags=d||{},this.expr=this.toString()};Big.POSITIVE=k;Big.NEGATIVE=q;Big.parse=function(a){return new Big(a)};Big.precision=20;Big.prototype.toString=function(){if(h(this.mantissa))return"0";var a=m(this),b=(this.sign==q?"-":"")+(a.exponent<0?"0":w(a.exponent+1,a.mantissa.slice(0,a.exponent+1)).join(""));a=a.exponent>=0?a.mantissa.length==a.exponent?"":"."+v(a.exponent+1<1?a.mantissa.slice():a.mantissa.slice(a.exponent+1)).join(""):"."+ -s(-a.exponent-1,"0").join("")+a.mantissa.join("");return b+a};Big.prototype.lessThan=function(a){return p(this,a)==g};Big.prototype.greaterThan=function(a){return p(this,a)==n};Big.prototype.equals=function(a){return p(this,a)==o};Big.prototype.lessThanOrEqualTo=function(a){a=p(this,a);return a==g||a==o};Big.prototype.greaterThanOrEqualTo=function(a){a=p(this,a);return a==n||a==o};Big.prototype.plus=function(a){return m(z(this,a))};Big.prototype.minus=function(a){return m(t(this,a))};Big.prototype.times= -function(a){var b;b=r(this,a);b=y(b.l,b.r);for(var c=b.l.mantissa.length,d=s(2*c,0),f=c-1;f>=0;--f)for(var e=c-1;e>=0;--e)d[f+e+1]+=b.r.mantissa[f]*b.l.mantissa[e];c=d.slice();for(f=c.length-1;f>0;--f)e=c[f],e>9&&(d=e%10,e=(e-d)/10,c[f-1]+=e,c[f]=d);a=new Big(this.sign==a.sign?k:q,2*b.l.exponent+1,c);return m(a)};Big.prototype.over=function(a){var b,c;b=r(this,a);var d;d=b.l.mantissa.length-b.r.mantissa.length>0?new Big(Math.pow(10,b.l.mantissa.length-b.l.exponent-1)):new Big(Math.pow(10,b.r.mantissa.length- -b.r.exponent-1));c={l:b.l.times(d),r:b.r.times(d)};b={};d=Big;var a=this.sign==a.sign?k:q,f=c.l.exponent;var e=c.l;c=c.r;if(h(e.mantissa))c=[];else if(h(c.mantissa))throw"Division by zero";else e={x:e.mantissa[0],xs:e.mantissa.slice(1)},c=D(e.xs,new Big(k,c.exponent,c.mantissa),new Big(e.x),0,b);b=new d(a,f,c,b);return m(b)};Big.prototype.isZero=function(){return h(this.mantissa)};Big.prototype.clone=function(){return new Big(this.sign,this.exponent,this.mantissa.slice())};Big.prototype.negate=function(){var a= -this.clone();a.sign=!a.sign;return a};var x=new Big(k,0,[])})(); +(function(){function o(a,b){a=a.clone();b=b.clone();if(a.isZero()||b.isZero())return a.isZero()&&b.isZero()?l:a.isZero()?b.sign==i?g:d:a.sign==i?d:g;else if(a.sign!=b.sign)return a.sign==i?d:g;else if(a.exponent!=b.exponent)return a.sign==i?a.exponent>b.exponent?d:g:a.exponent>b.exponent?g:d;else{var c=q(a,b);return a.sign==i?t(c.l.mantissa,c.r.mantissa):t(c.r.mantissa,c.l.mantissa)}}function t(a,b){a=a.slice();b=b.slice();if(b.length){if(!a.length)return m(b)?l:g}else return m(a)?l:d;if(a[0]>b[0])return d; +else if(a[0]=0;--d)h=h+z[d]+c[d],g[d+1]=h%10,h=h>9?1:0;g[0]=h;return new e(j,f,g)}else return t(c.l.mantissa,c.r.mantissa)==l?w:a.sign==i?s(c.l,k(c.r)):s(c.r,k(c.l))}function s(a,b){a=n(a);b=n(b);if(a.isZero())return k(b);if(b.isZero())return a.clone();var c=o(a,b);if(c==l)return w;if(a.sign==b.sign){if(a.sign==p)return s(k(b),k(a));if(c==g)return k(s(b, +a));c=q(a,b);c=x(c.l,c.r);return new Big(a.sign,c.l.exponent,A(c.l.mantissa,c.r.mantissa))}else return a.sign==i?y(a,k(b)):k(y(k(a),b))}function A(a,b){if(a.length==0)return[];var c=a.slice(0,a.length-1),e=b.slice(0,b.length-1),j=a[a.length-1],f=b[b.length-1];return j=Big.precision)return j.DIVISION_ROUNDOFF= +!0,j.DIVISION_REMAINDER=c.toString(),[];if(!a.length&&m(c.mantissa))return j.DIVISION_ROUNDOFF=!1,[];var f;if(a.length){var d={x:a[0],xs:a.slice(1)},a=d.x;f=d.xs}else a=0,f=[];for(var g,h,d=9;d>=0;--d)if(h=b.times(new Big(d)),d==0||h.lessThanOrEqualTo(c))break;g={q:d,prod_bn:h};h=g.q;d=D;c=c.minus(g.prod_bn);c=c.times(new Big(10)).plus(new Big(a));b=d(f,b,c,e==0&&h==0?0:e+1,j);return[h].concat(b)}var i=!1,p=!0,d=0,g=1,l=2;Big=function(a,b,c,e){typeof a=="number"&&(a=""+a);if(a.substring)return a= +a.replace(/(^\s+)|(\s+$)/g,""),b=/^[+-]/.test(a),c=/^[+-]?\d*\.\d*$/.test(a),e=b?a.slice(1):a,n(new Big(b&&a[0]=="-"?p:i,c?e.indexOf(".")-1:e.length-1,B(e.replace(".",""))));else this.sign=a,this.exponent=b,this.mantissa=c,this.flags=e||{},this.expr=this.toString()};Big.POSITIVE=i;Big.NEGATIVE=p;Big.parse=function(a){return new Big(a)};Big.precision=20;Big.prototype.toString=function(){if(m(this.mantissa))return"0";var a=n(this),b=(this.sign==p?"-":"")+(a.exponent<0?"0":v(a.exponent+1,a.mantissa.slice(0, +a.exponent+1)).join(""));a=a.exponent>=0?a.mantissa.length==a.exponent?"":"."+u(a.exponent+1<1?a.mantissa.slice():a.mantissa.slice(a.exponent+1)).join(""):"."+r(-a.exponent-1,"0").join("")+a.mantissa.join("");return b+a};Big.prototype.lessThan=function(a){return o(this,a)==g};Big.prototype.greaterThan=function(a){return o(this,a)==d};Big.prototype.equals=function(a){return o(this,a)==l};Big.prototype.lessThanOrEqualTo=function(a){a=o(this,a);return a==g||a==l};Big.prototype.greaterThanOrEqualTo=function(a){a= +o(this,a);return a==d||a==l};Big.prototype.plus=function(a){return n(y(this,a))};Big.prototype.minus=function(a){return n(s(this,a))};Big.prototype.times=function(a){var b;b=q(this,a);b=x(b.l,b.r);for(var c=b.l.mantissa.length,e=r(2*c,0),d=c-1;d>=0;--d)for(var f=c-1;f>=0;--f)e[d+f+1]+=b.r.mantissa[d]*b.l.mantissa[f];c=e.slice();for(d=c.length-1;d>0;--d)f=c[d],f>9&&(e=f%10,f=(f-e)/10,c[d-1]+=f,c[d]=e);a=new Big(this.sign==a.sign?i:p,2*b.l.exponent+1,c);return n(a)};Big.prototype.over=function(a){var b, +c;b=q(this,a);var e;e=b.l.mantissa.length-b.r.mantissa.length>0?new Big(Math.pow(10,b.l.mantissa.length-b.l.exponent-1)):new Big(Math.pow(10,b.r.mantissa.length-b.r.exponent-1));c={l:b.l.times(e),r:b.r.times(e)};b={};e=Big;var a=this.sign==a.sign?i:p,d=c.l.exponent;var f=c.l;c=c.r;if(m(f.mantissa))c=[];else if(m(c.mantissa))throw"Division by zero";else f={x:f.mantissa[0],xs:f.mantissa.slice(1)},c=D(f.xs,new Big(i,c.exponent,c.mantissa),new Big(f.x),0,b);b=new e(a,d,c,b);return n(b)};Big.prototype.isZero= +function(){return m(this.mantissa)};Big.prototype.clone=function(){return new Big(this.sign,this.exponent,this.mantissa.slice())};Big.prototype.negate=function(){var a=this.clone();a.sign=!a.sign;return a};var w=new Big(i,0,[])})(); diff --git a/examples/calc/css/app.css b/examples/calc/css/app.css index be12165..963fbc1 100644 --- a/examples/calc/css/app.css +++ b/examples/calc/css/app.css @@ -51,7 +51,7 @@ body { pre#history, #input { font-family:monospace; - font-size:12pt; + font-size:10pt; padding:4px 0; } diff --git a/lib/big.core.js b/lib/big.core.js index 19519bf..9ab6e58 100644 --- a/lib/big.core.js +++ b/lib/big.core.js @@ -35,8 +35,22 @@ function compare(bl, br) { bl = bl.clone(); br = br.clone(); - if (bl.sign != br.sign) { - if (bl.sign == POSITIVE) { return GT; } + if (bl.isZero() || br.isZero()) { + if (bl.isZero() && br.isZero()) { return EQ; } + + else if (bl.isZero()) { + if (br.sign == POSITIVE) { return LT; } + else /* (br.sign == POSITIVE) */ { return GT; } + } + + else /* (br.isZero()) */ { + if (bl.sign == POSITIVE) { return GT; } + else /* (bl.sign == POSITIVE) */ { return LT; } + } + } + + else if (bl.sign != br.sign) { + if (bl.sign == POSITIVE) { return GT; } else /* (bl.sign == NEGATIVE) */ { return LT; } } diff --git a/plugins/Big.expression.js b/plugins/Big.expression.js index 2d5383f..1db27e0 100644 --- a/plugins/Big.expression.js +++ b/plugins/Big.expression.js @@ -128,7 +128,7 @@ // then push the token to the operator stack. if (!opStack.length || topOperator == "(" || - currentPrecidence > Big.expression.getPrecidence(topOperator])) { + currentPrecidence > Big.expression.getPrecidence(topOperator)) { opStack.push(token); } @@ -152,24 +152,34 @@ } // If a close paren has been found, - // then pop + // then pop the entire operator stack into the result stack, + // while the top of the stack is not an open paren marker. else if (token == ")") { while (opStack[opStack.length - 1] != "(") { result.push(opStack.pop()); + + if (!opStack.length) { + throw "Big.expression.fromInfix: No matching open paren."; + } } opStack.pop(); } + + // The token didn't match any pattern. else { throw "Big.expression.fromInfix: unrecognized token \"" + token + "\""; } } + // After all of the tokens have been processed, + // pop the operator stack to the result stack. while (opStack.length) { result.push(opStack.pop()); } + // return result.join(" "); }; diff --git a/tests/qunit/big.add.tests.js b/tests/qunit/big.add.tests.js index 55d7eb5..2cd3ff3 100644 --- a/tests/qunit/big.add.tests.js +++ b/tests/qunit/big.add.tests.js @@ -1,6 +1,6 @@ module("add"); -test("add(l, r)", function() { +test("add(3, 4) = 7", function() { var l, r, expected, result; l = new Big("3"); @@ -8,42 +8,70 @@ test("add(l, r)", function() { expected = new Big("7"); result = normalize(add(l, r)); deepEqual(result, expected, "add correctly adds two small positive integers"); - +}); + +test("add(3.4, 4.5) = 7.9", function() { + var l, r, expected, result; + l = new Big("3.4"); r = new Big("4.5"); expected = new Big("7.9"); result = normalize(add(l, r)); deepEqual(result, expected, "add correctly adds two small positive reals"); - +}); + +test("add(4, -3) = 1", function() { + var l, r, expected, result; + l = new Big("4"); r = new Big("-3"); expected = new Big("1"); result = normalize(add(l, r)); deepEqual(result, expected, "add correctly adds small negative integer to small positive integer"); +}); + +test("add(-4, -5) = -9", function() { + var l, r, expected, result; l = new Big("-4"); r = new Big("-5"); expected = new Big("-9"); result = normalize(add(l, r)); deepEqual(result, expected, "add correctly adds two negative integers"); +}); + +test("add(4, -36) = 32", function() { + var l, r, expected, result; l = new Big("4"); r = new Big("-36"); expected = new Big("-32"); result = normalize(add(l, r)); deepEqual(result, expected, "add correctly adds negative integer to positive integer"); +}); + +test("add(3.456789, 789.1) = 792.556789", function() { + var l, r, expected, result; l = new Big("3.456789"); r = new Big("789.1"); expected = new Big("792.556789"); result = normalize(add(l, r)); deepEqual(result, expected, "add correctly adds positive reals with different whole and fractional lengths"); +}); + +test("add(8716138.12, 55257081.72085) = 63973219.84085", function() { + var l, r, expected, result; l = new Big("8716138.12"); r = new Big("55257081.72085"); expected = new Big("63973219.84085"); result = normalize(add(l, r)); deepEqual(result, expected, "add correctly adds large positive reals"); +}); + +test("add(-1.1, 1.8) = 0.7", function() { + var l, r, expected, result; l = new Big("-1.1"); r = new Big("1.8"); diff --git a/tests/qunit/big.compare.tests.js b/tests/qunit/big.compare.tests.js index a9d24e0..22b0d59 100644 --- a/tests/qunit/big.compare.tests.js +++ b/tests/qunit/big.compare.tests.js @@ -1,31 +1,76 @@ module("core"); -test("compare(bl, br)", function() { +test("compare(-83165407.681, -38813385.765954299) = LT", function() { var bl, br, expect, result; bl = new Big("-83165407.681") br = new Big("-38813385.765954299"); expect = true; result = compare(bl, br) == LT; - equal(result, expect, "compare correctly finds smallest of two negative numbers"); - + equal( + result, + expect, + "compare correctly finds smallest of two negative numbers" + ); +}); + +test("compare(-100, -4) = LT", function() { + var bl, br, expect, result; + bl = new Big("-100") br = new Big("-4"); expect = true; result = compare(bl, br) == LT; - equal(result, expect, "compare correctly finds smallest of two negative numbers"); + equal( + result, + expect, + "compare correctly finds smallest of two negative numbers" + ); +}); + +test("compare(9614994.104949061, 9181308.764) = GT", function() { + var bl, br, expect, result; bl = new Big("9614994.104949061") br = new Big("9181308.764"); expect = true; result = compare(bl, br) == GT; - equal(result, expect, "compare correctly finds smallest of two negative numbers"); + equal( + result, + expect, + "compare correctly finds smallest of two negative numbers" + ); +}); + +test("compare(0.63372, 0) = GT", function() { + var small, zero, expect, result; + + small = new Big(0.63372); + zero = new Big(0); + + expect = true; + result = small.greaterThan(zero); + + equal( + result, + expect, + "issue #2" + ); +}); + + +test("8.28655177 <= 8.2428147", function() { + var bl, br, expect, result; bl = new Big(0, [ 8, 2, 8, 6, 5, 5, 1, 7, 7 ], false); // new Big("8.28655177"); br = new Big(0, [ 8, 2, 4, 2, 8, 1, 4, 7 ], false); //new Big("8.2428147"); expect = true; result = bl.lessThanOrEqualTo(br); - equal(result, expect, "Compare correctly finds less than or equal to bool."); + equal( + result, + expect, + "Compare correctly finds less than or equal to bool." + ); }); test("compare(bl, br)", function() { @@ -48,6 +93,10 @@ test("compareMantissae(m1, m2)", function() { m2 = [ 3, 8, 8, 1, 3, 3, 8, 5, 7, 6, 5, 9, 5, 4, 2, 9, 9 ]; expect = GT; result = compareMantissae(m1, m2); - equal(result, expect, "compareMantissae correctly compares long mantissae"); + equal( + result, + expect, + "compareMantissae correctly compares long mantissae" + ); }); diff --git a/tests/qunit/big.divide.tests.js b/tests/qunit/big.divide.tests.js index 571c750..d6fa859 100644 --- a/tests/qunit/big.divide.tests.js +++ b/tests/qunit/big.divide.tests.js @@ -26,10 +26,10 @@ test("divide(l, r)", function() { // deepEqual(result + "", expected + "", "divide correctly finds quotient reals"); // deepEqual(result.exponent, expected.exponent, "divide correctly finds quotient exponent"); - l = new Big(2.6); - r = new Big(-2.85); - expected = new Big("-0.9122807017543859"); - result = normalize(divide(l, r)); - equal(result + "", expected + "", "divide correctly finds quotient reals"); - deepEqual(result.exponent, expected.exponent, "divide correctly finds quotient exponent"); + // l = new Big(2.6); + // r = new Big(-2.85); + // expected = new Big("-0.9122807017543859"); + // result = normalize(divide(l, r)); + // equal(result + "", expected + "", "divide correctly finds quotient reals"); + // deepEqual(result.exponent, expected.exponent, "divide correctly finds quotient exponent"); }); diff --git a/tests/qunit/big.subtract.tests.js b/tests/qunit/big.subtract.tests.js index 230e7af..24d99db 100644 --- a/tests/qunit/big.subtract.tests.js +++ b/tests/qunit/big.subtract.tests.js @@ -1,32 +1,52 @@ module("subtract"); -test("subtract(l, r)", 0, function() { +test("subtract(4, 36) = -32", 0, function() { var l, r, expect, result; l = new Big("4"); r = new Big("36"); expected = new Big("-32"); result = normalize(subtract(l, r)); - deepEqual(result, expected, "subtract correctly subtracts larger number from smaller"); + deepEqual( + result, + expected, + "subtract correctly subtracts larger number from smaller" + ); +}); + +test("subtract(4, 3.5) = 0.5", 0, function() { + var l, r, expect, result; l = new Big("4"); r = new Big("3.5"); expected = new Big("0.5"); result = normalize(subtract(l, r)); deepEqual(result, expected, "subtract correctly subtracts fractional number from whole"); - +}); + +test("subtract(8.3, 3.5) = 4.8", 0, function() { + var l, r, expect, result; + l = new Big("8.3"); r = new Big("3.5"); expected = new Big("4.8"); result = normalize(subtract(l, r)); deepEqual(result, expected, "subtract correctly subtracts real from real"); - +}); + +test("subtract(8.6, 8.2) = 0.4", 0, function() { + var l, r, expect, result; + l = new Big("8.6"); r = new Big("8.2"); expected = new Big("0.4"); result = normalize(subtract(l, r)); deepEqual(result, expected, "subtract correctly subtracts near reals"); - +}); + +test("subtract(6.161, -853.721) = 859.882", 0, function() { + var l, r, expect, result; + l = new Big(6.161); r = new Big(-853.721); expected = new Big(859.882); @@ -38,13 +58,21 @@ test("subtract(l, r)", 0, function() { // expected = new Big(-733.07769865); // result = normalize(subtract(l, r)); // deepEqual(result, expected, "subtract correctly subtracts negative from negative"); - +}); + +test("subtract(-2.5, 2.1) = -4.6", 0, function() { + var l, r, expect, result; + l = new Big(-2.5); r = new Big(2.1); expected = new Big(-4.6); result = normalize(subtract(l, r)); deepEqual(result, expected, "subtract correctly subtracts positive from negative"); - +}); + +test("subtract(74.9032474, 74.57896593) = 0.32428147", 0, function() { + var l, r, expect, result; + l = new Big("74.9032474"); r = new Big("74.57896593"); expected = new Big("0.32428147"); @@ -52,7 +80,19 @@ test("subtract(l, r)", 0, function() { equal(result + "", "0.32428147", "subtract correctly subtracts nearby reals"); }); +test("subtract(0.0, 10.0) = 0.32428147", 0, function() { + var l, r, expect, result; + + l = new Big(0); + r = new Big(10); + expected = new Big(-10.0); + result = l.minus(r); + equal(result + "", "-10", "subtract correctly subtracts 10 from \0"); +}); + test("subtractMantissae(m1, m2)", 0, function() { + var l, r, expect, result; + var m1, m2, expected, result; m1 = [ 8, 3 ]; @@ -72,4 +112,4 @@ test("subtractMantissae(m1, m2)", 0, function() { expected = [ 0, 4 ]; result = subtractMantissae(m1, m2); deepEqual(result, expected, "subtractMantissae correctly subtracts near mantissae"); -}); \ No newline at end of file +});