为什么 MSTest 向导使用双打的 F 后缀而不是 D?
当我使用 MS Visual Studio 的内置单元测试向导创建测试时,它会创建如下所示的代码:
double number = 0F;
在 C# 中,“F”代表浮点型、与大小写无关,“D”代表双精度型。 使用“F”后缀而不是“D”会导致精度丢失。
如果是错误,我可以在哪里向 Microsoft 报告?
When I create a test using MS Visual Studio's builtin unit test wizard it creates code with lines like the below:
double number = 0F;
In C# "F" stands for float, case-independent, and "D" for double. Using "F" suffix instead of "D" leads to precision lost.
If it's a bug, where can I report it to Microsoft?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不明白这怎么可能只是一个错误。 在这种情况下完全无害,但仍然是一个错误。 您可以使用 Connect 报告此类情况。 然而,我已经清除了比这更重要的错误,所以我不期望采取太多行动。
I don't see how that could be anything but a bug. Completely harmless in this case, but still a bug. You can use Connect to report this kind of thing. However, I've had much more important bugs swept aside than this so I wouldn't expect much action.
如果该值始终为 0F,则根本不会丢失任何信息。
一般来说,任何浮点数都可以转换为双精度数,而不会损失精度(假设是 IEEE 754)。
只要测试值不需要截断来表示为浮点数,那么正确性就没有问题。 最终用户感到困惑以及想要修改值时增加的麻烦仍然是一个问题。
If the value is always 0F then no information will be lost at all.
In general any float can be converted to a double with no loss of precision (IEEE 754 assumed).
So long as the test value has not needed truncation to be represented as a float then there is no problem with regards to correctness. The confusion to end users and increased hassle when wanting to modify the values is still a problem.
如果您使用十进制(M 后缀),那么您不必担心它有估计错误或精度损失。
If you use a Decimal (M suffix) then you don't have to worry about it having estimation errors or precision loss.