Why does the number 1e9999… (31 9s) cause problems in R?

前端 未结 3 1526
执笔经年
执笔经年 2021-02-05 01:16

When entering 1e9999999999999999999999999999999 into R, R hangs and will not respond - requiring it to be terminated.

It seems to happen across 3 different

3条回答
  •  鱼传尺愫
    2021-02-05 01:39

    This is interesting, but I think R has systemic problems with parsing numbers that have very large exponents:

    > 1e10000000000000000000000000000000
    [1] 0
    > 1e1000000000000000000000000000000
    [1] Inf
    > 1e100000000000000000000
    [1] Inf
    > 1e10000000000000000000
    [1] 0
    > 1e1000
    [1] Inf
    > 1e100
    [1] 1e+100
    

    There we go, finally something reasonable. According to this output and Joshua Ulrich's comment below, R appears to support representing numbers up to about 2e308 and parsing numbers with exponents up to about +2*10^9, but it cannot represent them. After that, there is undefined behavior apparently due to overflow.

提交回复
热议问题