While doing arithmetic, how is infinity represented on a computer?
Thanks, Ramanraj.
On 6/7/05, Ramanraj K ramanraj.k@gmail.com wrote:
While doing arithmetic, how is infinity represented on a computer?
well use some arbitrary large number which is out of bounds from the current set being operated upon.
regards VK
On 6/7/05, Vivek Khurana hiddenharmony@gmail.com wrote:
On 6/7/05, Ramanraj K ramanraj.k@gmail.com wrote:
While doing arithmetic, how is infinity represented on a computer?
well use some arbitrary large number which is out of bounds from the current set being operated upon.
Joe Steeve wrote:
There is no such thing as infinity in a computer. When a integer is divided by zero., the CPU will throw an exception.
Take the following equation:
sqrt{1 + 2 sqrt{1 + 3 sqrt{1 + 4 sqrt{1 + ...} } } } = 3
Ramanujam proved the equation to be true. Please paste the above equation into OpenOffice Math and it would be more clear. In this equation, we cannot use "some arbitrary large number" as Vivek suggests and division by zero is not the only use for infinity. (BTW division by zero is assumed to be infinity and afaik there is no proof for that).
There should be a way to represent ... or infinity in the above equation on computers. If there are no standard ways of doing it then, we should devise a way to do it. It is fairly important to be able to represent infinity on computers just as easily as we represent numbers, because it has many practical uses as well. We may have to define max and min values for variables, and sometimes it has to be set at infinity.
If there are no standards for this, then: [1] A special character could represent infinity (lemniscate : sleeping 8 :) or three dots ...
AND/OR
[2] The last bit could be used to represent infinity. If a n bit word is used to represent integers, then the allowed integers have values between -2^(n-1) and (2^(n-1)) - 1. The maximum integer value could be reserved to represent infinity
Whenever I had to represent infinity, I had used this notation: Suppose for a variable x the max value is set to 3 and min value is set to 0, then x could be any number between 0 and 3. If max is set to 0, and min is not 0, then it represents infinity, x could represent any value from min to infinity. This works fine when min would always be greater than 0, but if x would have to start from 0 then solution [1] or [2] becomes necessary.
On Wed, 2005-06-08 at 08:32 +0530, Ramanraj K wrote:
(BTW division by zero is assumed to be infinity and afaik there is no proof for that).
If I remember my math, division by zero is properly said to be indeterminate, and not infinity. Infinity is not a number, but a concept -- if that does make sense.
There should be a way to represent ... or infinity in the above equation on computers. If there are no standard ways of doing it then, we should devise a way to do it. It is fairly important to be able to represent infinity on computers just as easily as we represent numbers, because it has many practical uses as well. We may have to define max and min values for variables, and sometimes it has to be set at infinity.
If there are no standards for this, then: [1] A special character could represent infinity (lemniscate : sleeping 8 :) or three dots ...
AND/OR
[2] The last bit could be used to represent infinity. If a n bit word is used to represent integers, then the allowed integers have values between -2^(n-1) and (2^(n-1)) - 1. The maximum integer value could be reserved to represent infinity
I am a little confused. Are you talking of writing infinity? In that case, the infinity character is available. But when you want to do actual computation, you cannot obviously do an iteration an infinite number of times. So there we are forced to select an appropriately large number that could stand for infinity.
It may be interesting to know that there are different kinds of infinity. For instance, there are an infinite number of integers. But there are an infinite number of rational numbers between any two integers. So these two infinities cannot be considered to be of the same kind. If I remember right, they are represented by the Hebrew alphabet aleph. So we have aleph1, aleph2 and so on.
Best V. Sasi Kumar
,----[ Ramanraj K ramanraj.k@gmail.com ] | While doing arithmetic, how is infinity represented on a computer? `---- Most modern computers support the IEEE floating point standard, which provides for positive infinity and negative infinity as floating point values. It also provides for a class of values called NaN or "not-a-number"; numerical functions return such values in cases where there is no correct answer.
Positive infinity `.0e+INF' Negative infinity `.0e+NaN'. Not-a-number `.0e+NaN'.
Under GNU Guile (Scheme) (define +Inf (/ 1.0 0.0)) (define -Inf (- +Inf)) (define NaN (/ 0.0 0.0))
guile> +Inf +#.# guile> -Inf -#.# guile> NaN #.#
Under GNU Emacs (elisp) (setq +Inf (/ 1.0 0.0)) => 1.0e+INF (setq -Inf (- +Inf)) => -1.0e+INF (setq NaN (/ 0.0 0.0)) => -0.0e+NaN
Under GCC (C) #include <stdio.h> int main () { float p_inf=1e30000; /* causes overflow and sets to infinity */ float n_inf=-p_inf; float nan = p_inf/p_inf; printf ("%f %f %f\n", p_inf, n_inf, nan);
return (0); } => inf -inf nan
And now you can do arithmetic using these symbols.
On 6/8/05, Anand Babu ab@gnu.org.in wrote:
,----[ Ramanraj K ramanraj.k@gmail.com ] | While doing arithmetic, how is infinity represented on a computer? `---- Most modern computers support the IEEE floating point standard, which provides for positive infinity and negative infinity as floating point values. It also provides for a class of values called NaN or "not-a-number"; numerical functions return such values in cases where there is no correct answer.
Thanks for the information. The current IEEE standard appears to be implemented in PHP and python too.
PHP users could try this: <?php $inf = 1.8e300; do { $inf = $inf * 10; echo "<p>$inf</p>"; } while (is_finite($inf)); # stops when $inf exceeds 1.8e307 ?> There is an is_infinite function also.
The standard provides for +∞ and -∞ but overlooks the overflow at the point of transition to the next whole number. The overflow there should be explicitly represented.
To avoid any confusion in this discussion, a few practical uses of these representations:
First, why infinity should be represented as integers. Take the question: On how many computers can a user install and run free software licensed under the GPL?
Answer: On an unlimited number of computers.
ie: $gnu_computers = infinite
Infinity should therefore be supported not only in floats, but also integers. Practically, we may do very little arithmetic with the infinity values themselves. Now, on how many computers can we install software licensed under the FreeBSD license? The answer again may be written as $bsd_computers = infinite. But, it makes no sense to add this infinity with the previous one. The question, on how many computers a user has actually installed free software is very different, and the answer would always be finite and countable. Much useful arithmetic could be done with such data, and we may never accept infinity as an answer here, and we would like to see a clear figure no matter how large or how difficult it is for programmers to represent it.
Secondly, the IEEE standard representing inf should be made more useful. As Dr. Sasi Kumar pointed out earlier, there are an infinite number of rational numbers between two integers, and floats on machines cannot represent all the values in between. It would be more useful to return INF at the point where the machine cannot represent a required float value. For example, we may list the steps in a procedure as follows: 1.1 - Step 1 1.2 - Step 2 If a new step is to be inserted between Steps 1 and 2, it could be inserted as Step 1.1 and the float representing it could be (1.1 + 1.2)/2 = 1.15 The new list of steps would be: 1.1 - Step 1 1.15 - Step 1.1 1.2 - Step 2
The float values help to sort the list when required. Though it is a bad idea to keep inserting new steps infinitely this way in the real world, in theory, this should be possible. But, there would be a point when the machine is unable to generate a float for inserting a new step where it would give a value after "rounding off" that is not between 1 and 2, which would defeat the purpose and design. It would be better if INF is returned instead of rounding off at this point, so that we may trap the overflow and handle it appropriately.
Positive infinity `.0e+INF' Negative infinity `.0e+NaN'. Not-a-number `.0e+NaN'.
Under GNU Guile (Scheme) (define +Inf (/ 1.0 0.0)) (define -Inf (- +Inf)) (define NaN (/ 0.0 0.0))
guile> +Inf +#.# guile> -Inf -#.# guile> NaN #.#
Under GNU Emacs (elisp) (setq +Inf (/ 1.0 0.0)) => 1.0e+INF (setq -Inf (- +Inf)) => -1.0e+INF (setq NaN (/ 0.0 0.0)) => -0.0e+NaN
Under GCC (C) #include <stdio.h> int main () { float p_inf=1e30000; /* causes overflow and sets to infinity */ float n_inf=-p_inf; float nan = p_inf/p_inf; printf ("%f %f %f\n", p_inf, n_inf, nan);
return (0);
} => inf -inf nan
And now you can do arithmetic using these symbols.
and with recursion :)
IEEE floating point numbers include a value that stands for infinity. I think there are actually two of them--plus infinity and minus infinity.
On Tue, 7 Jun 2005, Vivek Khurana wrote:
On 6/7/05, Ramanraj K ramanraj.k@gmail.com wrote:
While doing arithmetic, how is infinity represented on a computer?
This cannot be done because a number ( whether integer or floating point ) is represented by finite number of bytes, no matter what precision one uses. An infinitely large number cannot be represented by finite bytes. This and other limitations like granularity of floating point numbers cannot be avoided in numerical computations and one has to live with these. One can DEFINE infinity to be the largest number that can be represented but strictly speaking that is not correct. One may actually have a number larger than this number which is not infinite.
It may be possible to define infinity in algebraic computation if the computer is 'taught' the rules of analysis ( which is done in some packages ).
Shashikant Phatak
Ramanraj K ramanraj.k@gmail.com writes:
While doing arithmetic, how is infinity represented on a computer?
There is no such thing as infinity in a computer. When a integer is divided by zero., the CPU will throw an exception.