summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/atan2.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/atan2.c b/src/atan2.c
index 444546495..b1ae9eaf6 100644
--- a/src/atan2.c
+++ b/src/atan2.c
@@ -161,10 +161,17 @@ mpfr_atan2 (mpfr_ptr dest, mpfr_srcptr y, mpfr_srcptr x, mpfr_rnd_t rnd_mode)
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;
+ if (MPFR_LIKELY (mpfr_div_2si (yoverx, y, MPFR_EXP (x) - 1, MPFR_RNDN) == 0))
+ {
+ r = mpfr_atan (dest, yoverx, rnd_mode);
+ mpfr_clear (yoverx);
+ return r;
+ }
+ else
+ {
+ /* Division is inexact because of a small exponent range */
+ mpfr_clear (yoverx);
+ }
}
MPFR_SAVE_EXPO_MARK (expo);