This commit is contained in:
Michael Mclaughlin 2013-08-01 18:57:00 +01:00
parent 4473a6c888
commit a977d784a1
4 changed files with 32 additions and 23 deletions

View File

@ -1,15 +1,15 @@
# bignumber.js #
A Javascript library for arbitrary-precision decimal and non-decimal arithmetic.
A JavaScript library for arbitrary-precision decimal and non-decimal arithmetic.
## Features
- Faster, smaller, and perhaps easier to use than Javascript versions of Java's BigDecimal
- 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 or without fraction digits in bases from 2 to 36 inclusive
- Replicates the `toExponential`, `toFixed`, `toPrecision` and `toString` methods of Javascript's Number type
- 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
@ -21,8 +21,7 @@ It also does not allow `NaN` or `Infinity`, or have the configuration options of
## Load
The library is the single Javascript file *bignumber.js*
(or *bignumber.min.js*, which is *bignumber.js* minified using uglify-js).
The library is the single JavaScript file *bignumber.js* (or minified, *bignumber.min.js*).
It can be loaded via a script tag in an HTML document for the browser
@ -41,7 +40,6 @@ The library is also available from the [npm](https://npmjs.org/) registry, so
$ npm install bignumber.js
will install this entire directory in a *node_modules* directory within the current directory.
It can then be loaded with `require('bignumber.js')`.
To load with AMD loader libraries such as [requireJS](http://requirejs.org/):
@ -85,7 +83,7 @@ Method names over 5 letters in length have a shorter alias.
x.squareRoot().dividedBy(y).toPower(3).equals(x.sqrt().div(y).pow(3)) // true
x.cmp(y.mod(z).neg()) == 1 && x.comparedTo(y.modulo(z).negated()) == 1 // true
Like Javascript's Number type, there are `toExponential`, `toFixed` and `toPrecision` methods
Like JavaScript's Number type, there are `toExponential`, `toFixed` and `toPrecision` methods
x = new BigNumber(255.5)
x.toExponential(5) // "2.55500e+2"
@ -153,13 +151,13 @@ To test all the methods in more depth
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.
*bignumber-vs-number.html* enables some of the methods of bignumber.js to be compared with those of JavaScript's Number type.
## Performance
The *perf* directory contains two applications and a *lib* directory containing the BigDecimal libraries used by both.
*bignumber-vs-bigdecimal.html* tests the performance of bignumber.js against the Javascript translations of two versions of BigDecimal, its use should be more or less self-explanatory.
*bignumber-vs-bigdecimal.html* tests the performance of bignumber.js against the JavaScript translations of two versions of BigDecimal, its use should be more or less self-explanatory.
(The GWT version doesn't work in IE 6.)
* GWT: java.math.BigDecimal
@ -198,7 +196,7 @@ will create *bignumber.min.js*.
Bugs: surely not! Open an issue, please.
Other feedback to:
Michael Mclaughlin
Michael
<a href="mailto:M8ch88l@gmail.com">M8ch88l@gmail.com</a>
Bitcoin donation to:
@ -211,12 +209,13 @@ See LICENCE.
## Change Log
####1.1.0
* 1/8/2013 Allow numbers with trailing radix point.
####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
* 8/11/2012 Initial release
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/50b85fd919b406ef9312551092a95fb7 "githalytics.com")](http://githalytics.com/MikeMcl/bignumber.js)

View File

@ -145,7 +145,7 @@ code,pre{font-family:Monaco,Consolas,"Lucida Console",monospace;
<h1>bignumber.js</h1>
<p>A Javascript library for arbitrary-precision arithmetic.</p>
<p>A JavaScript library for arbitrary-precision arithmetic.</p>
<p>
<a href="https://github.com/MikeMcl/bignumber.js">Hosted on GitHub</a>.
@ -190,7 +190,7 @@ code,pre{font-family:Monaco,Consolas,"Lucida Console",monospace;
</dd>
<dd>
There is no limit to the number of digits of a value of type
<em>string</em> (other than that of Javascript's maximum array size).
<em>string</em> (other than that of JavaScript's maximum array size).
</dd>
<dd>
Decimal string values may be in exponential, as well as normal
@ -351,7 +351,7 @@ BigNumber.config(null, BigNumber.ROUND_UP) // equivalent</pre>
above which the same.
</dd>
<dd>
For example, to emulate Javascript numbers in terms of the exponent
For example, to emulate JavaScript numbers in terms of the exponent
values at which they begin to use exponential notation, use
<code>[-7, 20]</code>.
</dd>
@ -408,7 +408,7 @@ BigNumber.config({ EXPONENTIAL_AT : 0 })</pre>
exponent limit.
</dd>
<dd>
For example, to emulate Javascript numbers in terms of the exponent
For example, to emulate JavaScript numbers in terms of the exponent
values at which they become zero and Infinity, use
<code>[-324, 308]</code>.
</dd>
@ -575,7 +575,7 @@ BigNumber.config({ ROUNDING_MODE : 2 }) // equivalent</pre>
</p>
<p>
The treatment of &plusmn;<code>0</code>, &plusmn;<code>Infinity</code> and
<code>NaN</code> is consistent with how Javascript treats these values.
<code>NaN</code> is consistent with how JavaScript treats these values.
</p>
<p>
Method names over 5 letters in length have a shorter alias (except
@ -850,7 +850,7 @@ x.minus(0.6, 20) // '0'</pre>
</p>
<p>
The result will have the same sign as this BigNumber, and it will match
that of Javascript's % operator (within the limits of its precision) and
that of JavaScript's % operator (within the limits of its precision) and
BigDecimal's remainder method.
</p>
<pre>
@ -961,7 +961,7 @@ new BigNumber(2).pow(1e+6) // Time taken (Node.js): 9 minutes 34 secs.</pre>
<p>
Returns <code>true</code> if the value of this BigNumber equals the value
of <code>n</code>, otherwise returns <code>false</code>.<br />
As with Javascript, NaN does not equal NaN.
As with JavaScript, NaN does not equal NaN.
<br />Note : This method uses the <code>comparedTo</code> method
internally.
</p>
@ -1383,7 +1383,7 @@ y // '1234.56'</pre>
(left-most) digit of the coefficient.
</p>
<p>
Note that, as with Javascript numbers, the original exponent and
Note that, as with JavaScript numbers, the original exponent and
fractional trailing zeros are not preserved.
</p>
<pre>x = new BigNumber(0.123) // '0.123'
@ -1691,7 +1691,7 @@ z = x.multiply(y) // 4.1400000</pre>
misleading.
</p>
<p>
This library, like Javascript and most calculators, does not
This library, like binary floating point and most calculators, does not
retain trailing fractional zeros. Instead, the <code>toExponential</code>,
<code>toFixed</code> and <code>toPrecision</code> methods enable trailing
zeros to be added if and when required.

View File

@ -1,7 +1,7 @@
{
"name": "bignumber.js",
"description": "A library for arbitrary-precision decimal and non-decimal arithmetic",
"version": "1.0.1",
"version": "1.1.0",
"keywords": [
"arbitrary",
"precision",

View File

@ -478,6 +478,10 @@ var count = (function config(BigNumber) {
assert('0', new BigNumber(0).toS());
assert('0', new BigNumber(-0).toS());
assert('0', new BigNumber('.0').toS());
assert('0', new BigNumber('0.').toS());
assert('0', new BigNumber('-0.').toS());
assert('0', new BigNumber('+0.').toS());
assert('0', new BigNumber('+0').toS());
assert('0', new BigNumber('-0').toS());
assert('0', new BigNumber(' +0').toS());
@ -497,6 +501,7 @@ var count = (function config(BigNumber) {
assertException(function () {new BigNumber('++0')}, "++0");
assertException(function () {new BigNumber('.-0')}, ".-0");
assertException(function () {new BigNumber('.+0')}, ".+0");
assertException(function () {new BigNumber('0 .')}, "0 .");
assertException(function () {new BigNumber('. 0')}, ". 0");
assertException(function () {new BigNumber('..0')}, "..0");
assertException(function () {new BigNumber('+.-0')}, "+.-0");
@ -510,6 +515,10 @@ var count = (function config(BigNumber) {
assert('-2', new BigNumber(' -2').toS());
assert('2', new BigNumber(' +2 ').toS());
assert('-2', new BigNumber(' -2 ').toS());
assert('0.2', new BigNumber('.2').toS());
assert('2', new BigNumber('2.').toS());
assert('-2', new BigNumber('-2.').toS());
assert('2', new BigNumber('+2.').toS());
assert('0.2', new BigNumber('+.2').toS());
assert('-0.2', new BigNumber('-.2').toS());
assert('0.2', new BigNumber(' +.2').toS());
@ -523,6 +532,7 @@ var count = (function config(BigNumber) {
assertException(function () {new BigNumber('++2')}, "++2");
assertException(function () {new BigNumber('.-2')}, ".-2");
assertException(function () {new BigNumber('.+2')}, ".+2");
assertException(function () {new BigNumber('2 .')}, "2 .");
assertException(function () {new BigNumber('. 2')}, ". 2");
assertException(function () {new BigNumber('..2')}, "..2");
assertException(function () {new BigNumber('+.-2')}, "+.-2");