How to set -1.#IND to print as '0'

I have a function that calculates the area of a triangle; however, when the area for the triangle is negative, the area is represented as '-1.#IND'. How do you force a function to set the area to 0.0 when the area of a triangle is negative?
this is what the appropriate function contains so far:

double calcArea(double side1, double side2, double side3) //AAAAAAAAAAA
{
double s = 0.5 * (side1 + side2 + side3);
double area = (sqrt (s*(s - side1) * (s-side2) * (s-side3)));

return area;
}

Thanks in advance,
Couldn't you just use an if statement that checks if area is less than 0 then area = 0.0?
Your formula is wrong.
s=.5*abs(AB*AC)
OR
s=.5*abs(AB*BC)
OR
s=.5*abs(BC*CA)
(The two sides must be adjacent.)
OR
s=sqrt(pow(AB,2)*pow(AC,2)-pow(AB*AC,2))

There's no such thing as negative surface (well, there is in calculus, but not in geometry).

http://en.wikipedia.org/wiki/Triangle#Using_vectors
Do you mean like this?


double calcArea(double side1, double side2, double side3) //AAAAAAAAAAA
{
double s = 0.5 * (side1 + side2 + side3);
double area = (sqrt (s*(s - side1) * (s-side2) * (s-side3)));

if (area < 0)
{
area == 0;
}

return area;
}


if so, it doesn't solve the problem, unfortunately.
I believe the equation is supposed to present this problem, and I am supposed to solve it with code rather than mathematically. :-\
I don't see what you're saying.
The formula is wrong. Period. It's not calculating the area of a triangle, but something completely different. There's no point in adding any checks after it, because it's the whole formula, not the data, that's wrong.
Thanks for your help :)
Topic archived. No new replies allowed.