Last Comment Bug 5856 - (js-ieee-double-hurts) javascript rounding bug
(js-ieee-double-hurts)
: javascript rounding bug
Status: VERIFIED INVALID
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: All All
: P3 normal (vote)
: ---
Assigned To: Norris Boyd
: cbegle
:
Mentors:
http://www.browsertune.com/bt2kdemo/m...
: 1813 20140 190303 251585 280544 281659 283303 297361 320093 356566 369803 378956 393209 396764 408202 409726 413965 444938 452198 460943 466822 480475 516355 520754 538209 557530 582086 618839 624189 656887 699645 832727 839324 1118287 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 1999-05-02 20:24 PDT by AriB
Modified: 2015-01-06 08:37 PST (History)
38 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description AriB 1999-05-02 20:24:27 PDT
Just to give one example
14.28 x 9 should be 128.52;
your browser's answer = 128.51999999999998

This bug is also from Netscape 4.5
Comment 1 Waldemar Horwat 1999-05-05 13:05:59 PDT
ECMAScript requires the use of IEEE double precision for numbers.

14.28 correctly rounded as an IEEE double is represented as

1.1100100011110101110000101000111101011100001010001111e3 in base 2, which is

exactly equal to 14.2799999999999993605115378159098327159881591796875 decimal.

Multiplying this value by 9 yields exactly

128.5199999999999942446038403431884944438934326171875.

Per the ECMA spec, this is again rounded to the nearest IEEE double, which is

1.0000000100001010001111010111000010100011110101110000e7 base 2, or

128.51999999999998181010596454143524169921875 decimal.



Why does the result print as 128.51999999999998?  Well, the ECMA spec requires

numbers to be printed with sufficient precision (and no more than that precision)

so that if the printed string were read in again and converted back to a number,

it would round to exactly the same IEEE double that was printed.  Printing 128.52

would be incorrect because the rounding 128.52 to the closest IEEE double yields

128.520000000000010231815394945442676544189453125, which is closer than

128.51999999999998181010596454143524169921875.  Thus we must print

128.51999999999998.

Every other language that uses standard IEEE double-precision arithmetic will

also give this result.  This includes Java and most implementations of C and C++.
Comment 2 leger 1999-06-07 15:59:59 PDT
Changing component to "Javascript Engine".  "Javascript" component is being
retired.
Comment 3 Jay Patel [:jay] 1999-07-12 14:18:59 PDT
Verified Invalid
Comment 4 Bill Mason 2004-07-15 09:34:23 PDT
*** Bug 251585 has been marked as a duplicate of this bug. ***
Comment 5 Brendan Eich [:brendan] 2004-07-15 09:43:13 PDT
Note that ECMA-262 Edition 3 added Number.prototype.toFixed, which takes a
precision argument telling how many digits after the decimal point to show.  Use
this method well and you won't mind the disparity between finite precision base
2 and the "arbitrary" or "appropriate" precision base 10 that we use every day.

/be
Comment 6 Boris Zbarsky [:bz] (still a bit busy) 2005-02-22 13:41:08 PST
*** Bug 281659 has been marked as a duplicate of this bug. ***
Comment 7 Jesse Ruderman 2005-02-24 21:40:37 PST
*** Bug 20140 has been marked as a duplicate of this bug. ***
Comment 8 Jesse Ruderman 2005-02-24 21:41:52 PST
*** Bug 1813 has been marked as a duplicate of this bug. ***
Comment 9 Brendan Eich [:brendan] 2005-02-24 23:42:53 PST
*** Bug 283303 has been marked as a duplicate of this bug. ***
Comment 10 :Gavin Sharp [email: gavin@gavinsharp.com] 2005-06-10 20:06:59 PDT
*** Bug 297361 has been marked as a duplicate of this bug. ***
Comment 11 Elmar Ludwig 2005-12-13 04:14:42 PST
*** Bug 320093 has been marked as a duplicate of this bug. ***
Comment 12 :Mook 2006-10-13 07:13:30 PDT
*** Bug 356566 has been marked as a duplicate of this bug. ***
Comment 13 Brian Crowder 2007-04-26 17:03:44 PDT
*** Bug 378956 has been marked as a duplicate of this bug. ***
Comment 14 :Gavin Sharp [email: gavin@gavinsharp.com] 2007-08-22 10:28:59 PDT
*** Bug 393209 has been marked as a duplicate of this bug. ***
Comment 15 Dave Townsend [:mossop] 2007-12-13 07:29:41 PST
*** Bug 408202 has been marked as a duplicate of this bug. ***
Comment 16 Robert Longson 2007-12-13 07:34:47 PST
*** Bug 369803 has been marked as a duplicate of this bug. ***
Comment 17 Frank Wein [:mcsmurf] 2007-12-23 12:08:47 PST
*** Bug 396764 has been marked as a duplicate of this bug. ***
Comment 18 :Gavin Sharp [email: gavin@gavinsharp.com] 2007-12-24 11:23:49 PST
*** Bug 409726 has been marked as a duplicate of this bug. ***
Comment 19 Dave Townsend [:mossop] 2008-01-25 03:32:55 PST
*** Bug 413965 has been marked as a duplicate of this bug. ***
Comment 20 Robert Longson 2008-07-12 14:12:48 PDT
*** Bug 444938 has been marked as a duplicate of this bug. ***
Comment 21 Dave Townsend [:mossop] 2008-08-26 01:23:54 PDT
*** Bug 452198 has been marked as a duplicate of this bug. ***
Comment 22 Robert Longson 2008-10-21 03:59:37 PDT
*** Bug 460943 has been marked as a duplicate of this bug. ***
Comment 23 Brian Crowder 2008-11-05 08:46:46 PST
*** Bug 463163 has been marked as a duplicate of this bug. ***
Comment 24 Dave Townsend [:mossop] 2008-11-26 06:38:56 PST
*** Bug 466822 has been marked as a duplicate of this bug. ***
Comment 25 Mike Shaver (:shaver -- probably not reading bugmail closely) 2009-02-26 18:47:47 PST
*** Bug 480475 has been marked as a duplicate of this bug. ***
Comment 26 Robert Longson 2009-09-14 03:32:54 PDT
*** Bug 516355 has been marked as a duplicate of this bug. ***
Comment 27 Jo Hermans 2009-10-06 07:20:55 PDT
*** Bug 520754 has been marked as a duplicate of this bug. ***
Comment 28 Jo Hermans 2009-10-06 07:21:20 PDT
*** Bug 190303 has been marked as a duplicate of this bug. ***
Comment 29 Jo Hermans 2009-10-06 07:21:55 PDT
*** Bug 280544 has been marked as a duplicate of this bug. ***
Comment 30 Brendan Eich [:brendan] 2010-01-06 11:13:36 PST
*** Bug 538209 has been marked as a duplicate of this bug. ***
Comment 31 Brendan Eich [:brendan] 2010-04-06 13:08:23 PDT
*** Bug 557530 has been marked as a duplicate of this bug. ***
Comment 32 Robert Longson 2010-07-26 14:57:27 PDT
*** Bug 582086 has been marked as a duplicate of this bug. ***
Comment 33 Robert Longson 2010-12-13 09:03:04 PST
*** Bug 618839 has been marked as a duplicate of this bug. ***
Comment 34 Mike Shaver (:shaver -- probably not reading bugmail closely) 2011-01-08 13:42:07 PST
*** Bug 624189 has been marked as a duplicate of this bug. ***
Comment 35 Robert Longson 2011-05-13 06:04:22 PDT
*** Bug 656887 has been marked as a duplicate of this bug. ***
Comment 36 Matthias Versen [:Matti] 2011-11-04 12:22:53 PDT
*** Bug 699645 has been marked as a duplicate of this bug. ***
Comment 37 Matthias Versen [:Matti] 2013-01-20 12:00:17 PST
*** Bug 832727 has been marked as a duplicate of this bug. ***
Comment 38 Boris Zbarsky [:bz] (still a bit busy) 2013-02-08 05:14:57 PST
*** Bug 839324 has been marked as a duplicate of this bug. ***
Comment 39 Sebastian Prodan 2013-06-09 00:38:34 PDT
Duplicate of the Bug: 15* 1.33 (instead of expected 19.95 it return 19.950000000000003)
Comment 40 Robert Longson 2015-01-06 08:37:41 PST
*** Bug 1118287 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.