summaryrefslogtreecommitdiff
path: root/src/ubf.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-05-23 14:23:11 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2016-05-23 14:23:11 +0000
commit912aa998b518869863f8b93e717dbb4e6edd5f1d (patch)
treeb1890e1a0a23e592c7e8a51dbcbfd2da5fad27d2 /src/ubf.c
parentd7efcf0fed1ff92af216e8b3f7b00707bd2375dd (diff)
downloadmpfr-912aa998b518869863f8b93e717dbb4e6edd5f1d.tar.gz
Added UBF support for mpfr_cmp2.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/branches/ubf@10322 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/ubf.c')
-rw-r--r--src/ubf.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/ubf.c b/src/ubf.c
index 1aa67d759..fe596c32e 100644
--- a/src/ubf.c
+++ b/src/ubf.c
@@ -178,3 +178,37 @@ mpfr_ubf_exp_less_p (mpfr_srcptr x, mpfr_srcptr y)
mpz_clear (ye);
return c;
}
+
+/* Return the difference of the exponents of x and y, restricted to
+ the interval [MPFR_EXP_MIN,MPFR_EXP_MAX]. */
+mpfr_exp_t
+mpfr_ubf_diff_exp (mpfr_srcptr x, mpfr_srcptr y)
+{
+ mpz_t xe, ye;
+ mp_size_t n;
+ mpfr_eexp_t e;
+ mpfr_t d;
+ int inex;
+ MPFR_SAVE_EXPO_DECL (expo);
+
+ mpfr_get_zexp (xe, x);
+ mpfr_get_zexp (ye, y);
+ mpz_sub (xe, xe, ye);
+ mpz_clear (ye);
+ n = ABSIZ(xe); /* limb size of xe */
+ if (n == 0)
+ return 0;
+ MPFR_SAVE_EXPO_MARK (expo);
+ mpfr_init2 (d, n * GMP_NUMB_BITS);
+ MPFR_DBGRES (inex = mpfr_set_z (d, xe, MPFR_RNDN));
+ MPFR_ASSERTD (inex == 0);
+ mpz_clear (xe);
+ e = mpfr_get_exp_t (d, MPFR_RNDZ);
+ mpfr_clear (d);
+ MPFR_SAVE_EXPO_FREE (expo);
+ if (MPFR_UNLIKELY (e < MPFR_EXP_MIN))
+ return MPFR_EXP_MIN;
+ if (MPFR_UNLIKELY (e > MPFR_EXP_MAX))
+ return MPFR_EXP_MAX;
+ return e;
+}