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?
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?
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.
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.
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.
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).
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.
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.
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/
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