precision/rounding bug with floating point numbers on 32-bit-platforms
Comparing floating point numbers (Floats or Doubles, using (==)) that are constructed by equal terms sometimes evaluates to False. A term that produces normal floating point values (as opposed to NaN or Infinity) should always be equal to itself. This bug effectively breaks referential transparency.
This bug occurs with ghc-7.4.2 when compiling with "-O2" on 32-bit linux ubuntu-11.10. (I guess, it happens on all 32-bit platforms.)
The attached file demonstrates the bug.
Simon Marlow expressed his doubts, this bug will be fixed. See also: http://www.haskell.org/pipermail/glasgow-haskell-users/2012-July/thread.html#22565
Possible workarounds:
- compile with "-msse2" if available
- use approximate equivalence
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.4.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |