stages/*: change license to Apache 2.0
[dragora.git] / patches / mpfr / patch01
blob5c742f0ee44de38533430ffa53db77d4d16085ed
1 diff -Naurd mpfr-3.1.6-a/PATCHES mpfr-3.1.6-b/PATCHES
2 --- mpfr-3.1.6-a/PATCHES        2017-10-26 13:55:51.168013439 +0000
3 +++ mpfr-3.1.6-b/PATCHES        2017-10-26 13:55:51.236013121 +0000
4 @@ -0,0 +1 @@
5 +mpfr_get
6 diff -Naurd mpfr-3.1.6-a/VERSION mpfr-3.1.6-b/VERSION
7 --- mpfr-3.1.6-a/VERSION        2017-09-07 11:36:44.000000000 +0000
8 +++ mpfr-3.1.6-b/VERSION        2017-10-26 13:55:51.236013121 +0000
9 @@ -1 +1 @@
10 -3.1.6
11 +3.1.6-p1
12 diff -Naurd mpfr-3.1.6-a/src/get_ld.c mpfr-3.1.6-b/src/get_ld.c
13 --- mpfr-3.1.6-a/src/get_ld.c   2017-01-01 01:39:09.000000000 +0000
14 +++ mpfr-3.1.6-b/src/get_ld.c   2017-10-26 13:55:51.208013252 +0000
15 @@ -41,6 +41,9 @@
16        mpfr_exp_t sh; /* exponent shift, so that x/2^sh is in the double range */
17        mpfr_t y, z;
18        int sign;
19 +      MPFR_SAVE_EXPO_DECL (expo);
21 +      MPFR_SAVE_EXPO_MARK (expo);
23        /* first round x to the target long double precision, so that
24           all subsequent operations are exact (this avoids double rounding
25 @@ -103,6 +106,7 @@
26          }
27        if (sign < 0)
28          r = -r;
29 +      MPFR_SAVE_EXPO_FREE (expo);
30        return r;
31      }
32  }
33 diff -Naurd mpfr-3.1.6-a/src/get_si.c mpfr-3.1.6-b/src/get_si.c
34 --- mpfr-3.1.6-a/src/get_si.c   2017-01-01 01:39:09.000000000 +0000
35 +++ mpfr-3.1.6-b/src/get_si.c   2017-10-26 13:55:51.208013252 +0000
36 @@ -28,6 +28,7 @@
37    mpfr_prec_t prec;
38    long s;
39    mpfr_t x;
40 +  MPFR_SAVE_EXPO_DECL (expo);
42    if (MPFR_UNLIKELY (!mpfr_fits_slong_p (f, rnd)))
43      {
44 @@ -39,14 +40,22 @@
45    if (MPFR_IS_ZERO (f))
46      return (long) 0;
48 -  /* determine prec of long */
49 -  for (s = LONG_MIN, prec = 0; s != 0; s /= 2, prec++)
50 +  /* Determine the precision of long. |LONG_MIN| may have one more bit
51 +     as an integer, but in this case, this is a power of 2, thus fits
52 +     in a precision-prec floating-point number. */
53 +  for (s = LONG_MAX, prec = 0; s != 0; s /= 2, prec++)
54      { }
56 +  MPFR_SAVE_EXPO_MARK (expo);
58    /* first round to prec bits */
59    mpfr_init2 (x, prec);
60    mpfr_rint (x, f, rnd);
62 +  /* The flags from mpfr_rint are the wanted ones. In particular,
63 +     it sets the inexact flag when necessary. */
64 +  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
66    /* warning: if x=0, taking its exponent is illegal */
67    if (MPFR_UNLIKELY (MPFR_IS_ZERO(x)))
68      s = 0;
69 @@ -65,5 +74,7 @@
71    mpfr_clear (x);
73 +  MPFR_SAVE_EXPO_FREE (expo);
75    return s;
76  }
77 diff -Naurd mpfr-3.1.6-a/src/get_sj.c mpfr-3.1.6-b/src/get_sj.c
78 --- mpfr-3.1.6-a/src/get_sj.c   2017-01-01 01:39:09.000000000 +0000
79 +++ mpfr-3.1.6-b/src/get_sj.c   2017-10-26 13:55:51.208013252 +0000
80 @@ -35,6 +35,7 @@
81    intmax_t r;
82    mpfr_prec_t prec;
83    mpfr_t x;
84 +  MPFR_SAVE_EXPO_DECL (expo);
86    if (MPFR_UNLIKELY (!mpfr_fits_intmax_p (f, rnd)))
87      {
88 @@ -46,20 +47,24 @@
89    if (MPFR_IS_ZERO (f))
90       return (intmax_t) 0;
92 -  /* determine the precision of intmax_t */
93 -  for (r = MPFR_INTMAX_MIN, prec = 0; r != 0; r /= 2, prec++)
94 +  /* Determine the precision of intmax_t. |INTMAX_MIN| may have one
95 +     more bit as an integer, but in this case, this is a power of 2,
96 +     thus fits in a precision-prec floating-point number. */
97 +  for (r = MPFR_INTMAX_MAX, prec = 0; r != 0; r /= 2, prec++)
98      { }
99 -  /* Note: though INTMAX_MAX would have been sufficient for the conversion,
100 -     we chose INTMAX_MIN so that INTMAX_MIN - 1 is always representable in
101 -     precision prec; this is useful to detect overflows in MPFR_RNDZ (will
102 -     be needed later). */
104 -  /* Now, r = 0. */
105 +  MPFR_ASSERTD (r == 0);
107 +  MPFR_SAVE_EXPO_MARK (expo);
109    mpfr_init2 (x, prec);
110    mpfr_rint (x, f, rnd);
111    MPFR_ASSERTN (MPFR_IS_FP (x));
113 +  /* The flags from mpfr_rint are the wanted ones. In particular,
114 +     it sets the inexact flag when necessary. */
115 +  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
117    if (MPFR_NOTZERO (x))
118      {
119        mp_limb_t *xp;
120 @@ -67,15 +72,15 @@
122        xp = MPFR_MANT (x);
123        sh = MPFR_GET_EXP (x);
124 -      MPFR_ASSERTN ((mpfr_prec_t) sh <= prec);
125 +      MPFR_ASSERTN ((mpfr_prec_t) sh <= prec + 1);
126        if (MPFR_INTMAX_MIN + MPFR_INTMAX_MAX != 0
127 -          && MPFR_UNLIKELY ((mpfr_prec_t) sh == prec))
128 +          && MPFR_UNLIKELY ((mpfr_prec_t) sh > prec))
129          {
130            /* 2's complement and x <= INTMAX_MIN: in the case mp_limb_t
131               has the same size as intmax_t, we cannot use the code in
132               the for loop since the operations would be performed in
133               unsigned arithmetic. */
134 -          MPFR_ASSERTN (MPFR_IS_NEG (x) && (mpfr_powerof2_raw (x)));
135 +          MPFR_ASSERTN (MPFR_IS_NEG (x) && mpfr_powerof2_raw (x));
136            r = MPFR_INTMAX_MIN;
137          }
138        else if (MPFR_IS_POS (x))
139 @@ -117,6 +122,8 @@
141    mpfr_clear (x);
143 +  MPFR_SAVE_EXPO_FREE (expo);
145    return r;
148 diff -Naurd mpfr-3.1.6-a/src/get_ui.c mpfr-3.1.6-b/src/get_ui.c
149 --- mpfr-3.1.6-a/src/get_ui.c   2017-01-01 01:39:09.000000000 +0000
150 +++ mpfr-3.1.6-b/src/get_ui.c   2017-10-26 13:55:51.208013252 +0000
151 @@ -30,6 +30,7 @@
152    mpfr_t x;
153    mp_size_t n;
154    mpfr_exp_t exp;
155 +  MPFR_SAVE_EXPO_DECL (expo);
157    if (MPFR_UNLIKELY (!mpfr_fits_ulong_p (f, rnd)))
158      {
159 @@ -44,10 +45,16 @@
160    for (s = ULONG_MAX, prec = 0; s != 0; s /= 2, prec ++)
161      { }
163 +  MPFR_SAVE_EXPO_MARK (expo);
165    /* first round to prec bits */
166    mpfr_init2 (x, prec);
167    mpfr_rint (x, f, rnd);
169 +  /* The flags from mpfr_rint are the wanted ones. In particular,
170 +     it sets the inexact flag when necessary. */
171 +  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
173    /* warning: if x=0, taking its exponent is illegal */
174    if (MPFR_IS_ZERO(x))
175      s = 0;
176 @@ -61,5 +68,7 @@
178    mpfr_clear (x);
180 +  MPFR_SAVE_EXPO_FREE (expo);
182    return s;
184 diff -Naurd mpfr-3.1.6-a/src/get_uj.c mpfr-3.1.6-b/src/get_uj.c
185 --- mpfr-3.1.6-a/src/get_uj.c   2017-01-01 01:39:09.000000000 +0000
186 +++ mpfr-3.1.6-b/src/get_uj.c   2017-10-26 13:55:51.208013252 +0000
187 @@ -35,6 +35,7 @@
188    uintmax_t r;
189    mpfr_prec_t prec;
190    mpfr_t x;
191 +  MPFR_SAVE_EXPO_DECL (expo);
193    if (MPFR_UNLIKELY (!mpfr_fits_uintmax_p (f, rnd)))
194      {
195 @@ -50,12 +51,18 @@
196    for (r = MPFR_UINTMAX_MAX, prec = 0; r != 0; r /= 2, prec++)
197      { }
199 -  /* Now, r = 0. */
200 +  MPFR_ASSERTD (r == 0);
202 +  MPFR_SAVE_EXPO_MARK (expo);
204    mpfr_init2 (x, prec);
205    mpfr_rint (x, f, rnd);
206    MPFR_ASSERTN (MPFR_IS_FP (x));
208 +  /* The flags from mpfr_rint are the wanted ones. In particular,
209 +     it sets the inexact flag when necessary. */
210 +  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
212    if (MPFR_NOTZERO (x))
213      {
214        mp_limb_t *xp;
215 @@ -76,6 +83,8 @@
217    mpfr_clear (x);
219 +  MPFR_SAVE_EXPO_FREE (expo);
221    return r;
224 diff -Naurd mpfr-3.1.6-a/src/get_z.c mpfr-3.1.6-b/src/get_z.c
225 --- mpfr-3.1.6-a/src/get_z.c    2017-01-01 01:39:09.000000000 +0000
226 +++ mpfr-3.1.6-b/src/get_z.c    2017-10-26 13:55:51.208013252 +0000
227 @@ -29,6 +29,7 @@
228    int inex;
229    mpfr_t r;
230    mpfr_exp_t exp;
231 +  MPFR_SAVE_EXPO_DECL (expo);
233    if (MPFR_UNLIKELY (MPFR_IS_SINGULAR (f)))
234      {
235 @@ -41,6 +42,8 @@
236        return 0;
237      }
239 +  MPFR_SAVE_EXPO_MARK (expo);
241    exp = MPFR_GET_EXP (f);
242    /* if exp <= 0, then |f|<1, thus |o(f)|<=1 */
243    MPFR_ASSERTN (exp < 0 || exp <= MPFR_PREC_MAX);
244 @@ -50,6 +53,11 @@
245    MPFR_ASSERTN (inex != 1 && inex != -1); /* integral part of f is
246                                               representable in r */
247    MPFR_ASSERTN (MPFR_IS_FP (r));
249 +  /* The flags from mpfr_rint are the wanted ones. In particular,
250 +     it sets the inexact flag when necessary. */
251 +  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
253    exp = mpfr_get_z_2exp (z, r);
254    if (exp >= 0)
255      mpz_mul_2exp (z, z, exp);
256 @@ -57,5 +65,7 @@
257      mpz_fdiv_q_2exp (z, z, -exp);
258    mpfr_clear (r);
260 +  MPFR_SAVE_EXPO_FREE (expo);
262    return inex;
264 diff -Naurd mpfr-3.1.6-a/src/mpfr.h mpfr-3.1.6-b/src/mpfr.h
265 --- mpfr-3.1.6-a/src/mpfr.h     2017-09-07 11:36:44.000000000 +0000
266 +++ mpfr-3.1.6-b/src/mpfr.h     2017-10-26 13:55:51.232013138 +0000
267 @@ -27,7 +27,7 @@
268  #define MPFR_VERSION_MAJOR 3
269  #define MPFR_VERSION_MINOR 1
270  #define MPFR_VERSION_PATCHLEVEL 6
271 -#define MPFR_VERSION_STRING "3.1.6"
272 +#define MPFR_VERSION_STRING "3.1.6-p1"
274  /* Macros dealing with MPFR VERSION */
275  #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
276 diff -Naurd mpfr-3.1.6-a/src/version.c mpfr-3.1.6-b/src/version.c
277 --- mpfr-3.1.6-a/src/version.c  2017-09-07 11:36:44.000000000 +0000
278 +++ mpfr-3.1.6-b/src/version.c  2017-10-26 13:55:51.232013138 +0000
279 @@ -25,5 +25,5 @@
280  const char *
281  mpfr_get_version (void)
283 -  return "3.1.6";
284 +  return "3.1.6-p1";