#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 daniel.is.fischer):

 Adding a check for a return value of 1.0 and replacing that with 0.0 (so
 that all `Float` results are rounded to from approximately the same number
 of `Double` results - the round-to-even strategy makes the numbers not
 quite identical) doesn't cost much performance, actually I found no
 consistently measurable slowdown in my benchmarks.
 But I'm not entirely sure that it works reliably,
 {{{
 case realToFrac y of
   x -> x - int2Float (float2Int x)
 }}}
 failed due to using extended precision (so the result of realToFrac wasn't
 really 1.0, float2Int x was 0, result finally rounded to 1 anyway) when
 compiled with optimisations but without -msse2.
 I don't know whether that can also happen with
 {{{
 case realToFrac y of
   1.0 -> 0.0
   x   -> x
 }}}
 It would take someone who knows what's actually going on in the FPU (and
 code generator).

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5133#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to