#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 igloo):

 OK, in the `Read Double/Float` instances, we now have access to the
 integer part, the fractional part, and the exponent. The remaining part of
 the problem is how to convert these into a `Double/Float`.

 One approach that doesn't work well is converting the `x.y` part and then
 multiplying by `(10 ^ z)`. For example, given `4.2e-1` we would like to
 get this `Double`:
 {{{
 Prelude> 0.42 :: Double
 0.42
 }}}
 but we would actually get this `Double`:
 {{{
 Prelude> (4.2 :: Double) * (10 ** (-1))
 0.42000000000000004
 }}}

 Something else that works with the current code, is:
 {{{
 Prelude> read (show (10 ^ 1000) ++ "e-1000") :: Double
 1.0
 }}}
 despite this:
 {{{
 Prelude> read (show (10 ^ 1000)) :: Double
 Infinity
 }}}
 and similarly
 {{{
 Prelude> read ("0." ++ replicate 1000 '0' ++ "1e1001") :: Double
 1.0
 }}}
 despite:
 {{{
 Prelude> read ("0." ++ replicate 1000 '0' ++ "1") :: Double
 0.0
 }}}

 So my thoughts are that the first example should be supported (i.e. give
 us 0.42), but the second and third should break (I'm not sure what they
 should return. Whichever of Infinity, -Infinity, NaN and 0.0 best fits the
 implementation, I guess).

 What do people think?

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