From 6b2d391f012bd38e878fdedba90d4e0b4a37b6ad Mon Sep 17 00:00:00 2001 From: vlefevre Date: Mon, 6 Jun 2016 10:59:02 +0000 Subject: [src/set_float128.c] Fix: removed the divisions by zero, replacing them by comparisons with the maximum finite binary128 number. Changes to be similar to the handling of infinities in "src/set_ld.c". git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@10434 280ebfd0-de03-0410-8827-d642c229c3f4 --- src/set_float128.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/set_float128.c b/src/set_float128.c index fb3a8402f..8aa11bd43 100644 --- a/src/set_float128.c +++ b/src/set_float128.c @@ -28,6 +28,9 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., #ifdef MPFR_WANT_FLOAT128 +/* The q suffix is a GNU C extension, but so is __float128. */ +#define MPFR_FLOAT128_MAX 0x1.ffffffffffffffffffffffffffffp+16383q + int mpfr_set_float128 (mpfr_ptr r, __float128 d, mpfr_rnd_t rnd_mode) { @@ -44,18 +47,16 @@ mpfr_set_float128 (mpfr_ptr r, __float128 d, mpfr_rnd_t rnd_mode) } /* Check for INF */ - /* FIXME: The code below generates a divide-by-zero exception, thus - will fail if this exception is trapped. Replace it by > and < - comparisons with the maximum positive (resp. negative) finite - binary128 numbers? */ - if (MPFR_UNLIKELY (d == ((__float128) 1.0 / (__float128) 0.0))) + if (MPFR_UNLIKELY (d > MPFR_FLOAT128_MAX)) { - mpfr_set_inf (r, 1); + MPFR_SET_INF (r); + MPFR_SET_POS (r); return 0; } - else if (MPFR_UNLIKELY (d == ((__float128) -1.0 / (__float128) 0.0))) + else if (MPFR_UNLIKELY (d < -MPFR_FLOAT128_MAX)) { - mpfr_set_inf (r, -1); + MPFR_SET_INF (r); + MPFR_SET_NEG (r); return 0; } /* Check for ZERO */ -- cgit v1.2.1