Files
haikuports/dev-libs/mpfr/patches/mpfr-3.1.6.patchset
2017-11-20 21:03:49 +01:00

305 lines
8.6 KiB
Plaintext

From 04bac4acf89545d453021bc8104055bfa6244c39 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Mon, 20 Nov 2017 20:58:06 +0100
Subject: 3.1.6-p1
diff --git a/PATCHES b/PATCHES
index e69de29..aebe097 100644
--- a/PATCHES
+++ b/PATCHES
@@ -0,0 +1 @@
+mpfr_get
diff --git a/VERSION b/VERSION
index 9cec716..9fa2663 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.1.6
+3.1.6-p1
diff --git a/src/get_ld.c b/src/get_ld.c
index b1d77c7..51bd015 100644
--- a/src/get_ld.c
+++ b/src/get_ld.c
@@ -41,6 +41,9 @@ mpfr_get_ld (mpfr_srcptr x, mpfr_rnd_t rnd_mode)
mpfr_exp_t sh; /* exponent shift, so that x/2^sh is in the double range */
mpfr_t y, z;
int sign;
+ MPFR_SAVE_EXPO_DECL (expo);
+
+ MPFR_SAVE_EXPO_MARK (expo);
/* first round x to the target long double precision, so that
all subsequent operations are exact (this avoids double rounding
@@ -103,6 +106,7 @@ mpfr_get_ld (mpfr_srcptr x, mpfr_rnd_t rnd_mode)
}
if (sign < 0)
r = -r;
+ MPFR_SAVE_EXPO_FREE (expo);
return r;
}
}
diff --git a/src/get_si.c b/src/get_si.c
index 134874c..3afad58 100644
--- a/src/get_si.c
+++ b/src/get_si.c
@@ -28,6 +28,7 @@ mpfr_get_si (mpfr_srcptr f, mpfr_rnd_t rnd)
mpfr_prec_t prec;
long s;
mpfr_t x;
+ MPFR_SAVE_EXPO_DECL (expo);
if (MPFR_UNLIKELY (!mpfr_fits_slong_p (f, rnd)))
{
@@ -39,14 +40,22 @@ mpfr_get_si (mpfr_srcptr f, mpfr_rnd_t rnd)
if (MPFR_IS_ZERO (f))
return (long) 0;
- /* determine prec of long */
- for (s = LONG_MIN, prec = 0; s != 0; s /= 2, prec++)
+ /* Determine the precision of long. |LONG_MIN| may have one more bit
+ as an integer, but in this case, this is a power of 2, thus fits
+ in a precision-prec floating-point number. */
+ for (s = LONG_MAX, prec = 0; s != 0; s /= 2, prec++)
{ }
+ MPFR_SAVE_EXPO_MARK (expo);
+
/* first round to prec bits */
mpfr_init2 (x, prec);
mpfr_rint (x, f, rnd);
+ /* The flags from mpfr_rint are the wanted ones. In particular,
+ it sets the inexact flag when necessary. */
+ MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
+
/* warning: if x=0, taking its exponent is illegal */
if (MPFR_UNLIKELY (MPFR_IS_ZERO(x)))
s = 0;
@@ -65,5 +74,7 @@ mpfr_get_si (mpfr_srcptr f, mpfr_rnd_t rnd)
mpfr_clear (x);
+ MPFR_SAVE_EXPO_FREE (expo);
+
return s;
}
diff --git a/src/get_sj.c b/src/get_sj.c
index 5e92199..f270f37 100644
--- a/src/get_sj.c
+++ b/src/get_sj.c
@@ -35,6 +35,7 @@ mpfr_get_sj (mpfr_srcptr f, mpfr_rnd_t rnd)
intmax_t r;
mpfr_prec_t prec;
mpfr_t x;
+ MPFR_SAVE_EXPO_DECL (expo);
if (MPFR_UNLIKELY (!mpfr_fits_intmax_p (f, rnd)))
{
@@ -46,20 +47,24 @@ mpfr_get_sj (mpfr_srcptr f, mpfr_rnd_t rnd)
if (MPFR_IS_ZERO (f))
return (intmax_t) 0;
- /* determine the precision of intmax_t */
- for (r = MPFR_INTMAX_MIN, prec = 0; r != 0; r /= 2, prec++)
+ /* Determine the precision of intmax_t. |INTMAX_MIN| may have one
+ more bit as an integer, but in this case, this is a power of 2,
+ thus fits in a precision-prec floating-point number. */
+ for (r = MPFR_INTMAX_MAX, prec = 0; r != 0; r /= 2, prec++)
{ }
- /* Note: though INTMAX_MAX would have been sufficient for the conversion,
- we chose INTMAX_MIN so that INTMAX_MIN - 1 is always representable in
- precision prec; this is useful to detect overflows in MPFR_RNDZ (will
- be needed later). */
- /* Now, r = 0. */
+ MPFR_ASSERTD (r == 0);
+
+ MPFR_SAVE_EXPO_MARK (expo);
mpfr_init2 (x, prec);
mpfr_rint (x, f, rnd);
MPFR_ASSERTN (MPFR_IS_FP (x));
+ /* The flags from mpfr_rint are the wanted ones. In particular,
+ it sets the inexact flag when necessary. */
+ MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
+
if (MPFR_NOTZERO (x))
{
mp_limb_t *xp;
@@ -67,15 +72,15 @@ mpfr_get_sj (mpfr_srcptr f, mpfr_rnd_t rnd)
xp = MPFR_MANT (x);
sh = MPFR_GET_EXP (x);
- MPFR_ASSERTN ((mpfr_prec_t) sh <= prec);
+ MPFR_ASSERTN ((mpfr_prec_t) sh <= prec + 1);
if (MPFR_INTMAX_MIN + MPFR_INTMAX_MAX != 0
- && MPFR_UNLIKELY ((mpfr_prec_t) sh == prec))
+ && MPFR_UNLIKELY ((mpfr_prec_t) sh > prec))
{
/* 2's complement and x <= INTMAX_MIN: in the case mp_limb_t
has the same size as intmax_t, we cannot use the code in
the for loop since the operations would be performed in
unsigned arithmetic. */
- MPFR_ASSERTN (MPFR_IS_NEG (x) && (mpfr_powerof2_raw (x)));
+ MPFR_ASSERTN (MPFR_IS_NEG (x) && mpfr_powerof2_raw (x));
r = MPFR_INTMAX_MIN;
}
else if (MPFR_IS_POS (x))
@@ -117,6 +122,8 @@ mpfr_get_sj (mpfr_srcptr f, mpfr_rnd_t rnd)
mpfr_clear (x);
+ MPFR_SAVE_EXPO_FREE (expo);
+
return r;
}
diff --git a/src/get_ui.c b/src/get_ui.c
index 48a5f33..3c084ea 100644
--- a/src/get_ui.c
+++ b/src/get_ui.c
@@ -30,6 +30,7 @@ mpfr_get_ui (mpfr_srcptr f, mpfr_rnd_t rnd)
mpfr_t x;
mp_size_t n;
mpfr_exp_t exp;
+ MPFR_SAVE_EXPO_DECL (expo);
if (MPFR_UNLIKELY (!mpfr_fits_ulong_p (f, rnd)))
{
@@ -44,10 +45,16 @@ mpfr_get_ui (mpfr_srcptr f, mpfr_rnd_t rnd)
for (s = ULONG_MAX, prec = 0; s != 0; s /= 2, prec ++)
{ }
+ MPFR_SAVE_EXPO_MARK (expo);
+
/* first round to prec bits */
mpfr_init2 (x, prec);
mpfr_rint (x, f, rnd);
+ /* The flags from mpfr_rint are the wanted ones. In particular,
+ it sets the inexact flag when necessary. */
+ MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
+
/* warning: if x=0, taking its exponent is illegal */
if (MPFR_IS_ZERO(x))
s = 0;
@@ -61,5 +68,7 @@ mpfr_get_ui (mpfr_srcptr f, mpfr_rnd_t rnd)
mpfr_clear (x);
+ MPFR_SAVE_EXPO_FREE (expo);
+
return s;
}
diff --git a/src/get_uj.c b/src/get_uj.c
index 805c8a1..8d5e112 100644
--- a/src/get_uj.c
+++ b/src/get_uj.c
@@ -35,6 +35,7 @@ mpfr_get_uj (mpfr_srcptr f, mpfr_rnd_t rnd)
uintmax_t r;
mpfr_prec_t prec;
mpfr_t x;
+ MPFR_SAVE_EXPO_DECL (expo);
if (MPFR_UNLIKELY (!mpfr_fits_uintmax_p (f, rnd)))
{
@@ -50,12 +51,18 @@ mpfr_get_uj (mpfr_srcptr f, mpfr_rnd_t rnd)
for (r = MPFR_UINTMAX_MAX, prec = 0; r != 0; r /= 2, prec++)
{ }
- /* Now, r = 0. */
+ MPFR_ASSERTD (r == 0);
+
+ MPFR_SAVE_EXPO_MARK (expo);
mpfr_init2 (x, prec);
mpfr_rint (x, f, rnd);
MPFR_ASSERTN (MPFR_IS_FP (x));
+ /* The flags from mpfr_rint are the wanted ones. In particular,
+ it sets the inexact flag when necessary. */
+ MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
+
if (MPFR_NOTZERO (x))
{
mp_limb_t *xp;
@@ -76,6 +83,8 @@ mpfr_get_uj (mpfr_srcptr f, mpfr_rnd_t rnd)
mpfr_clear (x);
+ MPFR_SAVE_EXPO_FREE (expo);
+
return r;
}
diff --git a/src/get_z.c b/src/get_z.c
index 68249a4..3c48117 100644
--- a/src/get_z.c
+++ b/src/get_z.c
@@ -29,6 +29,7 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
int inex;
mpfr_t r;
mpfr_exp_t exp;
+ MPFR_SAVE_EXPO_DECL (expo);
if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
{
@@ -41,6 +42,8 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
return 0;
}
+ MPFR_SAVE_EXPO_MARK (expo);
+
exp = MPFR_GET_EXP (f);
/* if exp <= 0, then |f|<1, thus |o(f)|<=1 */
MPFR_ASSERTN (exp < 0 || exp <= MPFR_PREC_MAX);
@@ -50,6 +53,11 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
MPFR_ASSERTN (inex != 1 && inex != -1); /* integral part of f is
representable in r */
MPFR_ASSERTN (MPFR_IS_FP (r));
+
+ /* The flags from mpfr_rint are the wanted ones. In particular,
+ it sets the inexact flag when necessary. */
+ MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
+
exp = mpfr_get_z_2exp (z, r);
if (exp >= 0)
mpz_mul_2exp (z, z, exp);
@@ -57,5 +65,7 @@ mpfr_get_z (mpz_ptr z, mpfr_srcptr f, mpfr_rnd_t rnd)
mpz_fdiv_q_2exp (z, z, -exp);
mpfr_clear (r);
+ MPFR_SAVE_EXPO_FREE (expo);
+
return inex;
}
diff --git a/src/mpfr.h b/src/mpfr.h
index 6dba95f..7c15508 100644
--- a/src/mpfr.h
+++ b/src/mpfr.h
@@ -27,7 +27,7 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
#define MPFR_VERSION_MAJOR 3
#define MPFR_VERSION_MINOR 1
#define MPFR_VERSION_PATCHLEVEL 6
-#define MPFR_VERSION_STRING "3.1.6"
+#define MPFR_VERSION_STRING "3.1.6-p1"
/* Macros dealing with MPFR VERSION */
#define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
diff --git a/src/version.c b/src/version.c
index 12d31a5..84fdc4a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -25,5 +25,5 @@ http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
const char *
mpfr_get_version (void)
{
- return "3.1.6";
+ return "3.1.6-p1";
}
--
2.14.2