diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-10-19 10:25:49 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2002-10-19 10:25:49 +0000 |
commit | 6460086c9ad02ed80a92fff9feff1bde6893ed23 (patch) | |
tree | aedc6da60100c9cf0c0a5422e64a84e188a119ca /hypot.c | |
parent | 6a97470bb74a6c8415a74cb7c712d2ac9bec7a36 (diff) | |
download | mpfr-6460086c9ad02ed80a92fff9feff1bde6893ed23.tar.gz |
Some fixes to avoid overflows.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@2072 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'hypot.c')
-rw-r--r-- | hypot.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -40,7 +40,8 @@ mpfr_hypot (mpfr_ptr z, mpfr_srcptr x , mpfr_srcptr y , mp_rnd_t rnd_mode) mpfr_t t, te, ti; /* auxiliary variables */ mp_prec_t Nx, Ny, Nz; /* size variables */ mp_prec_t Nt; /* precision of the intermediary variable */ - mp_exp_t Ex, Ey, diff_exp, sh; + mp_exp_t Ex, Ey, sh; + mp_exp_unsigned_t diff_exp; /* particular cases */ @@ -79,7 +80,7 @@ mpfr_hypot (mpfr_ptr z, mpfr_srcptr x , mpfr_srcptr y , mp_rnd_t rnd_mode) Ex = MPFR_EXP(x); Ey = MPFR_EXP(y); - diff_exp = Ex - Ey; + diff_exp = (mp_exp_unsigned_t) Ex - Ey; Nz = MPFR_PREC(z); /* Precision of output variable */ @@ -90,7 +91,7 @@ mpfr_hypot (mpfr_ptr z, mpfr_srcptr x , mpfr_srcptr y , mp_rnd_t rnd_mode) i.e. a sufficient condition is y^2 < |x|*ulp(x,Nz), or 2^(2*Ey) <= 2^(2*Ex-1-Nz), i.e. 2*diff_exp > Nz */ - if (2 * diff_exp > Nz) /* result is |x| or |x|+ulp(|x|,Nz) */ + if (diff_exp > Nz / 2) /* result is |x| or |x|+ulp(|x|,Nz) */ { if (rnd_mode == GMP_RNDU) { |