summaryrefslogtreecommitdiff
path: root/patches/mpfr/3.0.0/170-mpfr_set_ld.patch
blob: 9209afe93283ed79b059174fc1f69c54920dd9e7 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
diff -Naurd mpfr-3.0.0-a/PATCHES mpfr-3.0.0-b/PATCHES
--- mpfr-3.0.0-a/PATCHES	2010-10-21 21:18:26.000000000 +0000
+++ mpfr-3.0.0-b/PATCHES	2010-10-21 21:18:26.000000000 +0000
@@ -0,0 +1 @@
+mpfr_set_ld
diff -Naurd mpfr-3.0.0-a/VERSION mpfr-3.0.0-b/VERSION
--- mpfr-3.0.0-a/VERSION	2010-10-21 20:59:32.000000000 +0000
+++ mpfr-3.0.0-b/VERSION	2010-10-21 21:18:26.000000000 +0000
@@ -1 +1 @@
-3.0.0-p6
+3.0.0-p7
diff -Naurd mpfr-3.0.0-a/mpfr.h mpfr-3.0.0-b/mpfr.h
--- mpfr-3.0.0-a/mpfr.h	2010-10-21 20:59:32.000000000 +0000
+++ mpfr-3.0.0-b/mpfr.h	2010-10-21 21:18:26.000000000 +0000
@@ -27,7 +27,7 @@
 #define MPFR_VERSION_MAJOR 3
 #define MPFR_VERSION_MINOR 0
 #define MPFR_VERSION_PATCHLEVEL 0
-#define MPFR_VERSION_STRING "3.0.0-p6"
+#define MPFR_VERSION_STRING "3.0.0-p7"
 
 /* Macros dealing with MPFR VERSION */
 #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
diff -Naurd mpfr-3.0.0-a/set_ld.c mpfr-3.0.0-b/set_ld.c
--- mpfr-3.0.0-a/set_ld.c	2010-06-10 11:00:14.000000000 +0000
+++ mpfr-3.0.0-b/set_ld.c	2010-10-21 21:18:26.000000000 +0000
@@ -102,21 +102,25 @@
             {
               x /= div13; /* exact */
               shift_exp += 8192;
+              mpfr_div_2si (t, t, 8192, MPFR_RNDZ);
             }
           if (ABS (x) >= div12)
             {
               x /= div12; /* exact */
               shift_exp += 4096;
+              mpfr_div_2si (t, t, 4096, MPFR_RNDZ);
             }
           if (ABS (x) >= div11)
             {
               x /= div11; /* exact */
               shift_exp += 2048;
+              mpfr_div_2si (t, t, 2048, MPFR_RNDZ);
             }
           if (ABS (x) >= div10)
             {
               x /= div10; /* exact */
               shift_exp += 1024;
+              mpfr_div_2si (t, t, 1024, MPFR_RNDZ);
             }
           /* warning: we may have DBL_MAX=2^1024*(1-2^(-53)) < x < 2^1024,
              therefore we have one extra exponent reduction step */
@@ -124,9 +128,10 @@
             {
               x /= div9; /* exact */
               shift_exp += 512;
+              mpfr_div_2si (t, t, 512, MPFR_RNDZ);
             }
         } /* Check overflow of double */
-      else
+      else /* no overflow on double */
         {
           long double div9, div10, div11;
 
@@ -149,29 +154,34 @@
                 {
                   x /= div13; /* exact */
                   shift_exp -= 8192;
+                  mpfr_mul_2si (t, t, 8192, MPFR_RNDZ);
                 }
               if (ABS (x) <= div12)
                 {
                   x /= div12; /* exact */
                   shift_exp -= 4096;
+                  mpfr_mul_2si (t, t, 4096, MPFR_RNDZ);
                 }
               if (ABS (x) <= div11)
                 {
                   x /= div11; /* exact */
                   shift_exp -= 2048;
+                  mpfr_mul_2si (t, t, 2048, MPFR_RNDZ);
                 }
               if (ABS (x) <= div10)
                 {
                   x /= div10; /* exact */
                   shift_exp -= 1024;
+                  mpfr_mul_2si (t, t, 1024, MPFR_RNDZ);
                 }
               if (ABS(x) <= div9)
                 {
                   x /= div9;  /* exact */
                   shift_exp -= 512;
+                  mpfr_mul_2si (t, t, 512, MPFR_RNDZ);
                 }
             }
-          else
+          else /* no underflow */
             {
               inexact = mpfr_set_d (u, (double) x, MPFR_RNDZ);
               MPFR_ASSERTD (inexact == 0);
diff -Naurd mpfr-3.0.0-a/tests/tset_ld.c mpfr-3.0.0-b/tests/tset_ld.c
--- mpfr-3.0.0-a/tests/tset_ld.c	2010-06-10 11:00:13.000000000 +0000
+++ mpfr-3.0.0-b/tests/tset_ld.c	2010-10-21 21:18:26.000000000 +0000
@@ -147,12 +147,39 @@
 test_fixed_bugs (void)
 {
   mpfr_t x;
-  long double d;
+  long double l, m;
 
   /* bug found by Steve Kargl (2009-03-14) */
   mpfr_init2 (x, 64);
   mpfr_set_ui_2exp (x, 1, -16447, MPFR_RNDN);
-  d = mpfr_get_ld (x, MPFR_RNDN);  /* an assertion failed in init2.c:50 */
+  mpfr_get_ld (x, MPFR_RNDN);  /* an assertion failed in init2.c:50 */
+
+  /* bug reported by Jakub Jelinek (2010-10-17)
+     https://gforge.inria.fr/tracker/?func=detail&aid=11300 */
+  mpfr_set_prec (x, MPFR_LDBL_MANT_DIG);
+  /* l = 0x1.23456789abcdef0123456789abcdp-914L; */
+  l = 8.215640181713713164092636634579e-276;
+  mpfr_set_ld (x, l, MPFR_RNDN);
+  m = mpfr_get_ld (x, MPFR_RNDN);
+  if (m != l)
+    {
+      printf ("Error in get_ld o set_ld for l=%Le\n", l);
+      printf ("Got m=%Le instead of l\n", m);
+      exit (1);
+    }
+
+  /* another similar test which failed with extended double precision and the
+     generic code for mpfr_set_ld */
+  /* l = 0x1.23456789abcdef0123456789abcdp-968L; */
+  l = 4.560596445887084662336528403703e-292;
+  mpfr_set_ld (x, l, MPFR_RNDN);
+  m = mpfr_get_ld (x, MPFR_RNDN);
+  if (m != l)
+    {
+      printf ("Error in get_ld o set_ld for l=%Le\n", l);
+      printf ("Got m=%Le instead of l\n", m);
+      exit (1);
+    }
 
   mpfr_clear (x);
 }
diff -Naurd mpfr-3.0.0-a/version.c mpfr-3.0.0-b/version.c
--- mpfr-3.0.0-a/version.c	2010-10-21 20:59:32.000000000 +0000
+++ mpfr-3.0.0-b/version.c	2010-10-21 21:18:26.000000000 +0000
@@ -25,5 +25,5 @@
 const char *
 mpfr_get_version (void)
 {
-  return "3.0.0-p6";
+  return "3.0.0-p7";
 }