#5118: Numeric.floatToDigits fails for large floatRange
--------------------------------+-------------------------------------------
    Reporter:  claudiusmaximus  |       Owner:                             
        Type:  bug              |      Status:  new                        
    Priority:  normal           |   Component:  libraries/base             
     Version:  6.12.3           |    Keywords:                             
    Testcase:                   |   Blockedby:                             
          Os:  Linux            |    Blocking:                             
Architecture:  x86_64 (amd64)   |     Failure:  Incorrect result at runtime
--------------------------------+-------------------------------------------
Changes (by daniel.is.fischer):

 * cc: daniel.is.fischer@… (added)


Comment:

 You get underflow with `floatRange _ = (minBound, maxBound)`:
 {{{
 floatToDigits base x =
  let
   (f0, e0) = decodeFloat x
   (minExp0, _) = floatRange x
   p = floatDigits x
   b = floatRadix x
   minExp = minExp0 - p -- the real minimum exponent
   -- Haskell requires that f be adjusted so denormalized numbers
   -- will have an impossibly low exponent.  Adjust for this.
   (f, e) =
    let n = minExp - e0 in
    if n > 0 then (f0 `quot` (expt b n), e0+n) else (f0, e0)
 }}}
 So with 64 bits of precision, you try to compute
 {{{
 (771*2^54) `quot` 2^(maxBound-63-(-54))
 }}}
 which will take some time and a lot of memory if it succeeds at all,
 resulting in a 0 where a positive integer is required, leading to an
 infinite recursion a few lines later.

 Even with the halved `floatRange`, for `HugeFloat`s of very small or very
 large modulus, `floatToDigits` will perform abysmally bad if it succeeds
 at all.

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

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to