I want to initialize a variable in C language to be the plus infinity or minus infinity, how can I do that ? The below fails:
float plus_inf = 0.0/0.0;
I want to initialize a variable in C language to be the plus infinity or minus infinity, how can I do that ? The below fails:
float plus_inf = 0.0/0.0;
You can try
#include <math.h>
....
float x = INFINITY;
According to the standard:
The macro
INFINITY
expands to a constant expression of type float representing positive or unsigned infinity, if available; else to a positive constant of type float that overflows at translation time.
0.0/0.0
is a nan
(not a number), as an alternative to INFINITY
(c89 and earlier) try:
float plus_inf = 1.0/0.0;
Macro Infinity is defined under library.
float variable = INFINITY;