Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of minus sign from signed zero

I am using asin to calculate the angle. The code is as below :

double FindAngle(const double theValue)
{
     return asin(theValue);
}

FindAngle returns a -0.0 (signed zero), when the argument theValue = -0.0. Now, how do i get rid of the minus sign from the return value.

like image 342
ratnaveer Avatar asked Jan 18 '10 09:01

ratnaveer


3 Answers

You can do the following:

double FindAngle(const double theValue)
{
     return (asin(theValue) + 0.0);
}

I had the same problem and that worked for me.

like image 109
FacundoJ Avatar answered Nov 20 '22 18:11

FacundoJ


If you just want to convert -0 to 0 and leave other untouched, just do a comparison.

double FindAngle(double value) {
    double res = asin(value);
    if (res == 0.0) res = 0.0;
    return res;
}
like image 32
kennytm Avatar answered Nov 20 '22 18:11

kennytm


include <cmath> and use the abs function on your return value, if you want all results to be positive, or check if your return value is equal to -0.0 and take the abs value of it, for just that case.

abs function (c++ reference)

like image 37
Matt Ellen Avatar answered Nov 20 '22 18:11

Matt Ellen