The wonderful jsbin.js tool by Tom Wu is a step in the right direction. It is essentially a port of the
BigInteger API included in the Sun Java programming language. However, it sadly does not have support for fractional numbers (only integers).
For me, in my development of jQuery.validity, it is necessary for me to be able to check the mathematical inequality of numbers of any length. Particularly as a result of this bug report, it became clear that parsing strings as floats was not a viable way of checking inequalities. The report provides the following example:
At the moment, Big.js is only able to perform inequality operations on numbers (i.e.
equals) on positive and negative numbers.
// Numbers in Big.js are called with the Big() constructor: var number1 = new Big("12.00000000000000005"); var number2 = new Big("12"); number1.lessThanOrEqualTo(number2); // False, like it should be. // To boot... number1.lessThan(number2); // False number1.greaterThan(number2); // True number1.greaterThanOrEqualTo(number2); // True number1.equals(number2); // False
Inequality is all that is needed, technically, for the library to be useful in validation. Big.js is therefore in version 0.7.* (beta) at the time of writing this article. Version 0.8.* will have addition and subtraction support, and 0.9.* will have support for other mathematical operators. Finally culminating in version 1.0.* which will be considered “out of beta”.
The 0.7.0 beta is available on Github now under an MIT licence. More operators to be implemented soon!