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

GHC ghc-devs at haskell.org
Mon Dec 29 14:58:04 UTC 2014


#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


More information about the ghc-tickets mailing list