Floating point arithmetics can produce wrong results

RESOLVED DUPLICATE of bug 20140

Status

()

Core
JavaScript Engine
RESOLVED DUPLICATE of bug 20140
14 years ago
6 years ago

People

(Reporter: escaillas, Unassigned)

Tracking

Trunk
x86
Windows 2000
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)

A simple operation like :
  2.00000000000001 - 1
produces
  1.0000000000000102

If the 15th digit of a float is not relevant, the comparison operator should not
take it into account as in :
  1 == (1 / 54 + 1) * 54 - 54
wich resolves to :
  1 == 1.000000000000007


Reproducible: Always
Steps to Reproduce:
1. document.write( 1 == (1 / 54 + 1) * 54 - 54 )
2.
3.

Actual Results:  
false

Expected Results:  
true


CPU is AMD Athlon 1.2 Ghz
printf("%99.99f\n", (1.0/54.0 + 1.0) * 54.0 - 54.0);
1.000000000000007105427357601001858711242675781250000000000000000000000000000000000000000000000000000

Your issue is with IEEE754 rules, not Mozilla.
Status: UNCONFIRMED → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → INVALID

Updated

14 years ago
Whiteboard: DUPEME
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---

*** This bug has been marked as a duplicate of 20140 ***
Status: UNCONFIRMED → RESOLVED
Last Resolved: 14 years ago14 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.