gpt4 book ai didi

excel - 为什么 Excel 不根据 8 字节 IEEE 754 进行舍入

转载 作者:行者123 更新时间:2023-12-02 06:10:29 32 4
gpt4 key购买 nike

以下表达式在 C# 中的计算结果为 false:

(1 + 1 + 0.85) / 3 <= 0.95

我想在大多数实现 IEEE 754 的其他编程语言中也是如此,因为 (1 + 1 + 0.85)/3 的计算结果为 0.95000000000000007,这是更大的低于 0.95

但是,尽管 Excel should implement most of IEEE 754 too ,以下在 Excel 2013 中计算结果为 TRUE:

= ((1 + 1 + 0.85) / 3 <= 0.95)

有什么具体原因吗?上面链接的文章没有提到任何可能导致此行为的 Excel 自定义实现。你能告诉 Excel 严格按照 IEEE 754 进行舍入吗?

请注意,尽管大多数 Excel 问题都应在 superuser.com 上提出,但该问题涉及浮点运算,这是编程语言中的常见问题。从这个问题的主题来看,Excel 是一种类似于 C# 或 Java 的编程语言。

最佳答案

article that you linked to 明确表示要执行一些接近 0 的非标准操作:

Example when a value reaches zero 1.In Excel 95 or earlier, enter the following into a new workbook: A1: =1.333+1.225-1.333-1.225

2.Right-click cell A1, and then click Format Cells. On the Number tab, click Scientific under Category. Set the Decimal places to 15. Instead of displaying 0, Excel 95 displays -2.22044604925031E-16.

Excel 97, however, introduced an optimization that attempts to correct for this problem. Should an addition or subtraction operation result in a value at or very close to zero, Excel 97 and later will compensate for any error introduced as a result of converting an operand to and from binary.

未指定的“尝试纠正此问题的优化”确实意味着,当需要与 IEEE 754 严格一致时,在使用 Excel 进行数值计算时应谨慎行事。也许使用 VBA(不太可能有这种“优化”?)可能是一种解决方法。

关于excel - 为什么 Excel 不根据 8 字节 IEEE 754 进行舍入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36452194/

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