D
David Mathog
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
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