Sign in to follow this  
xdotdt

corrupt float

Recommended Posts

How can I detect whether a float variable is corrupt? When I debug some codes, sometimes it happens that a float variable becomes like 1.#QNAN0, or similar forms. How can I know this in code, not in debugging-mode by doing like below.
if( corrupt( float_var ) )
{
    printf( "corrupt" );
}
And someone knows what that means? I mean what 1.#QNAN0 or similar one means? [Edited by - xdotdt on July 11, 2005 1:08:04 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
All NaN values have the property that any comparison operations (, >=, !=,==) are false: so it is not equal to itself.

bool IsNum(float f) { return (f == f); }

Share this post


Link to post
Share on other sites
thanks glSmurf.
I found a similar function.

_CRTIMP int __cdecl _finite(double);
_CRTIMP int __cdecl _isnan(double);

Are _finite() and _isnan() different?
If so, how are they different?

Plus, is there a version for float?

Share this post


Link to post
Share on other sites
Quote:
Original post by xdotdt
thanks glSmurf.
I found a similar function.

_CRTIMP int __cdecl _finite(double);
_CRTIMP int __cdecl _isnan(double);

Are _finite() and _isnan() different?
If so, how are they different?

They are different in how they treat infinity.

finite returns true for normal numbers, and false for Inf (Infnity) and NaN (Not a Number). isnan returns true for NaN, and false for Inf and normal numbers. It's just a matter of whether Inf is "treated" as a number or a NaN, so to speak. As there are three "states"; number, Inf and NaN, a single true/false function is not enough to identity the different "states".

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this