Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Negative Infinity

2 views
Skip to first unread message

David Sachs

unread,
Apr 8, 2006, 12:59:42 PM4/8/06
to
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.


---
[ 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 ]

kuy...@wizard.net

unread,
Apr 8, 2006, 3:00:08 PM4/8/06
to
"David Sachs" wrote:
> 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 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.

Tomás

unread,
Apr 8, 2006, 5:10:00 PM4/8/06
to
"David Sachs" posted:

> 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

P.J. Plauger

unread,
Apr 8, 2006, 5:10:11 PM4/8/06
to
""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

David Sachs

unread,
Apr 8, 2006, 11:20:59 PM4/8/06
to

""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.

P.J. Plauger

unread,
Apr 9, 2006, 7:44:05 PM4/9/06
to
""David Sachs"" <sa...@fnal.gov> wrote in message
news:4s6dnZ5lMf_M9KXZ...@comcast.com...

> ""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

0 new messages