Re: Testing for IEEE infinity and NaN?



On Thu, 15 Jun 2006 17:15:41 UTC, Raymond Toy <raymond.toy@xxxxxxxxxxxx> wrote:

Is there a "fast" way to check if an IEEE floating-point number is
infinity? I pretty sure that NaN can be test easily by doing x = x,
which is always true, except if x i NaN. Is there something just as
easy for infinity? Or do I have to look at the exponent of the number
to figure that out?

In C99 terms:
#define isnan(x) ( (x) != (x) )
#define isinf(x) ( !isnan(x) && isnan( (x) - (x) ) )

---
Fred J. Tydeman Tydeman Consulting
tydeman@xxxxxxxxx Testing, numerics, programming
+1 (775) 358-9748 Vice-chair of J11 (ANSI "C")
Sample C99+FPCE tests: http://www.tybor.com
Savers sleep well, investors eat well, spenders work forever.
.



Relevant Pages

  • Re: Calculus XOR Probability
    ... have a number, so it's NaN. ... What kind of math can you do on a Java ... similarly any operation involving an infinity operand results in either ... You described counting the size of a finite set. ...
    (sci.math)
  • Re: Calculus XOR Probability
    ... have a number, so it's NaN. ... What kind of math can you do on a Java ... similarly any operation involving an infinity operand results in either ... You described counting the size of a finite set. ...
    (sci.math)
  • Re: testing for floating point equality
    ... possible exponent values in single precision and 2 out of 2048 values ... The other reserved value is used to encode infinity, ... 0.0/0.0 or infinity/infinity yields NaN. ... Having a representation for infinity ...
    (comp.lang.fortran)
  • Re: math.nroot [was Re: A brief question.]
    ... floating point if everyone wrote in hex - indeed, i believe that C99 has hex floating-point literals. ... py> inf inf ... bit-pattern and call it NaN, but mathematically subtracting infinity from infinity is not defined. ...
    (comp.lang.python)
  • Re: math.nroot [was Re: A brief question.]
    ... > there is no clean programmatic way to make an inf or a NaN; ... infinity isn't a number either. ... Apple Computer had a maths library that implemented a superset of IEEE ...
    (comp.lang.python)