Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nvbalfieri committed Mar 10, 2019
1 parent b664d31 commit b2ca539
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions Cordic.h
Original file line number Diff line number Diff line change
Expand Up @@ -3694,10 +3694,15 @@ T Cordic<T,FLT>::atan2( const T& _y, const T& _x, bool is_final, bool x_is_one,

// check for special cases
T rr;
if ( exp_class == EXP_CLASS::ZERO ) {
// 0
bool did_neg = false;
if ( exp_class == EXP_CLASS::ZERO || exp_class == EXP_CLASS::INFINITE ) {
// 0 or inf
//
rr = 0;
} else if ( exp_class == EXP_CLASS::NOT_A_NUMBER ) {
// NaN
rr = (x > 0) ? x : 1; // must be non-zero

} else {
cassert( exp_class == EXP_CLASS::NORMAL || exp_class == EXP_CLASS::SUBNORMAL,
"atan2: unexpected exp_class=" + to_str(exp_class) );
Expand All @@ -3706,13 +3711,14 @@ T Cordic<T,FLT>::atan2( const T& _y, const T& _x, bool is_final, bool x_is_one,
// reduce
T xx, yy;
circular_vectoring( x, y, _zero, xx, yy, rr );
}

bool did_neg = rr < 0;
if ( did_neg ) {
rr = -rr;
rr_sign = !rr_sign;
did_neg = rr < 0;
if ( did_neg ) {
rr = -rr;
rr_sign = !rr_sign;
}
}

reconstruct( rr, exp_class, 0, rr_sign );
rr = scalbn( rr, 1, false );
if ( swapped ) rr = sub( did_neg ? _neg_pi : _pi, rr, false );
Expand Down

0 comments on commit b2ca539

Please sign in to comment.