Invalid Math.Pi constant

I know well that Double only has so many bits of precision, but we should still try to achieve high precision if possible. Therefore, of course, I do not expect to see this in the official .NET 4 library.

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

Why only 6 digits? It would be easy and free to use the exact value. I do not do any scientific work in .NET, but I am sure that others do this and they are surprised when Pi is inaccurate. The same goes for E.

Edit: This is configured to reflect constants in Visual Studio. See follow-up question

-one
math
source share
4 answers

Copy and paste from Math.cs into the source code for .NET 4.0:

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

I don’t know what you are watching.

It was reconstructed from the following question that you looked at automatically generated text that was created from assembly metadata when you use the Go To Definition context menu. Yes, the code that generates this text is used to format the default% f for public double constant values. Quite rarely, there are not many open constants that are double in the .NET environment. You can send a feedback report on connect.microsoft.com

+14
source share

A quick test shows that Console.WriteLine(Math.PI) outputs 3.14159265358979 , so how can this be true? You say that ToString() adds extra numbers by magic?

+4
source share

The problem is that all metadata constants are printed using the default printf () behavior, which should use% f, which ends up trimming what you see when you press F12 in VS on a constant. See This Question Are double constants truncated for display in VS?

+2
source share

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

More seriously, don't do the math in .NET unless you really know what you are doing.

0
source share

All Articles