NaN and inf literal constants g++
From: Jon Wilson (jsw_at_fnal.gov)
Date: 12/31/04
- Next message: E. Robert Tisdale: "Re: Rate yourself as a C++ programmer, 1 to 10"
- Previous message: Dave O'Hearn: "Re: Rate yourself as a C++ programmer, 1 to 10"
- Next in thread: Victor Bazarov: "Re: NaN and inf literal constants g++"
- Reply: Victor Bazarov: "Re: NaN and inf literal constants g++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 31 Dec 2004 02:41:41 GMT
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
- Next message: E. Robert Tisdale: "Re: Rate yourself as a C++ programmer, 1 to 10"
- Previous message: Dave O'Hearn: "Re: Rate yourself as a C++ programmer, 1 to 10"
- Next in thread: Victor Bazarov: "Re: NaN and inf literal constants g++"
- Reply: Victor Bazarov: "Re: NaN and inf literal constants g++"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|