diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-06 10:59:02 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-06-06 10:59:02 +0000 |
commit | 6b2d391f012bd38e878fdedba90d4e0b4a37b6ad (patch) | |
tree | c37a507809ba0d66560bb34213d3e418666571f4 | |
parent | c813c5cb8996caea308298e4246fa8a17b49dc97 (diff) | |
download | mpfr-6b2d391f012bd38e878fdedba90d4e0b4a37b6ad.tar.gz |
[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
-rw-r--r-- | src/set_float128.c | 17 |
1 files 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 */ |