0

使用 .NET 执行计算时应该记住什么?

例如,我对浮点错误知之甚少,但对 CodeProject 上的这个论坛帖子不熟悉。为了完善基于 .NET 的数学知识,我需要知道什么,以便我可以建议如何使用不同位大小的参数和结果。

4

2 回答 2

1

You need to remember that different numeric types have different ranges: take a look at the static MinValue and MaxValue properties. If you exceed these ranges (by addition, multiplication or whatever) then the answers won't be what you think they should be. (Numbers wrap around from the maximum back to the minimum.)

于 2010-11-03T11:27:55.707 回答
1

永远记住浮点存储二进制分数,即您的数字将用 2^(-n) 的总和系列表示,其中 n 是从 1 到(尾数大小)的任何整数,提升到某个指数 N。decimal用于财务计算。

还要记住,32 位处理器上的 64 位字读/写不是原子的,因此不是线程安全的。更一般地说,尽量不要期望共享的可变状态总是可以安全阅读。

于 2010-11-02T22:15:33.027 回答