Where is NAN Defined?

2008-02-10 Thread Jim Razmus
I'm trying to compile a program that uses NAN.  It includes math.h which
I'm told C99 says should define it.  I've grepped the entire source tree
and read up on man 3 math and man 3 isinf.  Still no joy.

Trying to compile the program yields error: `NAN' undeclared (first use
in this function).

Can anyone point me in the right direction?

Thanks,
Jim



Re: Where is NAN Defined?

2008-02-10 Thread Marc Balmer

Jim Razmus wrote:

I'm trying to compile a program that uses NAN.  It includes math.h which
I'm told C99 says should define it.  I've grepped the entire source tree
and read up on man 3 math and man 3 isinf.  Still no joy.

Trying to compile the program yields error: `NAN' undeclared (first use
in this function).

Can anyone point me in the right direction?


you can use the isnan(3) function to test for NaN.  Does that not work
in your program?



Re: Where is NAN Defined?

2008-02-10 Thread Chris Kuethe
On Feb 10, 2008 8:31 AM, Jim Razmus [EMAIL PROTECTED] wrote:
 I'm trying to compile a program that uses NAN.  It includes math.h which
 I'm told C99 says should define it.  I've grepped the entire source tree
 and read up on man 3 math and man 3 isinf.  Still no joy.

 Trying to compile the program yields error: `NAN' undeclared (first use
 in this function).

 Can anyone point me in the right direction?

#ifndef NAN
#define NAN (0.0/0.0)
#endif


-- 
GDB has a 'break' feature; why doesn't it have 'fix' too?



Re: Where is NAN Defined?

2008-02-10 Thread Floor Terra
On 2/10/08, Jim Razmus [EMAIL PROTECTED] wrote:
 I'm trying to compile a program that uses NAN.  It includes math.h which
 I'm told C99 says should define it.  I've grepped the entire source tree
 and read up on man 3 math and man 3 isinf.  Still no joy.

 Trying to compile the program yields error: `NAN' undeclared (first use
 in this function).

 Can anyone point me in the right direction?

 Thanks,
 Jim



Not OpenBSD related, but I was curious myself.

Try reading http://en.wikipedia.org/wiki/NaN

Or read isnan(3) if you just want to test is a number is NaN. (NaN != NaN)


Floor



Re: Where is NAN Defined?

2008-02-10 Thread Jim Razmus
* Chris Kuethe [EMAIL PROTECTED] [080210 12:34]:
 On Feb 10, 2008 8:31 AM, Jim Razmus [EMAIL PROTECTED] wrote:
  I'm trying to compile a program that uses NAN.  It includes math.h which
  I'm told C99 says should define it.  I've grepped the entire source tree
  and read up on man 3 math and man 3 isinf.  Still no joy.
 
  Trying to compile the program yields error: `NAN' undeclared (first use
  in this function).
 
  Can anyone point me in the right direction?
 
 #ifndef NAN
 #define NAN (0.0/0.0)
 #endif
 
 
 -- 
 GDB has a 'break' feature; why doesn't it have 'fix' too?
 

I'm told that math.h should do this for me.  Moreover, I think NAN is a
machine dependent value.

Adding the line you mention would break on VAX (assuming I understand
this correctly).  Although I don't think anyone would run this program
on a VAX, if it's in the ports tree there's the possibility.

Worst case, I could add those defines though.

Thanks.
Jim



Re: Where is NAN Defined?

2008-02-10 Thread Jim Razmus
* Marc Balmer [EMAIL PROTECTED] [080210 12:06]:
 Jim Razmus wrote:
 I'm trying to compile a program that uses NAN.  It includes math.h which
 I'm told C99 says should define it.  I've grepped the entire source tree
 and read up on man 3 math and man 3 isinf.  Still no joy.
 Trying to compile the program yields error: `NAN' undeclared (first use
 in this function).
 Can anyone point me in the right direction?

 you can use the isnan(3) function to test for NaN.  Does that not work
 in your program?


The isnan test is not the issue.  The program actually sets a variable to
the value NAN.  It's those lines that gak the compiler.

The lines that fail are:

sp-t_req = NAN;
sp-t_resp = NAN;

and the error during compilation is:

gcc -DHAVE_CONFIG_H -I. -I../.. -I../../include   -include config.h
-DVARNISH_STATE_DIR='/usr/local/var/varnish' -g -O2 -MT
varnishd-cache_center.o -MD -MP -MF .deps/varnishd-cache_center.Tpo -c
-o varnishd-cache_center.o `test -f 'cache_center.c' || echo
'./'`cache_center.c
cache_center.c: In function `cnt_done':
cache_center.c:212: error: `NAN' undeclared (first use in this function)
cache_center.c:212: error: (Each undeclared identifier is reported only
once
cache_center.c:212: error: for each function it appears in.)
*** Error code 1

