十进制数学是否使用 FPU
十进制数学是否使用 FPU?
我认为答案是肯定的,但我不确定,因为小数不是浮点数,而是固定精度的数字。
我主要寻找.NET,但一般答案也很有用。
Does decimal math use the FPU?
I would think that the answer is yes, but I'm not sure, since a decimal is not a floating point, but a fixed precision number.
I'm looking mostly for .NET, but a general answer would be useful too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 .NET,更具体地说是 C#,不,System.Decimal 不使用 FPU,因为该类型是在软件中模拟的。
另外,
System.Decimal
是浮点数,而不是数据库中常见的固定精度数字。该类型实际上是一个十进制浮点,它使用 10 作为其基数,而不是二进制浮点(即System.Single
或System.Double
),它使用 2 作为基数。如果您尝试存储无法精确表示的分数(例如 1/3),它仍然存在相同的精度问题。With regards to .NET and more specifically C#, no,
System.Decimal
does not use the FPU because the type is emulated in software.Also,
System.Decimal
is a floating point number, not a fixed precision number like commonly found in a database. The type is actually a decimal floating point that uses 10 for its base as opposed to a binary floating point (i.e.System.Single
orSystem.Double
) which uses 2 as its base. It still has the same precision problems if you attempt to store a fraction that cannot be exactly represented, for example, 1/3.是的,现代语言通常支持浮点数学和整数数学,仅此而已;不直接支持定点、BCD 等。浮点数学将使用浮点处理器指令完成;现代架构不包含单独的 FPU。
Yes, modern languages in general support floating point math and integer math, and that's it; there's no direct support for fixed point, BCD, etc. Floating-point math is going to be done using floating-point processor instructions; modern architectures don't include a separate FPU.