 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
David Sachs Guest
|
Posted: Sat Apr 08, 2006 5:06 pm Post subject: Negative Infinity |
|
|
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 ] |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Apr 08, 2006 7:06 pm Post subject: Re: Negative Infinity |
|
|
"David Sachs" wrote:
| Quote: | 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 ] |
|
| Back to top |
|
 |
Tomás Guest
|
Posted: Sat Apr 08, 2006 10:06 pm Post subject: Re: Negative Infinity |
|
|
"David Sachs" posted:
| Quote: | 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
---
[ 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 ] |
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Sat Apr 08, 2006 10:06 pm Post subject: Re: Negative Infinity |
|
|
""David Sachs"" <sachs (AT) fnal (DOT) gov> wrote in message
news:DY6dnSFL2JsNharZRVn-ug (AT) comcast (DOT) com...
| Quote: | 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 ] |
|
| Back to top |
|
 |
David Sachs Guest
|
Posted: Sun Apr 09, 2006 4:06 am Post subject: Re: Negative Infinity |
|
|
""P.J. Plauger"" <pjp (AT) dinkumware (DOT) com> wrote in message
news:3v6dnVE8n8ennKXZRVn-vQ (AT) giganews (DOT) com...
| Quote: | ""David Sachs"" <sachs (AT) fnal (DOT) gov> wrote in message
news:DY6dnSFL2JsNharZRVn-ug (AT) comcast (DOT) 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 ] |
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Mon Apr 10, 2006 12:06 am Post subject: Re: Negative Infinity |
|
|
""David Sachs"" <sachs (AT) fnal (DOT) gov> wrote in message
news:4s6dnZ5lMf_M9KXZnZ2dnUVZ_uidnZ2d (AT) comcast (DOT) com...
| Quote: | ""P.J. Plauger"" <pjp (AT) dinkumware (DOT) com> wrote in message
news:3v6dnVE8n8ennKXZRVn-vQ (AT) giganews (DOT) com...
""David Sachs"" <sachs (AT) fnal (DOT) gov> wrote in message
news:DY6dnSFL2JsNharZRVn-ug (AT) comcast (DOT) 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 ] |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|