While the IEEE floating point standard provides for both positive and
negative infinity, the C++ standard header provides only for Positive
infinity.
The negative infinity value is needed as the minimum value for a
distribution that covers the entire real number range.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
The C++ standard deliberately doesn't say much about details like this,
leaving it for other standards to cover, such as IEC 559 (which is the
same as IEEE 754). If std::numeric_limits<T>::is_iec559 is true, then
IEC 559 is supposed to apply, and therefore
-std::numeric_limits<T>::infinity() should give you a negative
infinity. It's probably also true if is_iec559 is false, since that's a
very reasonable result, but you have no guarantees in that case.
> What is the C++ standard way to return a value of Negative Infinity?
>
> While the IEEE floating point standard provides for both positive and
> negative infinity, the C++ standard header provides only for Positive
> infinity.
>
> The negative infinity value is needed as the minimum value for a
> distribution that covers the entire real number range.
Have you tried:
double positive_infinity = ...
double negative_infinity = -positive_infinity;
-Tomás
> What is the C++ standard way to return a value of Negative Infinity?
>
> While the IEEE floating point standard provides for both positive and
> negative infinity, the C++ standard header provides only for Positive
> infinity.
>
> The negative infinity value is needed as the minimum value for a
> distribution that covers the entire real number range.
Try -std::numeric_limits<double>::infinity(). You have to first
include <limits>.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
"-std::numeric_limits<TYPE>::infinity()" is what I did use. It works with
GCC, and probably with any IEEE conforming floating point re[resentation,
but I could not find anything that guarantees its conformance with the C++
standard.
> ""P.J. Plauger"" <p...@dinkumware.com> wrote in message
> news:3v6dnVE8n8e...@giganews.com...
>> ""David Sachs"" <sa...@fnal.gov> wrote in message
>> news:DY6dnSFL2Js...@comcast.com...
>>
>>> What is the C++ standard way to return a value of Negative Infinity?
>>>
>>> While the IEEE floating point standard provides for both positive and
>>> negative infinity, the C++ standard header provides only for Positive
>>> infinity.
>>>
>>> The negative infinity value is needed as the minimum value for a
>>> distribution that covers the entire real number range.
>>
>> Try -std::numeric_limits<double>::infinity(). You have to first
>> include <limits>.
>>
>> P.J. Plauger
>> Dinkumware, Ltd.
>> http://www.dinkumware.com
>
> "-std::numeric_limits<TYPE>::infinity()" is what I did use. It works with
> GCC, and probably with any IEEE conforming floating point re[resentation,
> but I could not find anything that guarantees its conformance with the
> C++ standard.
Conform in what way? Certainly the reference to numeric_limits is
conforming. Whether it can deliver a true infinity depends on the
underlying representation for floating point. Perhaps you're worried
that you can't negate infinity -- well, in IEC 60559 (IEEE/754) you
can.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com