Math.Pi不变的是错误的的是、错误、Math、Pi

2023-09-04 01:28:03 作者:山月不知心底事

我很清楚地知道,一个双人间有只有这么多了precision位,但我们还是应该尝试,如果能够达到较高的精度。所以,我当然不希望看到这个在官方.NET 4的系统库。

I'm well aware that a Double has only so many bits of precision, but we should still try to achieve high accuracy if possible. So I certainly do not expect to see this in the official .NET 4 system library.

// Summary:
//     Represents the ratio of the circumference of a circle to its diameter,
//     specified by the constant, π.
public const double PI = 3.14159;

为什么只有6个数字?这将是很容易和免费使用的精确值。我没有做科学工作的.NET,但我相信其他人做的,他们都在为一个惊喜,当皮是不准确的。也是一样的如

Why only 6 digits? It would be easy and free to use an accurate value. I'm not doing scientific work in .NET, but I'm sure others do and they are in for a surprise when Pi is inaccurate. Same goes for E.

编辑:此调出约常量在Visual Studio中的反映。请参阅followup问题

This tuned out to be about reflection of constants in Visual Studio. See followup question

推荐答案

复制并Math.cs在.NET 4.0参考源粘贴:

Copy and pasted from Math.cs in the .NET 4.0 Reference Source:

  public const double PI = 3.14159265358979323846;
  public const double E  = 2.7182818284590452354;

不知道你在看什么。

No idea what you are looking at.

据反向工程,你看这是从程序集元数据,当您使用转到定义上下文菜单项创建的自动生成的文本后续问题。是的,code生成该文本显示使用默认%F公共双常数值格式。相当罕见顺便说一句,还有的没有的很多公共常量是双在.NET框架。您可以在connect.microsoft.com

It was reverse-engineered from a follow-up question that you looked at the auto-generated text that was created from the assembly metadata when you use the Go To Definition context menu item. Yes, the code that generates this text appears to use the default %f formatting on public double constant values. Quite rare btw, there are not a lot of public constants that are double in the .NET framework. You can file a feedback report at connect.microsoft.com