4 ms·
I like the fact that NaN taints other numbers - early failure is better, than trying to hide it. #include <math.h> #include <stdio.h> int main(int argc,
by malkia 12y ago
I like the fact that NaN taints other numbers - early failure is better, than trying to hide it.
#include <math.h>
#include <stdio.h>
int main(int argc, const char* argv[] )
{
double nan = 0.0 / 0.0;
double x = 1.0;
double y = nan + x;
printf( "nan=%f\n", nan );
printf( " x=%f\n", x );
printf( " y=%f\n", y );
return 0;
}
/* Should print (gcc):
nan=nan
x=1.000000
y=nan
*/
- dllthomas 12y agoI dislike the fact that NaN taints other numbers - for precisely the same reason. Much better, in terms of early failure, would be signalling NaN or something like... ... maybenan_double maybe_nan = 0.0 / 0.0; double x = 1.0; if(is_nan(maybe_nan)) { fprintf(stderr, "maybe_nan is NaN\n"); return 1; } double not_nan = from_maybenan(maybe_nan); double y = not_nan + x; ... Of course, there are other dimensions in which this is not better, but I don't like silent propagation if it might stretch over a lot of code.