Closed Bug 408202 Opened 14 years ago Closed 14 years ago

Javascript modulo operator returns incorrect result when using floating point numbers

Categories

(Firefox :: General, defect)

PowerPC
macOS
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 5856

People

(Reporter: rob, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11

This statement, (23.98*3600) % 23.98, yields the answer 23.979999999998466, which is obviously illogical. (24*3600) % 24 yields 0, which is correct. (59.97*3600) % 59.97 yields 4.092726157978177e-12, which is way off the mark.

This happens in html pages, but can also be seen in the error console.

Reproducible: Always

Steps to Reproduce:
1. Open error console
2. Type in (23.98*3600) % 23.98 in the evaluate field
3. Press Evaluate
Actual Results:  
Messages window displays 23.979999999998466

Expected Results:  
Message window should display 0
This is just the general issue with the presumed accuracy of floating point values.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 20140
Duplicate of bug: js-ieee-double-hurts
You need to log in before you can comment on or make changes to this bug.