r***@yahoo.com
2005-01-16 05:50:36 UTC
Let's say I have this sample code fragment.
#include <stdio.h>
#include <stdlib.h>
int main() {
double dim = 0.0;
double invdim;
invdim = 0.0/(double)dim; // NaN is produced here.
invdim += 0.1; // I want to catch Nan before performing
//any arithmetic operations on it.
//How do I do it ?
printf("invdim: %lf\n", invdim);
return EXIT_SUCCESS;
}
I want to catch the Nan value before I do any arithmetic operations on
the same. How would I do it ?
<--
"A quiet NaN propagates through almost every arithmetic operation
without raising a floating-point exception; a signaling NaN generally
raises a floating-point exception when occurring as an arithmetic
operand."
-->
$ gcc -Wall -fsignaling-nans fp_test.c
When I ran the program, my program went past the nan creation point and
printed the value.
invdim: nan
But I expected an exception / crash at the point when -fnan is
specified. What am i missing here. thanks for letting me know.
#include <stdio.h>
#include <stdlib.h>
int main() {
double dim = 0.0;
double invdim;
invdim = 0.0/(double)dim; // NaN is produced here.
invdim += 0.1; // I want to catch Nan before performing
//any arithmetic operations on it.
//How do I do it ?
printf("invdim: %lf\n", invdim);
return EXIT_SUCCESS;
}
I want to catch the Nan value before I do any arithmetic operations on
the same. How would I do it ?
From the ANSI spec 5.2.4.2.2 Characteristics of floating types
<float.h><--
"A quiet NaN propagates through almost every arithmetic operation
without raising a floating-point exception; a signaling NaN generally
raises a floating-point exception when occurring as an arithmetic
operand."
-->
$ gcc -Wall -fsignaling-nans fp_test.c
When I ran the program, my program went past the nan creation point and
printed the value.
invdim: nan
But I expected an exception / crash at the point when -fnan is
specified. What am i missing here. thanks for letting me know.