I use ANSI C89 (not C++), and I want to generate NaN
, -Infinity
and +Infinity
.
Is there any standard way (eg. standard macro)? Or is there any platform and compiler independent way to generate these numbers?
float f = 0.0 / 0.0; // Is f ALWAYS in any platform is NaN?
In C, the isnan macro and the _isnan and _isnanf functions return a non-zero value if the argument x is a NAN; otherwise they return 0. In C++, the isnan template function returns true if the argument x is a NaN; otherwise it returns false .
The sqrt() function is defined in math. h header file. To find the square root of int , float or long double data types, you can explicitly convert the type to double using cast operator. int x = 0; double result; result = sqrt(double(x));
The math. h header defines various mathematical functions and one macro. All the functions available in this library take double as an argument and return double as the result.
The range of double is 1.7E-308 to 1.7E+308. Double data can be represents in real number (1, 10), decimals (0.1, 11.002) and minus (-1, -0.00002). It can hold approximately 15 to 16 digits before and after the decimal point. For example, 4.5672, 2.45354, -5.22234, 3.12345678901, 0.15197e-7 etc.
There is in C99, but not in previous standards AFAIK.
In C99, you'll have NAN
and INFINITY
macros.
From "Mathematics <math.h>
" (§7.12) section
The macro INFINITY expands to a constant expression of type float representing positive or unsigned infinity, if available; ...
If you're stuck with ANSI C89, you're out of luck. See C-FAQ 14.9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With