[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

initialize a double with NAN?

David Mathog

5/13/2011 5:52:00 PM

How does one initialize a variable to NAN in compliance with the c99
standard? This doesn't work:

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
int main(void){
double dnan=FP_NAN;
fprintf(stdout,"dnan is %lf\n",dnan);
dnan=log(-1);
fprintf(stdout,"dnan is %lf\n",dnan);
exit(EXIT_SUCCESS);
}

gcc -std=c99 -pedantic -lm -o test test.c
../test
dnan is 0.000000
dnan is nan

Changing the declaration line to

double dnan=log(-1);

does result in dnan being initialized to nan. Is that method standard
compliant, or are compilers allowed to thow an error there???

Thanks,

David Mathog