just a really random question but is the property Math.PI in javascript always 3.141592653589793 in every browser/engine?
+5
A:
I should hope so.
The ECMAScript Spec says:
15.8.1.6 PI
The Number value for π, the ratio of the circumference of a circle to its diameter, which is approximately
3.1415926535897932
.
SLaks
2010-10-29 02:38:18
"approximately" - doesn't that mean they could make it 3.1415926535897931 ? :-) Or even just 3.14159? Or even 3 for that matter.
paxdiablo
2010-10-29 02:50:50
Pretty sure they say "approximately" because PI is an irrational number (though the wording is admittedly confusing).
Ed Swangren
2010-10-29 02:58:32
The term "approximately" describes the relationship between 3.1415926535897932 and the exact value of PI. Earlier in the spec it is noted that the phrase "the Number value" has a technical meaning defined in section 8.5, which states that it must be the closest IEEE-754 double precision value. +1, but the answer would be improved by incorporating this information explicitly.
Philip Starhill
2010-10-29 03:20:13
yeah, it would be pretty interesting to know if those Math object static values like PI etc. are all the same in every javascript implementation... but i guess you're right.
Tobias
2010-10-29 19:55:11
A:
This is what the spec says about Math.PI
:
The Number value for π, the ratio of the circumference of a circle to its diameter, which is approximately 3.1415926535897932.
Note that it says "approximately", which means it makes no guarantees about the exact value. However since numbers are required to use the standard IEEE 754 representation, you can expect most implementations to have a similar accuracy.
casablanca
2010-10-29 02:41:44
It says "approximately" because PI is an irrational number. Remember 6th grade?
Ed Swangren
2010-10-29 02:48:26