diff options
author | lfousse <lfousse@280ebfd0-de03-0410-8827-d642c229c3f4> | 2011-01-13 16:24:41 +0000 |
---|---|---|
committer | lfousse <lfousse@280ebfd0-de03-0410-8827-d642c229c3f4> | 2011-01-13 16:24:41 +0000 |
commit | 99cb73a2cdf8b66e54cdf607b8dab73299bce096 (patch) | |
tree | 0aab93cc70265a1d713a5c0e90e67695d478f583 /src/atan2.c | |
parent | 1dd42b9b5e870bb18a537c1856ff515a70cf4555 (diff) | |
download | mpfr-99cb73a2cdf8b66e54cdf607b8dab73299bce096.tar.gz |
Add special case for atan2(x,y) when x is a power of 2.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@7332 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/atan2.c')
-rw-r--r-- | src/atan2.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/atan2.c b/src/atan2.c index 786c4a017..444546495 100644 --- a/src/atan2.c +++ b/src/atan2.c @@ -154,10 +154,18 @@ mpfr_atan2 (mpfr_ptr dest, mpfr_srcptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode) goto set_zero; } - /* When x=1, atan2(y,x) = atan(y). FIXME: more generally, if x is a power - of two, we could call directly atan(y/x) since y/x is exact. */ - if (mpfr_cmp_ui (x, 1) == 0) - return mpfr_atan (dest, y, rnd_mode); + /* When x is a power of two, we call directly atan(y/x) since y/x is + exact. */ + if (MPFR_UNLIKELY (MPFR_IS_POWER_OF_2 (x))) + { + int r; + mpfr_t yoverx; + mpfr_init2 (yoverx, MPFR_PREC (y)); + mpfr_div_2si (yoverx, y, MPFR_EXP (x) - 1, MPFR_RNDN); + r = mpfr_atan (dest, yoverx, rnd_mode); + mpfr_clear (yoverx); + return r; + } MPFR_SAVE_EXPO_MARK (expo); |