Hacker News new | ask | show | jobs
by xanthine 1380 days ago
I happened to notice that PI is #define'd to 3.1415926538, which isn't the correctly rounded off value of 3.14159265358...

Seems like they missed a '5'.

4 comments

That’s a little bit more accuracy than what is needed for this post, but good catch :-) https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimal...
Thats an interestring post, thank you! Do you think that's why for example JavaScripts Math.PI also comes out to 3.141592653589793?
Not really, that's more related to the fixed precision of IEEE 754 floating-point numbers. In any fixed-precision representation there's always a certain representation which happens to be the best approximation of any constant like pi. That's the one you would pick.

However, you could perhaps infer from the article that IEEE 754 double-precision numbers are sufficient for most physical calculations.

It must be either a coincidence or backwards. Math.PI is a double precision floating point number that is set to a closest value of pi that could fit in its 64-bit encoding. https://en.m.wikipedia.org/wiki/Double-precision_floating-po...
Other way around, they use that value because that's the most precision you get with IEEE-754 64-bit floating-point numbers, which is the representation also used by JS for floating-point.
Lol, wow what a find. You notice the details. I corrected it. Thank you.
At school, I somehow talked myself into a dumb competition with my math geek about memorizing digits of pi.

I won, with 35 digits memorized (he gave up early; that's also around where the first '0' occurs in pi).

I don't miss any opportunities to test that I still remember them correctly, to this day. ;)

I had a hard time getting past the "399" out about 43. I wanted to round it to "4".

But these days I would rather memorize tau:

  6.28318530717958647692528676655900576839433879875021
It has that "00" at 27 digits in that must be got past.
Interesting point if it had been apparent it would have been an issue, at what point does a poor Pi become an issue?

What would a Pi of 3.0 do?

Here's a presentation show what happens to rendering in the game Doom when π has different values.

https://media.ccc.de/v/mch2022-236-non-euclidean-doom-what-h...

A professor comes around and criticizes it as it is about to become law:

- https://en.wikipedia.org/wiki/Indiana_Pi_Bill

- https://www.straightdope.com/21341975/did-a-state-legislatur...

The value was superior to mathematical Pi (as is best float approximation, but not best double approximation), such as having 2*PI normalized into [0,2*Pi] by standard trigonometric functions (which use accurate approximations of Pi) would not preserve it and yield a value close to 4.2e-10, which could cause suprises (for example if angular ranges are defined as (start,end) and not (start,span)).
In this case not a lot happens since it's only used for Z rotation.
I'm surprised you'd have to define pi in a fragment shader at all. Surely such a commonly used constant would be defined in the language/headers already?
You should always define Pi in your code, in case the value ever changes.
I've always though about that fact myself. Can somone find the answer to why didn't the GLSL designers / video card driver people make PI built into their language?