R largest/smallest representable numbers

后端 未结 2 647
南旧
南旧 2021-02-19 03:51

I\'m trying to get the largest/smallest representable number in R.

After typing \".Machine\"

I got:

$double.xmin
[1] 2.225074e-308

$double.xmax
         


        
2条回答
  •  失恋的感觉
    2021-02-19 04:49

    .Machine$double.xmin gives the value of the smallest positive number whose representation meets the requirements of IEEE 754 technical standard for floating point computation. As is mentioned in the Wikipedia article on double-precision floating point numbers, that standard requires that:

    If a decimal string with at most 15 significant digits is converted to IEEE 754 double precision representation and then converted back to a string with the same number of significant digits, then the final string should match the original. If an IEEE 754 double precision is converted to a decimal string with at least 17 significant digits and then converted back to double, then the final number must match the original.

    The same article goes on to note that, by compromising precision, even smaller positive numbers (which do not meet the standards' precision requirements) can be represented:

    The 11 bit width of the exponent allows the representation of numbers between 10-308 and 10308, with full 15–17 decimal digits precision. By compromising precision, the subnormal representation allows even smaller values up to about 5 × 10-324.

    R's doubles behave in exactly this way, as is noted in the Details section of ?.Machine:

    Note that on most platforms smaller positive values than ‘.Machine$double.xmin’ can occur. On a typical R platform the smallest positive double is about ‘5e-324’.

    To confirm that that is the smallest positive value that can be represented using R's doubles and to see the cost in loss of precision, try out a few operations like this:

    5e-324
    # [1] 4.940656e-324
    2e-324
    # [1] 0
    1.4 * 5e-324
    # [1] 4.940656e-324
    1.6 * 5e-324
    # [1] 9.881313e-324
    

提交回复
热议问题