Infinite-precision arithmetic in JavaScript -
in javascript, function alert((3*3*math.sqrt(2))/13) prints 0.9790709277967582, approximation of expression's true value. there way perform arithmetic operations in javascript 1 without loss of precision, 3*3*sqrt(2))/13 output 9*(2)^(1/2)/13, exact value, instead of 0.9790709277967582, approximation?
there's library here: https://github.com/whatgoodisaroad/big-js/downloads
it has bunch of functions mynum.add(othernum), might little harder use. however, if need infinite precision have do.
example:
var number1 = new big("12.00000000000000005"); var number2 = new big("12"); number1.lessthanorequalto(number2); // false, should be. javascript precision
No comments:
Post a Comment