diff options
author | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-12-21 17:08:38 +0000 |
---|---|---|
committer | zimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4> | 2000-12-21 17:08:38 +0000 |
commit | c74d024d1bfb5cffbd9cf27664f824bb4087dda8 (patch) | |
tree | 5785612341cfeeaab51d555c975ec973b480292a /reldiff.c | |
parent | 783f93b38a3d8264f81fb1b303c11c9e9cd9c27e (diff) | |
download | mpfr-c74d024d1bfb5cffbd9cf27664f824bb4087dda8.tar.gz |
k2r -> ansi style
removed #include <math.h> by defining auxiliary functions
fixed several tiny remaining bugs with NaN/Inf
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@925 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'reldiff.c')
-rw-r--r-- | reldiff.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -21,8 +21,9 @@ MA 02111-1307, USA. */ #include <stdio.h> #include "gmp.h" -#include "mpfr.h" #include "gmp-impl.h" +#include "mpfr.h" +#include "mpfr-impl.h" /* reldiff(b, c) = abs(b-c)/b */ void @@ -36,6 +37,8 @@ mpfr_reldiff(a, b, c, rnd_mode) mp_rnd_t rnd_mode; #endif { + mpfr_t b_copy; + if (MPFR_IS_NAN(b) || MPFR_IS_NAN(c)) { MPFR_CLEAR_FLAGS(a); MPFR_SET_NAN(a); return; } if (MPFR_IS_INF(b)) @@ -58,9 +61,16 @@ mpfr_reldiff(a, b, c, rnd_mode) /* TODO: faire preciser la SEMANTIQUE DE CE FOUTOIR. */ mpfr_set_ui(a, MPFR_SIGN(c), rnd_mode); else { + if (a == b) { + mpfr_init2 (b_copy, MPFR_PREC(b)); + mpfr_set (b_copy, b, GMP_RNDN); + } + mpfr_sub(a, b, c, rnd_mode); mpfr_abs(a, a, rnd_mode); /* for compatibility with MPF */ - mpfr_div(a, a, b, rnd_mode); + mpfr_div(a, a, (a == b) ? b_copy : b, rnd_mode); + + if (a == b) mpfr_clear (b_copy); } } |