You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
Currently, multiply can sometimes produce incorrect results. For instance, multiply(3, 0.123002) returns 0.36900599999999995 instead of the expected 0.369006.
I believe the problem is on Line 35 of numbers.js, where an exponent (i.e. the number of decimal places to overcome) is derived by Math.floor( Math.log(num) * -1 ). This can produce unnecessarily large exponents, or incorrectly small ones in certain cases (e.g. num = 0.123002).
Currently, multiply can sometimes produce incorrect results. For instance,
multiply(3, 0.123002)
returns0.36900599999999995
instead of the expected0.369006
.I believe the problem is on Line 35 of numbers.js, where an exponent (i.e. the number of decimal places to overcome) is derived by
Math.floor( Math.log(num) * -1 )
. This can produce unnecessarily large exponents, or incorrectly small ones in certain cases (e.g. num = 0.123002).(side note: I was surprised to find out that Math.log actually returns ln(x), not log10(x))
I'd propose finding the exponent by turning the number into a string and counting the decimal places:
Would this be a more appropriate solution?
The text was updated successfully, but these errors were encountered: