[GHC] #9304: Floating point woes; Different behavior on 32- vs 64-bit x86 (was: Floating point woes; Different behavior on Mac vs Linux)

GHC ghc-devs at haskell.org
Sun Jul 13 23:06:40 UTC 2014


#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 at morphism:/tmp/fp$ gcc -m32 mul.c -o mul
 rwbarton at morphism:/tmp/fp$ ./mul
 -10.999999999999982236431605997495
 rwbarton at morphism:/tmp/fp$ gcc -m64 mul.c -o mul
 rwbarton at 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


More information about the ghc-tickets mailing list