#5688: instance Read Integer/Rational/Double readsPrec out of memory and crash 
due
to exponential notation
-------------------------------+--------------------------------------------
  Reporter:  gracjan           |          Owner:  igloo           
      Type:  bug               |         Status:  new             
  Priority:  highest           |      Milestone:  7.4.2           
 Component:  libraries/base    |        Version:  6.12.3          
Resolution:                    |       Keywords:                  
        Os:  Unknown/Multiple  |   Architecture:  Unknown/Multiple
   Failure:  Runtime crash     |     Difficulty:  Unknown         
  Testcase:                    |      Blockedby:                  
  Blocking:                    |        Related:                  
-------------------------------+--------------------------------------------

Comment(by maeder):

 something like:

 {{{
 convert :: RealFloat a => Rational -> Integer -> a
 convert frac expo =
   let d = fromRational (frac * 10 ^^ expo)
   in if abs expo + abs (fromIntegral (length (show $ numerator frac)
               - length (show $ denominator frac)))
         < fromIntegral (uncurry max $ floatRange d) then d
     else case (frac < 0, expo < 0) of
      (True, True) -> -0
      (True, False) -> -1/0
      (False, True) -> 0
      (False, False) -> 1/0
 }}}

 floatRange returns 1024 for Double (that's the maximal size of the binary
 exponent).
 The size of the rational does almost not matter.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5688#comment:50>
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