IEC559, can't understand NaN,infinity..

I read that:
if the exponent is all ones, and the mantissa is all zeros, the value is considered “infinity.”
If the exponent is all ones and the mantissa is not all zeros, the value is considered as not-a-number, or NaN.
NaN comes in two varieties: quiet and signaling.
Arithmetic with quiet NaN always yields a NaN result.
Using a signaling NaN results in a machine interrupt.

I'm not understand what upper means. what's
the exponent is all ones
, is it mean 1 powers 1?
can you guys give me some example to illustrate what is infinity, NaN, qeiet, signal?

PS. do these thing frequently use in programming? I thought they might not use often.

If I define a float type, do I have to specify the number postfix f/F, like float a = 0.2f ? If I omit the postfix, is it okay?
Last edited on
Floating point numbers (floats & doubles) are stored conceptually like a scientific notation number - e.g. -1.23e+3 is -1230.0 Except that the whole thing is in binary.

This has 2 parts the mantissa and exponents, and each of these has a sign. The mantissa is stored as a binary fraction, and the exponent is in binary as well. The signs occupy their own bit respectively.

I wouldn't worry about the quiet & signalling stuff. Just be aware of what library functions return. For example the trig functions return EDOM to say that the argument was a domain error, or they return the answer otherwise. You should test these return values to see if the function call worked, or use exceptions.

In C++, if you do not put a 'f' at the end of your number, it will default to a double. I normally use doubles exclusively. An application might use a float if they weren't worried about the lesser precision and there were millions of them to be stored, so memory use was a concern.

Hope all goes well.
Last edited on
> give me some example to illustrate what is infinity, NaN

NaN - 0.0 / 0.0 or std::sqrt( -5.0 )

Infinity - 10.0 / 0.0
You should think of NaN as exactly that, not a number, not a mathematical entity. For example, the result of trying to treat some uninitialised bit pattern as a number.
Topic archived. No new replies allowed.