5

I'm printing a variable using cout in Visual C++ 2010 and it shows "1.$". What does it mean?

Google does not allow searches with $ so I couldn't find the meaning.

EDIT:

The code is like this:

double func(...);

std::cout << func(...);

I haven't modified cout's defaults

Fábio Diniz
  • 10,077
  • 3
  • 38
  • 45

2 Answers2

11

Its an infinite value with the precision set small:

#include <iostream>
#include <limits>
int main()
{
    std::cout << std::numeric_limits<double>::infinity() << "\n";
    std::cout << std::numeric_limits<double>::quiet_NaN()() << "\n";

    std::cout << std::setprecision(2) << std::numeric_limits<double>::infinity() << "\n";
    std::cout << std::setprecision(2) << std::numeric_limits<double>::quiet_NaN() << "\n";
}

This should print:

1.#INF
1.#QNAN
1.$
1.$

Edit:

From @ZoogieZork in the comments below (who pointed out that it was a precision problem).
This is directly related to this: What does floating point error -1.#J mean?

Community
  • 1
  • 1
Martin York
  • 257,169
  • 86
  • 333
  • 562
-2

$ has no special meaning in C++.

You are printing a string that contains $.

Steve Wellens
  • 20,506
  • 2
  • 28
  • 69