Fixed bug #702 and added unit test.

Thanks to Alexander Werner for the report.
This commit is contained in:
Christoph Hertzberg
2013-11-07 18:32:24 +01:00
parent 76c230a84d
commit ae83f5ede9
3 changed files with 48 additions and 5 deletions

View File

@@ -599,12 +599,10 @@ atan2(const AutoDiffScalar<DerTypeA>& a, const AutoDiffScalar<DerTypeB>& b)
PlainADS ret;
ret.value() = atan2(a.value(), b.value());
Scalar tmp2 = a.value() * a.value();
Scalar tmp3 = b.value() * b.value();
Scalar tmp4 = tmp3/(tmp2+tmp3);
Scalar squared_hypot = a.value() * a.value() + b.value() * b.value();
if (tmp4!=0)
ret.derivatives() = (a.derivatives() * b.value() - a.value() * b.derivatives()) * (tmp2+tmp3);
// if (squared_hypot==0) the derivation is undefined and the following results in a NaN:
ret.derivatives() = (a.derivatives() * b.value() - a.value() * b.derivatives()) / squared_hypot;
return ret;
}