[GHC] #13552: Enum Float/Double does not match Haskell Report

#13552: Enum Float/Double does not match Haskell Report -------------------------------------+------------------------------------- Reporter: Luke | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: | Version: 8.0.1 libraries/base | Keywords: | 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: -------------------------------------+------------------------------------- Section 6.3.4 of the report says that the `Enum` instance for `Float` and `Double` should define the `enumFromThen*` functions such that `enumFromThen e1 e2` is the list `[e1, e1 + i, e1 + 2i, ...]` where `i = e2 - e1`. The actual implementation in base is that of successive additions (which is approximately the same thing for some types). Successive additions causes issues with floating point rounding. Changing the definition to something like {{{#!hs enumFromThen_ e1 e2 = let i = e2 - e1 in map (\n -> e1 + n * i) [0..] }}} significantly improves the accuracy of floating point ranges, as well as **matching what the report says**. {{{ Prelude> last $ take 101 $ [0,0.1..] :: Float 10.000028 Prelude> last $ take 101 $ enumFromThen_ 0 0.1 :: Float 10.0 }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13552 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13552: Enum Float/Double does not match Haskell Report -------------------------------------+------------------------------------- Reporter: Luke | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: 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 simonpj): Looks good to me. Would someone care to look at the library code. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13552#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#13552: Enum Float/Double does not match Haskell Report -------------------------------------+------------------------------------- Reporter: Luke | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: libraries/base | Version: 8.0.1 Resolution: | Keywords: 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 bgamari): I'm rather confused, `GHC.Real.numericFrom` and friends (which the `Float` `Enum` instances use) claim that, {{{#!hs -- These 'numeric' enumerations come straight from the Report }}} Was the report changed? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13552#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC