[GHC] #15081: Finite list becomes infinite after maping fractional function for high numbers

GHC ghc-devs at haskell.org
Tue Apr 24 13:42:45 UTC 2018


#15081: Finite list becomes infinite after maping fractional function for high
numbers
-------------------------------------+-------------------------------------
           Reporter:  Onsed          |             Owner:  (none)
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:  8.6.1
          Component:  Compiler       |           Version:  8.2.2
           Keywords:                 |  Operating System:  Linux
       Architecture:  x86_64         |   Type of failure:  Incorrect result
  (amd64)                            |  at runtime
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Tested with version 8.2.2 and 8.0.2 (stack lts-11.5, lts-9.21,
 nightly-2018-04-14) with GHC and GHCi on archlinux amd64.

 **Code that produces wrong results**
 {{{
 map (/2) [9007199254740990..9007199254740991]
 }}}

 **Expected behaviour**

 same as with low values:
 {{{
 map (/2) [5..6]
 }}}

 resulting in:


 {{{
 [2.5,3.0]
 }}}

 **Actual behaviour**

 resulting in an infinite list:


 {{{
 [4.503599627370495e15,4.5035996273704955e15,4.503599627370496e15..]
 }}}

 **Similar code that produces expected results**

 multiplication works:

 {{{
 map (*2) [9007199254740990..9007199254740991]
 }}}

 slightly smaller number work:

 {{{
 map (/2) [9007199254740989..9007199254740990]
 }}}

 using a comma to produce the same list works:


 {{{
 map (/2) [9007199254740990,9007199254740991]
 }}}

 **Similar code that also produces unexpected results**

 more elements in the list:


 {{{
 map (/2) [9007199254740990..9007199254740999]
 map (/2) [9007199254740990..9007199354740999]
 }}}


 substituting the number and doing calculations:


 {{{
 map (/2) [9007199254740990..9007199254740990+1]
 let a = 9007199254740990
 map (/2) [a..a+1]
 }}}


 using scan and fold:


 {{{
 foldl1 (/) [9007199254740990..9007199254740991]
 scanl1 (/) [9007199254740990..9007199254740991]
 }}}

 **Notes**

 This somehow only happens with high numbers when using fractional
 operations and using .. to construct the list.

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


More information about the ghc-tickets mailing list