Home | History | Annotate | Line # | Download | only in tests
tadd.c revision 1.1.1.3.4.1
      1          1.1       mrg /* Test file for mpfr_add and mpfr_sub.
      2          1.1       mrg 
      3  1.1.1.3.4.1  christos Copyright 1999-2018 Free Software Foundation, Inc.
      4      1.1.1.3       mrg Contributed by the AriC and Caramba projects, INRIA.
      5          1.1       mrg 
      6          1.1       mrg This file is part of the GNU MPFR Library.
      7          1.1       mrg 
      8          1.1       mrg The GNU MPFR Library is free software; you can redistribute it and/or modify
      9          1.1       mrg it under the terms of the GNU Lesser General Public License as published by
     10          1.1       mrg the Free Software Foundation; either version 3 of the License, or (at your
     11          1.1       mrg option) any later version.
     12          1.1       mrg 
     13          1.1       mrg The GNU MPFR Library is distributed in the hope that it will be useful, but
     14          1.1       mrg WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     15          1.1       mrg or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
     16          1.1       mrg License for more details.
     17          1.1       mrg 
     18          1.1       mrg You should have received a copy of the GNU Lesser General Public License
     19          1.1       mrg along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
     20          1.1       mrg http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
     21          1.1       mrg 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
     22          1.1       mrg 
     23      1.1.1.2       mrg #define N 30000
     24          1.1       mrg 
     25          1.1       mrg #include <float.h>
     26          1.1       mrg 
     27          1.1       mrg #include "mpfr-test.h"
     28          1.1       mrg 
     29          1.1       mrg /* If the precisions are the same, we want to test both mpfr_add1sp
     30          1.1       mrg    and mpfr_add1. */
     31          1.1       mrg 
     32  1.1.1.3.4.1  christos /* FIXME: modify check() to test the ternary value and the flags. */
     33  1.1.1.3.4.1  christos 
     34          1.1       mrg static int usesp;
     35          1.1       mrg 
     36          1.1       mrg static int
     37          1.1       mrg test_add (mpfr_ptr a, mpfr_srcptr b, mpfr_srcptr c, mpfr_rnd_t rnd_mode)
     38          1.1       mrg {
     39          1.1       mrg   int res;
     40          1.1       mrg #ifdef CHECK_EXTERNAL
     41          1.1       mrg   int ok = rnd_mode == MPFR_RNDN && mpfr_number_p (b) && mpfr_number_p (c);
     42          1.1       mrg   if (ok)
     43          1.1       mrg     {
     44          1.1       mrg       mpfr_print_raw (b);
     45          1.1       mrg       printf (" ");
     46          1.1       mrg       mpfr_print_raw (c);
     47          1.1       mrg     }
     48          1.1       mrg #endif
     49          1.1       mrg   if (usesp || MPFR_ARE_SINGULAR(b,c) || MPFR_SIGN(b) != MPFR_SIGN(c))
     50          1.1       mrg     res = mpfr_add (a, b, c, rnd_mode);
     51          1.1       mrg   else
     52          1.1       mrg     {
     53          1.1       mrg       if (MPFR_GET_EXP(b) < MPFR_GET_EXP(c))
     54          1.1       mrg         res = mpfr_add1(a, c, b, rnd_mode);
     55          1.1       mrg       else
     56          1.1       mrg         res = mpfr_add1(a, b, c, rnd_mode);
     57          1.1       mrg     }
     58          1.1       mrg #ifdef CHECK_EXTERNAL
     59          1.1       mrg   if (ok)
     60          1.1       mrg     {
     61          1.1       mrg       printf (" ");
     62          1.1       mrg       mpfr_print_raw (a);
     63          1.1       mrg       printf ("\n");
     64          1.1       mrg     }
     65          1.1       mrg #endif
     66          1.1       mrg   return res;
     67          1.1       mrg }
     68          1.1       mrg 
     69          1.1       mrg /* checks that xs+ys gives the expected result zs */
     70          1.1       mrg static void
     71          1.1       mrg check (const char *xs, const char *ys, mpfr_rnd_t rnd_mode,
     72          1.1       mrg         unsigned int px, unsigned int py, unsigned int pz, const char *zs)
     73          1.1       mrg {
     74          1.1       mrg   mpfr_t xx,yy,zz;
     75          1.1       mrg 
     76          1.1       mrg   mpfr_init2 (xx, px);
     77          1.1       mrg   mpfr_init2 (yy, py);
     78          1.1       mrg   mpfr_init2 (zz, pz);
     79          1.1       mrg 
     80          1.1       mrg   mpfr_set_str1 (xx, xs);
     81          1.1       mrg   mpfr_set_str1 (yy, ys);
     82          1.1       mrg   test_add (zz, xx, yy, rnd_mode);
     83          1.1       mrg   if (mpfr_cmp_str1 (zz, zs) )
     84          1.1       mrg     {
     85          1.1       mrg       printf ("expected sum is %s, got ", zs);
     86  1.1.1.3.4.1  christos       mpfr_out_str (stdout, 10, 0, zz, MPFR_RNDN);
     87  1.1.1.3.4.1  christos       printf ("\nmpfr_add failed for x=%s y=%s with rnd_mode=%s\n",
     88          1.1       mrg               xs, ys, mpfr_print_rnd_mode (rnd_mode));
     89          1.1       mrg       exit (1);
     90          1.1       mrg     }
     91          1.1       mrg   mpfr_clears (xx, yy, zz, (mpfr_ptr) 0);
     92          1.1       mrg }
     93          1.1       mrg 
     94          1.1       mrg static void
     95          1.1       mrg check2b (const char *xs, int px,
     96          1.1       mrg          const char *ys, int py,
     97          1.1       mrg          const char *rs, int pz,
     98          1.1       mrg          mpfr_rnd_t rnd_mode)
     99          1.1       mrg {
    100          1.1       mrg   mpfr_t xx, yy, zz;
    101          1.1       mrg 
    102          1.1       mrg   mpfr_init2 (xx,px);
    103          1.1       mrg   mpfr_init2 (yy,py);
    104          1.1       mrg   mpfr_init2 (zz,pz);
    105          1.1       mrg   mpfr_set_str_binary (xx, xs);
    106          1.1       mrg   mpfr_set_str_binary (yy, ys);
    107          1.1       mrg   test_add (zz, xx, yy, rnd_mode);
    108          1.1       mrg   if (mpfr_cmp_str (zz, rs, 2, MPFR_RNDN))
    109          1.1       mrg     {
    110          1.1       mrg       printf ("(2) x=%s,%d y=%s,%d pz=%d,rnd=%s\n",
    111          1.1       mrg               xs, px, ys, py, pz, mpfr_print_rnd_mode (rnd_mode));
    112  1.1.1.3.4.1  christos       printf ("got        "); mpfr_dump (zz);
    113          1.1       mrg       mpfr_set_str(zz, rs, 2, MPFR_RNDN);
    114  1.1.1.3.4.1  christos       printf ("instead of "); mpfr_dump (zz);
    115          1.1       mrg       exit (1);
    116          1.1       mrg     }
    117          1.1       mrg   mpfr_clear(xx); mpfr_clear(yy); mpfr_clear(zz);
    118          1.1       mrg }
    119          1.1       mrg 
    120          1.1       mrg static void
    121          1.1       mrg check64 (void)
    122          1.1       mrg {
    123          1.1       mrg   mpfr_t x, t, u;
    124          1.1       mrg 
    125          1.1       mrg   mpfr_init (x);
    126          1.1       mrg   mpfr_init (t);
    127          1.1       mrg   mpfr_init (u);
    128          1.1       mrg 
    129          1.1       mrg   mpfr_set_prec (x, 29);
    130          1.1       mrg   mpfr_set_str_binary (x, "1.1101001000101111011010010110e-3");
    131          1.1       mrg   mpfr_set_prec (t, 58);
    132          1.1       mrg   mpfr_set_str_binary (t, "0.11100010011111001001100110010111110110011000000100101E-1");
    133          1.1       mrg   mpfr_set_prec (u, 29);
    134          1.1       mrg   test_add (u, x, t, MPFR_RNDD);
    135          1.1       mrg   mpfr_set_str_binary (t, "1.0101011100001000011100111110e-1");
    136          1.1       mrg   if (mpfr_cmp (u, t))
    137          1.1       mrg     {
    138          1.1       mrg       printf ("mpfr_add(u, x, t) failed for prec(x)=29, prec(t)=58\n");
    139          1.1       mrg       printf ("expected "); mpfr_out_str (stdout, 2, 29, t, MPFR_RNDN);
    140          1.1       mrg       puts ("");
    141          1.1       mrg       printf ("got      "); mpfr_out_str (stdout, 2, 29, u, MPFR_RNDN);
    142          1.1       mrg       puts ("");
    143          1.1       mrg       exit(1);
    144          1.1       mrg     }
    145          1.1       mrg 
    146          1.1       mrg   mpfr_set_prec (x, 4);
    147          1.1       mrg   mpfr_set_str_binary (x, "-1.0E-2");
    148          1.1       mrg   mpfr_set_prec (t, 2);
    149          1.1       mrg   mpfr_set_str_binary (t, "-1.1e-2");
    150          1.1       mrg   mpfr_set_prec (u, 2);
    151          1.1       mrg   test_add (u, x, t, MPFR_RNDN);
    152          1.1       mrg   if (MPFR_MANT(u)[0] << 2)
    153          1.1       mrg     {
    154          1.1       mrg       printf ("result not normalized for prec=2\n");
    155  1.1.1.3.4.1  christos       mpfr_dump (u);
    156          1.1       mrg       exit (1);
    157          1.1       mrg     }
    158          1.1       mrg   mpfr_set_str_binary (t, "-1.0e-1");
    159          1.1       mrg   if (mpfr_cmp (u, t))
    160          1.1       mrg     {
    161          1.1       mrg       printf ("mpfr_add(u, x, t) failed for prec(x)=4, prec(t)=2\n");
    162          1.1       mrg       printf ("expected -1.0e-1\n");
    163          1.1       mrg       printf ("got      "); mpfr_out_str (stdout, 2, 4, u, MPFR_RNDN);
    164          1.1       mrg       puts ("");
    165          1.1       mrg       exit (1);
    166          1.1       mrg     }
    167          1.1       mrg 
    168          1.1       mrg   mpfr_set_prec (x, 8);
    169          1.1       mrg   mpfr_set_str_binary (x, "-0.10011010"); /* -77/128 */
    170          1.1       mrg   mpfr_set_prec (t, 4);
    171          1.1       mrg   mpfr_set_str_binary (t, "-1.110e-5"); /* -7/128 */
    172          1.1       mrg   mpfr_set_prec (u, 4);
    173          1.1       mrg   test_add (u, x, t, MPFR_RNDN); /* should give -5/8 */
    174          1.1       mrg   mpfr_set_str_binary (t, "-1.010e-1");
    175          1.1       mrg   if (mpfr_cmp (u, t)) {
    176          1.1       mrg     printf ("mpfr_add(u, x, t) failed for prec(x)=8, prec(t)=4\n");
    177          1.1       mrg     printf ("expected -1.010e-1\n");
    178          1.1       mrg     printf ("got      "); mpfr_out_str (stdout, 2, 4, u, MPFR_RNDN);
    179          1.1       mrg     puts ("");
    180          1.1       mrg     exit (1);
    181          1.1       mrg   }
    182          1.1       mrg 
    183          1.1       mrg   mpfr_set_prec (x, 112); mpfr_set_prec (t, 98); mpfr_set_prec (u, 54);
    184          1.1       mrg   mpfr_set_str_binary (x, "-0.11111100100000000011000011100000101101010001000111E-401");
    185          1.1       mrg   mpfr_set_str_binary (t, "0.10110000100100000101101100011111111011101000111000101E-464");
    186          1.1       mrg   test_add (u, x, t, MPFR_RNDN);
    187          1.1       mrg   if (mpfr_cmp (u, x))
    188          1.1       mrg     {
    189          1.1       mrg       printf ("mpfr_add(u, x, t) failed for prec(x)=112, prec(t)=98\n");
    190          1.1       mrg       exit (1);
    191          1.1       mrg     }
    192          1.1       mrg 
    193          1.1       mrg   mpfr_set_prec (x, 92); mpfr_set_prec (t, 86); mpfr_set_prec (u, 53);
    194          1.1       mrg   mpfr_set_str (x, "-5.03525136761487735093e-74", 10, MPFR_RNDN);
    195          1.1       mrg   mpfr_set_str (t, "8.51539046314262304109e-91", 10, MPFR_RNDN);
    196          1.1       mrg   test_add (u, x, t, MPFR_RNDN);
    197          1.1       mrg   if (mpfr_cmp_str1 (u, "-5.0352513676148773509283672e-74") )
    198          1.1       mrg     {
    199          1.1       mrg       printf ("mpfr_add(u, x, t) failed for prec(x)=92, prec(t)=86\n");
    200          1.1       mrg       exit (1);
    201          1.1       mrg     }
    202          1.1       mrg 
    203          1.1       mrg   mpfr_set_prec(x, 53); mpfr_set_prec(t, 76); mpfr_set_prec(u, 76);
    204          1.1       mrg   mpfr_set_str_binary(x, "-0.10010010001001011011110000000000001010011011011110001E-32");
    205          1.1       mrg   mpfr_set_str_binary(t, "-0.1011000101110010000101111111011111010001110011110111100110101011110010011111");
    206          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDU);
    207          1.1       mrg   mpfr_set_str_binary(t, "0.1011000101110010000101111111011100111111101010011011110110101011101000000100");
    208          1.1       mrg   if (mpfr_cmp(u,t))
    209          1.1       mrg     {
    210  1.1.1.3.4.1  christos       printf ("expect "); mpfr_dump (t);
    211          1.1       mrg       printf ("mpfr_add failed for precisions 53-76\n");
    212          1.1       mrg       exit (1);
    213          1.1       mrg     }
    214          1.1       mrg   mpfr_set_prec(x, 53); mpfr_set_prec(t, 108); mpfr_set_prec(u, 108);
    215          1.1       mrg   mpfr_set_str_binary(x, "-0.10010010001001011011110000000000001010011011011110001E-32");
    216          1.1       mrg   mpfr_set_str_binary(t, "-0.101100010111001000010111111101111101000111001111011110011010101111001001111000111011001110011000000000111111");
    217          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDU);
    218          1.1       mrg   mpfr_set_str_binary(t, "0.101100010111001000010111111101110011111110101001101111011010101110100000001011000010101110011000000000111111");
    219          1.1       mrg   if (mpfr_cmp(u,t))
    220          1.1       mrg     {
    221  1.1.1.3.4.1  christos       printf ("expect "); mpfr_dump (t);
    222          1.1       mrg       printf ("mpfr_add failed for precisions 53-108\n");
    223          1.1       mrg       exit (1);
    224          1.1       mrg     }
    225          1.1       mrg   mpfr_set_prec(x, 97); mpfr_set_prec(t, 97); mpfr_set_prec(u, 97);
    226          1.1       mrg   mpfr_set_str_binary(x, "0.1111101100001000000001011000110111101000001011111000100001000101010100011111110010000000000000000E-39");
    227          1.1       mrg   mpfr_set_ui(t, 1, MPFR_RNDN);
    228          1.1       mrg   test_add (u, x, t, MPFR_RNDN);
    229          1.1       mrg   mpfr_set_str_binary(x, "0.1000000000000000000000000000000000000000111110110000100000000101100011011110100000101111100010001E1");
    230          1.1       mrg   if (mpfr_cmp(u,x))
    231          1.1       mrg     {
    232          1.1       mrg       printf ("mpfr_add failed for precision 97\n");
    233          1.1       mrg       exit (1);
    234          1.1       mrg     }
    235          1.1       mrg   mpfr_set_prec(x, 128); mpfr_set_prec(t, 128); mpfr_set_prec(u, 128);
    236          1.1       mrg   mpfr_set_str_binary(x, "0.10101011111001001010111011001000101100111101000000111111111011010100001100011101010001010111111101111010100110111111100101100010E-4");
    237          1.1       mrg   mpfr_set(t, x, MPFR_RNDN);
    238          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDN);
    239          1.1       mrg   mpfr_set_prec(x, 96); mpfr_set_prec(t, 96); mpfr_set_prec(u, 96);
    240          1.1       mrg   mpfr_set_str_binary(x, "0.111000000001110100111100110101101001001010010011010011100111100011010100011001010011011011000010E-4");
    241          1.1       mrg   mpfr_set(t, x, MPFR_RNDN);
    242          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDN);
    243          1.1       mrg   mpfr_set_prec(x, 85); mpfr_set_prec(t, 85); mpfr_set_prec(u, 85);
    244          1.1       mrg   mpfr_set_str_binary(x, "0.1111101110100110110110100010101011101001100010100011110110110010010011101100101111100E-4");
    245          1.1       mrg   mpfr_set_str_binary(t, "0.1111101110100110110110100010101001001000011000111000011101100101110100001110101010110E-4");
    246          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDU);
    247          1.1       mrg   mpfr_sub(x, x, t, MPFR_RNDU);
    248          1.1       mrg   if (mpfr_cmp(x, u) != 0)
    249          1.1       mrg     {
    250          1.1       mrg       printf ("Error in mpfr_sub: u=x-t and x=x-t give different results\n");
    251          1.1       mrg       exit (1);
    252          1.1       mrg     }
    253  1.1.1.3.4.1  christos   if (! MPFR_IS_NORMALIZED (u))
    254          1.1       mrg     {
    255          1.1       mrg       printf ("Error in mpfr_sub: result is not msb-normalized (1)\n");
    256          1.1       mrg       exit (1);
    257          1.1       mrg     }
    258          1.1       mrg   mpfr_set_prec(x, 65); mpfr_set_prec(t, 65); mpfr_set_prec(u, 65);
    259          1.1       mrg   mpfr_set_str_binary(x, "0.10011010101000110101010000000011001001001110001011101011111011101E623");
    260          1.1       mrg   mpfr_set_str_binary(t, "0.10011010101000110101010000000011001001001110001011101011111011100E623");
    261          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDU);
    262          1.1       mrg   if (mpfr_cmp_ui_2exp(u, 1, 558))
    263          1.1       mrg     { /* 2^558 */
    264          1.1       mrg       printf ("Error (1) in mpfr_sub\n");
    265          1.1       mrg       exit (1);
    266          1.1       mrg     }
    267          1.1       mrg 
    268          1.1       mrg   mpfr_set_prec(x, 64); mpfr_set_prec(t, 64); mpfr_set_prec(u, 64);
    269          1.1       mrg   mpfr_set_str_binary(x, "0.1000011110101111011110111111000011101011101111101101101100000100E-220");
    270          1.1       mrg   mpfr_set_str_binary(t, "0.1000011110101111011110111111000011101011101111101101010011111101E-220");
    271          1.1       mrg   test_add (u, x, t, MPFR_RNDU);
    272          1.1       mrg   if ((MPFR_MANT(u)[0] & 1) != 1)
    273          1.1       mrg     {
    274          1.1       mrg       printf ("error in mpfr_add with rnd_mode=MPFR_RNDU\n");
    275  1.1.1.3.4.1  christos       printf ("b=  "); mpfr_dump (x);
    276  1.1.1.3.4.1  christos       printf ("c=  "); mpfr_dump (t);
    277  1.1.1.3.4.1  christos       printf ("b+c="); mpfr_dump (u);
    278          1.1       mrg       exit (1);
    279          1.1       mrg     }
    280          1.1       mrg 
    281          1.1       mrg   /* bug found by Norbert Mueller, 14 Sep 2000 */
    282          1.1       mrg   mpfr_set_prec(x, 56); mpfr_set_prec(t, 83); mpfr_set_prec(u, 10);
    283          1.1       mrg   mpfr_set_str_binary(x, "0.10001001011011001111101100110100000101111010010111010111E-7");
    284          1.1       mrg   mpfr_set_str_binary(t, "0.10001001011011001111101100110100000101111010010111010111000000000111110110110000100E-7");
    285          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDU);
    286          1.1       mrg 
    287          1.1       mrg   /* array bound write found by Norbert Mueller, 26 Sep 2000 */
    288          1.1       mrg   mpfr_set_prec(x, 109); mpfr_set_prec(t, 153); mpfr_set_prec(u, 95);
    289          1.1       mrg   mpfr_set_str_binary(x,"0.1001010000101011101100111000110001111111111111111111111111111111111111111111111111111111111111100000000000000E33");
    290          1.1       mrg   mpfr_set_str_binary(t,"-0.100101000010101110110011100011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011100101101000000100100001100110111E33");
    291          1.1       mrg   test_add (u, x, t, MPFR_RNDN);
    292          1.1       mrg 
    293          1.1       mrg   /* array bound writes found by Norbert Mueller, 27 Sep 2000 */
    294          1.1       mrg   mpfr_set_prec(x, 106); mpfr_set_prec(t, 53); mpfr_set_prec(u, 23);
    295          1.1       mrg   mpfr_set_str_binary(x, "-0.1000011110101111111001010001000100001011000000000000000000000000000000000000000000000000000000000000000000E-59");
    296          1.1       mrg   mpfr_set_str_binary(t, "-0.10000111101011111110010100010001101100011100110100000E-59");
    297          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDN);
    298          1.1       mrg   mpfr_set_prec(x, 177); mpfr_set_prec(t, 217); mpfr_set_prec(u, 160);
    299          1.1       mrg   mpfr_set_str_binary(x, "-0.111010001011010000111001001010010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E35");
    300          1.1       mrg   mpfr_set_str_binary(t, "0.1110100010110100001110010010100100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111011010011100001111001E35");
    301          1.1       mrg   test_add (u, x, t, MPFR_RNDN);
    302          1.1       mrg   mpfr_set_prec(x, 214); mpfr_set_prec(t, 278); mpfr_set_prec(u, 207);
    303          1.1       mrg   mpfr_set_str_binary(x, "0.1000100110100110101101101101000000010000100111000001001110001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000E66");
    304          1.1       mrg   mpfr_set_str_binary(t, "-0.10001001101001101011011011010000000100001001110000010011100010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111011111001001100011E66");
    305          1.1       mrg   test_add (u, x, t, MPFR_RNDN);
    306          1.1       mrg   mpfr_set_prec(x, 32); mpfr_set_prec(t, 247); mpfr_set_prec(u, 223);
    307          1.1       mrg   mpfr_set_str_binary(x, "0.10000000000000000000000000000000E1");
    308          1.1       mrg   mpfr_set_str_binary(t, "0.1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111100000110001110100000100011110000101110110011101110100110110111111011010111100100000000000000000000000000E0");
    309          1.1       mrg   mpfr_sub(u, x, t, MPFR_RNDN);
    310  1.1.1.3.4.1  christos   if (! MPFR_IS_NORMALIZED (u))
    311          1.1       mrg     {
    312          1.1       mrg       printf ("Error in mpfr_sub: result is not msb-normalized (2)\n");
    313          1.1       mrg       exit (1);
    314          1.1       mrg     }
    315          1.1       mrg 
    316          1.1       mrg   /* bug found by Nathalie Revol, 21 March 2001 */
    317          1.1       mrg   mpfr_set_prec (x, 65);
    318          1.1       mrg   mpfr_set_prec (t, 65);
    319          1.1       mrg   mpfr_set_prec (u, 65);
    320          1.1       mrg   mpfr_set_str_binary (x, "0.11100100101101001100111011111111110001101001000011101001001010010E-35");
    321          1.1       mrg   mpfr_set_str_binary (t, "0.10000000000000000000000000000000000001110010010110100110011110000E1");
    322          1.1       mrg   mpfr_sub (u, t, x, MPFR_RNDU);
    323  1.1.1.3.4.1  christos   if (! MPFR_IS_NORMALIZED (u))
    324          1.1       mrg     {
    325          1.1       mrg       printf ("Error in mpfr_sub: result is not msb-normalized (3)\n");
    326          1.1       mrg       exit (1);
    327          1.1       mrg     }
    328          1.1       mrg 
    329          1.1       mrg   /* bug found by Fabrice Rouillier, 27 Mar 2001 */
    330          1.1       mrg   mpfr_set_prec (x, 107);
    331          1.1       mrg   mpfr_set_prec (t, 107);
    332          1.1       mrg   mpfr_set_prec (u, 107);
    333          1.1       mrg   mpfr_set_str_binary (x, "0.10111001001111010010001000000010111111011011011101000001001000101000000000000000000000000000000000000000000E315");
    334          1.1       mrg   mpfr_set_str_binary (t, "0.10000000000000000000000000000000000101110100100101110110000001100101011111001000011101111100100100111011000E350");
    335          1.1       mrg   mpfr_sub (u, x, t, MPFR_RNDU);
    336  1.1.1.3.4.1  christos   if (! MPFR_IS_NORMALIZED (u))
    337          1.1       mrg     {
    338          1.1       mrg       printf ("Error in mpfr_sub: result is not msb-normalized (4)\n");
    339          1.1       mrg       exit (1);
    340          1.1       mrg     }
    341          1.1       mrg 
    342          1.1       mrg   /* checks that NaN flag is correctly reset */
    343          1.1       mrg   mpfr_set_ui (t, 1, MPFR_RNDN);
    344          1.1       mrg   mpfr_set_ui (u, 1, MPFR_RNDN);
    345          1.1       mrg   mpfr_set_nan (x);
    346          1.1       mrg   test_add (x, t, u, MPFR_RNDN);
    347          1.1       mrg   if (mpfr_cmp_ui (x, 2))
    348          1.1       mrg     {
    349          1.1       mrg       printf ("Error in mpfr_add: 1+1 gives ");
    350          1.1       mrg       mpfr_out_str(stdout, 10, 0, x, MPFR_RNDN);
    351          1.1       mrg       exit (1);
    352          1.1       mrg     }
    353          1.1       mrg 
    354          1.1       mrg   mpfr_clear(x); mpfr_clear(t); mpfr_clear(u);
    355          1.1       mrg }
    356          1.1       mrg 
    357          1.1       mrg /* check case when c does not overlap with a, but both b and c count
    358          1.1       mrg    for rounding */
    359          1.1       mrg static void
    360          1.1       mrg check_case_1b (void)
    361          1.1       mrg {
    362          1.1       mrg   mpfr_t a, b, c;
    363          1.1       mrg   unsigned int prec_a, prec_b, prec_c, dif;
    364          1.1       mrg 
    365          1.1       mrg   mpfr_init (a);
    366          1.1       mrg   mpfr_init (b);
    367          1.1       mrg   mpfr_init (c);
    368          1.1       mrg 
    369          1.1       mrg     {
    370          1.1       mrg       prec_a = MPFR_PREC_MIN + (randlimb () % 63);
    371          1.1       mrg       mpfr_set_prec (a, prec_a);
    372          1.1       mrg       for (prec_b = prec_a + 2; prec_b <= 64; prec_b++)
    373          1.1       mrg         {
    374          1.1       mrg           dif = prec_b - prec_a;
    375          1.1       mrg           mpfr_set_prec (b, prec_b);
    376          1.1       mrg           /* b = 1 - 2^(-prec_a) + 2^(-prec_b) */
    377          1.1       mrg           mpfr_set_ui (b, 1, MPFR_RNDN);
    378          1.1       mrg           mpfr_div_2exp (b, b, dif, MPFR_RNDN);
    379          1.1       mrg           mpfr_sub_ui (b, b, 1, MPFR_RNDN);
    380          1.1       mrg           mpfr_div_2exp (b, b, prec_a, MPFR_RNDN);
    381          1.1       mrg           mpfr_add_ui (b, b, 1, MPFR_RNDN);
    382          1.1       mrg           for (prec_c = dif; prec_c <= 64; prec_c++)
    383          1.1       mrg             {
    384          1.1       mrg               /* c = 2^(-prec_a) - 2^(-prec_b) */
    385          1.1       mrg               mpfr_set_prec (c, prec_c);
    386          1.1       mrg               mpfr_set_si (c, -1, MPFR_RNDN);
    387          1.1       mrg               mpfr_div_2exp (c, c, dif, MPFR_RNDN);
    388          1.1       mrg               mpfr_add_ui (c, c, 1, MPFR_RNDN);
    389          1.1       mrg               mpfr_div_2exp (c, c, prec_a, MPFR_RNDN);
    390          1.1       mrg               test_add (a, b, c, MPFR_RNDN);
    391          1.1       mrg               if (mpfr_cmp_ui (a, 1) != 0)
    392          1.1       mrg                 {
    393          1.1       mrg                   printf ("case (1b) failed for prec_a=%u, prec_b=%u,"
    394          1.1       mrg                           " prec_c=%u\n", prec_a, prec_b, prec_c);
    395  1.1.1.3.4.1  christos                   printf ("b="); mpfr_dump (b);
    396  1.1.1.3.4.1  christos                   printf ("c="); mpfr_dump (c);
    397  1.1.1.3.4.1  christos                   printf ("a="); mpfr_dump (a);
    398          1.1       mrg                   exit (1);
    399          1.1       mrg                 }
    400          1.1       mrg             }
    401          1.1       mrg         }
    402          1.1       mrg     }
    403          1.1       mrg 
    404          1.1       mrg   mpfr_clear (a);
    405          1.1       mrg   mpfr_clear (b);
    406          1.1       mrg   mpfr_clear (c);
    407          1.1       mrg }
    408          1.1       mrg 
    409          1.1       mrg /* check case when c overlaps with a */
    410          1.1       mrg static void
    411          1.1       mrg check_case_2 (void)
    412          1.1       mrg {
    413          1.1       mrg   mpfr_t a, b, c, d;
    414          1.1       mrg 
    415          1.1       mrg   mpfr_init2 (a, 300);
    416          1.1       mrg   mpfr_init2 (b, 800);
    417          1.1       mrg   mpfr_init2 (c, 500);
    418          1.1       mrg   mpfr_init2 (d, 800);
    419          1.1       mrg 
    420          1.1       mrg   mpfr_set_str_binary(a, "1E110");  /* a = 2^110 */
    421          1.1       mrg   mpfr_set_str_binary(b, "1E900");  /* b = 2^900 */
    422          1.1       mrg   mpfr_set_str_binary(c, "1E500");  /* c = 2^500 */
    423          1.1       mrg   test_add (c, c, a, MPFR_RNDZ);   /* c = 2^500 + 2^110 */
    424          1.1       mrg   mpfr_sub (d, b, c, MPFR_RNDZ);   /* d = 2^900 - 2^500 - 2^110 */
    425          1.1       mrg   test_add (b, b, c, MPFR_RNDZ);   /* b = 2^900 + 2^500 + 2^110 */
    426          1.1       mrg   test_add (a, b, d, MPFR_RNDZ);   /* a = 2^901 */
    427          1.1       mrg   if (mpfr_cmp_ui_2exp (a, 1, 901))
    428          1.1       mrg     {
    429          1.1       mrg       printf ("b + d fails for b=2^900+2^500+2^110, d=2^900-2^500-2^110\n");
    430          1.1       mrg       printf ("expected 1.0e901, got ");
    431          1.1       mrg       mpfr_out_str (stdout, 2, 0, a, MPFR_RNDN);
    432          1.1       mrg       printf ("\n");
    433          1.1       mrg       exit (1);
    434          1.1       mrg     }
    435          1.1       mrg 
    436          1.1       mrg   mpfr_clear (a);
    437          1.1       mrg   mpfr_clear (b);
    438          1.1       mrg   mpfr_clear (c);
    439          1.1       mrg   mpfr_clear (d);
    440          1.1       mrg }
    441          1.1       mrg 
    442          1.1       mrg /* checks when source and destination are equal */
    443          1.1       mrg static void
    444          1.1       mrg check_same (void)
    445          1.1       mrg {
    446          1.1       mrg   mpfr_t x;
    447          1.1       mrg 
    448          1.1       mrg   mpfr_init(x); mpfr_set_ui(x, 1, MPFR_RNDZ);
    449          1.1       mrg   test_add (x, x, x, MPFR_RNDZ);
    450          1.1       mrg   if (mpfr_cmp_ui (x, 2))
    451          1.1       mrg     {
    452          1.1       mrg       printf ("Error when all 3 operands are equal\n");
    453          1.1       mrg       exit (1);
    454          1.1       mrg     }
    455          1.1       mrg   mpfr_clear(x);
    456          1.1       mrg }
    457          1.1       mrg 
    458          1.1       mrg #define check53(x, y, r, z) check(x, y, r, 53, 53, 53, z)
    459          1.1       mrg 
    460          1.1       mrg #define MAX_PREC 256
    461          1.1       mrg 
    462          1.1       mrg static void
    463          1.1       mrg check_inexact (void)
    464          1.1       mrg {
    465          1.1       mrg   mpfr_t x, y, z, u;
    466          1.1       mrg   mpfr_prec_t px, py, pu, pz;
    467          1.1       mrg   int inexact, cmp;
    468          1.1       mrg   mpfr_rnd_t rnd;
    469          1.1       mrg 
    470          1.1       mrg   mpfr_init (x);
    471          1.1       mrg   mpfr_init (y);
    472          1.1       mrg   mpfr_init (z);
    473          1.1       mrg   mpfr_init (u);
    474          1.1       mrg 
    475          1.1       mrg   mpfr_set_prec (x, 2);
    476          1.1       mrg   mpfr_set_str_binary (x, "0.1E-4");
    477          1.1       mrg   mpfr_set_prec (u, 33);
    478          1.1       mrg   mpfr_set_str_binary (u, "0.101110100101101100000000111100000E-1");
    479          1.1       mrg   mpfr_set_prec (y, 31);
    480  1.1.1.3.4.1  christos   inexact = test_add (y, x, u, MPFR_RNDN);
    481  1.1.1.3.4.1  christos 
    482  1.1.1.3.4.1  christos   if (inexact != 0)
    483          1.1       mrg     {
    484  1.1.1.3.4.1  christos       printf ("Wrong ternary value (2): expected 0, got %d\n", inexact);
    485          1.1       mrg       exit (1);
    486          1.1       mrg     }
    487          1.1       mrg 
    488          1.1       mrg   mpfr_set_prec (x, 2);
    489          1.1       mrg   mpfr_set_str_binary (x, "0.1E-4");
    490          1.1       mrg   mpfr_set_prec (u, 33);
    491          1.1       mrg   mpfr_set_str_binary (u, "0.101110100101101100000000111100000E-1");
    492          1.1       mrg   mpfr_set_prec (y, 28);
    493  1.1.1.3.4.1  christos   inexact = test_add (y, x, u, MPFR_RNDN);
    494  1.1.1.3.4.1  christos 
    495  1.1.1.3.4.1  christos   if (inexact != 0)
    496          1.1       mrg     {
    497  1.1.1.3.4.1  christos       printf ("Wrong ternary value (1): expected 0, got %d\n", inexact);
    498          1.1       mrg       exit (1);
    499          1.1       mrg     }
    500          1.1       mrg 
    501  1.1.1.3.4.1  christos   for (px = 2; px < MAX_PREC; px++)
    502          1.1       mrg     {
    503          1.1       mrg       mpfr_set_prec (x, px);
    504  1.1.1.3.4.1  christos 
    505          1.1       mrg       do
    506          1.1       mrg         {
    507          1.1       mrg           mpfr_urandomb (x, RANDS);
    508          1.1       mrg         }
    509          1.1       mrg       while (mpfr_cmp_ui (x, 0) == 0);
    510  1.1.1.3.4.1  christos 
    511  1.1.1.3.4.1  christos       for (pu = 2; pu < MAX_PREC; pu++)
    512          1.1       mrg         {
    513          1.1       mrg           mpfr_set_prec (u, pu);
    514  1.1.1.3.4.1  christos 
    515          1.1       mrg           do
    516          1.1       mrg             {
    517          1.1       mrg               mpfr_urandomb (u, RANDS);
    518          1.1       mrg             }
    519          1.1       mrg           while (mpfr_cmp_ui (u, 0) == 0);
    520  1.1.1.3.4.1  christos 
    521  1.1.1.3.4.1  christos           py = MPFR_PREC_MIN + (randlimb () % (MAX_PREC - 1));
    522  1.1.1.3.4.1  christos           mpfr_set_prec (y, py);
    523  1.1.1.3.4.1  christos           pz = mpfr_cmpabs (x, u) >= 0 ?
    524  1.1.1.3.4.1  christos             MPFR_EXP(x) - MPFR_EXP(u) :
    525  1.1.1.3.4.1  christos             MPFR_EXP(u) - MPFR_EXP(x);
    526  1.1.1.3.4.1  christos           /* x + u is exactly representable with precision
    527  1.1.1.3.4.1  christos              abs(EXP(x)-EXP(u)) + max(prec(x), prec(u)) + 1 */
    528  1.1.1.3.4.1  christos           pz = pz + MAX(MPFR_PREC(x), MPFR_PREC(u)) + 1;
    529  1.1.1.3.4.1  christos           mpfr_set_prec (z, pz);
    530  1.1.1.3.4.1  christos 
    531  1.1.1.3.4.1  christos           rnd = RND_RAND_NO_RNDF ();
    532  1.1.1.3.4.1  christos           inexact = test_add (z, x, u, rnd);
    533  1.1.1.3.4.1  christos           if (inexact != 0)
    534  1.1.1.3.4.1  christos             {
    535  1.1.1.3.4.1  christos               printf ("z <- x + u should be exact\n");
    536  1.1.1.3.4.1  christos               printf ("x="); mpfr_dump (x);
    537  1.1.1.3.4.1  christos               printf ("u="); mpfr_dump (u);
    538  1.1.1.3.4.1  christos               printf ("z="); mpfr_dump (z);
    539  1.1.1.3.4.1  christos               exit (1);
    540  1.1.1.3.4.1  christos             }
    541  1.1.1.3.4.1  christos 
    542  1.1.1.3.4.1  christos           rnd = RND_RAND_NO_RNDF ();
    543  1.1.1.3.4.1  christos           inexact = test_add (y, x, u, rnd);
    544  1.1.1.3.4.1  christos           cmp = mpfr_cmp (y, z);
    545  1.1.1.3.4.1  christos           if ((inexact == 0 && cmp != 0) ||
    546  1.1.1.3.4.1  christos               (inexact > 0 && cmp <= 0) ||
    547  1.1.1.3.4.1  christos               (inexact < 0 && cmp >= 0))
    548  1.1.1.3.4.1  christos             {
    549  1.1.1.3.4.1  christos               printf ("Wrong ternary value for rnd=%s\n",
    550  1.1.1.3.4.1  christos                       mpfr_print_rnd_mode (rnd));
    551  1.1.1.3.4.1  christos               printf ("expected %d, got %d\n", cmp, inexact);
    552  1.1.1.3.4.1  christos               printf ("x="); mpfr_dump (x);
    553  1.1.1.3.4.1  christos               printf ("u="); mpfr_dump (u);
    554  1.1.1.3.4.1  christos               printf ("y=  "); mpfr_dump (y);
    555  1.1.1.3.4.1  christos               printf ("x+u="); mpfr_dump (z);
    556  1.1.1.3.4.1  christos               exit (1);
    557          1.1       mrg             }
    558          1.1       mrg         }
    559          1.1       mrg     }
    560          1.1       mrg 
    561          1.1       mrg   mpfr_clear (x);
    562          1.1       mrg   mpfr_clear (y);
    563          1.1       mrg   mpfr_clear (z);
    564          1.1       mrg   mpfr_clear (u);
    565          1.1       mrg }
    566          1.1       mrg 
    567          1.1       mrg static void
    568          1.1       mrg check_nans (void)
    569          1.1       mrg {
    570          1.1       mrg   mpfr_t  s, x, y;
    571          1.1       mrg 
    572          1.1       mrg   mpfr_init2 (x, 8L);
    573          1.1       mrg   mpfr_init2 (y, 8L);
    574          1.1       mrg   mpfr_init2 (s, 8L);
    575          1.1       mrg 
    576          1.1       mrg   /* +inf + -inf == nan */
    577          1.1       mrg   mpfr_set_inf (x, 1);
    578          1.1       mrg   mpfr_set_inf (y, -1);
    579          1.1       mrg   test_add (s, x, y, MPFR_RNDN);
    580          1.1       mrg   MPFR_ASSERTN (mpfr_nan_p (s));
    581          1.1       mrg 
    582          1.1       mrg   /* +inf + 1 == +inf */
    583          1.1       mrg   mpfr_set_inf (x, 1);
    584          1.1       mrg   mpfr_set_ui (y, 1L, MPFR_RNDN);
    585          1.1       mrg   test_add (s, x, y, MPFR_RNDN);
    586          1.1       mrg   MPFR_ASSERTN (mpfr_inf_p (s));
    587          1.1       mrg   MPFR_ASSERTN (mpfr_sgn (s) > 0);
    588          1.1       mrg 
    589          1.1       mrg   /* -inf + 1 == -inf */
    590          1.1       mrg   mpfr_set_inf (x, -1);
    591          1.1       mrg   mpfr_set_ui (y, 1L, MPFR_RNDN);
    592          1.1       mrg   test_add (s, x, y, MPFR_RNDN);
    593          1.1       mrg   MPFR_ASSERTN (mpfr_inf_p (s));
    594          1.1       mrg   MPFR_ASSERTN (mpfr_sgn (s) < 0);
    595          1.1       mrg 
    596          1.1       mrg   /* 1 + +inf == +inf */
    597          1.1       mrg   mpfr_set_ui (x, 1L, MPFR_RNDN);
    598          1.1       mrg   mpfr_set_inf (y, 1);
    599          1.1       mrg   test_add (s, x, y, MPFR_RNDN);
    600          1.1       mrg   MPFR_ASSERTN (mpfr_inf_p (s));
    601          1.1       mrg   MPFR_ASSERTN (mpfr_sgn (s) > 0);
    602          1.1       mrg 
    603          1.1       mrg   /* 1 + -inf == -inf */
    604          1.1       mrg   mpfr_set_ui (x, 1L, MPFR_RNDN);
    605          1.1       mrg   mpfr_set_inf (y, -1);
    606          1.1       mrg   test_add (s, x, y, MPFR_RNDN);
    607          1.1       mrg   MPFR_ASSERTN (mpfr_inf_p (s));
    608          1.1       mrg   MPFR_ASSERTN (mpfr_sgn (s) < 0);
    609          1.1       mrg 
    610          1.1       mrg   mpfr_clear (x);
    611          1.1       mrg   mpfr_clear (y);
    612          1.1       mrg   mpfr_clear (s);
    613          1.1       mrg }
    614          1.1       mrg 
    615          1.1       mrg static void
    616          1.1       mrg check_alloc (void)
    617          1.1       mrg {
    618          1.1       mrg   mpfr_t a;
    619          1.1       mrg 
    620          1.1       mrg   mpfr_init2 (a, 10000);
    621          1.1       mrg   mpfr_set_prec (a, 53);
    622          1.1       mrg   mpfr_set_ui (a, 15236, MPFR_RNDN);
    623          1.1       mrg   test_add (a, a, a, MPFR_RNDN);
    624          1.1       mrg   mpfr_mul (a, a, a, MPFR_RNDN);
    625          1.1       mrg   mpfr_div (a, a, a, MPFR_RNDN);
    626          1.1       mrg   mpfr_sub (a, a, a, MPFR_RNDN);
    627          1.1       mrg   mpfr_clear (a);
    628          1.1       mrg }
    629          1.1       mrg 
    630          1.1       mrg static void
    631          1.1       mrg check_overflow (void)
    632          1.1       mrg {
    633          1.1       mrg   mpfr_t a, b, c;
    634  1.1.1.3.4.1  christos   mpfr_prec_t prec_a, prec_b, prec_c;
    635  1.1.1.3.4.1  christos   int r, up;
    636          1.1       mrg 
    637  1.1.1.3.4.1  christos   mpfr_init (a);
    638  1.1.1.3.4.1  christos   mpfr_init (b);
    639  1.1.1.3.4.1  christos   mpfr_init (c);
    640          1.1       mrg 
    641  1.1.1.3.4.1  christos   RND_LOOP_NO_RNDF (r)
    642  1.1.1.3.4.1  christos     for (prec_a = 2; prec_a <= 128; prec_a += 2)
    643  1.1.1.3.4.1  christos       for (prec_b = 2; prec_b <= 128; prec_b += 2)
    644  1.1.1.3.4.1  christos         for (prec_c = 2; prec_c <= 128; prec_c += 2)
    645          1.1       mrg           {
    646  1.1.1.3.4.1  christos             mpfr_set_prec (a, prec_a);
    647  1.1.1.3.4.1  christos             mpfr_set_prec (b, prec_b);
    648  1.1.1.3.4.1  christos             mpfr_set_prec (c, prec_c);
    649  1.1.1.3.4.1  christos 
    650  1.1.1.3.4.1  christos             mpfr_setmax (b, mpfr_get_emax ());
    651  1.1.1.3.4.1  christos 
    652  1.1.1.3.4.1  christos             up = r == MPFR_RNDA || r == MPFR_RNDU || r == MPFR_RNDN;
    653  1.1.1.3.4.1  christos 
    654  1.1.1.3.4.1  christos             /* set c with overlap with bits of b: will always overflow */
    655  1.1.1.3.4.1  christos             mpfr_set_ui_2exp (c, 1, mpfr_get_emax () - prec_b / 2, MPFR_RNDN);
    656  1.1.1.3.4.1  christos             mpfr_nextbelow (c);
    657  1.1.1.3.4.1  christos             mpfr_clear_overflow ();
    658  1.1.1.3.4.1  christos             test_add (a, b, c, (mpfr_rnd_t) r);
    659  1.1.1.3.4.1  christos             if (!mpfr_overflow_p () || (up && !mpfr_inf_p (a)))
    660  1.1.1.3.4.1  christos               {
    661  1.1.1.3.4.1  christos                 printf ("No overflow (1) in check_overflow for rnd=%s\n",
    662  1.1.1.3.4.1  christos                         mpfr_print_rnd_mode ((mpfr_rnd_t) r));
    663  1.1.1.3.4.1  christos                 printf ("b="); mpfr_dump (b);
    664  1.1.1.3.4.1  christos                 printf ("c="); mpfr_dump (c);
    665  1.1.1.3.4.1  christos                 printf ("a="); mpfr_dump (a);
    666  1.1.1.3.4.1  christos                 exit (1);
    667  1.1.1.3.4.1  christos               }
    668  1.1.1.3.4.1  christos 
    669  1.1.1.3.4.1  christos             if (r == MPFR_RNDZ || r == MPFR_RNDD || prec_a >= prec_b + prec_c)
    670  1.1.1.3.4.1  christos               continue;
    671  1.1.1.3.4.1  christos 
    672  1.1.1.3.4.1  christos             /* set c to 111...111 so that ufp(c) = 1/2 ulp(b): will only overflow
    673  1.1.1.3.4.1  christos                when prec_a < prec_b + prec_c, and rounding up or to nearest */
    674  1.1.1.3.4.1  christos             mpfr_set_ui_2exp (c, 1, mpfr_get_emax () - prec_b, MPFR_RNDN);
    675  1.1.1.3.4.1  christos             mpfr_nextbelow (c);
    676  1.1.1.3.4.1  christos             mpfr_clear_overflow ();
    677  1.1.1.3.4.1  christos             test_add (a, b, c, (mpfr_rnd_t) r);
    678  1.1.1.3.4.1  christos             /* b + c is exactly representable iff prec_a >= prec_b + prec_c */
    679  1.1.1.3.4.1  christos             if (!mpfr_overflow_p () || !mpfr_inf_p (a))
    680  1.1.1.3.4.1  christos               {
    681  1.1.1.3.4.1  christos                 printf ("No overflow (2) in check_overflow for rnd=%s\n",
    682  1.1.1.3.4.1  christos                         mpfr_print_rnd_mode ((mpfr_rnd_t) r));
    683  1.1.1.3.4.1  christos                 printf ("b="); mpfr_dump (b);
    684  1.1.1.3.4.1  christos                 printf ("c="); mpfr_dump (c);
    685  1.1.1.3.4.1  christos                 printf ("a="); mpfr_dump (a);
    686  1.1.1.3.4.1  christos                 exit (1);
    687  1.1.1.3.4.1  christos               }
    688          1.1       mrg           }
    689          1.1       mrg 
    690  1.1.1.3.4.1  christos   mpfr_set_prec (b, 256);
    691  1.1.1.3.4.1  christos   mpfr_setmax (b, mpfr_get_emax ());
    692  1.1.1.3.4.1  christos   mpfr_set_prec (c, 256);
    693  1.1.1.3.4.1  christos   mpfr_set_ui (c, 1, MPFR_RNDN);
    694          1.1       mrg   mpfr_set_exp (c, mpfr_get_emax () - 512);
    695          1.1       mrg   mpfr_set_prec (a, 256);
    696          1.1       mrg   mpfr_clear_overflow ();
    697  1.1.1.3.4.1  christos   mpfr_add (a, b, c, MPFR_RNDU);
    698          1.1       mrg   if (!mpfr_overflow_p ())
    699          1.1       mrg     {
    700  1.1.1.3.4.1  christos       printf ("No overflow (3) in check_overflow\n");
    701  1.1.1.3.4.1  christos       printf ("b="); mpfr_dump (b);
    702  1.1.1.3.4.1  christos       printf ("c="); mpfr_dump (c);
    703  1.1.1.3.4.1  christos       printf ("a="); mpfr_dump (a);
    704          1.1       mrg       exit (1);
    705          1.1       mrg     }
    706          1.1       mrg 
    707          1.1       mrg   mpfr_clear (a);
    708          1.1       mrg   mpfr_clear (b);
    709          1.1       mrg   mpfr_clear (c);
    710          1.1       mrg }
    711          1.1       mrg 
    712          1.1       mrg static void
    713          1.1       mrg check_1111 (void)
    714          1.1       mrg {
    715          1.1       mrg   mpfr_t one;
    716          1.1       mrg   long n;
    717          1.1       mrg 
    718          1.1       mrg   mpfr_init2 (one, MPFR_PREC_MIN);
    719          1.1       mrg   mpfr_set_ui (one, 1, MPFR_RNDN);
    720      1.1.1.2       mrg   for (n = 0; n < N; n++)
    721          1.1       mrg     {
    722          1.1       mrg       mpfr_prec_t prec_a, prec_b, prec_c;
    723          1.1       mrg       mpfr_exp_t tb=0, tc, diff;
    724          1.1       mrg       mpfr_t a, b, c, s;
    725          1.1       mrg       int m = 512;
    726          1.1       mrg       int sb, sc;
    727          1.1       mrg       int inex_a, inex_s;
    728          1.1       mrg       mpfr_rnd_t rnd_mode;
    729          1.1       mrg 
    730          1.1       mrg       prec_a = MPFR_PREC_MIN + (randlimb () % m);
    731          1.1       mrg       prec_b = MPFR_PREC_MIN + (randlimb () % m);
    732  1.1.1.3.4.1  christos       /* we need prec_c > 1 so that % (prec_c - 1) is well defined below */
    733  1.1.1.3.4.1  christos       do prec_c = MPFR_PREC_MIN + (randlimb () % m); while (prec_c == 1);
    734          1.1       mrg       mpfr_init2 (a, prec_a);
    735          1.1       mrg       mpfr_init2 (b, prec_b);
    736          1.1       mrg       mpfr_init2 (c, prec_c);
    737  1.1.1.3.4.1  christos       /* we need prec_b - (sb != 2) > 0 below */
    738  1.1.1.3.4.1  christos       do sb = randlimb () % 3; while (prec_b - (sb != 2) == 0);
    739          1.1       mrg       if (sb != 0)
    740          1.1       mrg         {
    741          1.1       mrg           tb = 1 + (randlimb () % (prec_b - (sb != 2)));
    742          1.1       mrg           mpfr_div_2ui (b, one, tb, MPFR_RNDN);
    743          1.1       mrg           if (sb == 2)
    744          1.1       mrg             mpfr_neg (b, b, MPFR_RNDN);
    745          1.1       mrg           test_add (b, b, one, MPFR_RNDN);
    746          1.1       mrg         }
    747          1.1       mrg       else
    748          1.1       mrg         mpfr_set (b, one, MPFR_RNDN);
    749          1.1       mrg       tc = 1 + (randlimb () % (prec_c - 1));
    750          1.1       mrg       mpfr_div_2ui (c, one, tc, MPFR_RNDN);
    751          1.1       mrg       sc = randlimb () % 2;
    752          1.1       mrg       if (sc)
    753          1.1       mrg         mpfr_neg (c, c, MPFR_RNDN);
    754          1.1       mrg       test_add (c, c, one, MPFR_RNDN);
    755          1.1       mrg       diff = (randlimb () % (2*m)) - m;
    756          1.1       mrg       mpfr_mul_2si (c, c, diff, MPFR_RNDN);
    757  1.1.1.3.4.1  christos       rnd_mode = RND_RAND_NO_RNDF ();
    758          1.1       mrg       inex_a = test_add (a, b, c, rnd_mode);
    759          1.1       mrg       mpfr_init2 (s, MPFR_PREC_MIN + 2*m);
    760          1.1       mrg       inex_s = test_add (s, b, c, MPFR_RNDN); /* exact */
    761          1.1       mrg       if (inex_s)
    762          1.1       mrg         {
    763          1.1       mrg           printf ("check_1111: result should have been exact.\n");
    764          1.1       mrg           exit (1);
    765          1.1       mrg         }
    766          1.1       mrg       inex_s = mpfr_prec_round (s, prec_a, rnd_mode);
    767          1.1       mrg       if ((inex_a < 0 && inex_s >= 0) ||
    768          1.1       mrg           (inex_a == 0 && inex_s != 0) ||
    769          1.1       mrg           (inex_a > 0 && inex_s <= 0) ||
    770          1.1       mrg           !mpfr_equal_p (a, s))
    771          1.1       mrg         {
    772          1.1       mrg           printf ("check_1111: results are different.\n");
    773          1.1       mrg           printf ("prec_a = %d, prec_b = %d, prec_c = %d\n",
    774          1.1       mrg                   (int) prec_a, (int) prec_b, (int) prec_c);
    775          1.1       mrg           printf ("tb = %d, tc = %d, diff = %d, rnd = %s\n",
    776          1.1       mrg                   (int) tb, (int) tc, (int) diff,
    777          1.1       mrg                   mpfr_print_rnd_mode (rnd_mode));
    778          1.1       mrg           printf ("sb = %d, sc = %d\n", sb, sc);
    779  1.1.1.3.4.1  christos           printf ("a = "); mpfr_dump (a);
    780  1.1.1.3.4.1  christos           printf ("s = "); mpfr_dump (s);
    781          1.1       mrg           printf ("inex_a = %d, inex_s = %d\n", inex_a, inex_s);
    782          1.1       mrg           exit (1);
    783          1.1       mrg         }
    784          1.1       mrg       mpfr_clear (a);
    785          1.1       mrg       mpfr_clear (b);
    786          1.1       mrg       mpfr_clear (c);
    787          1.1       mrg       mpfr_clear (s);
    788          1.1       mrg     }
    789          1.1       mrg   mpfr_clear (one);
    790          1.1       mrg }
    791          1.1       mrg 
    792          1.1       mrg static void
    793          1.1       mrg check_1minuseps (void)
    794          1.1       mrg {
    795          1.1       mrg   static mpfr_prec_t prec_a[] = {
    796          1.1       mrg     MPFR_PREC_MIN, 30, 31, 32, 33, 62, 63, 64, 65, 126, 127, 128, 129
    797          1.1       mrg   };
    798          1.1       mrg   static int supp_b[] = {
    799          1.1       mrg     0, 1, 2, 3, 4, 29, 30, 31, 32, 33, 34, 35, 61, 62, 63, 64, 65, 66, 67
    800          1.1       mrg   };
    801          1.1       mrg   mpfr_t a, b, c;
    802          1.1       mrg   unsigned int ia, ib, ic;
    803          1.1       mrg 
    804          1.1       mrg   mpfr_init2 (c, MPFR_PREC_MIN);
    805          1.1       mrg 
    806          1.1       mrg   for (ia = 0; ia < numberof (prec_a); ia++)
    807  1.1.1.3.4.1  christos     for (ib = 0; ib < numberof (supp_b); ib++)
    808          1.1       mrg       {
    809          1.1       mrg         mpfr_prec_t prec_b;
    810          1.1       mrg         int rnd_mode;
    811          1.1       mrg 
    812          1.1       mrg         prec_b = prec_a[ia] + supp_b[ib];
    813          1.1       mrg 
    814          1.1       mrg         mpfr_init2 (a, prec_a[ia]);
    815          1.1       mrg         mpfr_init2 (b, prec_b);
    816          1.1       mrg 
    817          1.1       mrg         mpfr_set_ui (c, 1, MPFR_RNDN);
    818          1.1       mrg         mpfr_div_ui (b, c, prec_a[ia], MPFR_RNDN);
    819          1.1       mrg         mpfr_sub (b, c, b, MPFR_RNDN);  /* b = 1 - 2^(-prec_a) */
    820          1.1       mrg 
    821  1.1.1.3.4.1  christos         for (ic = 0; ic < numberof (supp_b); ic++)
    822          1.1       mrg           for (rnd_mode = 0; rnd_mode < MPFR_RND_MAX; rnd_mode++)
    823          1.1       mrg             {
    824          1.1       mrg               mpfr_t s;
    825          1.1       mrg               int inex_a, inex_s;
    826          1.1       mrg 
    827  1.1.1.3.4.1  christos               if (rnd_mode == MPFR_RNDF)
    828  1.1.1.3.4.1  christos                 continue; /* inex_a, inex_s make no sense */
    829  1.1.1.3.4.1  christos 
    830          1.1       mrg               mpfr_set_ui (c, 1, MPFR_RNDN);
    831          1.1       mrg               mpfr_div_ui (c, c, prec_a[ia] + supp_b[ic], MPFR_RNDN);
    832          1.1       mrg               inex_a = test_add (a, b, c, (mpfr_rnd_t) rnd_mode);
    833          1.1       mrg               mpfr_init2 (s, 256);
    834          1.1       mrg               inex_s = test_add (s, b, c, MPFR_RNDN); /* exact */
    835          1.1       mrg               if (inex_s)
    836          1.1       mrg                 {
    837          1.1       mrg                   printf ("check_1minuseps: result should have been exact "
    838          1.1       mrg                           "(ia = %u, ib = %u, ic = %u)\n", ia, ib, ic);
    839          1.1       mrg                   exit (1);
    840          1.1       mrg                 }
    841          1.1       mrg               inex_s = mpfr_prec_round (s, prec_a[ia], (mpfr_rnd_t) rnd_mode);
    842          1.1       mrg               if ((inex_a < 0 && inex_s >= 0) ||
    843          1.1       mrg                   (inex_a == 0 && inex_s != 0) ||
    844          1.1       mrg                   (inex_a > 0 && inex_s <= 0) ||
    845          1.1       mrg                   !mpfr_equal_p (a, s))
    846          1.1       mrg                 {
    847          1.1       mrg                   printf ("check_1minuseps: results are different.\n");
    848          1.1       mrg                   printf ("ia = %u, ib = %u, ic = %u\n", ia, ib, ic);
    849          1.1       mrg                   exit (1);
    850          1.1       mrg                 }
    851          1.1       mrg               mpfr_clear (s);
    852          1.1       mrg             }
    853          1.1       mrg 
    854          1.1       mrg         mpfr_clear (a);
    855          1.1       mrg         mpfr_clear (b);
    856          1.1       mrg       }
    857          1.1       mrg 
    858          1.1       mrg   mpfr_clear (c);
    859          1.1       mrg }
    860          1.1       mrg 
    861          1.1       mrg /* Test case bk == 0 in add1.c (b has entirely been read and
    862          1.1       mrg    c hasn't been taken into account). */
    863          1.1       mrg static void
    864          1.1       mrg coverage_bk_eq_0 (void)
    865          1.1       mrg {
    866          1.1       mrg   mpfr_t a, b, c;
    867          1.1       mrg   int inex;
    868          1.1       mrg 
    869          1.1       mrg   mpfr_init2 (a, GMP_NUMB_BITS);
    870          1.1       mrg   mpfr_init2 (b, 2 * GMP_NUMB_BITS);
    871          1.1       mrg   mpfr_init2 (c, GMP_NUMB_BITS);
    872          1.1       mrg 
    873          1.1       mrg   mpfr_set_ui_2exp (b, 1, 2 * GMP_NUMB_BITS, MPFR_RNDN);
    874          1.1       mrg   mpfr_sub_ui (b, b, 1, MPFR_RNDN);
    875          1.1       mrg   /* b = 111...111 (in base 2) where the 1's fit 2 whole limbs */
    876          1.1       mrg 
    877          1.1       mrg   mpfr_set_ui_2exp (c, 1, -1, MPFR_RNDN);  /* c = 1/2 */
    878          1.1       mrg 
    879          1.1       mrg   inex = mpfr_add (a, b, c, MPFR_RNDU);
    880          1.1       mrg   mpfr_set_ui_2exp (c, 1, 2 * GMP_NUMB_BITS, MPFR_RNDN);
    881          1.1       mrg   if (! mpfr_equal_p (a, c))
    882          1.1       mrg     {
    883          1.1       mrg       printf ("Error in coverage_bk_eq_0\n");
    884          1.1       mrg       printf ("Expected ");
    885          1.1       mrg       mpfr_dump (c);
    886          1.1       mrg       printf ("Got      ");
    887          1.1       mrg       mpfr_dump (a);
    888          1.1       mrg       exit (1);
    889          1.1       mrg     }
    890          1.1       mrg   MPFR_ASSERTN (inex > 0);
    891          1.1       mrg 
    892          1.1       mrg   mpfr_clear (a);
    893          1.1       mrg   mpfr_clear (b);
    894          1.1       mrg   mpfr_clear (c);
    895          1.1       mrg }
    896          1.1       mrg 
    897          1.1       mrg static void
    898          1.1       mrg tests (void)
    899          1.1       mrg {
    900          1.1       mrg   check_alloc ();
    901          1.1       mrg   check_nans ();
    902          1.1       mrg   check_inexact ();
    903          1.1       mrg   check_case_1b ();
    904          1.1       mrg   check_case_2 ();
    905          1.1       mrg   check64();
    906          1.1       mrg   coverage_bk_eq_0 ();
    907          1.1       mrg 
    908          1.1       mrg   check("293607738.0", "1.9967571564050541e-5", MPFR_RNDU, 64, 53, 53,
    909          1.1       mrg         "2.9360773800002003e8");
    910          1.1       mrg   check("880524.0", "-2.0769715792901673e-5", MPFR_RNDN, 64, 53, 53,
    911          1.1       mrg         "8.8052399997923023e5");
    912          1.1       mrg   check("1196426492.0", "-1.4218093058435347e-3", MPFR_RNDN, 64, 53, 53,
    913          1.1       mrg         "1.1964264919985781e9");
    914          1.1       mrg   check("982013018.0", "-8.941829477291838e-7", MPFR_RNDN, 64, 53, 53,
    915          1.1       mrg         "9.8201301799999905e8");
    916          1.1       mrg   check("1092583421.0", "1.0880649218158844e9", MPFR_RNDN, 64, 53, 53,
    917          1.1       mrg         "2.1806483428158846e9");
    918          1.1       mrg   check("1.8476886419022969e-6", "961494401.0", MPFR_RNDN, 53, 64, 53,
    919          1.1       mrg         "9.6149440100000179e8");
    920          1.1       mrg   check("-2.3222118418069868e5", "1229318102.0", MPFR_RNDN, 53, 64, 53,
    921          1.1       mrg         "1.2290858808158193e9");
    922          1.1       mrg   check("-3.0399171300395734e-6", "874924868.0", MPFR_RNDN, 53, 64, 53,
    923          1.1       mrg         "8.749248679999969e8");
    924          1.1       mrg   check("9.064246624706179e1", "663787413.0", MPFR_RNDN, 53, 64, 53,
    925          1.1       mrg         "6.6378750364246619e8");
    926          1.1       mrg   check("-1.0954322421551264e2", "281806592.0", MPFR_RNDD, 53, 64, 53,
    927          1.1       mrg         "2.8180648245677572e8");
    928          1.1       mrg   check("5.9836930386056659e-8", "1016217213.0", MPFR_RNDN, 53, 64, 53,
    929          1.1       mrg         "1.0162172130000001e9");
    930          1.1       mrg   check("-1.2772161928500301e-7", "1237734238.0", MPFR_RNDN, 53, 64, 53,
    931          1.1       mrg         "1.2377342379999998e9");
    932          1.1       mrg   check("-4.567291988483277e8", "1262857194.0", MPFR_RNDN, 53, 64, 53,
    933          1.1       mrg         "8.0612799515167236e8");
    934          1.1       mrg   check("4.7719471752925262e7", "196089880.0", MPFR_RNDN, 53, 53, 53,
    935          1.1       mrg         "2.4380935175292528e8");
    936          1.1       mrg   check("4.7719471752925262e7", "196089880.0", MPFR_RNDN, 53, 64, 53,
    937          1.1       mrg         "2.4380935175292528e8");
    938          1.1       mrg   check("-1.716113812768534e-140", "1271212614.0", MPFR_RNDZ, 53, 64, 53,
    939          1.1       mrg         "1.2712126139999998e9");
    940          1.1       mrg   check("-1.2927455200185474e-50", "1675676122.0", MPFR_RNDD, 53, 64, 53,
    941          1.1       mrg         "1.6756761219999998e9");
    942          1.1       mrg 
    943          1.1       mrg   check53("1.22191250737771397120e+20", "948002822.0", MPFR_RNDN,
    944          1.1       mrg           "122191250738719408128.0");
    945          1.1       mrg   check53("9966027674114492.0", "1780341389094537.0", MPFR_RNDN,
    946          1.1       mrg           "11746369063209028.0");
    947          1.1       mrg   check53("2.99280481918991653800e+272", "5.34637717585790933424e+271",
    948          1.1       mrg           MPFR_RNDN, "3.5274425367757071711e272");
    949          1.1       mrg   check_same();
    950          1.1       mrg   check53("6.14384195492641560499e-02", "-6.14384195401037683237e-02",
    951          1.1       mrg           MPFR_RNDU, "9.1603877261370314499e-12");
    952          1.1       mrg   check53("1.16809465359248765399e+196", "7.92883212101990665259e+196",
    953          1.1       mrg           MPFR_RNDU, "9.0969267746123943065e196");
    954          1.1       mrg   check53("3.14553393112021279444e-67", "3.14553401015952024126e-67", MPFR_RNDU,
    955          1.1       mrg           "6.2910679412797336946e-67");
    956          1.1       mrg 
    957          1.1       mrg   check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDN,
    958          1.1       mrg           "5.4388530464436950905e185");
    959          1.1       mrg   check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDZ,
    960          1.1       mrg           "5.4388530464436944867e185");
    961          1.1       mrg   check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDU,
    962          1.1       mrg           "5.4388530464436950905e185");
    963          1.1       mrg   check53("5.43885304644369509058e+185","-1.87427265794105342763e-57",MPFR_RNDD,
    964          1.1       mrg           "5.4388530464436944867e185");
    965          1.1       mrg 
    966          1.1       mrg   check2b("1.001010101110011000000010100101110010111001010000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e358",187,
    967          1.1       mrg           "-1.11100111001101100010001111111110101101110001000000000000000000000000000000000000000000e160",87,
    968          1.1       mrg           "1.001010101110011000000010100101110010111001010000000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e358",178,
    969          1.1       mrg           MPFR_RNDD);
    970          1.1       mrg   check2b("-1.111100100011100111010101010101001010100100000111001000000000000000000e481",70,
    971          1.1       mrg           "1.1111000110100011110101111110110010010000000110101000000000000000e481",65,
    972          1.1       mrg           "-1.001010111111101011010000001100011101100101000000000000000000e472",61,
    973          1.1       mrg           MPFR_RNDD);
    974          1.1       mrg   check2b("1.0100010111010000100101000000111110011100011001011010000000000000000000000000000000e516",83,
    975          1.1       mrg           "-1.1001111000100001011100000001001100110011110010111111000000e541",59,
    976          1.1       mrg           "-1.1001111000100001011011110111000001001011100000011110100000110001110011010011000000000000000000000000000000000000000000000000e541",125,
    977          1.1       mrg           MPFR_RNDZ);
    978          1.1       mrg   check2b("-1.0010111100000100110001011011010000000011000111101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e261",155,
    979          1.1       mrg           "-1.00111110100011e239",15,
    980          1.1       mrg           "-1.00101111000001001100101010101110001100110001111010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e261",159,
    981          1.1       mrg           MPFR_RNDD);
    982          1.1       mrg   check2b("-1.110111000011111011000000001001111101101001010100111000000000000000000000000e880",76,
    983          1.1       mrg           "-1.1010010e-634",8,
    984          1.1       mrg           "-1.11011100001111101100000000100111110110100101010011100000000000000000000000e880",75,
    985          1.1       mrg           MPFR_RNDZ);
    986          1.1       mrg   check2b("1.00100100110110101001010010101111000001011100100101010000000000000000000000000000e-530",81,
    987          1.1       mrg           "-1.101101111100000111000011001010110011001011101001110100000e-908",58,
    988          1.1       mrg           "1.00100100110110101001010010101111000001011100100101010e-530",54,
    989          1.1       mrg           MPFR_RNDN);
    990          1.1       mrg   check2b("1.0101100010010111101000000001000010010010011000111011000000000000000000000000000000000000000000000000000000000000000000e374",119,
    991          1.1       mrg           "1.11100101100101e358",15,
    992          1.1       mrg           "1.01011000100110011000010110100100100100100110001110110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e374",150,
    993          1.1       mrg           MPFR_RNDZ);
    994          1.1       mrg   check2b("-1.10011001000010100000010100100110110010011111101111000000000000000000000000000000000000000000000000000000000000000000e-172",117,
    995          1.1       mrg           "1.111011100000101010110000100100110100100001001000011100000000e-173",61,
    996          1.1       mrg           "-1.0100010000001001010110011011101001001011101011110001000000000000000e-173",68,
    997          1.1       mrg           MPFR_RNDZ);
    998          1.1       mrg   check2b("-1.011110000111101011100001100110100011100101000011011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-189",175,
    999          1.1       mrg           "1.1e631",2,
   1000          1.1       mrg           "1.011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111e631",115,
   1001          1.1       mrg           MPFR_RNDZ);
   1002          1.1       mrg   check2b("-1.101011101001011101100011001000001100010100001101011000000000000000000000000000000000000000000e-449",94,
   1003          1.1       mrg           "-1.01111101010111000011000110011101000111001100110111100000000000000e-429",66,
   1004          1.1       mrg           "-1.01111101010111000100110010000110100100101111111111101100010100001101011000000000000000000000000000000000000000e-429",111,
   1005          1.1       mrg           MPFR_RNDU);
   1006          1.1       mrg   check2b("-1.101011101001011101100011001000001100010100001101011000000000000000000000000000000000000000000e-449",94,
   1007          1.1       mrg           "-1.01111101010111000011000110011101000111001100110111100000000000000e-429",66,
   1008          1.1       mrg           "-1.01111101010111000100110010000110100100101111111111101100010100001101011000000000000000000000000000000000000000e-429",111,
   1009          1.1       mrg           MPFR_RNDD);
   1010          1.1       mrg   check2b("-1.1001000011101000110000111110010100100101110101111100000000000000000000000000000000000000000000000000000000e-72",107,
   1011          1.1       mrg           "-1.001100011101100100010101101010101011010010111111010000000000000000000000000000e521",79,
   1012          1.1       mrg           "-1.00110001110110010001010110101010101101001011111101000000000000000000000000000000000000000000000001e521",99,
   1013          1.1       mrg           MPFR_RNDD);
   1014          1.1       mrg   check2b("-1.01010001111000000101010100100100110101011011100001110000000000e498",63,
   1015          1.1       mrg           "1.010000011010101111000100111100011100010101011110010100000000000e243",64,
   1016          1.1       mrg           "-1.010100011110000001010101001001001101010110111000011100000000000e498",64,
   1017          1.1       mrg           MPFR_RNDN);
   1018          1.1       mrg   check2b("1.00101100010101000011010000011000111111011110010111000000000000000000000000000000000000000000000000000000000e178",108,
   1019          1.1       mrg           "-1.10101101010101000110011011111001001101111111110000100000000e160",60,
   1020          1.1       mrg           "1.00101100010100111100100011000011111001000010011101110010000000001111100000000000000000000000000000000000e178",105,
   1021          1.1       mrg           MPFR_RNDN);
   1022          1.1       mrg   check2b("1.00110011010100111110011010110100111101110101100100110000000000000000000000000000000000000000000000e559",99,
   1023          1.1       mrg           "-1.011010110100111011100110100110011100000000111010011000000000000000e559",67,
   1024          1.1       mrg           "-1.101111111101011111111111001001100100011100001001100000000000000000000000000000000000000000000e556",94,
   1025          1.1       mrg           MPFR_RNDU);
   1026          1.1       mrg   check2b("-1.100000111100101001100111011100011011000001101001111100000000000000000000000000e843",79,
   1027          1.1       mrg           "-1.1101101010110000001001000100001100110011000110110111000000000000000000000000000000000000000000e414",95,
   1028          1.1       mrg           "-1.1000001111001010011001110111000110110000011010100000e843",53,
   1029          1.1       mrg           MPFR_RNDD);
   1030          1.1       mrg   check2b("-1.110110010110100010100011000110111001010000010111110000000000e-415",61,
   1031          1.1       mrg           "-1.0000100101100001111100110011111111110100011101101011000000000000000000e751",71,
   1032          1.1       mrg           "-1.00001001011000011111001100111111111101000111011010110e751",54,
   1033          1.1       mrg           MPFR_RNDN);
   1034          1.1       mrg   check2b("-1.1011011011110001001101010101001000010100010110111101000000000000000000000e258",74,
   1035          1.1       mrg           "-1.00011100010110110101001011000100100000100010101000010000000000000000000000000000000000000000000000e268",99,
   1036          1.1       mrg           "-1.0001110011001001000011110001000111010110101011110010011011110100000000000000000000000000000000000000e268",101,
   1037          1.1       mrg           MPFR_RNDD);
   1038          1.1       mrg   check2b("-1.1011101010011101011000000100100110101101101110000001000000000e629",62,
   1039          1.1       mrg           "1.111111100000011100100011100000011101100110111110111000000000000000000000000000000000000000000e525",94,
   1040          1.1       mrg           "-1.101110101001110101100000010010011010110110111000000011111111111111111111111111111111111111111111111111101e629",106,
   1041          1.1       mrg           MPFR_RNDD);
   1042          1.1       mrg   check2b("1.111001000010001100010000001100000110001011110111011000000000000000000000000000000000000e152",88,
   1043          1.1       mrg           "1.111110111001100100000100111111010111000100111111001000000000000000e152",67,
   1044          1.1       mrg           "1.1110111111011110000010101001011011101010000110110100e153",53,
   1045          1.1       mrg           MPFR_RNDN);
   1046          1.1       mrg   check2b("1.000001100011110010110000110100001010101101111011110100e696",55,
   1047          1.1       mrg           "-1.1011001111011100100001011110100101010101110111010101000000000000000000000000000000000000000000000000000000000000e730",113,
   1048          1.1       mrg           "-1.1011001111011100100001011110100100010100010011100010e730",53,
   1049          1.1       mrg           MPFR_RNDN);
   1050          1.1       mrg   check2b("-1.11010111100001001111000001110101010010001111111001100000000000000000000000000000000000000000000000000000000000e530",111,
   1051          1.1       mrg           "1.01110100010010000000010110111101011101000001111101100000000000000000000000000000000000000000000000e530",99,
   1052          1.1       mrg           "-1.1000110011110011101010101101111101010011011111000000000000000e528",62,
   1053          1.1       mrg           MPFR_RNDD);
   1054          1.1       mrg   check2b("-1.0001100010010100111101101011101000100100010011100011000000000000000000000000000000000000000000000000000000000e733",110,
   1055          1.1       mrg           "-1.001000000111110010100101010100110111001111011011001000000000000000000000000000000000000000000000000000000000e710",109,
   1056          1.1       mrg           "-1.000110001001010011111000111110110001110110011000110110e733",55,
   1057          1.1       mrg           MPFR_RNDN);
   1058          1.1       mrg   check2b("-1.1101011110000100111100000111010101001000111111100110000000000000000000000e530",74,
   1059          1.1       mrg           "1.01110100010010000000010110111101011101000001111101100000000000000000000000000000000000000000000000000000000000e530",111,
   1060          1.1       mrg           "-1.10001100111100111010101011011111010100110111110000000000000000000000000000e528",75,
   1061          1.1       mrg           MPFR_RNDU);
   1062          1.1       mrg   check2b("1.00110011010100111110011010110100111101110101100100110000000000000000000000000000000000000000000000e559",99,
   1063          1.1       mrg           "-1.011010110100111011100110100110011100000000111010011000000000000000e559",67,
   1064          1.1       mrg           "-1.101111111101011111111111001001100100011100001001100000000000000000000000000000000000000000000e556",94,
   1065          1.1       mrg           MPFR_RNDU);
   1066          1.1       mrg   check2b("-1.100101111110110000000110111111011010011101101111100100000000000000e-624",67,
   1067          1.1       mrg           "1.10111010101110100000010110101000000000010011100000100000000e-587",60,
   1068          1.1       mrg           "1.1011101010111010000001011010011111110100011110001011111111001000000100101100010010000011100000000000000000000e-587",110,
   1069          1.1       mrg           MPFR_RNDU);
   1070          1.1       mrg   check2b("-1.10011001000010100000010100100110110010011111101111000000000000000000000000000000000000000000000000000000000000000000e-172",117,
   1071          1.1       mrg           "1.111011100000101010110000100100110100100001001000011100000000e-173",61,
   1072          1.1       mrg           "-1.0100010000001001010110011011101001001011101011110001000000000000000e-173",68,
   1073          1.1       mrg           MPFR_RNDZ);
   1074          1.1       mrg   check2b("1.1000111000110010101001010011010011101100010110001001000000000000000000000000000000000000000000000000e167",101,
   1075          1.1       mrg           "1.0011110010000110000000101100100111000001110110110000000000000000000000000e167",74,
   1076          1.1       mrg           "1.01100101010111000101001111111111010101110001100111001000000000000000000000000000000000000000000000000000e168",105,
   1077          1.1       mrg           MPFR_RNDZ);
   1078          1.1       mrg   check2b("1.100101111111110010100101110111100001110000100001010000000000000000000000000000000000000000000000e808",97,
   1079          1.1       mrg           "-1.1110011001100000100000111111110000110010100111001011000000000000000000000000000000e807",83,
   1080          1.1       mrg           "1.01001001100110001100011111000000000001011010010111010000000000000000000000000000000000000000000e807",96,
   1081          1.1       mrg           MPFR_RNDN);
   1082          1.1       mrg   check2b("1e128",128,
   1083          1.1       mrg           "1e0",128,
   1084          1.1       mrg           "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e0",256,
   1085          1.1       mrg           MPFR_RNDN);
   1086          1.1       mrg 
   1087          1.1       mrg   /* Checking double precision (53 bits) */
   1088          1.1       mrg   check53("-8.22183238641455905806e-19", "7.42227178769761587878e-19",MPFR_RNDD,
   1089          1.1       mrg           "-7.9956059871694317927e-20");
   1090          1.1       mrg   check53("5.82106394662028628236e+234","-5.21514064202368477230e+89",MPFR_RNDD,
   1091          1.1       mrg           "5.8210639466202855763e234");
   1092          1.1       mrg   check53("5.72931679569871602371e+122","-5.72886070363264321230e+122",
   1093          1.1       mrg           MPFR_RNDN, "4.5609206607281141508e118");
   1094          1.1       mrg   check53("-5.09937369394650450820e+238", "2.70203299854862982387e+250",
   1095          1.1       mrg           MPFR_RNDD, "2.7020329985435301323e250");
   1096          1.1       mrg   check53("-2.96695924472363684394e+27", "1.22842938251111500000e+16",MPFR_RNDD,
   1097          1.1       mrg           "-2.96695924471135255027e27");
   1098          1.1       mrg   check53("1.74693641655743793422e-227", "-7.71776956366861843469e-229",
   1099          1.1       mrg           MPFR_RNDN, "1.669758720920751867e-227");
   1100          1.1       mrg   /*  x = -7883040437021647.0; for (i=0; i<468; i++) x = x / 2.0;*/
   1101          1.1       mrg   check53("-1.03432206392780011159e-125", "1.30127034799251347548e-133",
   1102          1.1       mrg           MPFR_RNDN,
   1103          1.1       mrg           "-1.0343220509150965661100887242027378881805094180354e-125");
   1104          1.1       mrg   check53("1.05824655795525779205e+71", "-1.06022698059744327881e+71",MPFR_RNDZ,
   1105          1.1       mrg           "-1.9804226421854867632e68");
   1106          1.1       mrg   check53("-5.84204911040921732219e+240", "7.26658169050749590763e+240",
   1107          1.1       mrg           MPFR_RNDD, "1.4245325800982785854e240");
   1108          1.1       mrg   check53("1.00944884131046636376e+221","2.33809162651471520268e+215",MPFR_RNDN,
   1109          1.1       mrg           "1.0094511794020929787e221");
   1110          1.1       mrg   /*x = 7045852550057985.0; for (i=0; i<986; i++) x = x / 2.0;*/
   1111          1.1       mrg   check53("4.29232078932667367325e-278",
   1112          1.1       mrg           "1.0773525047389793833221116707010783793203080117586e-281"
   1113          1.1       mrg           , MPFR_RNDU, "4.2933981418314132787e-278");
   1114          1.1       mrg   check53("5.27584773801377058681e-80", "8.91207657803547196421e-91", MPFR_RNDN,
   1115          1.1       mrg           "5.2758477381028917269e-80");
   1116          1.1       mrg   check53("2.99280481918991653800e+272", "5.34637717585790933424e+271",
   1117          1.1       mrg           MPFR_RNDN, "3.5274425367757071711e272");
   1118          1.1       mrg   check53("4.67302514390488041733e-184", "2.18321376145645689945e-190",
   1119          1.1       mrg           MPFR_RNDN, "4.6730273271186420541e-184");
   1120          1.1       mrg   check53("5.57294120336300389254e+71", "2.60596167942024924040e+65", MPFR_RNDZ,
   1121          1.1       mrg           "5.5729438093246831053e71");
   1122          1.1       mrg   check53("6.6052588496951015469e24", "4938448004894539.0", MPFR_RNDU,
   1123          1.1       mrg           "6.6052588546335505068e24");
   1124          1.1       mrg   check53("1.23056185051606761523e-190", "1.64589756643433857138e-181",
   1125          1.1       mrg           MPFR_RNDU, "1.6458975676649006598e-181");
   1126          1.1       mrg   check53("2.93231171510175981584e-280", "3.26266919161341483877e-273",
   1127          1.1       mrg           MPFR_RNDU, "3.2626694848445867288e-273");
   1128          1.1       mrg   check53("5.76707395945001907217e-58", "4.74752971449827687074e-51", MPFR_RNDD,
   1129          1.1       mrg           "4.747530291205672325e-51");
   1130          1.1       mrg   check53("277363943109.0", "11.0", MPFR_RNDN, "277363943120.0");
   1131          1.1       mrg   check53("1.44791789689198883921e-140", "-1.90982880222349071284e-121",
   1132          1.1       mrg           MPFR_RNDN, "-1.90982880222349071e-121");
   1133          1.1       mrg 
   1134          1.1       mrg 
   1135          1.1       mrg   /* tests for particular cases (Vincent Lefevre, 22 Aug 2001) */
   1136          1.1       mrg   check53("9007199254740992.0", "1.0", MPFR_RNDN, "9007199254740992.0");
   1137          1.1       mrg   check53("9007199254740994.0", "1.0", MPFR_RNDN, "9007199254740996.0");
   1138          1.1       mrg   check53("9007199254740992.0", "-1.0", MPFR_RNDN, "9007199254740991.0");
   1139          1.1       mrg   check53("9007199254740994.0", "-1.0", MPFR_RNDN, "9007199254740992.0");
   1140          1.1       mrg   check53("9007199254740996.0", "-1.0", MPFR_RNDN, "9007199254740996.0");
   1141          1.1       mrg 
   1142          1.1       mrg   check_overflow ();
   1143          1.1       mrg   check_1111 ();
   1144          1.1       mrg   check_1minuseps ();
   1145          1.1       mrg }
   1146          1.1       mrg 
   1147  1.1.1.3.4.1  christos static void
   1148  1.1.1.3.4.1  christos check_extreme (void)
   1149  1.1.1.3.4.1  christos {
   1150  1.1.1.3.4.1  christos   mpfr_t u, v, w, x, y;
   1151  1.1.1.3.4.1  christos   int i, inex, r;
   1152  1.1.1.3.4.1  christos 
   1153  1.1.1.3.4.1  christos   mpfr_inits2 (32, u, v, w, x, y, (mpfr_ptr) 0);
   1154  1.1.1.3.4.1  christos   mpfr_setmin (u, mpfr_get_emax ());
   1155  1.1.1.3.4.1  christos   mpfr_setmax (v, mpfr_get_emin ());
   1156  1.1.1.3.4.1  christos   mpfr_setmin (w, mpfr_get_emax () - 40);
   1157  1.1.1.3.4.1  christos   RND_LOOP (r)
   1158  1.1.1.3.4.1  christos     for (i = 0; i < 2; i++)
   1159  1.1.1.3.4.1  christos       {
   1160  1.1.1.3.4.1  christos         mpfr_add (x, u, v, (mpfr_rnd_t) r);
   1161  1.1.1.3.4.1  christos         mpfr_set_prec (y, 64);
   1162  1.1.1.3.4.1  christos         inex = mpfr_add (y, u, w, MPFR_RNDN);
   1163  1.1.1.3.4.1  christos         MPFR_ASSERTN (inex == 0);
   1164  1.1.1.3.4.1  christos         mpfr_prec_round (y, 32, (mpfr_rnd_t) r);
   1165  1.1.1.3.4.1  christos         /* for RNDF, the rounding directions are not necessarily consistent */
   1166  1.1.1.3.4.1  christos         if (! mpfr_equal_p (x, y) && r != MPFR_RNDF)
   1167  1.1.1.3.4.1  christos           {
   1168  1.1.1.3.4.1  christos             printf ("Error in u + v (%s)\n",
   1169  1.1.1.3.4.1  christos                     mpfr_print_rnd_mode ((mpfr_rnd_t) r));
   1170  1.1.1.3.4.1  christos             printf ("u = ");
   1171  1.1.1.3.4.1  christos             mpfr_dump (u);
   1172  1.1.1.3.4.1  christos             printf ("v = ");
   1173  1.1.1.3.4.1  christos             mpfr_dump (v);
   1174  1.1.1.3.4.1  christos             printf ("Expected ");
   1175  1.1.1.3.4.1  christos             mpfr_dump (y);
   1176  1.1.1.3.4.1  christos             printf ("Got      ");
   1177  1.1.1.3.4.1  christos             mpfr_dump (x);
   1178  1.1.1.3.4.1  christos             exit (1);
   1179  1.1.1.3.4.1  christos           }
   1180  1.1.1.3.4.1  christos         mpfr_neg (v, v, MPFR_RNDN);
   1181  1.1.1.3.4.1  christos         mpfr_neg (w, w, MPFR_RNDN);
   1182  1.1.1.3.4.1  christos       }
   1183  1.1.1.3.4.1  christos   mpfr_clears (u, v, w, x, y, (mpfr_ptr) 0);
   1184  1.1.1.3.4.1  christos }
   1185  1.1.1.3.4.1  christos 
   1186  1.1.1.3.4.1  christos static void
   1187  1.1.1.3.4.1  christos testall_rndf (mpfr_prec_t pmax)
   1188  1.1.1.3.4.1  christos {
   1189  1.1.1.3.4.1  christos   mpfr_t a, b, c, d;
   1190  1.1.1.3.4.1  christos   mpfr_prec_t pa, pb, pc;
   1191  1.1.1.3.4.1  christos   mpfr_exp_t eb;
   1192  1.1.1.3.4.1  christos 
   1193  1.1.1.3.4.1  christos   for (pa = MPFR_PREC_MIN; pa <= pmax; pa++)
   1194  1.1.1.3.4.1  christos     {
   1195  1.1.1.3.4.1  christos       mpfr_init2 (a, pa);
   1196  1.1.1.3.4.1  christos       mpfr_init2 (d, pa);
   1197  1.1.1.3.4.1  christos       for (pb = MPFR_PREC_MIN; pb <= pmax; pb++)
   1198  1.1.1.3.4.1  christos         {
   1199  1.1.1.3.4.1  christos           mpfr_init2 (b, pb);
   1200  1.1.1.3.4.1  christos           for (eb = 0; eb <= pmax + 3; eb ++)
   1201  1.1.1.3.4.1  christos             {
   1202  1.1.1.3.4.1  christos               mpfr_set_ui_2exp (b, 1, eb, MPFR_RNDN);
   1203  1.1.1.3.4.1  christos               while (mpfr_cmp_ui_2exp (b, 1, eb + 1) < 0)
   1204  1.1.1.3.4.1  christos                 {
   1205  1.1.1.3.4.1  christos                   for (pc = MPFR_PREC_MIN; pc <= pmax; pc++)
   1206  1.1.1.3.4.1  christos                     {
   1207  1.1.1.3.4.1  christos                       mpfr_init2 (c, pc);
   1208  1.1.1.3.4.1  christos                       mpfr_set_ui (c, 1, MPFR_RNDN);
   1209  1.1.1.3.4.1  christos                       while (mpfr_cmp_ui (c, 2) < 0)
   1210  1.1.1.3.4.1  christos                         {
   1211  1.1.1.3.4.1  christos                           mpfr_add (a, b, c, MPFR_RNDF);
   1212  1.1.1.3.4.1  christos                           mpfr_add (d, b, c, MPFR_RNDD);
   1213  1.1.1.3.4.1  christos                           if (!mpfr_equal_p (a, d))
   1214  1.1.1.3.4.1  christos                             {
   1215  1.1.1.3.4.1  christos                               mpfr_add (d, b, c, MPFR_RNDU);
   1216  1.1.1.3.4.1  christos                               if (!mpfr_equal_p (a, d))
   1217  1.1.1.3.4.1  christos                                 {
   1218  1.1.1.3.4.1  christos                                   printf ("Error: mpfr_add(a,b,c,RNDF) does not "
   1219  1.1.1.3.4.1  christos                                           "match RNDD/RNDU\n");
   1220  1.1.1.3.4.1  christos                                   printf ("b="); mpfr_dump (b);
   1221  1.1.1.3.4.1  christos                                   printf ("c="); mpfr_dump (c);
   1222  1.1.1.3.4.1  christos                                   printf ("a="); mpfr_dump (a);
   1223  1.1.1.3.4.1  christos                                   exit (1);
   1224  1.1.1.3.4.1  christos                                 }
   1225  1.1.1.3.4.1  christos                             }
   1226  1.1.1.3.4.1  christos                           mpfr_nextabove (c);
   1227  1.1.1.3.4.1  christos                         }
   1228  1.1.1.3.4.1  christos                       mpfr_clear (c);
   1229  1.1.1.3.4.1  christos                     }
   1230  1.1.1.3.4.1  christos                   mpfr_nextabove (b);
   1231  1.1.1.3.4.1  christos                 }
   1232  1.1.1.3.4.1  christos             }
   1233  1.1.1.3.4.1  christos           mpfr_clear (b);
   1234  1.1.1.3.4.1  christos         }
   1235  1.1.1.3.4.1  christos       mpfr_clear (a);
   1236  1.1.1.3.4.1  christos       mpfr_clear (d);
   1237  1.1.1.3.4.1  christos     }
   1238  1.1.1.3.4.1  christos }
   1239  1.1.1.3.4.1  christos 
   1240  1.1.1.3.4.1  christos static void
   1241  1.1.1.3.4.1  christos test_rndf_exact (mp_size_t pmax)
   1242  1.1.1.3.4.1  christos {
   1243  1.1.1.3.4.1  christos   mpfr_t a, b, c, d;
   1244  1.1.1.3.4.1  christos   mpfr_prec_t pa, pb, pc;
   1245  1.1.1.3.4.1  christos   mpfr_exp_t eb;
   1246  1.1.1.3.4.1  christos 
   1247  1.1.1.3.4.1  christos   for (pa = MPFR_PREC_MIN; pa <= pmax; pa++)
   1248  1.1.1.3.4.1  christos     {
   1249  1.1.1.3.4.1  christos       /* only check pa mod GMP_NUMB_BITS = -2, -1, 0, 1, 2 */
   1250  1.1.1.3.4.1  christos       if ((pa + 2) % GMP_NUMB_BITS > 4)
   1251  1.1.1.3.4.1  christos         continue;
   1252  1.1.1.3.4.1  christos       mpfr_init2 (a, pa);
   1253  1.1.1.3.4.1  christos       mpfr_init2 (d, pa);
   1254  1.1.1.3.4.1  christos       for (pb = MPFR_PREC_MIN; pb <= pmax; pb++)
   1255  1.1.1.3.4.1  christos         {
   1256  1.1.1.3.4.1  christos           if ((pb + 2) % GMP_NUMB_BITS > 4)
   1257  1.1.1.3.4.1  christos             continue;
   1258  1.1.1.3.4.1  christos           mpfr_init2 (b, pb);
   1259  1.1.1.3.4.1  christos           for (eb = 0; eb <= pmax + 3; eb ++)
   1260  1.1.1.3.4.1  christos             {
   1261  1.1.1.3.4.1  christos               mpfr_urandomb (b, RANDS);
   1262  1.1.1.3.4.1  christos               mpfr_mul_2exp (b, b, eb, MPFR_RNDN);
   1263  1.1.1.3.4.1  christos               for (pc = MPFR_PREC_MIN; pc <= pmax; pc++)
   1264  1.1.1.3.4.1  christos                 {
   1265  1.1.1.3.4.1  christos                   if ((pc + 2) % GMP_NUMB_BITS > 4)
   1266  1.1.1.3.4.1  christos                     continue;
   1267  1.1.1.3.4.1  christos                   mpfr_init2 (c, pc);
   1268  1.1.1.3.4.1  christos                   mpfr_urandomb (c, RANDS);
   1269  1.1.1.3.4.1  christos                   mpfr_add (a, b, c, MPFR_RNDF);
   1270  1.1.1.3.4.1  christos                   mpfr_add (d, b, c, MPFR_RNDD);
   1271  1.1.1.3.4.1  christos                   if (!mpfr_equal_p (a, d))
   1272  1.1.1.3.4.1  christos                     {
   1273  1.1.1.3.4.1  christos                       mpfr_add (d, b, c, MPFR_RNDU);
   1274  1.1.1.3.4.1  christos                       if (!mpfr_equal_p (a, d))
   1275  1.1.1.3.4.1  christos                         {
   1276  1.1.1.3.4.1  christos                           printf ("Error: mpfr_add(a,b,c,RNDF) does not "
   1277  1.1.1.3.4.1  christos                                   "match RNDD/RNDU\n");
   1278  1.1.1.3.4.1  christos                           printf ("b="); mpfr_dump (b);
   1279  1.1.1.3.4.1  christos                           printf ("c="); mpfr_dump (c);
   1280  1.1.1.3.4.1  christos                           printf ("a="); mpfr_dump (a);
   1281  1.1.1.3.4.1  christos                           exit (1);
   1282  1.1.1.3.4.1  christos                         }
   1283  1.1.1.3.4.1  christos                     }
   1284  1.1.1.3.4.1  christos 
   1285  1.1.1.3.4.1  christos                   /* now make the low bits from c match those from b */
   1286  1.1.1.3.4.1  christos                   mpfr_sub (c, b, d, MPFR_RNDN);
   1287  1.1.1.3.4.1  christos                   mpfr_add (a, b, c, MPFR_RNDF);
   1288  1.1.1.3.4.1  christos                   mpfr_add (d, b, c, MPFR_RNDD);
   1289  1.1.1.3.4.1  christos                   if (!mpfr_equal_p (a, d))
   1290  1.1.1.3.4.1  christos                     {
   1291  1.1.1.3.4.1  christos                       mpfr_add (d, b, c, MPFR_RNDU);
   1292  1.1.1.3.4.1  christos                       if (!mpfr_equal_p (a, d))
   1293  1.1.1.3.4.1  christos                         {
   1294  1.1.1.3.4.1  christos                           printf ("Error: mpfr_add(a,b,c,RNDF) does not "
   1295  1.1.1.3.4.1  christos                                   "match RNDD/RNDU\n");
   1296  1.1.1.3.4.1  christos                           printf ("b="); mpfr_dump (b);
   1297  1.1.1.3.4.1  christos                           printf ("c="); mpfr_dump (c);
   1298  1.1.1.3.4.1  christos                           printf ("a="); mpfr_dump (a);
   1299  1.1.1.3.4.1  christos                           exit (1);
   1300  1.1.1.3.4.1  christos                         }
   1301  1.1.1.3.4.1  christos                     }
   1302  1.1.1.3.4.1  christos 
   1303  1.1.1.3.4.1  christos                   mpfr_clear (c);
   1304  1.1.1.3.4.1  christos                 }
   1305  1.1.1.3.4.1  christos             }
   1306  1.1.1.3.4.1  christos           mpfr_clear (b);
   1307  1.1.1.3.4.1  christos         }
   1308  1.1.1.3.4.1  christos       mpfr_clear (a);
   1309  1.1.1.3.4.1  christos       mpfr_clear (d);
   1310  1.1.1.3.4.1  christos     }
   1311  1.1.1.3.4.1  christos }
   1312  1.1.1.3.4.1  christos 
   1313          1.1       mrg #define TEST_FUNCTION test_add
   1314          1.1       mrg #define TWO_ARGS
   1315          1.1       mrg #define RAND_FUNCTION(x) mpfr_random2(x, MPFR_LIMB_SIZE (x), randlimb () % 100, RANDS)
   1316          1.1       mrg #include "tgeneric.c"
   1317          1.1       mrg 
   1318          1.1       mrg int
   1319          1.1       mrg main (int argc, char *argv[])
   1320          1.1       mrg {
   1321          1.1       mrg   tests_start_mpfr ();
   1322          1.1       mrg 
   1323          1.1       mrg   usesp = 0;
   1324          1.1       mrg   tests ();
   1325          1.1       mrg 
   1326          1.1       mrg #ifndef CHECK_EXTERNAL /* no need to check twice */
   1327          1.1       mrg   usesp = 1;
   1328          1.1       mrg   tests ();
   1329          1.1       mrg #endif
   1330  1.1.1.3.4.1  christos 
   1331  1.1.1.3.4.1  christos   test_rndf_exact (200);
   1332  1.1.1.3.4.1  christos   testall_rndf (7);
   1333  1.1.1.3.4.1  christos   check_extreme ();
   1334  1.1.1.3.4.1  christos 
   1335  1.1.1.3.4.1  christos   test_generic (MPFR_PREC_MIN, 1000, 100);
   1336          1.1       mrg 
   1337          1.1       mrg   tests_end_mpfr ();
   1338          1.1       mrg   return 0;
   1339          1.1       mrg }
   1340