Bug 15631 - Arithmetic errors with LOG10E
Summary: Arithmetic errors with LOG10E
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 523.x (Safari 3)
Hardware: Macintosh OS X 10.4
: P2 Normal
Assignee: Nobody
URL: javascript:alert(Math.LOG10E*Math.log...
Keywords:
Depends on:
Blocks: 10489
  Show dependency treegraph
 
Reported: 2007-10-22 15:25 PDT by Jesse Costello-Good
Modified: 2011-04-01 17:53 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Costello-Good 2007-10-22 15:25:49 PDT
The value of the following should be 3, but on Safari it is 2.9999999999999996

Math.LOG10E * Math.log(1000)

This may be because Math.LOG10E is calculated too accurately. It is 0.43429448190325176 on Safari and 0.4342944819032518 on Firefox and IE.

One work around is to set the value of LOG10E to 0.4342944819032518. The following evaluates to 3 on Safari:

0.4342944819032518 * Math.log(1000)

This may affect other Math constants. LOG10E is the only one that I have checked.
Comment 1 Timothy P. Horton 2009-01-12 18:39:08 PST
I don't think this is actually a calculation problem, nor a problem with the constant.

Floating point representations are fundamentally flawed - not all numbers can be represented, and you will /quite/ often get strange errors like the one you described, even with very simple tests.

All numbers in JavaScriptCore (as far as I know) are represented internally as double-precision floating point numbers, thus everything is susceptible to this problem.

Take a peek:

http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

or, if you're really interested:

http://docs.sun.com/source/806-3568/ncg_goldberg.html

But I might be wrong. The fact that the constant is different than in FF/IE is strange, though. Actually, Mathematica agrees with FF/IE (in that LOG10E should be ~0.4342944819032518276511)... so maybe it /is/ a bug!
Comment 2 David Kilzer (:ddkilzer) 2009-05-22 10:29:44 PDT
Wolfram Alpha says it's 3.000000000000000000000000000000...

<http://www.wolframalpha.com/input/?i=Log10%5BE%5D+Log%5B1000%5D>

I still think Tibco should be rounding the result, though.
Comment 3 Sam Weinig 2011-04-01 17:53:58 PDT
This was fixed in http://trac.webkit.org/changeset/79246.