summaryrefslogtreecommitdiff
path: root/reldiff.c
diff options
context:
space:
mode:
authorzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2000-12-21 17:08:38 +0000
committerzimmerma <zimmerma@280ebfd0-de03-0410-8827-d642c229c3f4>2000-12-21 17:08:38 +0000
commitc74d024d1bfb5cffbd9cf27664f824bb4087dda8 (patch)
tree5785612341cfeeaab51d555c975ec973b480292a /reldiff.c
parent783f93b38a3d8264f81fb1b303c11c9e9cd9c27e (diff)
downloadmpfr-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.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/reldiff.c b/reldiff.c
index dcc62ee38..ea21a60b1 100644
--- a/reldiff.c
+++ b/reldiff.c
@@ -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);
}
}