R largest/smallest 可表示的数字
R largest/smallest representable numbers
我正在尝试在 R 中获取 largest/smallest 可表示的数字。
输入“.Machine”后
我得到了:
$double.xmin
[1] 2.225074e-308
$double.xmax
[1] 1.797693e+308
然而,即使我在 R 命令提示符下键入 2.225074e-309,我得到的是 2.225074e-309 而不是预期的 0
我如何找到 largest/smallest 数字,加 1 或减 1 会导致 Inf(最大数加 1)或 0(最小数减 1)?
.Machine$double.xmin
给出满足IEEE 754 technical standard for floating point computation. As is mentioned in the Wikipedia article对双精度浮点数要求的最小正数的值,该标准要求:
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 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 的双打行为正是这种方式,如 ?.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’.
要确认这是可以使用 R 的双精度表示的最小正值并查看精度损失的成本,请尝试如下操作:
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
这里有一些使用 SAS、IEEE 754 Big Endian 的表示法?
data _null_;
y=constant('big');
put y hex16.;
put y E21.3;
run;quit;
最大
7FEFFFFFFFFFFFFFF
1.79769313486230E+308
data _null_;
y=constant('small');
put y hex16.;
put y E21.3;
run;quit;
最小
0010000000000000
2.22507385850720E-308
我不确定最小值,因为 SAS 可能会留出一些缺失值。
我正在尝试在 R 中获取 largest/smallest 可表示的数字。
输入“.Machine”后
我得到了:
$double.xmin
[1] 2.225074e-308
$double.xmax
[1] 1.797693e+308
然而,即使我在 R 命令提示符下键入 2.225074e-309,我得到的是 2.225074e-309 而不是预期的 0
我如何找到 largest/smallest 数字,加 1 或减 1 会导致 Inf(最大数加 1)或 0(最小数减 1)?
.Machine$double.xmin
给出满足IEEE 754 technical standard for floating point computation. As is mentioned in the Wikipedia article对双精度浮点数要求的最小正数的值,该标准要求:
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 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 的双打行为正是这种方式,如 ?.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’.
要确认这是可以使用 R 的双精度表示的最小正值并查看精度损失的成本,请尝试如下操作:
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
这里有一些使用 SAS、IEEE 754 Big Endian 的表示法?
data _null_;
y=constant('big');
put y hex16.;
put y E21.3;
run;quit;
最大
7FEFFFFFFFFFFFFFF 1.79769313486230E+308
data _null_;
y=constant('small');
put y hex16.;
put y E21.3;
run;quit;
最小
0010000000000000 2.22507385850720E-308
我不确定最小值,因为 SAS 可能会留出一些缺失值。