4 ms·
There was a post awhile back from NASA saying how many digits of Pi they actually need [1]. import math pi = 31415926535897932384626433832795028841971
by munro 4y ago
There was a post awhile back from NASA saying how many digits of Pi they actually need [1].
import math
pi = 3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148086513282306647093844609550582231725359408128481117450284102701938521105559644622948954930381964428810975665933446128475648233786783165271201909145648566923460348610454326648213393607260249141273724587006606315588174881520920962829254091715364367892590360
sign_bits = 1
sig_bits = math.ceil(math.log2(pi))
exp_bits = math.floor(math.log2(sig_bits))
assert sign_bits + sig_bits + exp_bits == 1209
I'm sure I got something wrong here, def off-by-one, but roughly it looks like it would need 1209-bit floats (2048-bit rounded up!). IDK, mildly interesting. :>
[1] https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimals-of-pi-do-we-really-need/ https://www.jpl.nasa.gov/edu/news/2016/3/16/how-many-decimal...
- vanderZwan 4y agoThe value of Pi you mention was the one in the question, the one in the answer is: > For JPL's highest accuracy calculations, which are for interplanetary navigation, we use 3.141592653589793. Let's look at this a little more closely to understand why we don't use more decimal places. I think we can even see that there are no physically realistic calculations scientists ever perform for which it is necessary to include nearly as many decimal points as you present. That's sixteen digits, so a quick trip to the dev tools tels me:: >> Math.log2(3141592653589793) -> 51.480417552782754 The last statement of the text I quoted is more interesting though. Although not surprising to me, given how many astronomers I know who joke that Pi equals three all the time.
- munro 4y agoLol I should RTFA ;D
- vanderZwan 4y agoNah, just claim you were invoking Cunningham's Law ;)
- Beltiras 4y agoI have horrid memories of debugging I had to do to get some god-awful fourier transform to calculate with 15 digits of precision to fit a spec. It's right at the boundary where double-precision stops being deterministic. Worst debugging week of my life.
- vanderZwan 4y ago> stops being deterministic I'm imagining the maths equivalent of Heisenbugs, is that correct?
- Beltiras 4y agoNo, just having to match how Matlab did the calculation (development of an index) to implementing the same thing in C++ (necessitating showing the calculation returned same significant digits for the precision we expected). I've seen a Heisenbug and that was really weird. Happened during uni so I didn't have to start tracing down compiler bugs. Not even sure if I could, happened with Java.
- PaulDavisThe1st 4y agoThe size of required data types is mostly orthogonal to the size of memory addresses or filesystem offsets.
- jabl 4y agoPi is a bit special because in order to get accurate argument reduction for trigonometric functions you needs lots of digits (IIRC ~1000 for double precision). E.g. https://redirect.cs.umbc.edu/~phatak/645/supl/Ng-ArgReduction.pdf https://redirect.cs.umbc.edu/~phatak/645/supl/Ng-ArgReductio...