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,323
    • Issues 4,323
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 377
    • Merge Requests 377
  • 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
  • #10215

Closed
Open
Opened Mar 29, 2015 by Levent Erkök@LeventErkokReporter

Optimizer has bugs regarding handling of -0.0

This is most likely related to #9238 (closed)

Perhaps it can be merged into that if it is indeed the case, though it'd be good for an expert to take a look and make sure first that the culprit is indeed the same. In any case, the program in this ticket can at least serve as a test-case.

I observed this on 7.8.3; though I suspect the same holds in the just released 7.10.1 as well. For the following program:

testF :: Float -> Bool
testF x = x == 0 && not (isNegativeZero x)

testD :: Double -> Bool
testD x = x == 0 && not (isNegativeZero x)

main :: IO ()
main = do print $ testF (-0.0)
          print $ testD (-0.0)

If I compile with no optimizations, then I get the correct answers:

$ /bin/rm -f a.hi a.o a; ghc -O0 a; ./a
[1 of 1] Compiling Main             ( a.hs, a.o )
Linking a ...
False
False

But if I turn optimizations on, then I get:

$ /bin/rm -f a.hi a.o a; ghc -O2 a; ./a
[1 of 1] Compiling Main             ( a.hs, a.o )
Linking a ...
True
True

which is just plain wrong.

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