summaryrefslogtreecommitdiff
path: root/patches/mpfr/3.1.3/180-sqrt.patch
blob: 4887009456a2ad4019991a5b99d82cd00436b501 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
diff -Naurd mpfr-3.1.3-a/PATCHES mpfr-3.1.3-b/PATCHES
--- mpfr-3.1.3-a/PATCHES	2016-02-15 15:12:59.450314624 +0000
+++ mpfr-3.1.3-b/PATCHES	2016-02-15 15:12:59.510314695 +0000
@@ -0,0 +1 @@
+sqrt
diff -Naurd mpfr-3.1.3-a/VERSION mpfr-3.1.3-b/VERSION
--- mpfr-3.1.3-a/VERSION	2016-02-15 15:11:00.966156445 +0000
+++ mpfr-3.1.3-b/VERSION	2016-02-15 15:12:59.510314695 +0000
@@ -1 +1 @@
-3.1.3-p7
+3.1.3-p8
diff -Naurd mpfr-3.1.3-a/src/mpfr.h mpfr-3.1.3-b/src/mpfr.h
--- mpfr-3.1.3-a/src/mpfr.h	2016-02-15 15:11:00.962156439 +0000
+++ mpfr-3.1.3-b/src/mpfr.h	2016-02-15 15:12:59.510314695 +0000
@@ -27,7 +27,7 @@
 #define MPFR_VERSION_MAJOR 3
 #define MPFR_VERSION_MINOR 1
 #define MPFR_VERSION_PATCHLEVEL 3
-#define MPFR_VERSION_STRING "3.1.3-p7"
+#define MPFR_VERSION_STRING "3.1.3-p8"
 
 /* Macros dealing with MPFR VERSION */
 #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
diff -Naurd mpfr-3.1.3-a/src/sqrt.c mpfr-3.1.3-b/src/sqrt.c
--- mpfr-3.1.3-a/src/sqrt.c	2015-06-19 19:55:09.000000000 +0000
+++ mpfr-3.1.3-b/src/sqrt.c	2016-02-15 15:12:59.490314671 +0000
@@ -211,10 +211,11 @@
       rsize --;
       sh = 0;
     }
+  /* now rsize = MPFR_LIMB_SIZE(r) */
   if (mpn_add_1 (rp0, rp, rsize, MPFR_LIMB_ONE << sh))
     {
       expr ++;
-      rp[rsize - 1] = MPFR_LIMB_HIGHBIT;
+      rp0[rsize - 1] = MPFR_LIMB_HIGHBIT;
     }
   goto end;
 
diff -Naurd mpfr-3.1.3-a/src/version.c mpfr-3.1.3-b/src/version.c
--- mpfr-3.1.3-a/src/version.c	2016-02-15 15:11:00.966156445 +0000
+++ mpfr-3.1.3-b/src/version.c	2016-02-15 15:12:59.510314695 +0000
@@ -25,5 +25,5 @@
 const char *
 mpfr_get_version (void)
 {
-  return "3.1.3-p7";
+  return "3.1.3-p8";
 }
diff -Naurd mpfr-3.1.3-a/tests/tsqrt.c mpfr-3.1.3-b/tests/tsqrt.c
--- mpfr-3.1.3-a/tests/tsqrt.c	2015-06-19 19:55:10.000000000 +0000
+++ mpfr-3.1.3-b/tests/tsqrt.c	2016-02-15 15:12:59.490314671 +0000
@@ -569,6 +569,35 @@
   mpfr_clear (y);
 }
 
+/* Bug reported by Fredrik Johansson, occurring when:
+   - the precision of the result is a multiple of the number of bits
+     per word (GMP_NUMB_BITS),
+   - the rounding mode is to nearest (MPFR_RNDN),
+   - internally, the result has to be rounded up to a power of 2.
+*/
+static void
+bug20160120 (void)
+{
+  mpfr_t x, y;
+
+  mpfr_init2 (x, 4 * GMP_NUMB_BITS);
+  mpfr_init2 (y, GMP_NUMB_BITS);
+
+  mpfr_set_ui (x, 1, MPFR_RNDN);
+  mpfr_nextbelow (x);
+  mpfr_sqrt (y, x, MPFR_RNDN);
+  MPFR_ASSERTN(mpfr_check (y));
+  MPFR_ASSERTN(mpfr_cmp_ui (y, 1) == 0);
+
+  mpfr_set_prec (y, 2 * GMP_NUMB_BITS);
+  mpfr_sqrt (y, x, MPFR_RNDN);
+  MPFR_ASSERTN(mpfr_check (y));
+  MPFR_ASSERTN(mpfr_cmp_ui (y, 1) == 0);
+
+  mpfr_clear(x);
+  mpfr_clear(y);
+}
+
 #define TEST_FUNCTION test_sqrt
 #define TEST_RANDOM_POS 8
 #include "tgeneric.c"
@@ -704,6 +733,8 @@
   data_check ("data/sqrt", mpfr_sqrt, "mpfr_sqrt");
   bad_cases (mpfr_sqrt, mpfr_sqr, "mpfr_sqrt", 8, -256, 255, 4, 128, 800, 50);
 
+  bug20160120 ();
+
   tests_end_mpfr ();
   return 0;
 }