crosstool-ng/patches/mpfr/3.1.1/110-get_decimal64.patch
Kirill K. Smirnov 2e6a56d1cc patches: add patches for mpfr
This changeset adds official patches published on
mpfr website.

Signed-off-by: Kirill K. Smirnov <kirill.k.smirnov@gmail.com>
2016-09-18 00:01:42 +03:00

236 lines
7.4 KiB
Diff

diff -Naurd mpfr-3.1.1-a/PATCHES mpfr-3.1.1-b/PATCHES
--- mpfr-3.1.1-a/PATCHES 2012-08-30 09:28:51.000000000 +0000
+++ mpfr-3.1.1-b/PATCHES 2012-08-30 09:28:51.000000000 +0000
@@ -0,0 +1 @@
+get_decimal64
diff -Naurd mpfr-3.1.1-a/VERSION mpfr-3.1.1-b/VERSION
--- mpfr-3.1.1-a/VERSION 2012-07-03 15:01:13.000000000 +0000
+++ mpfr-3.1.1-b/VERSION 2012-08-30 09:28:51.000000000 +0000
@@ -1 +1 @@
-3.1.1
+3.1.1-p1
diff -Naurd mpfr-3.1.1-a/src/get_d64.c mpfr-3.1.1-b/src/get_d64.c
--- mpfr-3.1.1-a/src/get_d64.c 2012-07-03 15:01:18.000000000 +0000
+++ mpfr-3.1.1-b/src/get_d64.c 2012-08-30 09:28:51.000000000 +0000
@@ -32,6 +32,10 @@
#ifdef MPFR_WANT_DECIMAL_FLOATS
+#ifndef DEC64_MAX
+# define DEC64_MAX 9.999999999999999E384dd
+#endif
+
#ifdef DPD_FORMAT
static int T[1000] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 32,
@@ -142,26 +146,14 @@
static _Decimal64
get_decimal64_min (int negative)
{
- union ieee_double_extract x;
-
- x.s.sig = (negative) ? 1 : 0;
- x.s.exp = 0;
- x.s.manh = 0;
- x.s.manl = 1;
- return x.d;
+ return negative ? - 1E-398dd : 1E-398dd;
}
/* construct the decimal64 largest finite number with given sign */
static _Decimal64
get_decimal64_max (int negative)
{
- union ieee_double_extract x;
-
- x.s.sig = (negative) ? 1 : 0;
- x.s.exp = 1919;
- x.s.manh = 1048575; /* 2^20-1 */
- x.s.manl = ~0;
- return x.d;
+ return negative ? - DEC64_MAX : DEC64_MAX;
}
/* one-to-one conversion:
@@ -334,7 +326,8 @@
/* the largest decimal64 number is just below 10^(385) < 2^1279 */
else if (MPFR_UNLIKELY (e > 1279)) /* then src >= 2^1279 */
{
- if (MPFR_RNDZ || (rnd_mode == MPFR_RNDU && negative != 0)
+ if (rnd_mode == MPFR_RNDZ
+ || (rnd_mode == MPFR_RNDU && negative != 0)
|| (rnd_mode == MPFR_RNDD && negative == 0))
return get_decimal64_max (negative);
else
@@ -354,6 +347,15 @@
which corresponds to s=[0.]1000...000 and e=-397 */
if (e < -397)
{
+ if (rnd_mode == MPFR_RNDN && e == -398)
+ {
+ /* If 0.5E-398 < |src| < 1E-398 (smallest subnormal),
+ src should round to +/- 1E-398 in MPFR_RNDN. */
+ mpfr_get_str (s, &e, 10, 1, src, MPFR_RNDA);
+ return e == -398 && s[negative] <= '5' ?
+ get_decimal64_zero (negative) :
+ get_decimal64_min (negative);
+ }
if (rnd_mode == MPFR_RNDZ || rnd_mode == MPFR_RNDN
|| (rnd_mode == MPFR_RNDD && negative == 0)
|| (rnd_mode == MPFR_RNDU && negative != 0))
@@ -379,7 +381,8 @@
which corresponds to s=[0.]9999...999 and e=385 */
else if (e > 385)
{
- if (MPFR_RNDZ || (rnd_mode == MPFR_RNDU && negative != 0)
+ if (rnd_mode == MPFR_RNDZ
+ || (rnd_mode == MPFR_RNDU && negative != 0)
|| (rnd_mode == MPFR_RNDD && negative == 0))
return get_decimal64_max (negative);
else
diff -Naurd mpfr-3.1.1-a/src/mpfr.h mpfr-3.1.1-b/src/mpfr.h
--- mpfr-3.1.1-a/src/mpfr.h 2012-07-03 15:01:19.000000000 +0000
+++ mpfr-3.1.1-b/src/mpfr.h 2012-08-30 09:28:51.000000000 +0000
@@ -27,7 +27,7 @@
#define MPFR_VERSION_MAJOR 3
#define MPFR_VERSION_MINOR 1
#define MPFR_VERSION_PATCHLEVEL 1
-#define MPFR_VERSION_STRING "3.1.1"
+#define MPFR_VERSION_STRING "3.1.1-p1"
/* Macros dealing with MPFR VERSION */
#define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
diff -Naurd mpfr-3.1.1-a/src/version.c mpfr-3.1.1-b/src/version.c
--- mpfr-3.1.1-a/src/version.c 2012-07-03 15:01:18.000000000 +0000
+++ mpfr-3.1.1-b/src/version.c 2012-08-30 09:28:51.000000000 +0000
@@ -25,5 +25,5 @@
const char *
mpfr_get_version (void)
{
- return "3.1.1";
+ return "3.1.1-p1";
}
diff -Naurd mpfr-3.1.1-a/tests/tget_set_d64.c mpfr-3.1.1-b/tests/tget_set_d64.c
--- mpfr-3.1.1-a/tests/tget_set_d64.c 2012-07-03 15:01:24.000000000 +0000
+++ mpfr-3.1.1-b/tests/tget_set_d64.c 2012-08-30 09:28:51.000000000 +0000
@@ -25,6 +25,10 @@
#include <stdlib.h> /* for exit */
#include "mpfr-test.h"
+#ifndef DEC64_MAX
+# define DEC64_MAX 9.999999999999999E384dd
+#endif
+
/* #define DEBUG */
static void
@@ -149,6 +153,15 @@
mpfr_set_str (x, "9.999999999999999E384", 10, MPFR_RNDZ);
mpfr_set (y, x, MPFR_RNDZ);
d = mpfr_get_decimal64 (x, MPFR_RNDU);
+ ASSERT_ALWAYS (d == DEC64_MAX);
+ mpfr_set_ui (x, 0, MPFR_RNDZ);
+ mpfr_set_decimal64 (x, d, MPFR_RNDZ);
+ ASSERT_ALWAYS (mpfr_cmp (x, y) == 0);
+
+ mpfr_set_str (x, "-9.999999999999999E384", 10, MPFR_RNDZ);
+ mpfr_set (y, x, MPFR_RNDZ);
+ d = mpfr_get_decimal64 (x, MPFR_RNDA);
+ ASSERT_ALWAYS (d == -DEC64_MAX);
mpfr_set_ui (x, 0, MPFR_RNDZ);
mpfr_set_decimal64 (x, d, MPFR_RNDZ);
ASSERT_ALWAYS (mpfr_cmp (x, y) == 0);
@@ -225,6 +238,83 @@
mpfr_clear (x);
}
+static void
+check_overflow (void)
+{
+ mpfr_t x;
+ int err = 0, neg, rnd;
+
+ mpfr_init2 (x, 96);
+ for (neg = 0; neg < 2; neg++)
+ RND_LOOP (rnd)
+ {
+ _Decimal64 d, e;
+ mpfr_rnd_t r = (mpfr_rnd_t) rnd;
+ int sign = neg ? -1 : 1;
+
+ e = sign * (MPFR_IS_LIKE_RNDZ (r, neg) ? 1 : 2) * DEC64_MAX;
+ /* This tests the binary exponent e > 1279 case of get_d64.c */
+ mpfr_set_si_2exp (x, sign, 9999, MPFR_RNDN);
+ d = mpfr_get_decimal64 (x, r);
+ if (d != e)
+ {
+ printf ("Error 1 in check_overflow for %s, %s\n",
+ neg ? "negative" : "positive",
+ mpfr_print_rnd_mode (r));
+ err = 1;
+ }
+ /* This tests the decimal exponent e > 385 case of get_d64.c */
+ mpfr_set_si_2exp (x, sign * 31, 1274, MPFR_RNDN);
+ d = mpfr_get_decimal64 (x, r);
+ if (d != e)
+ {
+ printf ("Error 2 in check_overflow for %s, %s\n",
+ neg ? "negative" : "positive",
+ mpfr_print_rnd_mode (r));
+ err = 1;
+ }
+ /* This tests the last else (-382 <= e <= 385) of get_d64.c */
+ mpfr_set_decimal64 (x, e, MPFR_RNDA);
+ d = mpfr_get_decimal64 (x, r);
+ if (d != e)
+ {
+ printf ("Error 3 in check_overflow for %s, %s\n",
+ neg ? "negative" : "positive",
+ mpfr_print_rnd_mode (r));
+ err = 1;
+ }
+ }
+ mpfr_clear (x);
+ if (err)
+ exit (1);
+}
+
+static void
+check_tiny (void)
+{
+ mpfr_t x;
+ _Decimal64 d;
+
+ /* If 0.5E-398 < |x| < 1E-398 (smallest subnormal), x should round
+ to +/- 1E-398 in MPFR_RNDN. Note: the midpoint 0.5E-398 between
+ 0 and 1E-398 is not a representable binary number, so that there
+ are no tests for it. */
+ mpfr_init2 (x, 128);
+ mpfr_set_str (x, "1E-398", 10, MPFR_RNDZ);
+ d = mpfr_get_decimal64 (x, MPFR_RNDN);
+ MPFR_ASSERTN (d == 1.0E-398dd);
+ mpfr_neg (x, x, MPFR_RNDN);
+ d = mpfr_get_decimal64 (x, MPFR_RNDN);
+ MPFR_ASSERTN (d == -1.0E-398dd);
+ mpfr_set_str (x, "0.5E-398", 10, MPFR_RNDU);
+ d = mpfr_get_decimal64 (x, MPFR_RNDN);
+ MPFR_ASSERTN (d == 1.0E-398dd);
+ mpfr_neg (x, x, MPFR_RNDN);
+ d = mpfr_get_decimal64 (x, MPFR_RNDN);
+ MPFR_ASSERTN (d == -1.0E-398dd);
+ mpfr_clear (x);
+}
+
int
main (void)
{
@@ -241,6 +331,8 @@
check_inf_nan ();
check_random ();
check_native ();
+ check_overflow ();
+ check_tiny ();
tests_end_mpfr ();
return 0;