J
Jon Wilson
How do I write Not A Number or +/- infinity (floating point values) as
literal constants (I'm using g++)?
I have a function that returns float, and I need a flag value, and for
various reasons one of NaN, +/-inf would be most convenient. But how do
I tell my function to return one of these? The best I can come up with
so far is
float foo()
{
if(bar)
return (2 + 2);
else
return (0.0 / 0.0);
}
Which works, ( (0.0 / 0.0) == NaN, or (1.0 / 0.0) == inf ), but g++
gives me a divide-by-zero warning when I compile.
Regards,
Jon
literal constants (I'm using g++)?
I have a function that returns float, and I need a flag value, and for
various reasons one of NaN, +/-inf would be most convenient. But how do
I tell my function to return one of these? The best I can come up with
so far is
float foo()
{
if(bar)
return (2 + 2);
else
return (0.0 / 0.0);
}
Which works, ( (0.0 / 0.0) == NaN, or (1.0 / 0.0) == inf ), but g++
gives me a divide-by-zero warning when I compile.
Regards,
Jon