Topic: Negative Infinity
Author: sachs@fnal.gov ("David Sachs")
Date: Sat, 8 Apr 2006 16:59:42 GMT Raw View
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-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: kuyper@wizard.net
Date: 8 Apr 2006 19:00:08 GMT Raw View
"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.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: NULL@NULL.NULL ("Tom s")
Date: Sat, 8 Apr 2006 21:10:00 GMT Raw View
"David Sachs" posted:
> What is the C++ standard way to return a value of Negative Infinity?
>=20
> While the IEEE floating point standard provides for both positive and=20
> negative infinity, the C++ standard header provides only for Positive=20
> infinity.
>=20
> The negative infinity value is needed as the minimum value for a=20
> distribution that covers the entire real number range.=20
=20
=20
Have you tried:
double positive_infinity =3D ...
double negative_infinity =3D -positive_infinity;
-Tom=E1s
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: pjp@dinkumware.com ("P.J. Plauger")
Date: Sat, 8 Apr 2006 21:10:11 GMT Raw View
""David Sachs"" <sachs@fnal.gov> wrote in message
news:DY6dnSFL2JsNharZRVn-ug@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
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: sachs@fnal.gov ("David Sachs")
Date: Sun, 9 Apr 2006 03:20:59 GMT Raw View
""P.J. Plauger"" <pjp@dinkumware.com> wrote in message
news:3v6dnVE8n8ennKXZRVn-vQ@giganews.com...
> ""David Sachs"" <sachs@fnal.gov> wrote in message
> news:DY6dnSFL2JsNharZRVn-ug@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.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: pjp@dinkumware.com ("P.J. Plauger")
Date: Sun, 9 Apr 2006 23:44:05 GMT Raw View
""David Sachs"" <sachs@fnal.gov> wrote in message
news:4s6dnZ5lMf_M9KXZnZ2dnUVZ_uidnZ2d@comcast.com...
> ""P.J. Plauger"" <pjp@dinkumware.com> wrote in message
> news:3v6dnVE8n8ennKXZRVn-vQ@giganews.com...
>> ""David Sachs"" <sachs@fnal.gov> wrote in message
>> news:DY6dnSFL2JsNharZRVn-ug@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
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]