[GHC] #9936: Data.Fixed truncates 5.17 to 5.16

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 7.6.3 libraries/base | Operating System: Unknown/Multiple Keywords: | Type of failure: Incorrect result Architecture: | at runtime Unknown/Multiple | Blocked By: Test Case: | Related Tickets: Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- `(realToFrac (5.17 :: Double) :: Centi) == 5.16` is true -- it should be false. The offender seems to be the assumption in `fromRational`: `fromRational r = withResolution (\res -> MkFixed (floor (r * (toRational res))))` Uses `floor` assuming that the underlying floating point value is stored purely and not as 0.999999 or similar -- switching it to `round` fixes this issue. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: 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 ekmett): #9231 tackles somewhat similar issues. Does the fix there address this? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by ekmett): * related: => #9231 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by ekmett): * related: #9231 => #9231, #9240 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by singpolyma): * related: #9231, #9240 => #9231 Comment: @ekmett the changes there seem to be for reading from string -- this is just in the `fromRational`/`realToFrac` path. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by singpolyma): * related: #9231 => #9231, #9240 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by rwbarton): Replying to [comment:1 ekmett]:
#9231 & #9240 tackle somewhat similar issues.
Does the fix there address this?
The behavior reported in this ticket still occurs in 7.11. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Revisions: -------------------------------------+------------------------------------- Comment (by simonpj): It sounds as if the fix is simple. It would be great if someone wanted to offer a patch for this, with enough comments to explain the subtlety. Thanks! Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by thomie): * keywords: => newcomer Comment: For a newcomer: the description basically tells you what to do. So this is more an exercise in getting to know the GHC patch submission process. Don't forget an explanation, as mentioned in comment:7. And a test, see [wiki:Building/RunningTests/Adding] (or look at some examples in `libraries/base/tests`). Read [wiki:WorkingConventions/FixingBugs] and submit a patch to [wiki:Phabricator]. Good luck! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Rev(s): Phab:D1693 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bernalex): * status: new => patch * differential: => Phab:D1693 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Rev(s): Phab:D1693 Wiki Page: | -------------------------------------+------------------------------------- Comment (by bernalex): I tried this (see the differential), but it breaks things like read "38.009" :: Centi being the same as 38.009 :: Centi, which is not very nice. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:10 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Rev(s): Phab:D1693 Wiki Page: | -------------------------------------+------------------------------------- Comment (by Yance): I tried my luck with this one as my first contribution, and I get the same result as the comment right above me. I tried changing the way read works on fixed size floats, but there are a couple of tests that enforce for example read "38.009" :: Centi == 38.00, while I would find 38.01 to be a more reasonable answer. I couldn't find anything about this in the Haskell 2010 report, so my question is: Would it be possible to change this specification? Would it be desirable? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Rev(s): Phab:D1693 Wiki Page: | -------------------------------------+------------------------------------- Changes (by bgamari): * cc: core-libraries-committee@… (added) Comment: Hmm, this is rather tricky. On one hand, I agree with you that rounding seems sensible at first glance; on the other hand, I worry about what might break if we change this beneath users' feet. Perhaps the Core Libraries Committee should weigh in on this. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:12 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#9936: Data.Fixed truncates 5.17 to 5.16 -------------------------------------+------------------------------------- Reporter: singpolyma | Owner: (none) Type: bug | Status: patch Priority: normal | Milestone: Component: libraries/base | Version: 7.6.3 Resolution: | Keywords: newcomer Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect result | Unknown/Multiple at runtime | Test Case: Blocked By: | Blocking: Related Tickets: #9231, #9240 | Differential Rev(s): Phab:D1693 Wiki Page: | -------------------------------------+------------------------------------- Changes (by lelf): * cc: lelf (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9936#comment:13 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC