diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-05-23 14:23:11 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2016-05-23 14:23:11 +0000 |
commit | 912aa998b518869863f8b93e717dbb4e6edd5f1d (patch) | |
tree | b1890e1a0a23e592c7e8a51dbcbfd2da5fad27d2 /src/ubf.c | |
parent | d7efcf0fed1ff92af216e8b3f7b00707bd2375dd (diff) | |
download | mpfr-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.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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; +} |