patches/mpfr/2.4.2/100-sin_cos_underflow.patch
changeset 1699 10e9f9b59289
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/patches/mpfr/2.4.2/100-sin_cos_underflow.patch	Thu Jan 07 18:31:13 2010 +0100
     1.3 @@ -0,0 +1,184 @@
     1.4 +diff -Naurd mpfr-2.4.2-a/PATCHES mpfr-2.4.2-b/PATCHES
     1.5 +--- mpfr-2.4.2-a/PATCHES	2009-12-07 13:37:12.000000000 +0000
     1.6 ++++ mpfr-2.4.2-b/PATCHES	2009-12-07 13:37:12.000000000 +0000
     1.7 +@@ -0,0 +1 @@
     1.8 ++sin_cos_underflow
     1.9 +diff -Naurd mpfr-2.4.2-a/VERSION mpfr-2.4.2-b/VERSION
    1.10 +--- mpfr-2.4.2-a/VERSION	2009-11-30 02:43:08.000000000 +0000
    1.11 ++++ mpfr-2.4.2-b/VERSION	2009-12-07 13:37:12.000000000 +0000
    1.12 +@@ -1 +1 @@
    1.13 +-2.4.2
    1.14 ++2.4.2-p1
    1.15 +diff -Naurd mpfr-2.4.2-a/mpfr.h mpfr-2.4.2-b/mpfr.h
    1.16 +--- mpfr-2.4.2-a/mpfr.h	2009-11-30 02:43:08.000000000 +0000
    1.17 ++++ mpfr-2.4.2-b/mpfr.h	2009-12-07 13:37:12.000000000 +0000
    1.18 +@@ -27,7 +27,7 @@
    1.19 + #define MPFR_VERSION_MAJOR 2
    1.20 + #define MPFR_VERSION_MINOR 4
    1.21 + #define MPFR_VERSION_PATCHLEVEL 2
    1.22 +-#define MPFR_VERSION_STRING "2.4.2"
    1.23 ++#define MPFR_VERSION_STRING "2.4.2-p1"
    1.24 + 
    1.25 + /* Macros dealing with MPFR VERSION */
    1.26 + #define MPFR_VERSION_NUM(a,b,c) (((a) << 16L) | ((b) << 8) | (c))
    1.27 +diff -Naurd mpfr-2.4.2-a/sin_cos.c mpfr-2.4.2-b/sin_cos.c
    1.28 +--- mpfr-2.4.2-a/sin_cos.c	2009-11-30 02:43:09.000000000 +0000
    1.29 ++++ mpfr-2.4.2-b/sin_cos.c	2009-12-07 13:37:12.000000000 +0000
    1.30 +@@ -82,17 +82,19 @@
    1.31 +       if (y != x)
    1.32 +         /* y and x differ, thus we can safely try to compute y first */
    1.33 +         {
    1.34 +-          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2 * expx, 2, 0, rnd_mode,
    1.35 +-                                            { inexy = _inexact;
    1.36 +-                                              goto small_input; });
    1.37 ++          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
    1.38 ++            y, x, -2 * expx, 2, 0, rnd_mode,
    1.39 ++            { inexy = _inexact;
    1.40 ++              goto small_input; });
    1.41 +           if (0)
    1.42 +             {
    1.43 +             small_input:
    1.44 +               /* we can go here only if we can round sin(x) */
    1.45 +-              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (z, __gmpfr_one, -2 * expx,
    1.46 +-                                                1, 0, rnd_mode,
    1.47 +-                                                { inexz = _inexact;
    1.48 +-                                                  goto end; });
    1.49 ++              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
    1.50 ++                z, __gmpfr_one, -2 * expx, 1, 0, rnd_mode,
    1.51 ++                { inexz = _inexact;
    1.52 ++                  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
    1.53 ++                  goto end; });
    1.54 +             }
    1.55 + 
    1.56 +           /* if we go here, one of the two MPFR_FAST_COMPUTE_IF_SMALL_INPUT
    1.57 +@@ -101,18 +103,19 @@
    1.58 +       else /* y and x are the same variable: try to compute z first, which
    1.59 +               necessarily differs */
    1.60 +         {
    1.61 +-          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (z, __gmpfr_one, -2 * expx,
    1.62 +-                                            1, 0, rnd_mode,
    1.63 +-                                            { inexz = _inexact;
    1.64 +-                                              goto small_input2; });
    1.65 ++          MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
    1.66 ++            z, __gmpfr_one, -2 * expx, 1, 0, rnd_mode,
    1.67 ++            { inexz = _inexact;
    1.68 ++              goto small_input2; });
    1.69 +           if (0)
    1.70 +             {
    1.71 +             small_input2:
    1.72 +               /* we can go here only if we can round cos(x) */
    1.73 +-              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (y, x, -2 * expx, 2, 0,
    1.74 +-                                                rnd_mode,
    1.75 +-                                                { inexy = _inexact;
    1.76 +-                                                  goto end; });
    1.77 ++              MPFR_FAST_COMPUTE_IF_SMALL_INPUT (
    1.78 ++                y, x, -2 * expx, 2, 0, rnd_mode,
    1.79 ++                { inexy = _inexact;
    1.80 ++                  MPFR_SAVE_EXPO_UPDATE_FLAGS (expo, __gmpfr_flags);
    1.81 ++                  goto end; });
    1.82 +             }
    1.83 +         }
    1.84 +       m += 2 * (-expx);
    1.85 +@@ -207,7 +210,6 @@
    1.86 +   mpfr_clear (xr);
    1.87 + 
    1.88 +  end:
    1.89 +-  /* FIXME: update the underflow flag if need be. */
    1.90 +   MPFR_SAVE_EXPO_FREE (expo);
    1.91 +   mpfr_check_range (y, inexy, rnd_mode);
    1.92 +   mpfr_check_range (z, inexz, rnd_mode);
    1.93 +diff -Naurd mpfr-2.4.2-a/tests/tsin_cos.c mpfr-2.4.2-b/tests/tsin_cos.c
    1.94 +--- mpfr-2.4.2-a/tests/tsin_cos.c	2009-11-30 02:43:08.000000000 +0000
    1.95 ++++ mpfr-2.4.2-b/tests/tsin_cos.c	2009-12-07 13:37:12.000000000 +0000
    1.96 +@@ -382,23 +382,56 @@
    1.97 + consistency (void)
    1.98 + {
    1.99 +   mpfr_t x, s1, s2, c1, c2;
   1.100 ++  mp_exp_t emin, emax;
   1.101 +   mp_rnd_t rnd;
   1.102 ++  unsigned int flags_sin, flags_cos, flags, flags_before, flags_ref;
   1.103 ++  int inex_sin, inex_cos, inex, inex_ref;
   1.104 +   int i;
   1.105 + 
   1.106 ++  emin = mpfr_get_emin ();
   1.107 ++  emax = mpfr_get_emax ();
   1.108 ++
   1.109 +   for (i = 0; i <= 10000; i++)
   1.110 +     {
   1.111 +       mpfr_init2 (x, MPFR_PREC_MIN + (randlimb () % 8));
   1.112 +       mpfr_inits2 (MPFR_PREC_MIN + (randlimb () % 8), s1, s2, c1, c2,
   1.113 +                    (mpfr_ptr) 0);
   1.114 +-      tests_default_random (x, 256, -5, 50);
   1.115 +-      rnd = RND_RAND ();
   1.116 +-      mpfr_sin (s1, x, rnd);
   1.117 +-      mpfr_cos (c1, x, rnd);
   1.118 +-      mpfr_sin_cos (s2, c2, x, rnd);
   1.119 +-      if (!(mpfr_equal_p (s1, s2) && mpfr_equal_p (c1, c2)))
   1.120 ++      if (i < 8 * GMP_RND_MAX)
   1.121 +         {
   1.122 +-          printf ("mpfr_sin_cos and mpfr_sin/mpfr_cos disagree on %s,\nx = ",
   1.123 +-                  mpfr_print_rnd_mode (rnd));
   1.124 ++          int j = i / GMP_RND_MAX;
   1.125 ++          if (j & 1)
   1.126 ++            mpfr_set_emin (MPFR_EMIN_MIN);
   1.127 ++          mpfr_set_si (x, (j & 2) ? 1 : -1, GMP_RNDN);
   1.128 ++          mpfr_set_exp (x, mpfr_get_emin ());
   1.129 ++          rnd = (mpfr_rnd_t) (i % GMP_RND_MAX);
   1.130 ++          flags_before = 0;
   1.131 ++          if (j & 4)
   1.132 ++            mpfr_set_emax (-17);
   1.133 ++        }
   1.134 ++      else
   1.135 ++        {
   1.136 ++          tests_default_random (x, 256, -5, 50);
   1.137 ++          rnd = RND_RAND ();
   1.138 ++          flags_before = (randlimb () & 1) ?
   1.139 ++            (unsigned int) (MPFR_FLAGS_ALL ^ MPFR_FLAGS_ERANGE) :
   1.140 ++            (unsigned int) 0;
   1.141 ++        }
   1.142 ++      __gmpfr_flags = flags_before;
   1.143 ++      inex_sin = mpfr_sin (s1, x, rnd);
   1.144 ++      flags_sin = __gmpfr_flags;
   1.145 ++      __gmpfr_flags = flags_before;
   1.146 ++      inex_cos = mpfr_cos (c1, x, rnd);
   1.147 ++      flags_cos = __gmpfr_flags;
   1.148 ++      __gmpfr_flags = flags_before;
   1.149 ++      inex = !!mpfr_sin_cos (s2, c2, x, rnd);
   1.150 ++      flags = __gmpfr_flags;
   1.151 ++      inex_ref = inex_sin || inex_cos;
   1.152 ++      flags_ref = flags_sin | flags_cos;
   1.153 ++      if (!(mpfr_equal_p (s1, s2) && mpfr_equal_p (c1, c2)) ||
   1.154 ++          inex != inex_ref || flags != flags_ref)
   1.155 ++        {
   1.156 ++          printf ("mpfr_sin_cos and mpfr_sin/mpfr_cos disagree on %s,"
   1.157 ++                  " i = %d\nx = ", mpfr_print_rnd_mode (rnd), i);
   1.158 +           mpfr_dump (x);
   1.159 +           printf ("s1 = ");
   1.160 +           mpfr_dump (s1);
   1.161 +@@ -408,9 +441,16 @@
   1.162 +           mpfr_dump (c1);
   1.163 +           printf ("c2 = ");
   1.164 +           mpfr_dump (c2);
   1.165 ++          printf ("inex_sin = %d, inex_cos = %d, inex = %d (expected %d)\n",
   1.166 ++                  inex_sin, inex_cos, inex, inex_ref);
   1.167 ++          printf ("flags_sin = 0x%x, flags_cos = 0x%x, "
   1.168 ++                  "flags = 0x%x (expected 0x%x)\n",
   1.169 ++                  flags_sin, flags_cos, flags, flags_ref);
   1.170 +           exit (1);
   1.171 +         }
   1.172 +       mpfr_clears (x, s1, s2, c1, c2, (mpfr_ptr) 0);
   1.173 ++      mpfr_set_emin (emin);
   1.174 ++      mpfr_set_emax (emax);
   1.175 +     }
   1.176 + }
   1.177 + 
   1.178 +diff -Naurd mpfr-2.4.2-a/version.c mpfr-2.4.2-b/version.c
   1.179 +--- mpfr-2.4.2-a/version.c	2009-11-30 02:43:08.000000000 +0000
   1.180 ++++ mpfr-2.4.2-b/version.c	2009-12-07 13:37:12.000000000 +0000
   1.181 +@@ -25,5 +25,5 @@
   1.182 + const char *
   1.183 + mpfr_get_version (void)
   1.184 + {
   1.185 +-  return "2.4.2";
   1.186 ++  return "2.4.2-p1";
   1.187 + }