[GHC] #10754: truncate /= double2Int

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 7.10.2 libraries/base | Keywords: truncate, | Operating System: Unknown/Multiple double2Int, rewrite, rule | Architecture: | Type of failure: Incorrect result Unknown/Multiple | at runtime Test Case: | Blocked By: Blocking: | Related Tickets: Differential Revisions: | -------------------------------------+------------------------------------- There is a rule in libraries/base/GHC/Float.hs: {{{#!hs "truncate/Double->Int" truncate = double2Int }}} But it is not true for some values. Particularly, {{{#!hs let infinity = 1/0 :: Double truncate infinity :: Int == 0 double2Int infinity == -9223372036854775808 -- minBound }}} As a result, the value of {{{truncate (1/0 :: Double) :: Int}}} depends on optimization level. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: | Keywords: truncate, | double2Int, rewrite, rule Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by bgamari): One could even argue here that neither answer is in fact correct in light of the description of `truncate`,
`truncate x` returns the integer nearest `x` between zero and `x`
In this case `truncate infinity` should be `maxBound :: Int`, no? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: | Keywords: truncate, | double2Int, rewrite, rule Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by cblp): Infinity is not representable in Int. Maybe maxBound is the closest answer, and they both must return maxBound, maybe they both must throw an exception. I don't know the precise answer. But I know they must return the same value, or it must be documented as undefined behaviour. Currently this rule is invalid. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: | Keywords: truncate, | double2Int, rewrite, rule Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by cblp): Speaking mathematically, yes, as 1/0 is actually +infinity, nearest Int is maxBound, and for (-1/0) the nearest Int is minBound. But what is the correct answer for {{{truncate (1/0) :: Integer}}}? Now it is 179769313486231590772930519078902473361797697894230657273430081157732675805500963132708477322407536021120113879871393357658789768814416622492847430639474124377767893424865485276302219601246094119453082952085005768838150682342462881473913110540827237163350510684586298239947245938479716304835356329624224137216. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: duplicate | Keywords: truncate, | double2Int, rewrite, rule Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Changes (by rwbarton): * status: new => closed * resolution: => duplicate Comment: Essentially a duplicate of #3070. Feel free to continue the discussion there. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: duplicate | Keywords: truncate, | double2Int, rewrite, rule Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by cblp): rwbarton, I don't consider this a duplicate of #3070. That is about the value of NaN, but this is about consistency-breaking optimization. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: duplicate | Keywords: truncate, | double2Int, rewrite, rule Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): While not exactly identical, the issues here and in #3070 are so closely related that any attempt to address one should also take the other into consideration. So, it's more helpful if the discussion is consolidated into one ticket thread. Certainly we would not give up the rule `truncate = double2Int` simply because the two sides give different nonsense outputs for the same nonsense input. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#10754: truncate /= double2Int -------------------------------------+------------------------------------- Reporter: cblp | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: libraries/base | Version: 7.10.2 Resolution: duplicate | Keywords: truncate, | double2Int, rewrite, rule Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by cblp): I don't think you can consider Infinity a nonsense because it is a valid IEEE 754 value. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10754#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC