'the most accurate approximation of pi in IEEE-754 float64?

what is the most accurate approximation of pi possible in IEEE-754 float64?

fwiw it seems both Javascript and PHP use 3.141592653589793115997963468544185161590576171875 , which might be the answer, i don't know.



Solution 1:[1]

Yes, 3.141592653589793115997963468544185161590576171875 is the IEEE-754 binary641 number closest to ?. It can also be written as a hexadecimal floating-point constant, 0x1.921fb54442d18p1. (I keep 0x3.243f6a8885a308d313198a2e03707344ap0L on hand to have the value for wider formats as well.) The C standard requires C implementations that use a base-two floating-point format to correctly round hexadecimal floating-point constants, and it does not require that for decimal floating-point constants, so you may be more likely to get a correct result when you use the hexadecimal form.

Footnote

1 IEEE-754 2008 uses “binary64” for the standard 64-bit base-two format. It is also called “double precision.” Some programming languages might call it float64 or Float64.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1