From: Luke Kenneth Casson Leighton Date: Tue, 13 Aug 2019 19:26:30 +0000 (+0100) Subject: add hi-perf notes on ATAN/ATAN2 X-Git-Tag: convert-csv-opcode-to-binary~4207 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ab1990425d7cb0b2454f155a507aaf912194e3e0;p=libreriscv.git add hi-perf notes on ATAN/ATAN2 --- 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.