public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] NAN
@ 2008-02-04 18:23 Davies, Greg
  2008-02-04 20:26 ` Davies, Greg
  2008-02-04 20:32 ` Andrew Lunn
  0 siblings, 2 replies; 4+ messages in thread
From: Davies, Greg @ 2008-02-04 18:23 UTC (permalink / raw)
  To: ecos-discuss

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.

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [ECOS] NAN
  2008-02-04 18:23 [ECOS] NAN Davies, Greg
@ 2008-02-04 20:26 ` Davies, Greg
  2008-02-04 20:32 ` Andrew Lunn
  1 sibling, 0 replies; 4+ messages in thread
From: Davies, Greg @ 2008-02-04 20:26 UTC (permalink / raw)
  To: ecos-discuss

 Nevermind, my usual method of asking someone, the list in this case,
made the answer jump out at me. I still can't find the NAN I was using
before, but in my haste I forgot the std:: on the numeric_limits. All is
well in my tiny world now.

-----Original Message-----
From: ecos-discuss-owner@ecos.sourceware.org
[mailto:ecos-discuss-owner@ecos.sourceware.org] On Behalf Of Davies,
Greg
Sent: Monday, February 04, 2008 2:20 PM
To: ecos-discuss@ecos.sourceware.org
Subject: [ECOS] NAN

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.

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


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [ECOS] NAN
  2008-02-04 18:23 [ECOS] NAN Davies, Greg
  2008-02-04 20:26 ` Davies, Greg
@ 2008-02-04 20:32 ` Andrew Lunn
  2008-02-05 14:03   ` Kramer, Mat
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2008-02-04 20:32 UTC (permalink / raw)
  To: Davies, Greg; +Cc: ecos-discuss

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [ECOS] NAN
  2008-02-04 20:32 ` Andrew Lunn
@ 2008-02-05 14:03   ` Kramer, Mat
  0 siblings, 0 replies; 4+ messages in thread
From: Kramer, Mat @ 2008-02-05 14:03 UTC (permalink / raw)
  To: Davies, Greg; +Cc: ecos-discuss

Here's how we define a non-signaling NaN (on x86):

static const LONG DsiNan = 0x7FC00000;
#define _NANF		(*(float *)&DsiNan)

-Mat


-----Original Message-----
From: Andrew Lunn [mailto:andrew@lunn.ch] 
Sent: Monday, February 04, 2008 2:32 PM
To: Davies, Greg
Cc: ecos-discuss@ecos.sourceware.org
Subject: Re: [ECOS] 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-02-05 14:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-04 18:23 [ECOS] NAN Davies, Greg
2008-02-04 20:26 ` Davies, Greg
2008-02-04 20:32 ` Andrew Lunn
2008-02-05 14:03   ` Kramer, Mat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).