|
Prev | Next |
result = CondExpOp(left, right, trueCase, falseCase)
if( left op right )
result = trueCase
else result = falseCase
The notation Op and op
above have the following correspondence:
Op
|
Lt
|
Le
|
Eq
|
Ge
|
Gt
|
| op |
<
|
<=
|
==
|
>=
|
>
|
float, double, or in the
AD levels above
above float or double.
Lt, Le, Eq, Ge, Gt.
As in the table above,
Op determines the comparison operator op.
const Type &left
It specifies the value for the left side of the comparison operator.
const Type &right
It specifies the value for the right side of the comparison operator.
const Type &trueCase
It specifies the return value if the result of the comparison is true.
const Type &falseCase
It specifies the return value if the result of the comparison is false.
Type &falseCase
CondExp(flag, trueCase, falseCase)
for the same meaning as
CondExpGt(flag, Type(0), trueCase, falseCase)
Use of CondExp is deprecated, but continues to be supported.
template <class Base>
AD<Base> atan2 (const AD<Base> &y, const AD<Base> &x)
{ AD<Base> alpha;
AD<Base> beta;
AD<Base> theta;
AD<Base> zero = 0;
AD<Base> pi2 = 2. * atan(1.);
AD<Base> pi = 2. * pi2;
AD<Base> ax = abs(x);
AD<Base> ay = abs(y);
// if( ax > ay )
// theta = atan(ay / ax);
// else theta = pi2 - atan(ax / ay);
alpha = atan(ay / ax);
beta = pi2 - atan(ax / ay);
theta = CondExpGt(ax, ay, alpha, beta); // use of CondExp
// if( x <= 0 )
// theta = pi - theta;
theta = CondExpLe(x, zero, pi - theta, theta); // use of CondExp
// if( y <= 0 )
// theta = - theta;
theta = CondExpLe(y, zero, -theta, theta); // use of CondExp
return theta;
}