summaryrefslogtreecommitdiff
path: root/src/ubf.c
diff options
context:
space:
mode:
authorvlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-02-12 01:38:57 +0000
committervlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4>2020-02-12 01:38:57 +0000
commitf3d72251d93baeb4a50b42c48889040e90c7bf16 (patch)
treeb5765ac5ddc030db51783849cbec52d43c9114a1 /src/ubf.c
parent9148099c1a7acb3e52e50e5f1295d3f2743b605c (diff)
downloadmpfr-f3d72251d93baeb4a50b42c48889040e90c7bf16.tar.gz
[src/ubf.c]
* Optimized mpfr_init_get_zexp() for _MPFR_EXP_FORMAT <= 3 (as in the default configuration). * Updated comments. git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@13704 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/ubf.c')
-rw-r--r--src/ubf.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/ubf.c b/src/ubf.c
index b0a2213fd..8b3ba066b 100644
--- a/src/ubf.c
+++ b/src/ubf.c
@@ -31,7 +31,8 @@ https://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
detected and handled separately, but for polynomial, this should not
be needed). */
-/* This function does not change the flags. */
+/* Get the exponent of a regular MPFR number or UBF as a mpz_t, which is
+ initialized by this function. The flags are not changed. */
static void
mpfr_init_get_zexp (mpz_ptr ez, mpfr_srcptr x)
{
@@ -41,20 +42,25 @@ mpfr_init_get_zexp (mpz_ptr ez, mpfr_srcptr x)
mpz_set (ez, MPFR_ZEXP (x));
else
{
+ mpfr_exp_t ex = MPFR_GET_EXP (x);
+
+#if _MPFR_EXP_FORMAT <= 3
+ /* mpfr_exp_t fits in a long */
+ mpz_set_si (ez, ex);
+#else
mp_limb_t e_limb[MPFR_EXP_LIMB_SIZE];
mpfr_t e;
int inex;
MPFR_SAVE_EXPO_DECL (expo);
- /* TODO: Once this has been tested, optimize based on whether
- _MPFR_EXP_FORMAT <= 3. */
MPFR_TMP_INIT1 (e_limb, e, sizeof (mpfr_exp_t) * CHAR_BIT);
MPFR_SAVE_EXPO_MARK (expo);
- MPFR_DBGRES (inex = mpfr_set_exp_t (e, MPFR_GET_EXP (x), MPFR_RNDN));
+ MPFR_DBGRES (inex = mpfr_set_exp_t (e, ex, MPFR_RNDN));
MPFR_ASSERTD (inex == 0);
MPFR_DBGRES (inex = mpfr_get_z (ez, e, MPFR_RNDN));
MPFR_ASSERTD (inex == 0);
MPFR_SAVE_EXPO_FREE (expo);
+#endif
}
}
@@ -181,6 +187,10 @@ mpfr_ubf_mul_exact (mpfr_ubf_ptr a, mpfr_srcptr b, mpfr_srcptr c)
}
}
+/* Compare the exponents of two numbers, which can be either MPFR numbers
+ or UBF numbers. If both numbers can be MPFR numbers, it is better to
+ use the MPFR_UBF_EXP_LESS_P wrapper macro, which is optimized for this
+ common case. */
int
mpfr_ubf_exp_less_p (mpfr_srcptr x, mpfr_srcptr y)
{
@@ -195,7 +205,7 @@ mpfr_ubf_exp_less_p (mpfr_srcptr x, mpfr_srcptr y)
return c;
}
-/* Convert an mpz_t to an mpfr_exp_t, restricted to
+/* Convert an mpz_t to an mpfr_exp_t, saturated to
the interval [MPFR_EXP_MIN,MPFR_EXP_MAX]. */
mpfr_exp_t
mpfr_ubf_zexp2exp (mpz_ptr ez)
@@ -224,7 +234,7 @@ mpfr_ubf_zexp2exp (mpz_ptr ez)
return e;
}
-/* Return the difference of the exponents of x and y, restricted to
+/* Return the difference of the exponents of x and y, saturated to
the interval [MPFR_EXP_MIN,MPFR_EXP_MAX]. */
mpfr_exp_t
mpfr_ubf_diff_exp (mpfr_srcptr x, mpfr_srcptr y)