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

The standard defines five basic formats that are named for their numeric base and the number of bits used in their interchange encoding. There are three binary floating-point basic formats (encoded with 32, 64 or 128 bits) and two decimal floating-point basic formats (encoded with 64 or 128 bits). The binary32 and binary64 formats are the single and double formats of IEEE 754-1985 respectively. A conforming implementation must fully implement at least one of the basic formats.
The standard also ...

2 Likes

CAROR567
(CarorDeHauteville)
August 7, 2021, 1:15pm
#3
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.