What should std::cout << std::numeric_limits<double>::infinity ()print?

S

Stuart Redmann

Dear newsgroup,

I'm struggling with the most famous compiler of all time (probably
many of you can guess which I mean ;-), and I think I got another
point where it is (supposedly) not standard-conform. For example

#include <iostream>
#include <limits>
int main ()
{
std::cout << std::numeric_limits<double>::infinity ();
}

prints "1.#INF". Is this behaviour according to the standard? I
haven't found anything valuable in the net about this, not even on
www.cplusplus.com. I'm starting to think that this may be even
implementation-defined.

Thanks,
Stuart
 
V

Victor Bazarov

I'm struggling with the most famous compiler of all time (probably
many of you can guess which I mean ;-), and I think I got another
point where it is (supposedly) not standard-conform. For example

#include<iostream>
#include<limits>
int main ()
{
std::cout<< std::numeric_limits<double>::infinity ();
}

prints "1.#INF". Is this behaviour according to the standard? I
haven't found anything valuable in the net about this, not even on
www.cplusplus.com. I'm starting to think that this may be even
implementation-defined.

I don't think the Standard specifies any particular output if the value
is one of "special" values, like infinity, minus infinity, not-a-number.
In fact, the section 22.2.2.2.2 says that the output should be like
the 'printf's with a particular format specifier ('f', 'e', 'g')
depending on some settings. Consider asking in 'comp.lang.c', they know
a bit more about C standard library, and you probably need to ask about
the obsolete C90 anyway. The 1999 C standard says that an infinity
value should output [-]inf or [-]infinity, defined by the
implementation. I am guessing some implementation don't follow the
recommendations of the Standard, or the specification in C90 used to be
different (I don't have the document to check).

V
 
S

Stuart Redmann

On 6/4/2010 4:12 AM, Stuart Redmann wrote:
[snipped question:
What should
std::cout << std::numeric_limits<double>::infinity ();
print?]

I don't think the Standard specifies any particular output if the value
is one of "special" values, like infinity, minus infinity, not-a-number. [snip]
The 1999 C standard says that an infinity
value should output [-]inf or [-]infinity, defined by the
implementation.  

That's what I guessed. Wouldn't it be a good idea to incorporate some
standard behaviour for "special" floating point values into the
upcoming C++0x standard, too?

Thanks,
Stuart
 
V

Victor Bazarov

On 6/4/2010 4:12 AM, Stuart Redmann wrote:
[snipped question:
What should
std::cout<< std::numeric_limits<double>::infinity ();
print?]

I don't think the Standard specifies any particular output if the value
is one of "special" values, like infinity, minus infinity, not-a-number. [snip]
The 1999 C standard says that an infinity
value should output [-]inf or [-]infinity, defined by the
implementation.

That's what I guessed. Wouldn't it be a good idea to incorporate some
standard behaviour for "special" floating point values into the
upcoming C++0x standard, too?

Personally, I don't really care. Outputting infinity or not-a-number is
not something I need often. And if I had to do it, I'd find a way,
without adding to the endless list of small things the Committee has to
look at. A simple comparison (with itself for NaNs) and a custom output
(of a string) should be sufficient.

If you feel up to it, write it up, submit to 'comp.std.c++'... The steps
for making a proposal are not secret. Don't count on succeeding in
adding it to the upcoming Standard, though. The work on it is pretty
much done.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top