#9304: Floating point woes; Different behavior on 32- vs 64-bit x86 -------------------------------------+------------------------------------ Reporter: lerkok | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.8.3 Resolution: | Keywords: floating point Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: 9276 Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by rwbarton): * priority: high => normal Comment: The optimizer is constant-folding the multiplication in Carter's first test program, but not the second (thanks to NOINLINE). The one mystery to me is why this constant folding is apparently performed using 64-bit floating point while multiplication in GHCi is apparently performed using 80-bit floating point. Edward's comments explain the rest of the observed behavior. You can see the same behavior in C: {{{ #include <stdio.h> int main(void) { double x, y; x = -4.4; y = 2.4999999999999956; printf("%.30lf\n", x*y); return 0; } }}} {{{ rwbarton@morphism:/tmp/fp$ gcc -m32 mul.c -o mul rwbarton@morphism:/tmp/fp$ ./mul -10.999999999999982236431605997495 rwbarton@morphism:/tmp/fp$ gcc -m64 mul.c -o mul rwbarton@morphism:/tmp/fp$ ./mul -10.999999999999980460074766597245 }}} The Haskell Report makes no guarantee that Double is even IEEE floating- point arithmetic of any kind, and GHC's behavior is documented: https://www.haskell.org/ghc/docs/7.6.1/html/users_guide/bugs.html#bugs- ghc. -- Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/9304#comment:25> GHC <http://www.haskell.org/ghc/> The Glasgow Haskell Compiler