This is the mail archive of the ecos-discuss@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: NAN


On Mon, Feb 04, 2008 at 02:19:39PM -0400, Davies, Greg wrote:
> Hi,
> 	I'm trying to compile a program that assigns the value NAN to
> some floats to indicate that no real data has come out of a sensor yet.
> My problem is that I can't find a header that defines NAN. I used math.h
> when I was writing this class the first time around. I even tried using
> numeric_limits<float>::quiet_NaN() from <limits> but everything I try
> gives me an error along the lines of: NAN is not declared in this scope.
> 
> 
> Could there be something I'm missing from the eCos configuration do add
> a header that defines NAN? All help is greatly appreciated.

I could not find anywhere in the sources where NAN is
defined. Interesting isnan() is available, but it uses hard coded
values.

According to C99 it should be in <math.h>.

I wounder if the problem is to do with none-signalling NAN against
signalling NAN. NAN should have a value which does not cause a
floating point exception to be raised. But that is architecture
dependent. So maybe the HAL needs to define it. That is messy, so
maybe it has just been left out.

So you probably need to declare it yourself. This should help you
figure out the value:

        int isnan(double x)
{
        int hx,lx;
        hx = (CYG_LIBM_HI(x)&0x7fffffff);
        lx = CYG_LIBM_LO(x);
        hx |= (unsigned)(lx|(-lx))>>31; 
        hx = 0x7ff00000 - hx;
        return ((unsigned)(hx))>>31;
}

        Andrew

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]