Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are Double constants truncated for display in VS?

The constant Math.Pi is, according to reflector and MSDN, equal to 3.14159265358979323846. When looking at the Math class in Visual Studio 2010, the value is displayed as 3.14159. Whom can I blame for truncating precious constants?

like image 496
mafu Avatar asked Sep 18 '10 17:09

mafu


2 Answers

I don't know why the OP isn't posting this, as it would clear things up so incredibly much, but you can reproduce as follows:

  • Open the IDE
  • Enter Math.PI into a .cs file.
  • Right-click on Math.PI and click on 'Go To Definition'

This opens up the Metadata file for Math, which contains the following:

    //
    // Summary:
    //     Represents the ratio of the circumference of a circle to its diameter, specified
    //     by the constant, π.
    public const double PI = 3.14159;
like image 88
mpeterson Avatar answered Oct 06 '22 23:10

mpeterson


Sorry to repeat myself, but how do you get that number? If I hover over the constant or print it in the Immediate or Watch window in VS2010, I get 3.1415926535897931, which is also the value I get when looking at mscorlib in Reflector.

While it is less precision than MSDN claims, it is still far better than the number you're talking about. VS has to pick a formatting for printing floating point numbers. With the results I see I find the default quite acceptable.

like image 32
Brian Rasmussen Avatar answered Oct 07 '22 01:10

Brian Rasmussen