From aeb5646957d30b260c8117fe15e3553cde6583c7 Mon Sep 17 00:00:00 2001 From: Michael Mclaughlin Date: Thu, 19 Sep 2013 12:15:54 +0100 Subject: [PATCH] v1.2.0 Throw Error objects --- README.md | 5 +++-- bignumber.js | 25 +++++++++++++------------ bignumber.min.js | 2 +- doc/API.html | 35 ++++++++++++++++++----------------- package.json | 2 +- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 72e4b3d..e653589 100644 --- a/README.md +++ b/README.md @@ -211,6 +211,9 @@ See LICENCE. ## Change Log +####1.2.0 +* 19/9/2013 Throw Error objects for stack. + ####1.1.1 * 22/8/2013 Show original value in constructor error message. @@ -222,5 +225,3 @@ See LICENCE. ####1.0.0 * 8/11/2012 Initial release - -[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/50b85fd919b406ef9312551092a95fb7 "githalytics.com")](http://githalytics.com/MikeMcl/bignumber.js) diff --git a/bignumber.js b/bignumber.js index 68215fb..c93a122 100644 --- a/bignumber.js +++ b/bignumber.js @@ -1,9 +1,9 @@ -/* bignumber.js v1.1.1 https://github.com/MikeMcl/bignumber.js/LICENCE */ +/* bignumber.js v1.2.0 https://github.com/MikeMcl/bignumber.js/LICENCE */ ;(function ( global ) { 'use strict'; /* - bignumber.js v1.1.1 + bignumber.js v1.2.0 A JavaScript library for arbitrary-precision arithmetic. https://github.com/MikeMcl/bignumber.js Copyright (c) 2012 Michael Mclaughlin @@ -409,32 +409,33 @@ // Assemble error messages. Throw BigNumber Errors. function ifExceptionsThrow( arg, i, j, isArray, isRange, isErrors) { + if ( ERRORS ) { - var method = ['new BigNumber', 'cmp', 'div', 'eq', 'gt', 'gte', 'lt', + var error, + method = ['new BigNumber', 'cmp', 'div', 'eq', 'gt', 'gte', 'lt', 'lte', 'minus', 'mod', 'plus', 'times', 'toFr' ][ id ? id < 0 ? -id : id : 1 / id < 0 ? 1 : 0 ] + '()', - error = outOfRange ? ' out of range' : ' not a' + + message = outOfRange ? ' out of range' : ' not a' + ( isRange ? ' non-zero' : 'n' ) + ' integer'; - error = ( [ + message = ( [ method + ' number type has more than 15 significant digits', method + ' not a base ' + j + ' number', - method + ' base' + error, + method + ' base' + message, method + ' not a number' ][i] || j + '() ' + i + ( isErrors ? ' not a boolean or binary digit' - : error + ( isArray + : message + ( isArray ? ' or not [' + ( outOfRange ? ' negative, positive' : ' integer, integer' ) + ' ]' : '' ) ) ) + ': ' + arg; outOfRange = id = 0; - throw { - name : 'BigNumber Error', - message : error, - toString : function () {return this.name + ': ' + this.message} - } + error = new Error(message); + error['name'] = 'BigNumber Error'; + + throw error } } diff --git a/bignumber.min.js b/bignumber.min.js index 5304019..949821f 100644 --- a/bignumber.min.js +++ b/bignumber.min.js @@ -1 +1 @@ -/* bignumber.js v1.1.1 https://github.com/MikeMcl/bignumber.js/LICENCE */(function(n){"use strict";function t(n,i){var c,l,a,b,w,p,o=this;if(!(o instanceof t))return new t(n,i);if(n instanceof t)if(r=0,i!==c)n+="";else{o.s=n.s;o.e=n.e;o.c=(n=n.c)?n.slice():n;return}if(typeof n!="string"&&(n=(a=typeof n=="number"||Object.prototype.toString.call(n)=="[object Number]")&&n===0&&1/n<0?"-0":n+""),p=n,i===c&&g.test(n))o.s=n.charAt(0)=="-"?(n=n.slice(1),-1):1;else{if(i==10)return k(n,s,u);if(n=rt.call(n).replace(/^\+(?!-)/,""),o.s=n.charAt(0)=="-"?(n=n.replace(/^-(?!-)/,""),-1):1,i!=null?i!=(i|0)&&y||(e=!(i>=2&&i<=36))?(f(i,2),w=g.test(n)):(b="["+d.slice(0,i=i|0)+"]+",n=n.replace(/\.$/,"").replace(/^\./,"0."),(w=new RegExp("^"+b+"(?:\\."+b+")?$","i").test(n))?(a&&(n.replace(/^0\.0*|\./,"").length>15&&f(p,0),a=!a),n=tt(n,10,i,o.s)):n!="Infinity"&&n!="NaN"&&(f(p,1,i),n="NaN")):w=g.test(n),!w){o.c=o.e=null;n!="Infinity"&&(n!="NaN"&&f(p,3),o.s=null);r=0;return}}for((c=n.indexOf("."))>-1&&(n=n.replace(".","")),(l=n.search(/e/i))>0?(c<0&&(c=l),c+=+n.slice(l+1),n=n.substring(0,l)):c<0&&(c=n.length),l=0;n.charAt(l)=="0";l++);if(i=n.length,a&&i>15&&n.slice(l).length>15&&f(p,0),r=0,(c-=l+1)>h)o.c=o.e=null;else if(l==i||ci-1&&(f[u+1]==null&&(f[u+1]=0),f[u+1]+=f[u]/i^0,f[u]%=i)}return f.reverse()}function o(n){for(var t=0,r=n.length,i="";t-1)if(e=n.length-e-1,c=h(new t(r).pow(e).toF(),10),f=n.split("."),l=h(f[1]),f=h(f[0]),a=it(l,c,l.length-c.length,u,i,f[f.length-1]&1),s=a.c,e=a.e){for(;++e;s.unshift(0));n=o(f)+"."+o(s)}else s[0]?f[e=f.length-1]c?1:-1;else for(a=-1,w=0;++ao[a]?1:-1;break}if(w<0){for(d=c==y?i:rt;c;){if(o[--c]it&&b(l,s,f,e,o[0]!=null),l.e>h?l.c=l.e=null:l.e++i&&b(n,u,10),u=f[0]==0?u+1:r?i:n.e+u+1;f.length1?(f.splice(1,0,"."),f.join("")):f[0])+(u<0?"e":"e+")+u:n.toS()}function b(n,t,i,r,f){var e=n.c,s=n.s<0,c=i/2,o=n.e+t+1,h=e[o],l=f||o<0||e[o+1]!=null;if(f=u<4?(h!=null||l)&&(u==0||u==2&&!s||u==3&&s):h>c||h==c&&(u==4||l||u==6&&(e[o-1]&1||!t&&r)||u==7&&!s||u==8&&s),o<1||!e[0])return e.length=0,e.push(0),f?(e[0]=1,n.e=-t):n.e=0,n;if(e.length=o--,f)for(--i;++e[o]>i;)e[o]=0,o--||(++n.e,e.unshift(1));for(o=e.length;!e[--o];e.pop());return n}function k(n,i,r){var f=u;return u=r,n=new t(n),n.c&&b(n,i,10),u=f,n}var o=1e9,nt=1e6,s=20,u=4,c=-7,a=21,v=-o,h=o,y=!0,l=parseInt,i=t.prototype,d="0123456789abcdefghijklmnopqrstuvwxyz",e,r=0,g=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,rt=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},p=t(1);t.ROUND_UP=0;t.ROUND_DOWN=1;t.ROUND_CEIL=2;t.ROUND_FLOOR=3;t.ROUND_HALF_UP=4;t.ROUND_HALF_DOWN=5;t.ROUND_HALF_EVEN=6;t.ROUND_HALF_CEIL=7;t.ROUND_HALF_FLOOR=8;t.config=function(){var n,t,g=0,p={},d=arguments,k=d[0],w="config",i=function(n,t,i){return!((e=ni)||l(n)!=n&&n!==0)},b=k&&typeof k=="object"?function(){if(k.hasOwnProperty(t))return(n=k[t])!=null}:function(){if(d.length>g)return(n=d[g++])!=null};return b(t="DECIMAL_PLACES")&&(i(n,0,o)?s=n|0:f(n,t,w)),p[t]=s,b(t="ROUNDING_MODE")&&(i(n,0,8)?u=n|0:f(n,t,w)),p[t]=u,b(t="EXPONENTIAL_AT")&&(i(n,-o,o)?c=-(a=~~(n<0?-n:+n)):!e&&n&&i(n[0],-o,0)&&i(n[1],0,o)?(c=~~n[0],a=~~n[1]):f(n,t,w,1)),p[t]=[c,a],b(t="RANGE")&&(i(n,-o,o)&&~~n?v=-(h=~~(n<0?-n:+n)):!e&&n&&i(n[0],-o,-1)&&i(n[1],1,o)?(v=~~n[0],h=~~n[1]):f(n,t,w,1,1)),p[t]=[v,h],b(t="ERRORS")&&(n===!!n||n===1||n===0?l=(e=r=0,y=!!n)?parseInt:parseFloat:f(n,t,w,0,0,1)),p[t]=y,p};i.abs=i.absoluteValue=function(){var n=new t(this);return n.s<0&&(n.s=1),n};i.ceil=function(){return k(this,0,2)};i.comparedTo=i.cmp=function(n,i){var f,l=this,e=l.c,o=(r=-r,n=new t(n,i)).c,u=l.s,c=n.s,s=l.e,h=n.e;if(!u||!c)return null;if(f=e&&!e[0],i=o&&!o[0],f||i)return f?i?0:-c:u;if(u!=c)return u;if(f=u<0,i=s==h,!e||!o)return i?0:!e^f?1:-1;if(!i)return s>h^f?1:-1;for(u=-1,c=(s=e.length)<(h=o.length)?s:h;++uo[u]^f?1:-1;return s==h?0:s>h^f?1:-1};i.dividedBy=i.div=function(n,i){var u=this.c,o=this.e,s=this.s,f=(r=2,n=new t(n,i)).c,h=n.e,c=n.s,e=s==c?1:-1;return!o&&(!u||!u[0])||!h&&(!f||!f[0])?new t(!s||!c||(u?f&&u[0]==f[0]:!f)?NaN:u&&u[0]==0||!f?e*0:e/0):it(u,f,o-h,e,10)};i.equals=i.eq=function(n,t){return r=3,this.cmp(n,t)===0};i.floor=function(){return k(this,0,3)};i.greaterThan=i.gt=function(n,t){return r=4,this.cmp(n,t)>0};i.greaterThanOrEqualTo=i.gte=function(n,t){return r=5,(t=this.cmp(n,t))==1||t===0};i.isFinite=i.isF=function(){return!!this.c};i.isNaN=function(){return!this.s};i.isNegative=i.isNeg=function(){return this.s<0};i.isZero=i.isZ=function(){return!!this.c&&this.c[0]==0};i.lessThan=i.lt=function(n,t){return r=6,this.cmp(n,t)<0};i.lessThanOrEqualTo=i.lte=function(n,t){return r=7,(t=this.cmp(n,t))==-1||t===0};i.minus=function(n,i){var s,c,l,a,h=this,e=h.s;if(i=(r=8,n=new t(n,i)).s,!e||!i)return new t(NaN);if(e!=i)return n.s=-i,h.plus(n);var u=h.c,y=h.e,f=n.c,o=n.e;if(!y||!o){if(!u||!f)return u?(n.s=-i,n):new t(f?h:NaN);if(!u[0]||!f[0])return f[0]?(n.s=-i,n):new t(u[0]?h:0)}if(u=u.slice(),e=y-o){for(s=(a=e<0)?(e=-e,u):(o=y,f),s.reverse(),i=e;i--;s.push(0));s.reverse()}else for(l=((a=u.length0)for(;i--;u[l++]=0);for(i=f.length;i>e;){if(u[--i]0?(s=l,e):(f=-f,u),o.reverse();f--;o.push(0));o.reverse()}for(u.length-e.length<0&&(o=e,e=u,u=o),f=e.length,i=0;f;i=(u[--f]=u[f]+e[f]+i)/10^0,u[f]%=10);for(i&&(u.unshift(i),++s>h&&(u=s=null)),f=u.length;u[--f]==0;u.pop());return n.c=u,n.e=s,n};i.toPower=i.pow=function(n){var i=n*0==0?n|0:n,r=new t(this),u=new t(p);if(((e=n<-nt||n>nt)&&(i=n/0)||l(n)!=n&&n!==0&&!(i=NaN))&&!f(n,"exponent","pow")||!i)return new t(Math.pow(r.toS(),i));for(i=i<0?-i:i;;){if(i&1&&(u=u.times(r)),i>>=1,!i)break;r=r.times(r)}return n<0?p.div(u):u};i.round=function(n,t){return n=n==null||((e=n<0||n>o)||l(n)!=n)&&!f(n,"decimal places","round")?0:n|0,t=t==null||((e=t<0||t>8)||l(t)!=t&&t!==0)&&!f(t,"mode","round")?u:t|0,k(this,n,t)};i.squareRoot=i.sqrt=function(){var f,i,e,r=this,u=r.c,n=r.s,o=r.e,h=new t("0.5");if(n!==1||!u||!u[0])return new t(!n||n<0&&(!u||u[0])?NaN:u?r:1/0);n=Math.sqrt(r.toS());n==0||n==1/0?(f=u.join(""),f.length+o&1||(f+="0"),i=new t(Math.sqrt(f).toString()),i.e=((o+1)/2|0)-(o<0||o&1)):i=new t(n.toString());n=i.e+(s+=4);do e=i,i=h.times(e.plus(r.div(e)));while(e.c.slice(0,n).join("")!==i.c.slice(0,n).join(""));return b(i,s-=4,10),i};i.times=function(n,i){var f,l=this,e=l.c,o=(r=11,n=new t(n,i)).c,s=l.e,u=n.e,c=l.s;if(n.s=c==(i=n.s)?1:-1,!s&&(!e||!e[0])||!u&&(!o||!o[0]))return new t(!c||!i||e&&!e[0]&&!o||o&&!o[0]&&!e?NaN:!e||!o?n.s/0:n.s*0);for(n.e=s+u,(c=e.length)<(i=o.length)&&(f=e,e=o,o=f,u=c,c=i,i=u),u=c+i,f=[];u--;f.push(0));for(s=i-1;s>-1;s--){for(i=0,u=c+s;u>s;i=f[u]+o[s]*e[u-s-1]+i,f[u--]=i%10|0,i=i/10|0);i&&(f[u]=(f[u]+i)%10)}for(i&&++n.e,f[0]||f.shift(),u=f.length;!f[--u];f.pop());return n.c=n.e>h?n.e=null:n.eo)||l(n)!=n&&n!==0)&&!f(n,"decimal places","toE"))&&this.c?this.c.length-1:n|0,1)};i.toFixed=i.toF=function(n){var u,t,r,i=this;return n==null||((e=n<0||n>o)||l(n)!=n&&n!==0)&&!f(n,"decimal places","toF")||(r=i.e+(n|0)),u=c,n=a,c=-(a=1/0),r==t?t=i.toS():(t=w(i,r),i.s<0&&i.c&&(i.c[0]?t.indexOf("-")<0&&(t="-"+t):t=t.replace(/^-/,""))),c=u,a=n,t};i.toFraction=i.toFr=function(n){var k,nt,c,l,i,o,d,a=l=new t(p),v=c=new t("0"),w=this,g=w.c,tt=h,it=s,rt=u,b=new t(p);if(!g)return w.toS();for(d=b.e=g.length-w.e-1,(n==null||(!(r=12,o=new t(n)).s||(e=o.cmp(a)<0||!o.c)||y&&o.e0)&&(n=d>0?b:a),h=1/0,o=new t(g.join("")),s=0,u=1;;){if(k=o.div(b),i=l.plus(k.times(v)),i.cmp(n)==1)break;l=v;v=i;a=c.plus(k.times(i=a));c=i;b=o.minus(k.times(i=b));o=i}return i=n.minus(l).div(v),c=c.plus(i.times(a)),l=l.plus(i.times(v)),c.s=a.s=w.s,s=d*2,u=rt,nt=a.div(v).minus(w).abs().cmp(c.div(l).minus(w).abs())<1?[a.toS(),v.toS()]:[c.toS(),l.toS()],h=tt,s=it,nt};i.toPrecision=i.toP=function(n){return n==null||((e=n<1||n>o)||l(n)!=n)&&!f(n,"precision","toP")?this.toS():w(this,--n|0,2)};i.toString=i.toS=function(n){var u,t,o,r=this,i=r.e;if(i===null)t=r.s?"Infinity":"NaN";else{if(n===u&&(i<=c||i>=a))return w(r,r.c.length-1,1);if(t=r.c.join(""),i<0){for(;++i;t="0"+t);t="0."+t}else if(o=t.length,i>0)if(++i>o)for(i-=o;i--;t+="0");else i1)t=u+"."+t.slice(1);else if(u=="0")return u;if(n!=null)if((e=!(n>=2&&n<=36))||n!=(n|0)&&y)f(n,"base","toS");else if(t=tt(t,n|0,10,r.s),t=="0")return t}return r.s<0?"-"+t:t};i.valueOf=function(){return this.toS()};typeof module!="undefined"&&module.exports?module.exports=t:typeof define=="function"&&define.amd?define(function(){return t}):n.BigNumber=t})(this) \ No newline at end of file +/* bignumber.js v1.2.0 https://github.com/MikeMcl/bignumber.js/LICENCE */;(function(n){"use strict";function t(n,i){var c,l,a,b,w,p,o=this;if(!(o instanceof t))return new t(n,i);if(n instanceof t)if(r=0,i!==c)n+="";else{o.s=n.s;o.e=n.e;o.c=(n=n.c)?n.slice():n;return}if(typeof n!="string"&&(n=(a=typeof n=="number"||Object.prototype.toString.call(n)=="[object Number]")&&n===0&&1/n<0?"-0":n+""),p=n,i===c&&g.test(n))o.s=n.charAt(0)=="-"?(n=n.slice(1),-1):1;else{if(i==10)return k(n,s,u);if(n=rt.call(n).replace(/^\+(?!-)/,""),o.s=n.charAt(0)=="-"?(n=n.replace(/^-(?!-)/,""),-1):1,i!=null?i!=(i|0)&&y||(e=!(i>=2&&i<=36))?(f(i,2),w=g.test(n)):(b="["+d.slice(0,i=i|0)+"]+",n=n.replace(/\.$/,"").replace(/^\./,"0."),(w=new RegExp("^"+b+"(?:\\."+b+")?$","i").test(n))?(a&&(n.replace(/^0\.0*|\./,"").length>15&&f(p,0),a=!a),n=tt(n,10,i,o.s)):n!="Infinity"&&n!="NaN"&&(f(p,1,i),n="NaN")):w=g.test(n),!w){o.c=o.e=null;n!="Infinity"&&(n!="NaN"&&f(p,3),o.s=null);r=0;return}}for((c=n.indexOf("."))>-1&&(n=n.replace(".","")),(l=n.search(/e/i))>0?(c<0&&(c=l),c+=+n.slice(l+1),n=n.substring(0,l)):c<0&&(c=n.length),l=0;n.charAt(l)=="0";l++);if(i=n.length,a&&i>15&&n.slice(l).length>15&&f(p,0),r=0,(c-=l+1)>h)o.c=o.e=null;else if(l==i||ci-1&&(f[u+1]==null&&(f[u+1]=0),f[u+1]+=f[u]/i^0,f[u]%=i)}return f.reverse()}function o(n){for(var t=0,r=n.length,i="";t-1)if(e=n.length-e-1,c=h(new t(r).pow(e).toF(),10),f=n.split("."),l=h(f[1]),f=h(f[0]),a=it(l,c,l.length-c.length,u,i,f[f.length-1]&1),s=a.c,e=a.e){for(;++e;s.unshift(0));n=o(f)+"."+o(s)}else s[0]?f[e=f.length-1]c?1:-1;else for(a=-1,w=0;++ao[a]?1:-1;break}if(w<0){for(d=c==y?i:rt;c;){if(o[--c]it&&b(l,s,f,e,o[0]!=null),l.e>h?l.c=l.e=null:l.e++i&&b(n,u,10),u=f[0]==0?u+1:r?i:n.e+u+1;f.length1?(f.splice(1,0,"."),f.join("")):f[0])+(u<0?"e":"e+")+u:n.toS()}function b(n,t,i,r,f){var e=n.c,s=n.s<0,c=i/2,o=n.e+t+1,h=e[o],l=f||o<0||e[o+1]!=null;if(f=u<4?(h!=null||l)&&(u==0||u==2&&!s||u==3&&s):h>c||h==c&&(u==4||l||u==6&&(e[o-1]&1||!t&&r)||u==7&&!s||u==8&&s),o<1||!e[0])return e.length=0,e.push(0),f?(e[0]=1,n.e=-t):n.e=0,n;if(e.length=o--,f)for(--i;++e[o]>i;)e[o]=0,o--||(++n.e,e.unshift(1));for(o=e.length;!e[--o];e.pop());return n}function k(n,i,r){var f=u;return u=r,n=new t(n),n.c&&b(n,i,10),u=f,n}var o=1e9,nt=1e6,s=20,u=4,c=-7,a=21,v=-o,h=o,y=!0,l=parseInt,i=t.prototype,d="0123456789abcdefghijklmnopqrstuvwxyz",e,r=0,g=/^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,rt=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},p=t(1);t.ROUND_UP=0;t.ROUND_DOWN=1;t.ROUND_CEIL=2;t.ROUND_FLOOR=3;t.ROUND_HALF_UP=4;t.ROUND_HALF_DOWN=5;t.ROUND_HALF_EVEN=6;t.ROUND_HALF_CEIL=7;t.ROUND_HALF_FLOOR=8;t.config=function(){var n,t,g=0,p={},d=arguments,k=d[0],w="config",i=function(n,t,i){return!((e=ni)||l(n)!=n&&n!==0)},b=k&&typeof k=="object"?function(){if(k.hasOwnProperty(t))return(n=k[t])!=null}:function(){if(d.length>g)return(n=d[g++])!=null};return b(t="DECIMAL_PLACES")&&(i(n,0,o)?s=n|0:f(n,t,w)),p[t]=s,b(t="ROUNDING_MODE")&&(i(n,0,8)?u=n|0:f(n,t,w)),p[t]=u,b(t="EXPONENTIAL_AT")&&(i(n,-o,o)?c=-(a=~~(n<0?-n:+n)):!e&&n&&i(n[0],-o,0)&&i(n[1],0,o)?(c=~~n[0],a=~~n[1]):f(n,t,w,1)),p[t]=[c,a],b(t="RANGE")&&(i(n,-o,o)&&~~n?v=-(h=~~(n<0?-n:+n)):!e&&n&&i(n[0],-o,-1)&&i(n[1],1,o)?(v=~~n[0],h=~~n[1]):f(n,t,w,1,1)),p[t]=[v,h],b(t="ERRORS")&&(n===!!n||n===1||n===0?l=(e=r=0,y=!!n)?parseInt:parseFloat:f(n,t,w,0,0,1)),p[t]=y,p};i.abs=i.absoluteValue=function(){var n=new t(this);return n.s<0&&(n.s=1),n};i.ceil=function(){return k(this,0,2)};i.comparedTo=i.cmp=function(n,i){var f,l=this,e=l.c,o=(r=-r,n=new t(n,i)).c,u=l.s,c=n.s,s=l.e,h=n.e;if(!u||!c)return null;if(f=e&&!e[0],i=o&&!o[0],f||i)return f?i?0:-c:u;if(u!=c)return u;if(f=u<0,i=s==h,!e||!o)return i?0:!e^f?1:-1;if(!i)return s>h^f?1:-1;for(u=-1,c=(s=e.length)<(h=o.length)?s:h;++uo[u]^f?1:-1;return s==h?0:s>h^f?1:-1};i.dividedBy=i.div=function(n,i){var u=this.c,o=this.e,s=this.s,f=(r=2,n=new t(n,i)).c,h=n.e,c=n.s,e=s==c?1:-1;return!o&&(!u||!u[0])||!h&&(!f||!f[0])?new t(!s||!c||(u?f&&u[0]==f[0]:!f)?NaN:u&&u[0]==0||!f?e*0:e/0):it(u,f,o-h,e,10)};i.equals=i.eq=function(n,t){return r=3,this.cmp(n,t)===0};i.floor=function(){return k(this,0,3)};i.greaterThan=i.gt=function(n,t){return r=4,this.cmp(n,t)>0};i.greaterThanOrEqualTo=i.gte=function(n,t){return r=5,(t=this.cmp(n,t))==1||t===0};i.isFinite=i.isF=function(){return!!this.c};i.isNaN=function(){return!this.s};i.isNegative=i.isNeg=function(){return this.s<0};i.isZero=i.isZ=function(){return!!this.c&&this.c[0]==0};i.lessThan=i.lt=function(n,t){return r=6,this.cmp(n,t)<0};i.lessThanOrEqualTo=i.lte=function(n,t){return r=7,(t=this.cmp(n,t))==-1||t===0};i.minus=function(n,i){var s,c,l,a,h=this,e=h.s;if(i=(r=8,n=new t(n,i)).s,!e||!i)return new t(NaN);if(e!=i)return n.s=-i,h.plus(n);var u=h.c,y=h.e,f=n.c,o=n.e;if(!y||!o){if(!u||!f)return u?(n.s=-i,n):new t(f?h:NaN);if(!u[0]||!f[0])return f[0]?(n.s=-i,n):new t(u[0]?h:0)}if(u=u.slice(),e=y-o){for(s=(a=e<0)?(e=-e,u):(o=y,f),s.reverse(),i=e;i--;s.push(0));s.reverse()}else for(l=((a=u.length0)for(;i--;u[l++]=0);for(i=f.length;i>e;){if(u[--i]0?(s=l,e):(f=-f,u),o.reverse();f--;o.push(0));o.reverse()}for(u.length-e.length<0&&(o=e,e=u,u=o),f=e.length,i=0;f;i=(u[--f]=u[f]+e[f]+i)/10^0,u[f]%=10);for(i&&(u.unshift(i),++s>h&&(u=s=null)),f=u.length;u[--f]==0;u.pop());return n.c=u,n.e=s,n};i.toPower=i.pow=function(n){var i=n*0==0?n|0:n,r=new t(this),u=new t(p);if(((e=n<-nt||n>nt)&&(i=n/0)||l(n)!=n&&n!==0&&!(i=NaN))&&!f(n,"exponent","pow")||!i)return new t(Math.pow(r.toS(),i));for(i=i<0?-i:i;;){if(i&1&&(u=u.times(r)),i>>=1,!i)break;r=r.times(r)}return n<0?p.div(u):u};i.round=function(n,t){return n=n==null||((e=n<0||n>o)||l(n)!=n)&&!f(n,"decimal places","round")?0:n|0,t=t==null||((e=t<0||t>8)||l(t)!=t&&t!==0)&&!f(t,"mode","round")?u:t|0,k(this,n,t)};i.squareRoot=i.sqrt=function(){var f,i,e,r=this,u=r.c,n=r.s,o=r.e,h=new t("0.5");if(n!==1||!u||!u[0])return new t(!n||n<0&&(!u||u[0])?NaN:u?r:1/0);n=Math.sqrt(r.toS());n==0||n==1/0?(f=u.join(""),f.length+o&1||(f+="0"),i=new t(Math.sqrt(f).toString()),i.e=((o+1)/2|0)-(o<0||o&1)):i=new t(n.toString());n=i.e+(s+=4);do e=i,i=h.times(e.plus(r.div(e)));while(e.c.slice(0,n).join("")!==i.c.slice(0,n).join(""));return b(i,s-=4,10),i};i.times=function(n,i){var f,l=this,e=l.c,o=(r=11,n=new t(n,i)).c,s=l.e,u=n.e,c=l.s;if(n.s=c==(i=n.s)?1:-1,!s&&(!e||!e[0])||!u&&(!o||!o[0]))return new t(!c||!i||e&&!e[0]&&!o||o&&!o[0]&&!e?NaN:!e||!o?n.s/0:n.s*0);for(n.e=s+u,(c=e.length)<(i=o.length)&&(f=e,e=o,o=f,u=c,c=i,i=u),u=c+i,f=[];u--;f.push(0));for(s=i-1;s>-1;s--){for(i=0,u=c+s;u>s;i=f[u]+o[s]*e[u-s-1]+i,f[u--]=i%10|0,i=i/10|0);i&&(f[u]=(f[u]+i)%10)}for(i&&++n.e,f[0]||f.shift(),u=f.length;!f[--u];f.pop());return n.c=n.e>h?n.e=null:n.eo)||l(n)!=n&&n!==0)&&!f(n,"decimal places","toE"))&&this.c?this.c.length-1:n|0,1)};i.toFixed=i.toF=function(n){var u,t,r,i=this;return n==null||((e=n<0||n>o)||l(n)!=n&&n!==0)&&!f(n,"decimal places","toF")||(r=i.e+(n|0)),u=c,n=a,c=-(a=1/0),r==t?t=i.toS():(t=w(i,r),i.s<0&&i.c&&(i.c[0]?t.indexOf("-")<0&&(t="-"+t):t=t.replace(/^-/,""))),c=u,a=n,t};i.toFraction=i.toFr=function(n){var k,nt,c,l,i,o,d,a=l=new t(p),v=c=new t("0"),w=this,g=w.c,tt=h,it=s,rt=u,b=new t(p);if(!g)return w.toS();for(d=b.e=g.length-w.e-1,(n==null||(!(r=12,o=new t(n)).s||(e=o.cmp(a)<0||!o.c)||y&&o.e0)&&(n=d>0?b:a),h=1/0,o=new t(g.join("")),s=0,u=1;;){if(k=o.div(b),i=l.plus(k.times(v)),i.cmp(n)==1)break;l=v;v=i;a=c.plus(k.times(i=a));c=i;b=o.minus(k.times(i=b));o=i}return i=n.minus(l).div(v),c=c.plus(i.times(a)),l=l.plus(i.times(v)),c.s=a.s=w.s,s=d*2,u=rt,nt=a.div(v).minus(w).abs().cmp(c.div(l).minus(w).abs())<1?[a.toS(),v.toS()]:[c.toS(),l.toS()],h=tt,s=it,nt};i.toPrecision=i.toP=function(n){return n==null||((e=n<1||n>o)||l(n)!=n)&&!f(n,"precision","toP")?this.toS():w(this,--n|0,2)};i.toString=i.toS=function(n){var u,t,o,r=this,i=r.e;if(i===null)t=r.s?"Infinity":"NaN";else{if(n===u&&(i<=c||i>=a))return w(r,r.c.length-1,1);if(t=r.c.join(""),i<0){for(;++i;t="0"+t);t="0."+t}else if(o=t.length,i>0)if(++i>o)for(i-=o;i--;t+="0");else i1)t=u+"."+t.slice(1);else if(u=="0")return u;if(n!=null)if((e=!(n>=2&&n<=36))||n!=(n|0)&&y)f(n,"base","toS");else if(t=tt(t,n|0,10,r.s),t=="0")return t}return r.s<0?"-"+t:t};i.valueOf=function(){return this.toS()};typeof module!="undefined"&&module.exports?module.exports=t:typeof define=="function"&&define.amd?define(function(){return t}):n.BigNumber=t})(this); \ No newline at end of file diff --git a/doc/API.html b/doc/API.html index 6e57c3d..deee4bf 100644 --- a/doc/API.html +++ b/doc/API.html @@ -136,7 +136,7 @@ code,pre{font-family:Monaco,Consolas,"Lucida Console",monospace; Zero, NaN & Infinity Errors - + FAQ @@ -332,7 +332,7 @@ BigNumber.config(null, BigNumber.ROUND_UP) // equivalent
EXPONENTIAL_AT
- number : integer, magnitude 0 to + number : integer, magnitude 0 to 1e+9 inclusive, or
number[] : [ integer -1e+9 to 0 inclusive, integer 0 to 1e+9 inclusive ]
@@ -387,7 +387,7 @@ BigNumber.config({ EXPONENTIAL_AT : 0 })
RANGE
- number : integer, magnitude 1 to + number : integer, magnitude 1 to 1e+9 inclusive, or
number[] : [ integer -1e+9 to -1 inclusive, integer 1 to 1e+9 inclusive ]
@@ -978,7 +978,7 @@ y.equals(NaN) // false
- greaterThan.gt(n [, base]) ⇒ + greaterThan.gt(n [, base]) ⇒ boolean

