From 2663b68e3cae30a5465b2ed60b1895267208d921 Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Sun, 6 Jan 2013 17:21:43 +0000 Subject: [PATCH] version 1.0.1 --- README.md | 22 ++++++++++++++-------- bignumber.js | 4 ++-- bignumber.min.js | 2 +- package.json | 2 +- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1931b13..59ca3df 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,16 @@ A Javascript library for arbitrary-precision decimal and non-decimal arithmetic. - Faster, smaller, and perhaps easier to use than Javascript versions of Java's BigDecimal - 5 KB minified and gzipped - Simple API but full-featured - - Works with numbers with fraction digits in bases from 2 to 36 inclusive + - Works with numbers with or without fraction digits in bases from 2 to 36 inclusive - Replicates the `toExponential`, `toFixed`, `toPrecision` and `toString` methods of Javascript's Number type - Includes a `toFraction` and a `squareRoot` method - Stores values in an accessible decimal floating point format - No dependencies - Comprehensive documentation and test set -To see the library in action see [RADIX](http://mikemcl.github.com/RADIX/). - If an even smaller and simpler library is required see [big.js](https://github.com/MikeMcl/big.js/). -It's half the size with half the methods and only works with decimal numbers; it also does not allow `NaN` or `Infinity`, or have the configuration options of this library. +It's half the size but only works with decimal numbers and only has half the methods. +It also does not allow `NaN` or `Infinity`, or have the configuration options of this library. ## Load @@ -56,7 +55,7 @@ To load with AMD loader libraries such as [requireJS](http://requirejs.org/): If a commented-out value is in quotes it means `toString` has been called on the preceding expression.* The library exports a single function: BigNumber, the constructor of BigNumber instances. -It accepts a value of type Number, String or Object, +It accepts a value of type Number, String or BigNumber Object, x = new BigNumber(123.4567) y = BigNumber('123456.7e-3') // 'new' is optional @@ -98,7 +97,7 @@ Like Javascript's Number type, there are `toExponential`, `toFixed` and `toPreci x.toString(16) // "ff.8" The maximum number of decimal places and the rounding mode for division, square root, base conversion, and negative power operations is set by a configuration object passed to the `config` method of the `BigNumber` constructor. - The other arithmetic operations always give the exact result. +The other arithmetic operations always give the exact result. BigNumber.config({ DECIMAL_PLACES : 10, ROUNDING_MODE : 4 }) // Alternatively, BigNumber.config( 10, 4 ); @@ -152,7 +151,8 @@ To test all the methods in more depth $ node every-test -For the browser, see *quick-test.html*, *single-test.html* and *every-test.html* in the *test/browser* directory. +For the browser, see *quick-test.html*, *single-test.html* and *every-test.html* in the *test/browser* directory. + *bignumber-vs-number.html* enables some of the methods of bignumber.js to be compared with those of Javascript's Number type. ## Performance @@ -195,7 +195,8 @@ will create *bignumber.min.js*. ## Feedback -Bugs/issues/comments to: +Bugs: surely not! Open an issue, please. +Other feedback to: Michael Mclaughlin M8ch88l@gmail.com @@ -210,6 +211,11 @@ See LICENCE. ## Change Log +####1.0.1 +* Bugfix: error messages with incorrect method name +* Corrected a couple of spelling mistakes in comments +* Very minor regex tweaks + ####1.0.0 * 8/11/2012 Initial release diff --git a/bignumber.js b/bignumber.js index 4dd347e..c79e611 100644 --- a/bignumber.js +++ b/bignumber.js @@ -1,9 +1,9 @@ -/* bignumber.js v1.0.0 https://github.com/MikeMcl/bignumber.js/LICENCE */ +/* bignumber.js v1.0.1 https://github.com/MikeMcl/bignumber.js/LICENCE */ ;(function ( global ) { 'use strict'; /* - bignumber.js v1.0.0 + bignumber.js v1.0.1 A Javascript library for arbitrary-precision arithmetic. https://github.com/MikeMcl/bignumber.js Copyright (c) 2012 Michael Mclaughlin diff --git a/bignumber.min.js b/bignumber.min.js index f80ea81..21ad8ba 100644 --- a/bignumber.min.js +++ b/bignumber.min.js @@ -1 +1 @@ -/* bignumber.js v1.0.0 https://github.com/MikeMcl/bignumber.js/LICENCE */(function(e){"use strict";function y(e,t){var n,r,i,s=this;if(!(s instanceof y))return new y(e,t);if(e instanceof y){d=0;if(t===r){s.s=e.s,s.e=e.e,s.c=(e=e.c)?e.slice():e;return}e=e.toS()}typeof e!="string"&&(e=(n=Object.prototype.toString.call(e)=="[object Number]")&&e===0&&1/e<0?"-0":e+"");if(t===r&&v.test(e))s.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1;else{if(t==10)return(new y(e)).div(g);e=m.call(e).replace(/^\+(?!-)/,"").replace(/^(-?)\./,"$10."),s.s=e.charAt(0)=="-"?(e=e.replace(/^-(?!-)/,""),-1):1,t!=null?t!=(t|0)&&!!f||(p=!(t>=2&&t<=36))?(b(t,2),i=v.test(e)):(r="["+h.slice(0,t|=0)+"]+",(i=(new RegExp("^"+r+"(?:\\."+r+")?$","i")).test(e))?(n&&(e.replace(".","").length>15&&b(e,0),n=!n),e=w(e,10,t,s.s)):e!="Infinity"&&e!="NaN"&&(b(e,1,t),e="NaN")):i=v.test(e);if(!i){s.c=s.e=null,e!="Infinity"&&(e!="NaN"&&b(e,3),s.s=null),d=0;return}}(r=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(r<0&&(r=i),r+=+e.slice(i+1),e=e.substring(0,i)):r<0&&(r=e.length),(t=e.length,n&&t>15)&&b(e,0);for(d=i=0;e.charAt(i)=="0";i++);if((r-=i+1)>a)s.c=s.e=null;else if(i==t||rt-1&&(a[i+1]==null&&(a[i+1]=0),a[i+1]+=a[i]/t^0,a[i]%=t)}return a.reverse()}function c(e){var t=0,n=e.length,r="";for(;t-1){i=e.length-i-1,s=l((new y(n)).pow(i).toF(),10),u=e.split("."),o=l(u[1]),u=l(u[0]),f=E(o,s,o.length-s.length,r,t,u[u.length-1]&1),a=f.c;if(i=f.e){for(;++i;a.unshift(0));e=c(u)+"."+c(a)}else a[0]?u[i=u.length-1]w?1:-1;else for(p=-1,h=0;++pb[p]?1:-1;break}if(!(h<0))break;for(l=w==f?t:d;w;){if(b[--w]N&&x(E,r,s,o,b[0]!=null),E.e>a?E.c=E.e=null:E.e++t&&x(e,r,10),r=i[0]==0?r+1:n?t:e.e+r+1;for(;i.length1?(i.splice(1,0,"."),i.join("")):i[0])+(r<0?"e":"e+")+r:e.toS()}function x(e,t,n,r,s){var o=e.c,u=e.s<0,a=n/2,f=e.e+t+1,l=o[f],c=s||f<0||o[f+1]!=null;s=i<4?(l!=null||c)&&(i==0||i==2&&!u||i==3&&u):l>a||l==a&&(i==4||c||i==6&&(o[f-1]&1||!t&&r)||i==7&&!u||i==8&&u);if(f<1||!o[0])return o.length=0,o.push(0),s?(o[0]=1,e.e=-t):e.e=0,e;o.length=f--;if(s)for(--n;++o[f]>n;)o[f]=0,f--||(++e.e,o.unshift(1));for(f=o.length;!o[--f];o.pop());return e}function T(e,t,n){var r=i;return i=n,e=new y(e),e.c&&x(e,t,10),i=r,e}var t=1e9,n=1e6,r=20,i=4,s=-7,o=21,u=-t,a=t,f=!0,l=parseInt,c=y.prototype,h="0123456789abcdefghijklmnopqrstuvwxyz",p,d=0,v=/^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i,m=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=y(1);y.ROUND_UP=0,y.ROUND_DOWN=1,y.ROUND_CEIL=2,y.ROUND_FLOOR=3,y.ROUND_HALF_UP=4,y.ROUND_HALF_DOWN=5,y.ROUND_HALF_EVEN=6,y.ROUND_HALF_CEIL=7,y.ROUND_HALF_FLOOR=8,y.config=function(){var e,n,c=0,h={},v=arguments,m=v[0],g="config",y=function(e,t,n){return!((p=en)||l(e)!=e&&e!==0)},w=m&&typeof m=="object"?function(){if(m.hasOwnProperty(n))return(e=m[n])!=null}:function(){if(v.length>c)return(e=v[c++])!=null};return w(n="DECIMAL_PLACES")&&(y(e,0,t)?r=e|0:b(e,n,g)),h[n]=r,w(n="ROUNDING_MODE")&&(y(e,0,8)?i=e|0:b(e,n,g)),h[n]=i,w(n="EXPONENTIAL_AT")&&(y(e,-t,t)?s=-(o=~~(e<0?-e:+e)):!p&&e&&y(e[0],-t,0)&&y(e[1],0,t)?(s=~~e[0],o=~~e[1]):b(e,n,g,1)),h[n]=[s,o],w(n="RANGE")&&(y(e,-t,t)&&~~e?u=-(a=~~(e<0?-e:+e)):!p&&e&&y(e[0],-t,-1)&&y(e[1],1,t)?(u=~~e[0],a=~~e[1]):b(e,n,g,1,1)),h[n]=[u,a],w(n="ERRORS")&&(e===!!e||e===1||e===0?l=(p=d=0,f=!!e)?parseInt:parseFloat:b(e,n,g,0,0,1)),h[n]=f,h},c.abs=c.absoluteValue=function(){var e=new y(this);return e.s<0&&(e.s=1),e},c.ceil=function(){return T(this,0,2)},c.comparedTo=c.cmp=function(e,t){var n,r=this,i=r.c,s=(d=-d,e=new y(e,t)).c,o=r.s,u=e.s,a=r.e,f=e.e;if(!o||!u)return null;n=i&&!i[0],t=s&&!s[0];if(n||t)return n?t?0:-u:o;if(o!=u)return o;if(n=o<0,t=a==f,!i||!s)return t?0:!i^n?1:-1;if(!t)return a>f^n?1:-1;for(o=-1,u=(a=i.length)<(f=s.length)?a:f;++os[o]^n?1:-1;return a==f?0:a>f^n?1:-1},c.dividedBy=c.div=function(e,t){var n=this.c,r=this.e,i=this.s,s=(d=2,e=new y(e,t)).c,o=e.e,u=e.s,a=i==u?1:-1;return!r&&(!n||!n[0])||!o&&(!s||!s[0])?new y(!i||!u||(n?s&&n[0]==s[0]:!s)?NaN:n&&n[0]==0||!s?a*0:a/0):E(n,s,r-o,a,10)},c.equals=c.eq=function(e,t){return d=3,this.cmp(e,t)===0},c.floor=function(){return T(this,0,3)},c.greaterThan=c.gt=function(e,t){return d=4,this.cmp(e,t)>0},c.greaterThanOrEqualTo=c.gte=function(e,t){return d=5,(t=this.cmp(e,t))==1||t===0},c.isFinite=c.isF=function(){return!!this.c},c.isNaN=function(){return!this.s},c.isNegative=c.isNeg=function(){return this.s<0},c.isZero=c.isZ=function(){return!!this.c&&this.c[0]==0},c.lessThan=c.lt=function(e,t){return d=6,this.cmp(e,t)<0},c.lessThanOrEqualTo=c.lte=function(e,t){return d=7,(t=this.cmp(e,t))==-1||t===0},c.minus=function(e,t){var n,r,i,s,o=this,a=o.s;t=(d=8,e=new y(e,t)).s;if(!a||!t)return new y(NaN);if(a!=t)return e.s=-t,o.plus(e);var f=o.c,l=o.e,c=e.c,h=e.e;if(!l||!h){if(!f||!c)return f?(e.s=-t,e):new y(c?o:NaN);if(!f[0]||!c[0])return c[0]?(e.s=-t,e):new y(f[0]?o:0)}if(f=f.slice(),a=l-h){n=(s=a<0)?(a=-a,f):(h=l,c);for(n.reverse(),t=a;t--;n.push(0));n.reverse()}else{i=((s=f.length0)for(;t--;f[i++]=0);for(t=c.length;t>a;){if(f[--t]0?(u=s,f):(i=-i,o);for(n.reverse();i--;n.push(0));n.reverse()}o.length-f.length<0&&(n=f,f=o,o=n);for(i=f.length,t=0;i;t=(o[--i]=o[i]+f[i]+t)/10^0,o[i]%=10);t&&(o.unshift(t),++u>a&&(o=u=null));for(i=o.length;o[--i]==0;o.pop());return e.c=o,e.e=u,e},c.toPower=c.pow=function(e){var t=e*0==0?e|0:e,r=new y(this),i=new y(g);if(((p=e<-n||e>n)&&(t=e*1/0)||l(e)!=e&&e!==0&&!(t=NaN))&&!b(e,"exponent","pow")||!t)return new y(Math.pow(r.toS(),t));for(t=t<0?-t:t;;){t&1&&(i=i.times(r)),t>>=1;if(!t)break;r=r.times(r)}return e<0?g.div(i):i},c.round=function(e,n){return e=e==null||((p=e<0||e>t)||l(e)!=e)&&!b(e,"decimal places","round")?0:e|0,n=n==null||((p=n<0||n>8)||l(n)!=n&&n!==0)&&!b(n,"mode","round")?i:n|0,T(this,e,n)},c.squareRoot=c.sqrt=function(){var e,t,n,i=this,s=i.c,o=i.s,u=i.e,a=new y("0.5");if(o!==1||!s||!s[0])return new y(!o||o<0&&(!s||s[0])?NaN:s?i:1/0);o=Math.sqrt(i.toS()),o==0||o==1/0?(e=s.join(""),e.length+u&1||(e+="0"),t=new y(Math.sqrt(e).toString()),t.e=((u+1)/2|0)-(u<0||u&1)):t=new y(o.toString()),o=t.e+(r+=4);do n=t,t=a.times(n.plus(i.div(n)));while(n.c.slice(0,o).join("")!==t.c.slice(0,o).join(""));return x(t,r-=4,10),t},c.times=function(e,t){var n,r=this,i=r.c,s=(d=11,e=new y(e,t)).c,o=r.e,f=e.e,l=r.s;e.s=l==(t=e.s)?1:-1;if(!o&&(!i||!i[0])||!f&&(!s||!s[0]))return new y(!l||!t||i&&!i[0]&&!s||s&&!s[0]&&!i?NaN:!i||!s?e.s/0:e.s*0);e.e=o+f,(l=i.length)<(t=s.length)&&(n=i,i=s,s=n,f=l,l=t,t=f);for(f=l+t,n=[];f--;n.push(0));for(o=t-1;o>-1;o--){for(t=0,f=l+o;f>o;t=n[f]+s[o]*i[f-o-1]+t,n[f--]=t%10|0,t=t/10|0);t&&(n[f]=(n[f]+t)%10)}t&&++e.e,!n[0]&&n.shift();for(f=n.length;!n[--f];n.pop());return e.c=e.e>a?e.e=null:e.et)||l(e)!=e&&e!==0)&&!b(e,"decimal places","toE"))&&this.c?this.c.length-1:e|0,1)},c.toFixed=c.toF=function(e){var n,r,i,u=this;return e==null||((p=e<0||e>t)||l(e)!=e&&e!==0)&&!b(e,"decimal places","toF")||(i=u.e+(e|0)),n=s,e=o,s=-(o=1/0),i==r?r=u.toS():(r=S(u,i),u.s<0&&u.c&&(u.c[0]?r.indexOf("-")<0&&(r="-"+r):r=r.replace(/^-/,""))),s=n,o=e,r},c.toFraction=c.toFr=function(e){var t,n,s,o,u,l,c,h=o=new y(g),v=s=new y("0"),m=this,w=m.c,E=a,S=r,x=i,T=new y(g);if(!w)return m.toS();c=T.e=w.length-m.e-1;if(e==null||(!(d=12,l=new y(e)).s||(p=l.cmp(h)<0||!l.c)||f&&l.e0)e=c>0?T:h;a=1/0,l=new y(w.join(""));for(r=0,i=1;;){t=l.div(T),u=o.plus(t.times(v));if(u.cmp(e)==1)break;o=v,v=u,h=s.plus(t.times(u=h)),s=u,T=l.minus(t.times(u=T)),l=u}return u=e.minus(o).div(v),s=s.plus(u.times(h)),o=o.plus(u.times(v)),s.s=h.s=m.s,r=c*2,i=x,n=h.div(v).minus(m).abs().cmp(s.div(o).minus(m).abs())<1?[h.toS(),v.toS()]:[s.toS(),o.toS()],a=E,r=S,n},c.toPrecision=c.toP=function(e){return e==null||((p=e<1||e>t)||l(e)!=e)&&!b(e,"precision","toP")?this.toS():S(this,--e|0,2)},c.toString=c.toS=function(e){var t,n,r,i=this,u=i.e;if(u===null)n=i.s?"Infinity":"NaN";else{if(e===t&&(u<=s||u>=o))return S(i,i.c.length-1,1);n=i.c.join("");if(u<0){for(;++u;n="0"+n);n="0."+n}else if(r=n.length,u>0)if(++u>r)for(u-=r;u--;n+="0");else u1)n=t+"."+n.slice(1);else if(t=="0")return t;if(e!=null)if((p=!(e>=2&&e<=36))||e!=(e|0)&&!!f)b(e,"base","toS");else{n=w(n,e|0,10,i.s);if(n=="0")return n}}return i.s<0?"-"+n:n},c.valueOf=function(){return this.toS()},typeof module!="undefined"&&module.exports?module.exports=y:typeof define=="function"&&define.amd?define(function(){return y}):e.BigNumber=y})(this); \ No newline at end of file +/* bignumber.js v1.0.1 https://github.com/MikeMcl/bignumber.js/LICENCE */(function(e){"use strict";function y(e,t){var n,r,i,s=this;if(!(s instanceof y))return new y(e,t);if(e instanceof y){d=0;if(t===r){s.s=e.s,s.e=e.e,s.c=(e=e.c)?e.slice():e;return}e=e.toS()}typeof e!="string"&&(e=(n=Object.prototype.toString.call(e)=="[object Number]")&&e===0&&1/e<0?"-0":e+"");if(t===r&&v.test(e))s.s=e.charAt(0)=="-"?(e=e.slice(1),-1):1;else{if(t==10)return(new y(e)).div(g);e=m.call(e).replace(/^\+(?!-)/,"").replace(/^(-?)\./,"$10."),s.s=e.charAt(0)=="-"?(e=e.replace(/^-(?!-)/,""),-1):1,t!=null?t!=(t|0)&&!!f||(p=!(t>=2&&t<=36))?(b(t,2),i=v.test(e)):(r="["+h.slice(0,t|=0)+"]+",(i=(new RegExp("^"+r+"(?:\\."+r+")?$","i")).test(e))?(n&&(e.replace(".","").length>15&&b(e,0),n=!n),e=w(e,10,t,s.s)):e!="Infinity"&&e!="NaN"&&(b(e,1,t),e="NaN")):i=v.test(e);if(!i){s.c=s.e=null,e!="Infinity"&&(e!="NaN"&&b(e,3),s.s=null),d=0;return}}(r=e.indexOf("."))>-1&&(e=e.replace(".","")),(i=e.search(/e/i))>0?(r<0&&(r=i),r+=+e.slice(i+1),e=e.substring(0,i)):r<0&&(r=e.length),(t=e.length,n&&t>15)&&b(e,0);for(d=i=0;e.charAt(i)=="0";i++);if((r-=i+1)>a)s.c=s.e=null;else if(i==t||rt-1&&(a[i+1]==null&&(a[i+1]=0),a[i+1]+=a[i]/t^0,a[i]%=t)}return a.reverse()}function c(e){var t=0,n=e.length,r="";for(;t-1){i=e.length-i-1,s=l((new y(n)).pow(i).toF(),10),u=e.split("."),o=l(u[1]),u=l(u[0]),f=E(o,s,o.length-s.length,r,t,u[u.length-1]&1),a=f.c;if(i=f.e){for(;++i;a.unshift(0));e=c(u)+"."+c(a)}else a[0]?u[i=u.length-1]w?1:-1;else for(p=-1,h=0;++pb[p]?1:-1;break}if(!(h<0))break;for(l=w==f?t:d;w;){if(b[--w]N&&x(E,r,s,o,b[0]!=null),E.e>a?E.c=E.e=null:E.e++t&&x(e,r,10),r=i[0]==0?r+1:n?t:e.e+r+1;for(;i.length1?(i.splice(1,0,"."),i.join("")):i[0])+(r<0?"e":"e+")+r:e.toS()}function x(e,t,n,r,s){var o=e.c,u=e.s<0,a=n/2,f=e.e+t+1,l=o[f],c=s||f<0||o[f+1]!=null;s=i<4?(l!=null||c)&&(i==0||i==2&&!u||i==3&&u):l>a||l==a&&(i==4||c||i==6&&(o[f-1]&1||!t&&r)||i==7&&!u||i==8&&u);if(f<1||!o[0])return o.length=0,o.push(0),s?(o[0]=1,e.e=-t):e.e=0,e;o.length=f--;if(s)for(--n;++o[f]>n;)o[f]=0,f--||(++e.e,o.unshift(1));for(f=o.length;!o[--f];o.pop());return e}function T(e,t,n){var r=i;return i=n,e=new y(e),e.c&&x(e,t,10),i=r,e}var t=1e9,n=1e6,r=20,i=4,s=-7,o=21,u=-t,a=t,f=!0,l=parseInt,c=y.prototype,h="0123456789abcdefghijklmnopqrstuvwxyz",p,d=0,v=/^-?\d+(?:\.\d+)?(?:e[+-]?\d+)?$/i,m=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=y(1);y.ROUND_UP=0,y.ROUND_DOWN=1,y.ROUND_CEIL=2,y.ROUND_FLOOR=3,y.ROUND_HALF_UP=4,y.ROUND_HALF_DOWN=5,y.ROUND_HALF_EVEN=6,y.ROUND_HALF_CEIL=7,y.ROUND_HALF_FLOOR=8,y.config=function(){var e,n,c=0,h={},v=arguments,m=v[0],g="config",y=function(e,t,n){return!((p=en)||l(e)!=e&&e!==0)},w=m&&typeof m=="object"?function(){if(m.hasOwnProperty(n))return(e=m[n])!=null}:function(){if(v.length>c)return(e=v[c++])!=null};return w(n="DECIMAL_PLACES")&&(y(e,0,t)?r=e|0:b(e,n,g)),h[n]=r,w(n="ROUNDING_MODE")&&(y(e,0,8)?i=e|0:b(e,n,g)),h[n]=i,w(n="EXPONENTIAL_AT")&&(y(e,-t,t)?s=-(o=~~(e<0?-e:+e)):!p&&e&&y(e[0],-t,0)&&y(e[1],0,t)?(s=~~e[0],o=~~e[1]):b(e,n,g,1)),h[n]=[s,o],w(n="RANGE")&&(y(e,-t,t)&&~~e?u=-(a=~~(e<0?-e:+e)):!p&&e&&y(e[0],-t,-1)&&y(e[1],1,t)?(u=~~e[0],a=~~e[1]):b(e,n,g,1,1)),h[n]=[u,a],w(n="ERRORS")&&(e===!!e||e===1||e===0?l=(p=d=0,f=!!e)?parseInt:parseFloat:b(e,n,g,0,0,1)),h[n]=f,h},c.abs=c.absoluteValue=function(){var e=new y(this);return e.s<0&&(e.s=1),e},c.ceil=function(){return T(this,0,2)},c.comparedTo=c.cmp=function(e,t){var n,r=this,i=r.c,s=(d=-d,e=new y(e,t)).c,o=r.s,u=e.s,a=r.e,f=e.e;if(!o||!u)return null;n=i&&!i[0],t=s&&!s[0];if(n||t)return n?t?0:-u:o;if(o!=u)return o;if(n=o<0,t=a==f,!i||!s)return t?0:!i^n?1:-1;if(!t)return a>f^n?1:-1;for(o=-1,u=(a=i.length)<(f=s.length)?a:f;++os[o]^n?1:-1;return a==f?0:a>f^n?1:-1},c.dividedBy=c.div=function(e,t){var n=this.c,r=this.e,i=this.s,s=(d=2,e=new y(e,t)).c,o=e.e,u=e.s,a=i==u?1:-1;return!r&&(!n||!n[0])||!o&&(!s||!s[0])?new y(!i||!u||(n?s&&n[0]==s[0]:!s)?NaN:n&&n[0]==0||!s?a*0:a/0):E(n,s,r-o,a,10)},c.equals=c.eq=function(e,t){return d=3,this.cmp(e,t)===0},c.floor=function(){return T(this,0,3)},c.greaterThan=c.gt=function(e,t){return d=4,this.cmp(e,t)>0},c.greaterThanOrEqualTo=c.gte=function(e,t){return d=5,(t=this.cmp(e,t))==1||t===0},c.isFinite=c.isF=function(){return!!this.c},c.isNaN=function(){return!this.s},c.isNegative=c.isNeg=function(){return this.s<0},c.isZero=c.isZ=function(){return!!this.c&&this.c[0]==0},c.lessThan=c.lt=function(e,t){return d=6,this.cmp(e,t)<0},c.lessThanOrEqualTo=c.lte=function(e,t){return d=7,(t=this.cmp(e,t))==-1||t===0},c.minus=function(e,t){var n,r,i,s,o=this,a=o.s;t=(d=8,e=new y(e,t)).s;if(!a||!t)return new y(NaN);if(a!=t)return e.s=-t,o.plus(e);var f=o.c,l=o.e,c=e.c,h=e.e;if(!l||!h){if(!f||!c)return f?(e.s=-t,e):new y(c?o:NaN);if(!f[0]||!c[0])return c[0]?(e.s=-t,e):new y(f[0]?o:0)}if(f=f.slice(),a=l-h){n=(s=a<0)?(a=-a,f):(h=l,c);for(n.reverse(),t=a;t--;n.push(0));n.reverse()}else{i=((s=f.length0)for(;t--;f[i++]=0);for(t=c.length;t>a;){if(f[--t]0?(u=s,f):(i=-i,o);for(n.reverse();i--;n.push(0));n.reverse()}o.length-f.length<0&&(n=f,f=o,o=n);for(i=f.length,t=0;i;t=(o[--i]=o[i]+f[i]+t)/10^0,o[i]%=10);t&&(o.unshift(t),++u>a&&(o=u=null));for(i=o.length;o[--i]==0;o.pop());return e.c=o,e.e=u,e},c.toPower=c.pow=function(e){var t=e*0==0?e|0:e,r=new y(this),i=new y(g);if(((p=e<-n||e>n)&&(t=e*1/0)||l(e)!=e&&e!==0&&!(t=NaN))&&!b(e,"exponent","pow")||!t)return new y(Math.pow(r.toS(),t));for(t=t<0?-t:t;;){t&1&&(i=i.times(r)),t>>=1;if(!t)break;r=r.times(r)}return e<0?g.div(i):i},c.round=function(e,n){return e=e==null||((p=e<0||e>t)||l(e)!=e)&&!b(e,"decimal places","round")?0:e|0,n=n==null||((p=n<0||n>8)||l(n)!=n&&n!==0)&&!b(n,"mode","round")?i:n|0,T(this,e,n)},c.squareRoot=c.sqrt=function(){var e,t,n,i=this,s=i.c,o=i.s,u=i.e,a=new y("0.5");if(o!==1||!s||!s[0])return new y(!o||o<0&&(!s||s[0])?NaN:s?i:1/0);o=Math.sqrt(i.toS()),o==0||o==1/0?(e=s.join(""),e.length+u&1||(e+="0"),t=new y(Math.sqrt(e).toString()),t.e=((u+1)/2|0)-(u<0||u&1)):t=new y(o.toString()),o=t.e+(r+=4);do n=t,t=a.times(n.plus(i.div(n)));while(n.c.slice(0,o).join("")!==t.c.slice(0,o).join(""));return x(t,r-=4,10),t},c.times=function(e,t){var n,r=this,i=r.c,s=(d=11,e=new y(e,t)).c,o=r.e,f=e.e,l=r.s;e.s=l==(t=e.s)?1:-1;if(!o&&(!i||!i[0])||!f&&(!s||!s[0]))return new y(!l||!t||i&&!i[0]&&!s||s&&!s[0]&&!i?NaN:!i||!s?e.s/0:e.s*0);e.e=o+f,(l=i.length)<(t=s.length)&&(n=i,i=s,s=n,f=l,l=t,t=f);for(f=l+t,n=[];f--;n.push(0));for(o=t-1;o>-1;o--){for(t=0,f=l+o;f>o;t=n[f]+s[o]*i[f-o-1]+t,n[f--]=t%10|0,t=t/10|0);t&&(n[f]=(n[f]+t)%10)}t&&++e.e,!n[0]&&n.shift();for(f=n.length;!n[--f];n.pop());return e.c=e.e>a?e.e=null:e.et)||l(e)!=e&&e!==0)&&!b(e,"decimal places","toE"))&&this.c?this.c.length-1:e|0,1)},c.toFixed=c.toF=function(e){var n,r,i,u=this;return e==null||((p=e<0||e>t)||l(e)!=e&&e!==0)&&!b(e,"decimal places","toF")||(i=u.e+(e|0)),n=s,e=o,s=-(o=1/0),i==r?r=u.toS():(r=S(u,i),u.s<0&&u.c&&(u.c[0]?r.indexOf("-")<0&&(r="-"+r):r=r.replace(/^-/,""))),s=n,o=e,r},c.toFraction=c.toFr=function(e){var t,n,s,o,u,l,c,h=o=new y(g),v=s=new y("0"),m=this,w=m.c,E=a,S=r,x=i,T=new y(g);if(!w)return m.toS();c=T.e=w.length-m.e-1;if(e==null||(!(d=12,l=new y(e)).s||(p=l.cmp(h)<0||!l.c)||f&&l.e0)e=c>0?T:h;a=1/0,l=new y(w.join(""));for(r=0,i=1;;){t=l.div(T),u=o.plus(t.times(v));if(u.cmp(e)==1)break;o=v,v=u,h=s.plus(t.times(u=h)),s=u,T=l.minus(t.times(u=T)),l=u}return u=e.minus(o).div(v),s=s.plus(u.times(h)),o=o.plus(u.times(v)),s.s=h.s=m.s,r=c*2,i=x,n=h.div(v).minus(m).abs().cmp(s.div(o).minus(m).abs())<1?[h.toS(),v.toS()]:[s.toS(),o.toS()],a=E,r=S,n},c.toPrecision=c.toP=function(e){return e==null||((p=e<1||e>t)||l(e)!=e)&&!b(e,"precision","toP")?this.toS():S(this,--e|0,2)},c.toString=c.toS=function(e){var t,n,r,i=this,u=i.e;if(u===null)n=i.s?"Infinity":"NaN";else{if(e===t&&(u<=s||u>=o))return S(i,i.c.length-1,1);n=i.c.join("");if(u<0){for(;++u;n="0"+n);n="0."+n}else if(r=n.length,u>0)if(++u>r)for(u-=r;u--;n+="0");else u1)n=t+"."+n.slice(1);else if(t=="0")return t;if(e!=null)if((p=!(e>=2&&e<=36))||e!=(e|0)&&!!f)b(e,"base","toS");else{n=w(n,e|0,10,i.s);if(n=="0")return n}}return i.s<0?"-"+n:n},c.valueOf=function(){return this.toS()},typeof module!="undefined"&&module.exports?module.exports=y:typeof define=="function"&&define.amd?define(function(){return y}):e.BigNumber=y})(this); \ No newline at end of file diff --git a/package.json b/package.json index c1ebdf5..10fdf64 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bignumber.js", "description": "A library for arbitrary-precision decimal and non-decimal arithmetic", - "version": "1.0.0", + "version": "1.0.1", "keywords": [ "arbitrary", "precision",