views:

73

answers:

2

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
"approximately" - doesn't that mean they could make it 3.1415926535897931 ? :-) Or even just 3.14159? Or even 3 for that matter.
paxdiablo
Pretty sure they say "approximately" because PI is an irrational number (though the wording is admittedly confusing).
Ed Swangren
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
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
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
It says "approximately" because PI is an irrational number. Remember 6th grade?
Ed Swangren