Question

I'm curious about infinite numbers in computing, in particular pi.

For a computer to render a circle it would have to understand pi. But how can it if it is infinite?

Am I looking too much into this? Would it just use a rounded value?

Was it helpful?

Solution

Mathematically, computers are both finite and non-continuous and therefore can neither know PI completely, nor correctly render a circle.

However, in the digital realm neither of these exist anyway, so it is sufficient to approximate PI and then use that to approximately render the circle, resulting in exactly the same pixels that would have been calculated from an exact PI anyway.

Either way, the resulting pixels aren't really a circle either, because they are a finite collection of digital points and a circle is a curve made up of an infinite number of points, most with irrational values.

(It has been pointed out to me that PI is not normally used to plot a circle, which is true, however, the methods used to plot a circle are related to the formulas used to express and/or calculate the value of PI, which still have the same issues).

OTHER TIPS

An approximation is generally sufficient. To "render" a circle, the computer only needs to understand pi well enough to render accurately at whatever resolution (finite) is required.

Edit: as others have pointed out, you don't even need pi to render a circle. Still, the gist of the question was "how do computers deal with numbers like pi?" They use approximations, and whoever is using those approximations must decide whether they are precise enough for the given purpose.

You don't need PI at all to draw a circle. There are many ways to draw a circle. The naive way is with sine and cosine.

The algorithm I saw most often on 8-bit machines was Bresenham's circle. You don't even need floating point math for that.

Programming languages use a rounded constant for pi and similar "infinite" numbers.

In order to get higher precision you use iterative algorithms that are looped for as long as is required.

Computers just use a good approximation of pi.

From MSDN's article on System.Math.PI

The value of this field is 3.14159265358979323846.

BTW: PI is NOT infinite. It is irrational, meaning that it has an infinite number of non-repeating decimal places. There are several expressions for PI that are very short. (see the Wikipedia page for more details)

Here is a wonderfully short expression for PI:

PI as Integral

Somewhere I saw a proof that to draw a circle around the universe to millimetre accuracy, you'd need less than 100 digits of pi, in other words, far fewer digits than have been calculated by people with too much time on their hands (or too much computing power...). Now, if only I could find that proof... (edit) found it

I believe it rounds it to a very small number, and is most likely a constant. If you use PHP, this is how PI renders:

echo pi(); // 3.1415926535898
echo M_PI; // 3.1415926535898

Just like you only need 3.14159 in High School, computers only need so much to get it fairly accurate.

An approximation is often "good enough", whether you get it using a method from this site or another one.

"Rendering" is another matter. When you have a finite screen resolution, a perfect value of π doesn't matter as much.

UPDATE: Calculation might be another matter, different from rendering. Some applications might require greater precision than the standard double gives. It depends on the problem.

Computers just use rounded values of pi, unless of course there is a special case such as scientific computing. For example, in python pi is represented as:

>>> import math
>>> math.pi
3.1415926535897931

You can test this out for yourself in IDLE, pythons interactive interpreter.

Pi is not infinite it is irrational, what mean that you can not express it as quotient. It has infinite number of digits. http://en.wikipedia.org/wiki/Proof_that_π_is_irrational

About computing find some informations here. http://en.wikipedia.org/wiki/Computing_π

Nice page is also this http://3.141592653589793238462643383279502884197169399375105820974944592.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top