#1042: Floating point exception
-------------------------+--------------------------------------------------
    Reporter:  dons      |       Owner:         
        Type:  bug       |      Status:  new    
    Priority:  normal    |   Milestone:         
   Component:  Compiler  |     Version:  6.6    
    Severity:  normal    |    Keywords:         
  Difficulty:  Unknown   |    Testcase:         
Architecture:  x86       |          Os:  Unknown
-------------------------+--------------------------------------------------
The slightly evil expression:
 {{{
 (-2147483648::Int) `div` (-1::Int)
 }}}

 Can produce floating point exceptions in GHCi:

 {{{
 $ ghci-6.6
    ___         ___ _
   / _ \ /\  /\/ __(_)
  / /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
 / /_\\/ __  / /___| |      http://www.haskell.org/ghc/
 \____/\/ /_/\____/|_|      Type :? for help.

 Loading package base ... linking ... done.
 Prelude> (-2147483648::Int) `div` (-1::Int)
 zsh: floating point exception (core dumped)  ghci-6.6
 }}}

 Compiled:

 {{{
 $ cat A.hs
 main = print $ (-2147483648::Int) `div` (-1::Int)

 $ ghc A.hs

 $ ./a.out
 zsh: floating point exception (core dumped)  ./a.out
 }}}

 Compiled -O:
 {{{
 $ ghc -O -no-recomp A.hs

 $ ./a.out
 zsh: floating point exception (core dumped)  ./a.out
 }}}

 In Hugs:
 {{{
 Hugs.Base> (-2147483648::Int) `div` (-1::Int)
 Unexpected signal
 }}}

 A C test cases:
 {{{
 $ cat t.c
 #include <stdio.h>

 int main() {
     printf("%d\n",((int)(-2147483648)) / ((int)(-1)));
     return 0;
 }

 $ gcc t.c
 t.c: In function `main':
 t.c:4: warning: this decimal constant is unsigned only in ISO C90
 t.c:4: warning: integer overflow in expression

 $ ./a.out
 -2147483648
 }}}

 Another:
 {{{
 $ cat t.c
 #include <stdio.h>

 main () {
     int i = -2147483648;
     int j = -1;
     int k = i / j;
     printf("%d\n", k);
 }

 $ gcc t.c
 t.c: In function `main':
 t.c:4: warning: this decimal constant is unsigned only in ISO C90

 $ ./a.out
 zsh: floating point exception (core dumped)  ./a.out
 }}}

 What does H98 say about this?

 -- Don

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1042>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to