Is java.lang.Math.PI equal to GCC's M_PI? -
I am coding many reference algorithms in both Java and C / C ++. Use some of these algorithms & pi; I want to generate identical results without having to score different goals for each of the algorithms. One way to do this has been continuously worked out using custom-defined pi constant which is similar in both languages, such as 3.1415 9 However, to define my pie Foolishly, when high-precision stability is already set in Java and GCC libraries.
I've spent some time, writing quick test programs, reading documents for each, and reading at floating-point types. But I'm not able to understand myself that java.lang.Math.PI (or java.lang.StrictMath.PI) is equivalent to M_PI in mathematics.
GCC 3.4.4 (Saigwin) includes math.h:
#define M_PI 3.14159265358979323846 ^^^^^ But this
printf ("% 20f", M_PI); produces
3.14159265358979311600 ^^^^^ Which states that relying on the last 5 digits can not be done.
Meanwhile, Jawadox says that java.lang.Math.PI is:
doublevalue which is close to any other Pi , the ratio of diameter of the circumference of a circle.
and
public static final double PI 3.141592653589793d which leaves the suspicious last five digits continuously is.
System.out.printf ("% .20f \ n", Math.PI); produces
3.14159265358979300000 ^^^^^ If you have something in the floating point data type Have expertise, can you please explain that these library constants are exactly the same? Or are they definitely not equal?
Note the following.
Two numbers are equal to 16 decimal places. This is approximately 48 bits that are similar.
In an IEEE 64-bit floating-point number, these are all bits that are not signal or exponent.
The # Defined M_PI has 21 digits; This is 63 bit accurate, which is good for IEEE 80-bit floating-point values.
I think you are seeing M_PI is a simple cut of bits> value.
Comments
Post a Comment