[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Converting NaN to integer 0.

From: Luc Teirlinck
Subject: Re: Converting NaN to integer 0.
Date: Tue, 12 Feb 2002 10:46:29 -0600 (CST)

Richard Stallman wrote:

   Does anyone know what is the "correct" thing to do in this case
   according to IEEE?  Would returning NaN be correct?

The functiona ffloor, fceiling, ftruncate and fround all return (I
believe correctly) NaN when passed NaN.  They also return +INF or -INF
when passed those values.

The trouble with floor, ceiling, truncate and round seems to be that
these functions are supposed to return an integer, and NaN and the
infinities are floats, not integers.  So the problem is not what the
rounded value of NaN should be, that would clearly seem to be NaN, but
whether it makes sense to cast NaN to an integer.

I do not know what the IEEE floating point standard says about casting
these values to integers.  It is not guaranteed to say anything about
it, since it is a floating point standard.

The rounding functions in the GNU C library that return a floating
point number all behave like ffloor et al.  The rounding
functions that return integers (lrint and lround) seem to return
nonsense values when fed NAN or infinities.  So does trying to cast
NAN or an infinity to int.

floor, ceiling, truncate and round all produce an error when passed
infinity, I guess because the logical rounded value returned by ffloor
et al is not an integer.  Unless the IEEE standard says something
else, it would seem consistent to give an error message when NaN is
passed since the logical rounded value (NaN) returned by ffloor et al
is not an integer either.

It seems like somebody who expects NaN to be rounded to Nan would call
ffloor or similar, because he would not be insisting on an integer

reply via email to

[Prev in Thread] Current Thread [Next in Thread]