GCC4 math.h issue?

IRIX/Nekoware development, porting and related topics.
Forum rules
Any posts concerning pirated software or offering to buy/sell/trade commercial software are subject to removal.
User avatar
necron2600
Posts: 278
Joined: Tue May 26, 2015 10:38 pm
Location: Boston

GCC4 math.h issue?

Unread postby necron2600 » Mon Jun 06, 2016 1:27 pm

I am not a developer at all, but can anyone tell me why this fails to compile on IRIX and Nekoware GCC4.7?

#include <stdio.h>
#include <math.h>
int main() {
fprintf(stderr, "%d\n", FP_NAN);
return 0;
}

On IRIX (latest Nekoware GCC4.7 and stuff as of mid-last year):
gcc -o x x.c
x.c: In function 'main':
x.c:4:27: error: 'FP_NAN' undeclared (first use in this function)
x.c:4:27: note: each undeclared identifier is reported only once for each function it appears in

On Solaris 10 gcc 5.2.0 or 4.9 (opencsw packages)
Clean compile. (if you run the compiled binary, it returns "4" on the system im running on)

I know there is a cmath lib (i could use #include <cmath> with gcc -I /locationtoit/ but that does not seem to go down the right road)
/usr/nekoware/gcc-4.7/include/c++/4.7.1/cmath

Thanks in advance!

robespierre
Posts: 1577
Joined: Mon Sep 12, 2011 2:28 pm
Location: Boston

Re: GCC4 math.h issue?

Unread postby robespierre » Mon Jun 06, 2016 3:50 pm

You aren't calling any math function in that code, so linking with a math library will not make any difference.
At first I thought you meant to pass a IEEE-754 quiet NaN to printf (which would miscast it to an integer...), but that is a different macro. FLT_NAN is usually #defined to 0.0f / 0.0f;
FP_NAN is a return value code defined for the C99 macro fpclassify(). It only exists in C99.
:PI: :O2: :Indigo2IMP: :Indigo2IMP:

User avatar
necron2600
Posts: 278
Joined: Tue May 26, 2015 10:38 pm
Location: Boston

Re: GCC4 math.h issue?

Unread postby necron2600 » Mon Jun 13, 2016 8:03 pm

I tried to find where FP_NAN could be referenced...
I found this on IRIX:
/usr/include/internal/math_core.h
has a section:

/* C99: 7.12 6 defines for floating point classification */

#define FP_ZERO 1
#define FP_SUBNORMAL 2
#define FP_NORMAL 4
#define FP_INFINITE 8
#define FP_NAN 16

So i put in those defines in the source (x.c) file.. and it compiles now.

I guess I could have defined any value.... not sure why gcc on IRIX is not finding this value properly?

User avatar
foetz
Moderator
Moderator
Posts: 6590
Joined: Mon Apr 14, 2003 4:34 am
Contact:

Re: GCC4 math.h issue?

Unread postby foetz » Mon Jun 13, 2016 8:11 pm

try with -std=c99


Return to “SGI: Development”

Who is online

Users browsing this forum: No registered users and 2 guests