[GHC] #5133: Random instance for Float can generate values out of requested range
GHC
cvs-ghc at haskell.org
Wed Apr 20 18:53:57 CEST 2011
#5133: Random instance for Float can generate values out of requested range
---------------------------------+------------------------------------------
Reporter: richardsenington | Owner:
Type: bug | Status: new
Priority: normal | Component: libraries/base
Version: 7.1 | Keywords: System.Random
Testcase: | Blockedby:
Os: Linux | Blocking:
Architecture: x86 | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by scpmw):
This is probably a rounding issue -- while the documentation specifies a
[0,1) range, querying a `Float` random value gives 1.0, while querying a
`Double` gives 0.99999998. Digging deeper, the
[http://hackage.haskell.org/packages/archive/random/latest/doc/html/src
/System-Random.html#randomIvalDouble randomIvalDouble] implementation is
probably to blame: It generates the random Float using from 2^32^ possible
integer values, where single-precision `Float` only has 23 fraction bits
and therefore will round quite a few numbers up to 1.0.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5133#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list