yuntaozhu / closure-library

Automatically exported from code.google.com/p/closure-library
0 stars 0 forks source link

Issue with google.math.log10Floor #633

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The function `goog.math.log10Floor` at 
https://code.google.com/p/closure-library/source/browse/closure/goog/math/math.j
s#385 can return an incorrect value for some powers of 10.

    log10Floor(1e32);   // 32
    log10Floor(1e33);   // 32
    log10Floor(1e34);   // 33
    log10Floor(1e35);   // 35
    log10Floor(1e36);   // 36
    log10Floor(1e37);   // 36

The problem lies with `Math.pow()`.  `Math.pow(10, 33)` returns 
`1.0000000000000001e+33` for me in both Firefox 29 and Chrome 33 on Ubuntu 
Linux 13.10.

The solution I'm using is Number coercion and string concatenation:

    return x - (+('1e' + x) > num);

Original issue reported on code.google.com by andyearn...@gmail.com on 26 Mar 2014 at 9:28

GoogleCodeExporter commented 8 years ago
Thanks for the report. Fix is underway.

Original comment by pall...@google.com on 2 Apr 2014 at 8:30

GoogleCodeExporter commented 8 years ago
The fix will be rolled out with the next open source release.

Original comment by pall...@google.com on 2 Apr 2014 at 9:06

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 2bba24f802e9.

Original comment by nn...@google.com on 4 Apr 2014 at 10:44