mpfr-patch01 8.3 KB

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