,----[ 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.