gpt4 book ai didi

R 最大/最小可表示数

转载 作者:行者123 更新时间:2023-12-04 11:15:52 28 4
gpt4 key购买 nike

我正在尝试获得 R 中最大/最小的可表示数字。

输入“.Machine”后

我有:

$double.xmin
[1] 2.225074e-308

$double.xmax
[1] 1.797693e+308

但是,即使我在 R 命令提示符下输入 2.225074e-309 我也会得到 2.225074e-309 而不是预期的 0

如何找到加或减 1 会导致 Inf(加 1 到最大数)或 0(从最小数中减 1)的最大/最小数?

最佳答案

.Machine$double.xmin给出表示满足 IEEE 754 technical standard 要求的最小正数的值用于浮点计算。正如 Wikipedia article 中提到的在 double 浮点数上,该标准要求:

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.



正如 ?.Machine 的详细信息部分所指出的,R 的 double 表现正是如此。 :

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 的 double 表示的最小正值并查看精度损失的成本,请尝试以下操作:
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

关于R 最大/最小可表示数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38165221/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com