# -1.#IND in output???

• 01-18-2008
alyeska
-1.#IND in output???
Hi, what does this output mean?

Code:

`Discriminant = sqrtf(-16) or -1.#INDi`
Program code is as follows:

Code:

```cout << "Discriminant = sqrtf(" << discriminant << ") or ";         d1 = sqrtf(discriminant);         cout << d1 << "i" << endl << endl;```
Thanks a lot!
• 01-18-2008
dwks
It means that the sqrt() of discriminant could not be calculated properly. The square root of negative numbers is not defined.

Of course, you could always use
Code:

`sqrt(fabs(discriminant))`
As for a more technical description of why it's "-1.#INDi" . . . I'm not entirely sure, but I'd guess that perhaps the trailing "i" means it's an imaginary number, which is what you get when you sqrt() a negative number. Google for more info.
• 01-18-2008
Salem
http://www.randelshofer.ch/fhw/gri/float.html
#IND stands for indefinite.
Other things you can get from time to time are #INF and #NAN.

> I'm not entirely sure, but I'd guess that perhaps the trailing "i" means it's an imaginary number
Nah, that's just the trailing i in the cout statement.
• 01-18-2008
alyeska
Hi..

Thanks dwks and Salem.. what you guys said made a lot of sense. It was the first time I have encountered that -1.#IND and now, at least I have an idea of what it stands for.

Yes, the i came from the cout statement. However, I am trying to get the formula for the square root of the discriminant. Suppose, discriminant is equal to -16. Answer should be 4. How do I efficiently write the formula?

Any ideas? I will experiment on the fabs function.

Thanks guys..
• 01-19-2008
laserlight
Quote:

However, I am trying to get the formula for the square root of the discriminant. Suppose, discriminant is equal to -16. Answer should be 4. How do I efficiently write the formula?
Have you considered using the std::complex class template from <complex>? For example:
Code:

```#include <iostream> #include <complex> template<typename T> void print(std::ostream& out, const std::complex<T>& x); int main() {     std::complex<double> x(-16);     std::cout << "sqrt(";     print(std::cout, x);     std::cout << ") = ";     print(std::cout, sqrt(x));     std::cout << std::endl; } template<typename T> void print(std::ostream& out, const std::complex<T>& x) {     std::ios::fmtflags old_flags = out.flags();     out << x.real() << std::showpos << x.imag() << "i";     out.flags(old_flags); }```