# Thread: Allowing negative square root

1. ## Allowing negative square root

I don't have a clue how to "break" this to actually return a negative square, but that is what I need to figure out. For example, the sqrt of -100 should be -10, but I just get the error telling me that's silly (-1#.IND).

Code:
```#include <iostream>
#include <cmath>
using namespace std;
double wierdsquareroot(double x)
{
return sqrt(x);
}
int main ()  // Program calculates the square root of a number
{
double num;
do
{
cout << "Enter a number (a double): "; cin >> num;
cout << "The square root is " << wierdsquareroot(num) << endl;
}while (num != 0);
}```

2. If the number is negative, change it to its absolute value and then apply the square root. However, you also need some way to inform the caller that the result is imaginary.

3. Something like this?
Code:
```if (x < 0.0)
return -sqrt(-x);
return sqrt(x);```

4. Yes, if that is what you want.

5. Originally Posted by jae5086
For example, the sqrt of -100 should be -10
In what screwed-up universe is -10 * -10 == -100?

6. Originally Posted by brewbuck
In what screwed-up universe is -10 * -10 == -100?
the universe where every '-' is replaced by a '+'