I use ANSI C89 (not C++), and I want to generate NaN, -Infinity and +Infinity.
Is there any standard way (eg. standard macro)?
I don't know if this is standard or portable, but here's a start:
jcomeau@intrepid:/tmp$ cat test.c; make test; ./test
#include
int main() {
printf("%f\n", 1.0 / 0);
printf("%f\n", -1.0 / 0);
printf("%f\n", 0.0 / 0);
return 0;
}
cc test.c -o test
test.c: In function ‘main’:
test.c:3: warning: division by zero
test.c:4: warning: division by zero
test.c:5: warning: division by zero
inf
-inf
-nan
Strangely enough, I can't get positive NaN using this naive approach.