From ab1990425d7cb0b2454f155a507aaf912194e3e0 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Tue, 13 Aug 2019 20:26:30 +0100 Subject: [PATCH] add hi-perf notes on ATAN/ATAN2 --- ztrans_proposal.mdwn | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ztrans_proposal.mdwn b/ztrans_proposal.mdwn index 70d9247cc..0e192a0d9 100644 --- a/ztrans_proposal.mdwn +++ b/ztrans_proposal.mdwn @@ -275,3 +275,24 @@ one can then do high precision multiplies of π or other transcendental radixes. And GPUs have been doing this almost since the dawn of 3D. + + // calculate ATAN2 high performance style + // Note: at this point x != y + // + if( x > 0.0 ) + { + if( y < 0.0 && |y| < |x| ) return - π/2 - ATAN( x / y ); + if( y < 0.0 && |y| > |x| ) return + ATAN( y / x ); + if( y > 0.0 && |y| < |x| ) return + ATAN( y / x ); + if( y > 0.0 && |y| > |x| ) return + π/2 - ATAN( x / y ); + } + if( x < 0.0 ) + { + if( y < 0.0 && |y| < |x| ) return + π/2 + ATAN( x / y ); + if( y < 0.0 && |y| > |x| ) return + π - ATAN( y / x ); + if( y > 0.0 && |y| < |x| ) return + π - ATAN( y / x ); + if( y > 0.0 && |y| > |x| ) return +3π/2 + ATAN( x / y ); + } + +This way the adds and subtracts from the constant are not in a precision +precarious position. -- 2.30.2