Hope that helps clear up my question.

Jim



Re: Where is NAN Defined?

2008-02-10 Thread James

Jim Razmus wrote:

* Chris Kuethe [EMAIL PROTECTED] [080210 12:34]:
  

On Feb 10, 2008 8:31 AM, Jim Razmus [EMAIL PROTECTED] wrote:


I'm trying to compile a program that uses NAN.  It includes math.h which
I'm told C99 says should define it.  I've grepped the entire source tree
and read up on man 3 math and man 3 isinf.  Still no joy.

Trying to compile the program yields error: `NAN' undeclared (first use
in this function).

Can anyone point me in the right direction?
  

#ifndef NAN
#define NAN (0.0/0.0)
#endif


--
GDB has a 'break' feature; why doesn't it have 'fix' too?




I'm told that math.h should do this for me.  Moreover, I think NAN is a
machine dependent value.

Adding the line you mention would break on VAX (assuming I understand
this correctly).  Although I don't think anyone would run this program
on a VAX, if it's in the ports tree there's the possibility.

Worst case, I could add those defines though.

Thanks.
Jim


  


Have you tried using grep in the library tree to find it?



Re: Where is NAN Defined?

2008-02-10 Thread David Higgs
On Feb 10, 2008 12:55 PM, Jim Razmus [EMAIL PROTECTED] wrote:
 * Chris Kuethe [EMAIL PROTECTED] [080210 12:34]:
  On Feb 10, 2008 8:31 AM, Jim Razmus [EMAIL PROTECTED] wrote:
   I'm trying to compile a program that uses NAN.  It includes math.h which
   I'm told C99 says should define it.  I've grepped the entire source tree
   and read up on man 3 math and man 3 isinf.  Still no joy.
  
   Trying to compile the program yields error: `NAN' undeclared (first use
   in this function).
  
   Can anyone point me in the right direction?
 
  #ifndef NAN
  #define NAN (0.0/0.0)
  #endif
 
 
  --
  GDB has a 'break' feature; why doesn't it have 'fix' too?
 

 I'm told that math.h should do this for me.  Moreover, I think NAN is a
 machine dependent value.

 Adding the line you mention would break on VAX (assuming I understand
 this correctly).  Although I don't think anyone would run this program
 on a VAX, if it's in the ports tree there's the possibility.

 Worst case, I could add those defines though.

 Thanks.
 Jim

Is your source familiar with OpenBSD?
You say C99 math.h supposedly provides NAN.
math(3) says nothing about C99.  That's your first clue.
Looking through gcc(1) for -std=c99 points to the GCC webpage [1].
It says additional math library functions are missing.  That might
be another clue.

If you can't use NAN in a simple test program using -std=c99 and/or
-lm, you're SOL unless you start patching your program.

Both math(3) and the source for isnan(3) (see [2]) indicate that there
are many potential NaN values.  Unless you know exactly what this
program is doing or are very familiar with your arch's floating point
support, don't assume that #define will work 100% of the time.

I'm no expert though.  Good luck.

--david

[1] http://gcc.gnu.org/gcc-3.3/c99status.html
[2] http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libm/src/s_isnan.c



Re: Where is NAN Defined?

2008-02-10 Thread Woodchuck
On Sun, 10 Feb 2008, Jim Razmus wrote:

 I'm told that math.h should do this for me.  Moreover, I think NAN is a
 machine dependent value.

See  /usr/include/i386/ieee.h  for some hints.

 Adding the line you mention would break on VAX (assuming I understand
 this correctly).  Although I don't think anyone would run this program
 on a VAX, if it's in the ports tree there's the possibility.

Probably.  Vaxes didn't use IEEE floating point.

 Worst case, I could add those defines though.

I'd do some more research.  Examine the source code for isnan()

This is the i386 version

#include sys/types.h
#include machine/ieee.h
#include math.h

int
isnan(d)
double d;
{
struct ieee_double *p = (struct ieee_double *)d;

return (p-dbl_exp == DBL_EXP_INFNAN 
(p-dbl_frach != 0 || p-dbl_fracl != 0));
}

We notice the || in the comparison.  There is more than one NaN,
in other words.  DBL_EXP_INFNAN is defined in ieee.h

So there is no unique NaN.

Dave
-- 
   The president of the United States is the commander-in-chief of
   the armed forces.  He is not the commander-in-chief of the
   government, nor is he the commander-in-chief of the country.



Re: Where is NAN Defined?

2008-02-10 Thread Marc Espie
There's some newer stuff we don't have yet. Partly because of vax, since
it's the only non-ieee platform we support.

NAN is one of these issues, and not the only one.

For now, just cater around the problem by reading carefully the code,
and figuring out what you can put instead of NAN.