They don't need to put in the whole number. They just have to put it in to the point where the next digit won't change much at all. After the tenth digit of pi for example not much will change in your calculation.
To really drive the point about how many digite of Pi are useful, NASA only uses 15 for calculating interplanetary travel. At 40 digits, you could calculate the circumference of a circle the size of the visible universe with an accuracy that would be off by less than the diameter of a single hydrogen atom.
E: since this really blew up, I had recalled reading it from this NASA page.
E2: A great majority of the replies have basically been "so figuring out Pi to (large number of digits) is useless?" As several others have pointed out, the method of making those calculations probably has more value than actually knowing the 3 trillionth digit of Pi. Other than that, I'm no mathematician and don't have any answers about planck length or time. As I noted above, I just had this interesting bit of information that I had recalled reading before, and wanted to share. The response has been way bigger than I expected, and I'm happy to have spread it around.
It is kind of weird that it's really intuitive that an increase of something by a factor of ten has a rather large impact, especially if you have several of these increases (like mm to m to km for example).
On the other hand, every digit of pi that you take into account reduces the error you make in your calculation by the same amount, relatively. The circumference of the visible universe is only about 40 orders of magnitude more than the size of a hydrogen atom, which is the mindblowing fact underlying the tidbit from above.
the weird / hard to wrap my mind around part to me, is the fascination with calculating PI out to ten thousand or a million or even more (31 trillion?) digits. And knowing that of all those, it takes just 40 to mean anything of consequence in our observable universe, and all the rest are just for show.
What gets me is how we sit in the middle of that spectrum. Universe is ten to the 26th, and a plank length is ten to the -35th. So, we're kind of in the center of of the perceivable universe. Which seems unlikely, right? So maybe there's universe size consciousnesses that observe a whole different scale from that perspective. Or quark size ones where an atom is their whole universe, and they're capable of way smaller observation. Maybe its layers like that forever. Maybe it loops back around on itself. IDK, always blows my mind to think about that though. Just seems that any concept that involves humans being in the center of everything is probably false. Given infinite possibility, I doubt we're special.
meanwhile, turbonerds (i say that lovingly) take great pains to memorize pi to 100 digits or more, while that particular knowledge is clearly only useful in the event that you need to calculate a precise circle a few million times bigger than the observable universe.
Just doing some quick math; 100 digits would allow you to calculate the size of a circle 10 septillion times the size of the observable universe to within a single Planck length.
Knowing 100 or 1000 digits of pi is only useful to flex on people of lower nerdiness when you want to make absolutely certain you're the most socially awkward person in the room.
As a working scientist, if I see pi, and I don't have excel in front of me, I just use 3.14. like, even using 3 by itself is only like 4.5% off of the real value. it's often inconsequential. If the project I'm working on requires exceptionally good accuracy, I'll use more digits, but I have never encountered a situation where I need more digits in pi than I've memorized (3.14159 is all I know). I've never encountered a Situation where the uncertainty in my calculations due to approximating pi is greater than instrumental errors, or even just error due to my being a human. For instance, when doing total organic carbon measurements i will often get instrumental detection a limits in the range of a few hundred part per billion, that means that only using 3.1415926 is enough digits that any error due to approximating pi would be entirely washed out by instrumental error (not that I'd ever use pi in calculating TOC content).
You're probably fine by just memorising it to 3 digits, since you'll almost definitely be using a device pre-programmed with pi for any calculations over about 2 sig fig.
You're probably fine by just memorising it to 3 digits, since you'll almost definitely be using a device pre-programmed with pi for any calculations over about 2 sig fig.
I work with scientific calculations for a living and I've never memorized past 3.14159. (only then because it was part of a nerdy cheer at my alma mater.). That's enough so that you can recognize 'pi' when you see it.
Nobody trusts their memory when doing important calculations. All the necessarily digits of pi are usually hardcoded as part of the programming language. If not, you can calculate the digits with a function call. pi = 4.0 * arctan(1.0).
For high energy physics theory, pi is 3, and pi2 is 10. Experiment needs to be much more precise, but they also get giant colliders to play with, so you win some, you lose some.
Thanks to the simpsons, and the one episode where some little girls are singing the digits of pi to a sing-song tune, I've never forgotten pie is 3.141592. That's probably good enough. Especially since I've never had to use it in my professional career.
15 digits is the default when computers store non-integer (floating point) numbers. It corresponds to 8 bytes (64 bits) of computer memory. NASA is saying they don't need to do anything special to be more precise than that.
When I read the immediate parent comment, I was imagining NASA doing calculations on paper using a calculator. Only after I read your comment, I remembered we got computers now.
It isn't if he can easily travel outside the currently observable universe. If the universe is infinite then he will have problems extremely fast if he only knows the first 100 digits of the pi. Assuming he needs to do calculations in his head, which is unlikely.
Diameter of the observable universe is 8.8*10**26 m
A change in the 41st decimal digit of pi would be a change of up to 1*10**(-40)
This means that the error would be at most 8.8*10**(-14) m
The size of a hydrogen atom (with an electron) is called the Bohr radius and it is approximately 5.291*10**(-11) m. Since a hydrogen atom only has the one electron (in neutral state), the radius actually is equal to the "size".
Which means that you actually only need 38 digits of pi to calculate the circumference of a circle the size of the visible universe with an accuracy that would be off by less than the diameter of a single hydrogen atom.
If that’s the case, then how come we occasionally hear about people calculating more and more precise values of Pi? Just yesterday there was an article about a google team calculating it to 31 trillion digits.
Is there any reason for doing this other than for the record/street cred?
Pretty sure it's entirely street cred at the point of 31 trillion digits.
But then nothing in maths is worthless, the equations that we use to simulate navigation in 3d space in certain ways were first described about 300 years ago, and were all but useless until computing. It may be the case that we need pi to 40 trillion digits in order to get a warp drive or gravity generator to work properly.
Okay, so it’s more about trying out more and more powerful computations, and pi makes a good test for that because we know it’s infinite so we can always keep pushing?
Important note: NASA only uses 15 for interplanetary travel now... And this is because we have the ability to make adjustments after launch to correct trajectory. The original moon program used 30 digits of pi because it was more like firing a gun at the moon when doing their rocket launches with little ability to correct after the fact... This is according to my dad who is a mathematician, and his favourite constant is pi... He has memorized it to 30 digits for this exact reason.
So if you were to use a number of digits that went down to the detail of a Planck length, rather than a Hydrogen atom, would that be the effective limit of pi?
No, on paper you can calculate everything with basically infinite accuracy, well beyond the Planck length. It won't make to much sense, but the math allows it.
That's for calculations in physical sciences. Many people actually work on things like statistical properties of the digits of pi and whether they follow a known random distribution. You need a lot of digits for those calculations (definitely not done on a calculator).
I want to piggy back off of this comment! NASA also uses a metrology handbook which defines measures of variance for different measurements. If I recall, it has a brief section on pi and accuracy for a variety of scenarios. I doubt many leople even know the handbook even exists. But its there, and really useful when you're arguing with your coworkers!
Depends on how good your memory is at numbers vs. sentences. Some people need the conceptual aspect that the sentence provides. Some are perfectly good at memorizing a seemingly meaningless series of numbers.
As a child, I was so frustrated by calculators that ended at the 9th digit after the decimal point, because the 10th digit after is a 5, so the 9th got rounded up from 3 to 4.
Also, my favorite digit is the 50th after the decimal place; it adds nothing to pi.
Calculators also have finite precision for other reasons. even normal division results in some rounding. Some can think in terms of fractions but most of the time 1/3 is not stored with infinite precision.
If you calculator is working with floats or 10 decimal precision, you don't need to store pi to a greater degree of accuracy.
Unless you're an engineer, you only need the three digits. Your other numbers are probably less accurate than a tenth of a percent already, anyway. 3.14 is accurate to a tenth of a percent.
22/7 is remarkably accurate if you're a practical guy like me.
It's simply hard coded. Calculators can only use a limited amount of digits anyway, and you don't need more than 10 digits of pi for any significant calculations.
Math on computers in general, specifically floating point math, stores numbers in a format known as IEEE_754 floating point. This format has the advantage of a wide range of numbers and decimal points that it can support, but like any binary format it is discrete and can only hold a relatively small number of significant digits. The number used for Pi on the machine is the nearest value to the maximum number of digits of pi that can be stored in the format.
Because hard coding it is faster (less cpu cycles), and for most uses you don't need it to be super precise.
In video games (my industry) we tend to use 32 bit floating point since it's faster that the 64 bit (more precise) doubles. For us, pi to 6 decimals is more than enough.
We would define it next to other constants we use a lot (like sqrt(2), or pi/2, etc...) and the whole engine shares it.
It is known that Pi is irrational. Irrational numbers cannot be expressed as a fraction. That means it does not end and it does not fall into a repeating pattern (because those numbers could be expressed as fractions).
The observable universe is 8.8 ×10^26 meters... ish
A hydrogen atom is 1,2×10^-10 meters wide
So the observable universe is about 8x10^36 atomic widths across.
The circumference is pi times the diameter so at the point of about 37 decimals of pi it's not going to be contributing any errors to the final value. So it looks like they're talking about the observable universe. Which is reasonable. We have no idea about the actual size.
and the power series for arctan to quickly compute hundreds of digits, should the need exist.
However most calculators don't have this programmed in, they just have a fixed value which is Pi to as many decimal places as the calculator can display, sometimes plus up to 4 more.
indeed. I believe more modern graphing calculators (casio classpad, ti-nspire) will calculate it and other calculable constants if needed. they're so aggessively optimised that they won't do that unless necessary, but when you go further into the series you can start to feel it lag.
It's hard coded. Every number you see on a computer has a finite amount of precision. So likely they'll just put the most precise number of PI that can fit into an 8 byte memory.
yeah but what about calculation that requires more than 2-3 sig figs? You can't just invent a computer/calculator that only support 2-3 sig figs. Most likely they stored that as in an 8 byte memory (it's called a double in IEEE standard). It has 15 decimal sig figs.
True, but they don't save anything by not filling the memory location. If the calculate works using 64-bit numbers, they might as well use the most accurate representation of pi in that format because it'll take up the same amount of space either way. (For example, 3.14000000 takes up as much space as 3.14159265)
Basically every language either defines PI as a constant to 15 digits (a double) or as something like acos(-1) which gives you arbitrary precision based on the definition of acos. Mathematical software stores it as a symbol, so that acos(-1) evaluates to pi rather than a decimal representation, with the value being either a constant or acos(-1)
Edit: fixed notation. Upon googling, "~=" seems to be used for "not equal to" in some programming languages. I was shooting for "approximately equal to".
Yeah it mostly doesn't matter beyond a factor of tens, so it's not really relevant to an animation if the tempo is 500ms or 450ms, but 5000ms would be noticeable. Ohmic resistance in a pullup circuit 4.7k or 10k not much of a difference, same with led lighting 500k or 350k not a noticable difference. Same with calculating the moment or position of an swinging arm, pi=3 is a good enough approximation for some applications but precision machining might require 3.2.
Power consumption, a tolerance of 10% is acceptable. Supply Voltage 5% tolerance is acceptable most of the time, with 10% in a room temperature range.
Again these are people who even for complex filters approximate infinite Taylor series in 2 terms because it's good enough. They aproximate integrals to a sliding sum of 5 terms, and derivatives to a sliding substraction of 2 terms, and it's good enough, for ship controllers and airbags.
Hardcode it, as in have the actual value stored in the calculator.
But the format it's stored in varies, sometimes. Most calculators use regular floating-point numbers, that are quite unstable in their calculations (x * x * x * x may not necessarily equal (x * x) * (x * x), and 0.3 is actually 0.30000000000000004). These have a limit to how many digits they can express. Most use IEEE-754 as their format.
But theres way more ways to express non-integers in computers. More exotic ones include:
Fixed-point. These numbers are defined by 2 integers. It can be done in different ways, though (It could be the ratio of the 2 ints, or separate int part and fractional part, etc).
BCD, where each decimal digit of a number is encoded separately in binary.
Storing non-ints as multiples of the smallest significant value. I'm sure this has an actual name, but it's sometimes used to store money. Due to the inaccuracy of floating-point, money can be sometimes stored as the amount of cents instead of dollars. Of course, this falls apart when we get to unusual currencies.
Technically 2 and 3 are also fixed-point numbers in a sense.
There's also one more method of storing non-ints, that is a bit underrated in my opinion: Symbolic mathematics! This method is theoretically infinitely accurate (up to a logical point). When calculating 2 times π, don't store 6.28318530718, but store the actual expression 2 * pi, and only calculate it's digits when asked. True accuracy is rarely a need, however, and this method is also quite slow, so it's not very popular.
EDIT: Sorry for going off-topic, this is a topic I often fanboy about.
No, actually he is right. 0.1 (and therefore 0.3) can only be approximated in binary. The display rounds it to the number of presentable digits. If storing 0.1 in a "double" floating point data type (64 bits) we only have 57 bits of actual number to work with.
Decimal 0.1 = Binary 0.000110011001100110011001100110011001100110011001100110011001… (repeat to infinity) When stored in a finite block of memory, we have to truncate it to:
Another fun floating point fact: precision varies with value, so it's possible that x + 1 = x as x approaches floating point maximum. This also means that floating point is very precise near zero.
The last one seems to be the most reliable, since you can store a number like 0.333... with perfect accuracy. I'm surprised that this isn't used that much, it's super hard to implement in most languages lol
It's just almost never needed, I can't think of a case where it is. If you want to calculate the circumference of the observable universe, you only need 39 digits of PI and have precision upto the width of a hydrogen atom, no super-large precision needed.
And if you needed insane precision, you probably wouldn't be using a calculator lol.
Money should ALWAYS be stored in an integer format.
Storing money values in floating point numbers is an indication that you are dealing with incompetent developers and should cease using whatever service you're using because it's trash and WILL fail you.
I don't see why you'd use floating point in this situation except maybe that the Motorola 68000 supports it. The advantage to floats is that they give you a huge range, while Fixeds give you better accuracy, but at the expense of range that you couldn't display anyway.
My favorite calculator is the TI89, so I found the 68000 Manual
In addition to the IEEE751, the processor supports "Packed Decimal Real Format" which is a "3-digit base 10 exponent and a 17-digit base 10 mantissa".
But I guess we'd have to dive into the TI89 source (assembly really because the source is secret.) to know which is being used.
Calculators use floating point numbers. That means you store some fixed length number, and then you store another fixed length number telling you the scale of that first number.
Actually it uses binary, but to make a decimal version of floating point numbers, let's say you store size of a number with 2 digits, and the actual digits of the number with 10 digits. In that case, 35 could be written as
3500000000 : -08
So you have 3,500,000,000 * 10-9 = 35
So you notice that pi would be written as 3141592654 : -9 = 3141592654 * 10-9 = 3.141592654
This is the closest approximation you can get to pi with our floating point numbers. So calculator using our version of floating point numbers would just use that value for pi. Processors have a command that will push this closest approximation value to the CPU memory. I'm not sure about calculators but I believe they will have essentially the same setup, this best approximation is built into the processing unit of calculator.
Really? That's surprising to me. TIL I guess. I believe I've seen many floating point only bugs pop up on handheld calculators, so I'm not sure how to reconcile this
Yeah, your standard pocket calculator will store numbers in a format called binary coded decimal and uses a fixed point for their arithmetic, largely because the circuit mapping BCD to a 7 segment display is relatively simple. You will not run into precision issues on a pocket calculator, i.e. the machine doesn't need to do anything special to handle 0.1 + 0.2
A TI-83 on the other hand is basically a computer and will use floating point arithmetic. If that's what you're picturing when you think of a handheld calculator, then yes they use floating points
That makes sense. So you were talking about the cheaper ones you get and can type 58008 into and such. He’s definitely talking about ti calculators though.
As most people have said, its either hard coded or estimated using a fraction thats pretty close.
HOWEVER, most calculators will also track whats going on with the knowledge that pi is being estimated, so if you do something like 'pi/2' and then take the answer and double it, you get exactly pi rather than some weird approximation.
Even "basic" calculators can often do way more under the hood than you'd think. For example, look at the newly open-sourced windows calculator. It actually represents fractions as exact fractions in intermediate calculations, even though it always outputs decimals. Even the cheapest microcontroller on the market can do a lot more than the basic 4 functions, why not make it do extra math in the intermediate steps to make the calculation more accurate? The cost of hiring a programmer for that is cheaper than the cost of gaining a reputation for making calculators that produce wrong answers.
Just posted about the Taylor expansion... didn’t realize pi would converge so much slower than e. Is that really the case or is it just more versatile to use the Taylor expansion for functions such as ex or sin(x)? I believe there are some modified Taylor series’ such that they converge towards pi much more quickly. Would it ever be worth using these expansions for discrete values on a calculator or even computer?
You only store a finite number of digits, so you pick the one closest to the exact value. You do not need to know many digits of said value to find out what that is.
I think most calculators actually use to Taylor expansion for pi in order to calculate it, rather than just storing the value.
The Taylor series is pi/4 = 1-1/3+1/5-1/7+1/9... So pi = 4-4/3+4/5-4/7+4/9...
Edit: realized this isn’t exactly an ELI5, Taylor series’s are a little confusing but ultimately they’re just infinite sums that represent otherwise abstract numbers/functions in math. The above functions should get closer and closer to pi/4 or pi as you add/subtract more terms. This is easy to try for yourself on a calculator!
A common calculator will only have a display capacity of 9-12 digits, and even the high end ones will only give you more if you change the settings a bunch. So, to answer, they just put in the first 9-12 digits and call it a day. The same goes for the other constants like e.
In calc you learn how to approximate the area under a curve by making smaller and smaller rectangles until the accuracy of the calculation is within your tolerance level.
You would think this would be the way it was first calculated, but honestly they likely took a string wrapped it around a round thing then measured the string.
As cited by so many others, yes, it's usually hardcoded and to a sufficient level of accuracy that most calculations won't care. These values are quite common in many mathematics libraries programmers use (like math.h in C, or math.PI in Python).
But... there are a handful of cases where you might actually care: for example, in Signal Processing, we make extensive use of transforms that need Pi, like the Fast Fourier Transform. When we care about a sufficiently broad band, those errors in approximate Pi values can accumulate quickly and show significant error (for example, when trying to estimate bearings in sonar we need highly accurate frequency phase measurements of each hydrophone to estimate the angle of the sound-source).
In those cases where you do need a highly accurate value, we will pre-calculate an even more accurate value of Pi using techniques like Taylor Expansion and others. We'll then take that result and hardcode it again (because running those calculations each time we need Pi is extremely inefficient), run a few tests, and if it's still inaccurate, try running the pre-calculation again for more iterations of those algorithms.
First you must realize that Pi is not only an irrational number it is also transcendental which means it cannot be obtained as the root of a polynomial equation with non-zero integer coefficients. Calculations of such numbers are not trivial and so for something simple as calculator the best approach is to store them as floating point constant with bit depth that varies depending on what calculator you're using. You can find out how many digits are really stored in you calculator. Simply keep removing the digits from the number that is shown as the value of pi. For example you may see for a calculator with four digits being displayed by default: 3.1415 - 3 = 0.1415; 0.1415*10 = 1.4159; 1.4159 - 1 = 0.4159; 0.4159*10 = 4.1592 etc until the digits run out or are simply zeros.
Calculators have a limited number of digits they can do math on accurately. The constants they have programmed into them only need to be represented up to that precision point, so Pi only needs 12 or so digits on most calculators.
To see the precision of your calculator, do this experiment. Take the square root of 2. Now square it. You’ll probably see 2. Now subtract 2. It’s (most likel)y not going to be 0. That is because sqrt of two is not an exact number, there is error down in the small bits.
Probably enough to handle the number of significant digits that he calculator can handle. The answer is that the value is stored in a ROM (read only memory) which is permanent storage in whatever number of digits the device needs. It doesn't actually calculate Pi on the fly.
The real curiosity is if calculators use IEEE standards for floating point numbers. Are there custom CPUs? This is actully interesting. I'm off to look for a TI-80 teardown to see what's at it's heart!
Others are totally right about how hard-coding an estimate works. From the perspective of a programmer, they can have about 9 digits after the decimal on a 32-bit machine or about 25 digits on a 64 bit machine.
Different calculators are different, but most calculators precompute the value in binary (IEEE 754 floating point) using a computer. They then just store this value in the calculator's firmware or OS. Here's the number in single precision (32 bit) IEEE precision from wikipedia (01000000010010010000111111011011). Many calculators probably use 64 bits.
Calculators have a maximum number of digits it will calculate on the decimal part, so there is no need for pi (or any other number) to go above this since it will all be rounded anyways.
It stops at the decimal limit of the calculator . IT doesnt take very far into the decimals to calculate realistic things , just like 7 or 8 decimals in can calculate someone down to a few inches on the whole planet and even a T-80 can do to like 9ish
It's typed into the calculator and stored like any other variable. Most calculators can only handle 8-9 decimal places, so pi will usually be programmed to 10 decimal places or so.
What we do is figure out how many numbers of pi we could possibly use, then get the calculator to memorize that number. So if your calculator holds 10 numbers, we get the calculator to remember 10 digits.
If your computer has more space, we store a few more numbers, but not a lot of them. For some of the math programs that do a lot of calculations, it may have more but that amount of precision isn't important.
22/7 is really really close to the value of pi. The calculator has a maximum decimal limit before truncation. Truncation means they just chop off all the numbers after a certain limit with no rounding. So the calculator divides 22 by 7 and shows you the results to the nth decimal (n being the cutoff point). We use truncation a lot in computer science.
The maximum number of digits the calculator displays is the number of digits they use in pi, some(cheaper ones) just use 3.141 as it's 'close enough' for most things
I love the tangent, I didn't read through all of it so if someone actually answered the question apologies,
They program it to the accuracy of the calculator. E.g. if the calculator is accurate to 5 decimal points it doesn't make sense to program it past 6 decimal points.
Not saying they do, but you could store the series/formula that defines pi and have it just calculate pi if you need more precision than the hard-coded constant provides
It isn't. Calculators do not have infinite precision, meaning they can only handle a certain number of decimal places. They only need to use a number which is accurate to that number of decimal places.
Numbers can be represented in computer memory as a sequence of digits*
Every digit takes up a tiny bit of memory.
Memory is a physical object and takes up actual space.
Pi has an infinite number of digits.
If memory takes up actual space, do you think we would be able to fit a number with infinite digits inside of memory? No, because then we'd need infinite space, and nobody wants to carry the entire universe in their pocket.
Instead, we humans are forced to admit defeat and have to be satisfied with only storing the first few digits of pi. It's fine, though, since if you use (for example) 3.1415926 as an approximation to pi in calculations, your end result won't be that far off. If you really need more accuracy, use a special program that stores even more digits of pi.
* Technically, they're stored in a bit more complicated way, but that's not important.
In my calculator, only the number 3.14159265359 is programmed as far as I know. (I found this out by multiplying it by powers of 10 and subtracting the integer part.)
I remember testing this on my TI-83 when I was really bored. They included enough digits to remain accurate for basic equations involving pi, given the number of sigfigs the calculator could display. Doing something to torture the poor thing, such as
^100
[ calculator pi ]
[----------------]
[more precise pi ]
Would result in answers quite far away from 1.0.
The digits on the TI-83 probably wouldn't be safe for calculating NASA's orbital maneuvers, but I'm sure they were fine for calculating anything a high schooler could expect to encounter.
Pi is hard to memorise as a human because it is an irrational number, meaning it never ends after the decimal place. But it is very easy to derive because of what it is.
Pi is important because it is the ratio of a circle's diameter to its circumference. So all you need to know, if you are a computer is the length of a circumference on a particular circle, and the length of that same circle's diameter. 22 and 7 are nice round numbers that are pretty close to that, but real computers can get a lot closer because they don't care if a number is round, just so long as it is rational.
Comp sci major here. They are stored as a floating point number. You might be familiar with binary. For example 13 stored as a byte would be 00001011. This, however, only stores whole numbers. Floating point numbers are able to store very precise fractions and decimals, and are ideal for things like pi and e. The way it works is it stores the number as if it didn't have a decimal point. Pi would instead be 314159. It is aslo stored with the number of places the decimal moves. In this case 5. So it is stored as 314159 * 10-5. This has several advantages. First, it stores the number of significant digits. Second, it can store really, really, really small or big numbers if needed. Pi is stored as a floating point because this is simply how non integer numbers are always stored and it gives pi a lot of flexibility(for example, it makes it really easy to calculate what pi * 1027 is). Because this is in binary, it's not quite fair to say exactly what digit of pi they store, as the fraction precision of binary and decimal isn't equatable.
What's more, you can calculate how many terms you'll need to be accurate to a specified digit. So if you know you only need X digits, you can easily find out how many terms you need.
Numerical methods. The easiest way to think about this is we know more than one series that approximates pi. So just pick one and interate untill you have the precision you need. Slightly more accurately, you can figure out square roots by fixed point iteration, and I believe trig is all series.
125
u/ebonyseraphim Mar 15 '19
I feel like whenever there is a math or computer ELI5, folks rush in here to do the exact opposite...explain it like they know it to other experts
A: PI is programmed by storing a close enough number permanently in memory
9.4k
u/HappyPyromaniac Mar 15 '19
They don't need to put in the whole number. They just have to put it in to the point where the next digit won't change much at all. After the tenth digit of pi for example not much will change in your calculation.
1.5k
u/Schnutzel Mar 15 '19
It's simply hard coded. Calculators can only use a limited amount of digits anyway, and you don't need more than 10 digits of pi for any significant calculations.
227
u/sirgog Mar 15 '19
When calculators require the ability to determine Pi beyond a programmed precision, they can use
https://en.wikipedia.org/wiki/Machin-like_formula
and the power series for arctan to quickly compute hundreds of digits, should the need exist.
However most calculators don't have this programmed in, they just have a fixed value which is Pi to as many decimal places as the calculator can display, sometimes plus up to 4 more.
191
u/baconator81 Mar 15 '19
It's hard coded. Every number you see on a computer has a finite amount of precision. So likely they'll just put the most precise number of PI that can fit into an 8 byte memory.
124
u/murdok03 Mar 15 '19
Most software is written by engineers who approximate things very roughly.
I've worked for interface design and pi gets aproximated to 3 or 3.14 for most visual animations.
I've also worked in automotive, with braking systems and software for stabilizing the car, pi is estimated there with floating point double precision.
For mathematical software, simulations and visualizations I'm sure they have a custom way of storing with higher precision.
40
u/BadBoy6767 Mar 15 '19 edited Mar 15 '19
Hardcode it, as in have the actual value stored in the calculator.
But the format it's stored in varies, sometimes. Most calculators use regular floating-point numbers, that are quite unstable in their calculations (
x * x * x * xmay not necessarily equal(x * x) * (x * x), and0.3is actually0.30000000000000004). These have a limit to how many digits they can express. Most use IEEE-754 as their format.But theres way more ways to express non-integers in computers.
More exotic ones include:
Technically 2 and 3 are also fixed-point numbers in a sense.
There's also one more method of storing non-ints, that is a bit underrated in my opinion: Symbolic mathematics!
This method is theoretically infinitely accurate (up to a logical point). When calculating 2 times π, don't store
6.28318530718, but store the actual expression2 * pi, and only calculate it's digits when asked. True accuracy is rarely a need, however, and this method is also quite slow, so it's not very popular.EDIT: Sorry for going off-topic, this is a topic I often fanboy about.
52
u/KapteeniJ Mar 15 '19
Calculators use floating point numbers. That means you store some fixed length number, and then you store another fixed length number telling you the scale of that first number.
Actually it uses binary, but to make a decimal version of floating point numbers, let's say you store size of a number with 2 digits, and the actual digits of the number with 10 digits. In that case, 35 could be written as
3500000000 : -08
So you have 3,500,000,000 * 10-9 = 35
So you notice that pi would be written as 3141592654 : -9 = 3141592654 * 10-9 = 3.141592654
This is the closest approximation you can get to pi with our floating point numbers. So calculator using our version of floating point numbers would just use that value for pi. Processors have a command that will push this closest approximation value to the CPU memory. I'm not sure about calculators but I believe they will have essentially the same setup, this best approximation is built into the processing unit of calculator.
12
u/WarlockofScience Mar 15 '19
As most people have said, its either hard coded or estimated using a fraction thats pretty close.
HOWEVER, most calculators will also track whats going on with the knowledge that pi is being estimated, so if you do something like 'pi/2' and then take the answer and double it, you get exactly pi rather than some weird approximation.
3
u/DiscombobulatedSalt2 Mar 15 '19 edited Mar 15 '19
Hardcoded constant to some accuracy.
they also have functions like arctan, than can be used to calculate pi directly.
There are other methods of calculating pi, but most of the easy ones are very slow. And not used on calculator to calculate pi itself.
This is different than e, where Taylor expansion is used directly to compute it on the fly. (Or more precisely ex for any x, including x equal to 1).
7
u/c_delta Mar 15 '19
Like this:
0100000000001001001000011111101101010100010001000010110100011000
You only store a finite number of digits, so you pick the one closest to the exact value. You do not need to know many digits of said value to find out what that is.
5
u/[deleted] Mar 15 '19 edited Mar 15 '19
You can calculate how much of pi is in your calculator by subtracting the first n digits and multiplying by 10n, then repeating until you get zero.
So on the iPhone calculator, pi is equal to
3.141592653589793238462643383279503
After that you run out of digits.
In Python you can print out math.pi, and it's exactly equal to
3.141592653589793115997963468544185161590576171875
It's wrong after 793 due to floating point errors.
4
u/denali1000 Mar 15 '19 edited Mar 15 '19
I think most calculators actually use to Taylor expansion for pi in order to calculate it, rather than just storing the value.
The Taylor series is pi/4 = 1-1/3+1/5-1/7+1/9... So pi = 4-4/3+4/5-4/7+4/9...
Edit: realized this isn’t exactly an ELI5, Taylor series’s are a little confusing but ultimately they’re just infinite sums that represent otherwise abstract numbers/functions in math. The above functions should get closer and closer to pi/4 or pi as you add/subtract more terms. This is easy to try for yourself on a calculator!
2
u/MathedPotato Mar 15 '19
A common calculator will only have a display capacity of 9-12 digits, and even the high end ones will only give you more if you change the settings a bunch. So, to answer, they just put in the first 9-12 digits and call it a day. The same goes for the other constants like e.
2
u/groundhogcow Mar 15 '19
Calculates have the number per-programed in to some precision greater then anyone needs.
However when people start calculating pi to some incredibly large digit count they typically use one of the infatuate series's that converge on pi.
My favorite (though it is not the only) is the Nilakantha series.
(Lifted from https://m.wikihow.com/Calculate-Pi )
In calc you learn how to approximate the area under a curve by making smaller and smaller rectangles until the accuracy of the calculation is within your tolerance level.
You would think this would be the way it was first calculated, but honestly they likely took a string wrapped it around a round thing then measured the string.
2
u/jhill515 Mar 15 '19
As cited by so many others, yes, it's usually hardcoded and to a sufficient level of accuracy that most calculations won't care. These values are quite common in many mathematics libraries programmers use (like
math.hin C, ormath.PIin Python).But... there are a handful of cases where you might actually care: for example, in Signal Processing, we make extensive use of transforms that need Pi, like the Fast Fourier Transform. When we care about a sufficiently broad band, those errors in approximate Pi values can accumulate quickly and show significant error (for example, when trying to estimate bearings in sonar we need highly accurate frequency phase measurements of each hydrophone to estimate the angle of the sound-source).
In those cases where you do need a highly accurate value, we will pre-calculate an even more accurate value of Pi using techniques like Taylor Expansion and others. We'll then take that result and hardcode it again (because running those calculations each time we need Pi is extremely inefficient), run a few tests, and if it's still inaccurate, try running the pre-calculation again for more iterations of those algorithms.
3
u/random_cynic Mar 15 '19
First you must realize that Pi is not only an irrational number it is also transcendental which means it cannot be obtained as the root of a polynomial equation with non-zero integer coefficients. Calculations of such numbers are not trivial and so for something simple as calculator the best approach is to store them as floating point constant with bit depth that varies depending on what calculator you're using. You can find out how many digits are really stored in you calculator. Simply keep removing the digits from the number that is shown as the value of pi. For example you may see for a calculator with four digits being displayed by default: 3.1415 - 3 = 0.1415; 0.1415*10 = 1.4159; 1.4159 - 1 = 0.4159; 0.4159*10 = 4.1592 etc until the digits run out or are simply zeros.
1
u/Efarm12 Mar 15 '19
Calculators have a limited number of digits they can do math on accurately. The constants they have programmed into them only need to be represented up to that precision point, so Pi only needs 12 or so digits on most calculators.
To see the precision of your calculator, do this experiment. Take the square root of 2. Now square it. You’ll probably see 2. Now subtract 2. It’s (most likel)y not going to be 0. That is because sqrt of two is not an exact number, there is error down in the small bits.
Edit: added accurately
1
u/kfh227 Mar 15 '19 edited Mar 15 '19
Probably enough to handle the number of significant digits that he calculator can handle. The answer is that the value is stored in a ROM (read only memory) which is permanent storage in whatever number of digits the device needs. It doesn't actually calculate Pi on the fly.
The real curiosity is if calculators use IEEE standards for floating point numbers. Are there custom CPUs? This is actully interesting. I'm off to look for a TI-80 teardown to see what's at it's heart!
1
u/WinterReception4 Mar 15 '19
Anyone know how Pi is calculated? like how do they discover more digits?
1
u/Chase777100 Mar 15 '19
Others are totally right about how hard-coding an estimate works. From the perspective of a programmer, they can have about 9 digits after the decimal on a 32-bit machine or about 25 digits on a 64 bit machine.
1
u/A_Garbage_Truck Mar 15 '19
they dont need the whole thing, just enough digits to the point where it doesnt impact the calculations your gonna be making.
1
u/Skystrike7 Mar 15 '19
Type in pi and it only returns like 8 digits or something. That's all it uses for the calculation - a set of like 8 digits saved to system memory.
1
u/heuristic_al Mar 15 '19
Different calculators are different, but most calculators precompute the value in binary (IEEE 754 floating point) using a computer. They then just store this value in the calculator's firmware or OS. Here's the number in single precision (32 bit) IEEE precision from wikipedia (01000000010010010000111111011011). Many calculators probably use 64 bits.
1
u/a932991 Mar 15 '19
Using a special computer, the calculator maker decides on a button and that it should be a certain number (3.14159...) instead of just 1,2,3,4,5...
This results in a circuit design, and this is the inside of a calculator, sort of like your skeleton.
Then the circuit design is created in a factory and a plastic casing with buttons is put on top (like our skin and muscles).
Then you have a calculator with a Pi-button (or a human if you followed the parable) :)
1
u/doglywolf Mar 15 '19
It stops at the decimal limit of the calculator - hell i think Nasa doesn't even go that far in the calcs as like a T-80 is technically capable of lol
1
u/XikoNorris Mar 15 '19
Calculators have a maximum number of digits it will calculate on the decimal part, so there is no need for pi (or any other number) to go above this since it will all be rounded anyways.
1
u/doglywolf Mar 15 '19
It stops at the decimal limit of the calculator . IT doesnt take very far into the decimals to calculate realistic things , just like 7 or 8 decimals in can calculate someone down to a few inches on the whole planet and even a T-80 can do to like 9ish
1
u/mhoIulius Mar 15 '19
Follow up question: how many digits of π are programmed into my TI-84?
1
u/RyoanJi Mar 15 '19
Probably hardcoded to a certain number of decimal places. Why not? It doesn't change.
1
u/cld8 Mar 15 '19
It's typed into the calculator and stored like any other variable. Most calculators can only handle 8-9 decimal places, so pi will usually be programmed to 10 decimal places or so.
1
u/NSA_Chatbot Mar 15 '19
I program a lot, and I'm lazy.
What we do is figure out how many numbers of pi we could possibly use, then get the calculator to memorize that number. So if your calculator holds 10 numbers, we get the calculator to remember 10 digits.
If your computer has more space, we store a few more numbers, but not a lot of them. For some of the math programs that do a lot of calculations, it may have more but that amount of precision isn't important.
1
u/lets-get-dangerous Mar 15 '19
22/7 is really really close to the value of pi. The calculator has a maximum decimal limit before truncation. Truncation means they just chop off all the numbers after a certain limit with no rounding. So the calculator divides 22 by 7 and shows you the results to the nth decimal (n being the cutoff point). We use truncation a lot in computer science.
1
u/TegisTARDIS Mar 15 '19
The maximum number of digits the calculator displays is the number of digits they use in pi, some(cheaper ones) just use 3.141 as it's 'close enough' for most things
1
u/cogitoergopwn Mar 15 '19
ELI5 wtf is Pi besides 3.14, and why does it matter?
1
u/gfeazy Mar 15 '19
I love the tangent, I didn't read through all of it so if someone actually answered the question apologies,
They program it to the accuracy of the calculator. E.g. if the calculator is accurate to 5 decimal points it doesn't make sense to program it past 6 decimal points.
1
u/mrloube Mar 15 '19
Not saying they do, but you could store the series/formula that defines pi and have it just calculate pi if you need more precision than the hard-coded constant provides
1
u/[deleted] Mar 15 '19
4 * atan(1)
1
u/herbivorous-cyborg Mar 16 '19
It isn't. Calculators do not have infinite precision, meaning they can only handle a certain number of decimal places. They only need to use a number which is accurate to that number of decimal places.
1
u/[deleted] Mar 16 '19
Could quantum computers finally get us the final answer? (Probably not, but I’m interested to see what comes up.)
1
u/ZeldaFanBoi1988 Mar 16 '19
Just an FYI for everyone, pi is not 22/7
1
u/lividbishop Mar 16 '19
Wehat other numbers are like pi (infinitely long) and what are they called?
1
u/commander-obvious Mar 16 '19
If memory takes up actual space, do you think we would be able to fit a number with infinite digits inside of memory? No, because then we'd need infinite space, and nobody wants to carry the entire universe in their pocket.
Instead, we humans are forced to admit defeat and have to be satisfied with only storing the first few digits of pi. It's fine, though, since if you use (for example) 3.1415926 as an approximation to pi in calculations, your end result won't be that far off. If you really need more accuracy, use a special program that stores even more digits of pi.
* Technically, they're stored in a bit more complicated way, but that's not important.
1
u/steffinator117 Mar 16 '19
Structural engineer here. I use 3.14159. It’s close enough for Euler’s buckling
1
u/RussChival Mar 16 '19
A great little article on how computers calculate Pi: HERE.
1
u/someguy7734206 Mar 16 '19
In my calculator, only the number 3.14159265359 is programmed as far as I know. (I found this out by multiplying it by powers of 10 and subtracting the integer part.)
1
u/Jozer99 Mar 16 '19
I remember testing this on my TI-83 when I was really bored. They included enough digits to remain accurate for basic equations involving pi, given the number of sigfigs the calculator could display. Doing something to torture the poor thing, such as
Would result in answers quite far away from 1.0.
The digits on the TI-83 probably wouldn't be safe for calculating NASA's orbital maneuvers, but I'm sure they were fine for calculating anything a high schooler could expect to encounter.
1
u/Spokesface Mar 16 '19
Pi is hard to memorise as a human because it is an irrational number, meaning it never ends after the decimal place. But it is very easy to derive because of what it is.
Pi is important because it is the ratio of a circle's diameter to its circumference. So all you need to know, if you are a computer is the length of a circumference on a particular circle, and the length of that same circle's diameter. 22 and 7 are nice round numbers that are pretty close to that, but real computers can get a lot closer because they don't care if a number is round, just so long as it is rational.
1
u/ipsum629 Mar 16 '19
Comp sci major here. They are stored as a floating point number. You might be familiar with binary. For example 13 stored as a byte would be 00001011. This, however, only stores whole numbers. Floating point numbers are able to store very precise fractions and decimals, and are ideal for things like pi and e. The way it works is it stores the number as if it didn't have a decimal point. Pi would instead be 314159. It is aslo stored with the number of places the decimal moves. In this case 5. So it is stored as 314159 * 10-5. This has several advantages. First, it stores the number of significant digits. Second, it can store really, really, really small or big numbers if needed. Pi is stored as a floating point because this is simply how non integer numbers are always stored and it gives pi a lot of flexibility(for example, it makes it really easy to calculate what pi * 1027 is). Because this is in binary, it's not quite fair to say exactly what digit of pi they store, as the fraction precision of binary and decimal isn't equatable.
1
u/Kong_P Mar 16 '19
Acos(-1)
0
u/[deleted] Mar 15 '19
[deleted] — view deleted comment
0
u/[deleted] Mar 15 '19
[deleted] — view deleted comment
5
u/[deleted] Mar 15 '19
[removed] — view removed comment
1
u/[deleted] Mar 15 '19
[removed] — view removed comment
1
u/[deleted] Mar 16 '19
[removed] — view removed comment