@@ -1322,7 +1322,7 @@ pi.toFr(1) // '3, 1'

See Errors for the treatment of other - non-integer or out of range decimal_places or + non-integer or out of range decimal_places or rounding_mode values.

@@ -1465,9 +1465,10 @@ y.s                     // -1

Errors

- The table below shows the BigNumber Errors that may be thrown if - ERRORS is true, and what happens if - ERRORS is false. + The errors that are thrown are generic Error objects with + name BigNumber Error. The table below shows the errors + that may be thrown if ERRORS is true, and the + action taken if ERRORS is false.

@@ -1637,18 +1638,18 @@ y.s // -1*No error is thrown if the value is NaN or 'NaN'

- The message of a BigNumber Error will also contain the name of the + The message of a BigNumber Error will also contain the name of the method from which the error originated.

- To determine if an exception is a BigNumber Error: + To determine if an exception is a BigNumber Error:

 try {
-    // do something with BigNumbers
+    // ...
 } catch (e) {
-    if (e.name == 'BigNumber Error') {
-        // do something
+    if ( e instanceof Error && e.name == 'BigNumber Error' ) {
+        // ...
     }
 }
@@ -1662,8 +1663,8 @@ try {
 x = new BigDecimal("1.0")
 y = new BigDecimal("1.1000")
-z = x.add(y)                      // 2.1000   
-    
+z = x.add(y)                      // 2.1000
+
 x = new BigDecimal("1.20")
 y = new BigDecimal("3.45000")
 z = x.multiply(y)                 // 4.1400000
@@ -1694,10 +1695,10 @@ z = x.multiply(y) // 4.1400000 This library, like binary floating point and most calculators, does not retain trailing fractional zeros. Instead, the toExponential, toFixed and toPrecision methods enable trailing - zeros to be added if and when required. + zeros to be added if and when required.


- + diff --git a/package.json b/package.json index 6141c5e..32b80aa 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.1.1", + "version": "1.2.0", "keywords": [ "arbitrary", "precision",