Is Lua's math.pi results even correct?

Warning: if this is a wrong category just tell me instead of flagging this

so, math.pi in Lua would gives the value:

3.1415926535898

but I think this isn’t even right

this is the first 15 numbers of pi I searched:

3.14159265358979

I can see it was rounded, but which one should I use, standard ones or the ones that I searched?

Lua uses double precision which allows for 15 digits of precision. Even if you add more they aren’t guaranteed to be precise

2 Likes

Actually, the one you found is rounded too.
But anyway, I would recommend to use the math.pi one. I don’t think that 0.00000000000001 really matters.

2 Likes

well, I didn’t use it for math purposes

You don’t really need that many digits of pi; 3.1416 is really all you need.

Pi is an irrational number, you can’t write it without rounding somewhere. However, it gets to the point where the rounding only makes a negligible difference (it can be ignored). The 13 decimals provided in math.pi are enough to get an accurate result in any calculations you will need.