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.
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.
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;
}
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With