Bug 7748 - toPrecision sometimes messes up the last digit on intel Macs
Summary: toPrecision sometimes messes up the last digit on intel Macs
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: Mac OS X 10.4
: P2 Normal
Assignee: Maciej Stachowiak
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-12 19:21 PST by Maciej Stachowiak
Modified: 2006-04-04 02:00 PDT (History)
0 users

See Also:


Attachments
fix by adding intPow10 function (3.17 KB, patch)
2006-03-12 19:24 PST, Maciej Stachowiak
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej Stachowiak 2006-03-12 19:21:01 PST
The JSC implementation of Number.toPrecision sometimes gets a different last digit on intel Macs than on PowerPC Macs or non-Mac intel systems. This is most likely due to a bug in the system pow() function. Nevertheless, I have a patch that works around it by directly coding computation of integer powers of 10.
Comment 1 Maciej Stachowiak 2006-03-12 19:24:49 PST
Created attachment 7040 [details]
fix by adding intPow10 function

I only replaced toPrecision's use of pow(10.0, n) with intPow10(n). Should I do the same for toExponential and toFixed (even though we have not yet spotted a specific bug with those)? I am guessing they will face the same problem with pow()'s bad rounding of powers of 10.
Comment 2 Darin Adler 2006-03-12 20:44:17 PST
Comment on attachment 7040 [details]
fix by adding intPow10 function

-          e = static_cast<int>(log10(x));
+          e = static_cast<int>(trunc(log10(x)));

Why that change? Does trunc add value? Why trunc and not floor?

+	      n = floor(x / tens);

Looks like there's a tab in the patch.

r=me
Comment 3 Maciej Stachowiak 2006-04-04 02:00:52 PDT
Finally landed this.