Math.Pi constant is wrong

后端 未结 3 1433
悲哀的现实
悲哀的现实 2021-01-26 04:55

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 o

相关标签:
3条回答
  • 2021-01-26 05:14

    You can use Pi = Math.acos(-1).

    More seriously, do not do math in .NET unless you really know what you're doing.

    0 讨论(0)
  • 2021-01-26 05:24

    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.

    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

    0 讨论(0)
  • 2021-01-26 05:25

    A quick test shows that Console.WriteLine(Math.PI) outputs 3.14159265358979 so how can this be true? Are you saying ToString() adds extra digits by magic?

    0 讨论(0)
提交回复
热议问题