Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,326
    • Issues 4,326
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 390
    • Merge Requests 390
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #1042

Closed
Open
Opened Dec 08, 2006 by dons@trac-dons

Floating point exception

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

Trac metadata
Trac field Value
Version 6.6
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system Unknown
Architecture
Assignee
Assign to
6.6.1
Milestone
6.6.1
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#1042