16

I have :

double score = cvMatchContourTrees( CT1, CT2, CV_CONTOUR_TREES_MATCH_I1, 0.0 );
        cout<<score<<endl;

There are values returned as -1.#IND. Other than that, the positive values are normal, like 1.34543.

Why does this happen? How do I solve it?

Allball103
  • 131
  • 8
Chai
  • 161
  • 1
  • 1
  • 3

3 Answers3

15

As Frederic says, it's the result of a 'Not a Number' being formatted by an application built with visual studio on windows. John D Cook has an excellent reference:

Windows displays a NaN as -1.#IND ("IND" for "indeterminate") while Linux displays nan.

...

In short, if you get 1.#INF or inf, look for overflow or division by zero. If you get 1.#IND or nan, look for illegal operations.

Watch out for truncations if you do any sort of formatting with your string; I've encountered related issues when handling these sorts of errors myself.

Community
  • 1
  • 1
Jon Cage
  • 36,366
  • 38
  • 137
  • 215
  • I'm not sure about `0/0` yielding `NaN`. I think it's like any other division by zero in that you'll get a floating-point exception from the OS. – Lightness Races in Orbit Sep 19 '11 at 20:45
  • @Tomalak: With Visual Studio, 0 / 0 throws an exception. 0.0 / 0.0 either returns NaN or throws an exception, you control that by a flag. The default is that it returns NaN. – Johan Råde Sep 19 '11 at 20:49
  • @user763305: Yes, exactly. And that's not what the original quote said. My point is, beware the perils of Wikipedia... – Lightness Races in Orbit Sep 19 '11 at 20:50
  • Maybe.. ...or maybe it's in a library call and that library silently masks the exception but still spits out NaN as per the OPs question... ? – Jon Cage Sep 19 '11 at 20:51
5
std::cout << (0/0.f);
// Output: -1.#IND

It's NaN.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
3

In my experience -1.#IND comes from imaginary numbers. So, doing cout << sqrt(-1.); should output -1.#IND

viraj
  • 1,784
  • 4
  • 35
  • 52