[GHC] #15271: 1e1000000000 :: Double yields 0.0 instead of Infinity

GHC ghc-devs at haskell.org
Thu Jun 14 04:19:44 UTC 2018


#15271: 1e1000000000 :: Double yields 0.0 instead of Infinity
-------------------------------------+-------------------------------------
        Reporter:  claude            |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:  8.6.1
       Component:  Compiler          |              Version:  8.4.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Incorrect result  |  Unknown/Multiple
  at runtime                         |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by sighingnow):

 Currently we store literal rationals as `Rational` in parsed ast, that
 means, for `1e5`, we will have:

 {{{#!hs
 (HsFractional
     (FL (SourceText "1e1000")
         (False)
         (:% (100000) (1))))
 }}}

 Note that we have evaluate `1e5` as `100000`. A possible fix for this
 problem would be:

 1. In `readRational__` (in compiler/utils/Util.hs), we only validate the
 format of literal numbers, don't evaluate it.
 2. We evaluate the literal to numeric value during code generation, after
 typechecking. Then we can know the type of the literal number and once
 when we know the value is larger than the maximum bound of `Float/Double`
 type, we can safely feed a `Infinity` value into the cell, without
 evaluating the whole literal string and knowing the true `Rational` value
 of the literal.

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


More information about the ghc-tickets mailing list