~ubuntu-branches/ubuntu/intrepid/ecl/intrepid

« back to all changes in this revision

Viewing changes to src/gmp/mpfr/tests/reuse.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Van Eynde
  • Date: 2007-04-09 11:51:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070409115151-ql8cr0kalzx1jmla
Tags: 0.9i-20070324-2
Upload to unstable. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Test file for in-place operations.
2
 
 
3
 
Copyright 2000, 2001, 2002 Free Software Foundation.
4
 
 
5
 
This file is part of the MPFR Library.
6
 
 
7
 
The MPFR Library is free software; you can redistribute it and/or modify
8
 
it under the terms of the GNU Lesser General Public License as published by
9
 
the Free Software Foundation; either version 2.1 of the License, or (at your
10
 
option) any later version.
11
 
 
12
 
The MPFR Library is distributed in the hope that it will be useful, but
13
 
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
 
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15
 
License for more details.
16
 
 
17
 
You should have received a copy of the GNU Lesser General Public License
18
 
along with the MPFR Library; see the file COPYING.LIB.  If not, write to
19
 
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
 
MA 02111-1307, USA. */
21
 
 
22
 
#include <stdio.h>
23
 
#include <stdlib.h>
24
 
#include "gmp.h"
25
 
#include "mpfr.h"
26
 
#include "mpfr-impl.h"
27
 
 
28
 
typedef void (*fct_t)();
29
 
fct_t testfunc;
30
 
 
31
 
void test3 _PROTO ((char *, mp_prec_t, mp_rnd_t));
32
 
void test4 _PROTO ((char *, mp_prec_t, mp_rnd_t));
33
 
void test3a _PROTO ((char *, mp_prec_t, mp_rnd_t));
34
 
void test2ui _PROTO ((char *, mp_prec_t, mp_rnd_t));
35
 
void testui2 _PROTO ((char *, mp_prec_t, mp_rnd_t));
36
 
void test2 _PROTO ((char *, mp_prec_t, mp_rnd_t));
37
 
void test2a _PROTO ((char *, mp_prec_t));
38
 
int mpfr_compare _PROTO ((mpfr_t, mpfr_t));
39
 
 
40
 
/* same than mpfr_cmp, but returns 0 for both NaN's */
41
 
int
42
 
mpfr_compare (mpfr_t a, mpfr_t b)
43
 
{
44
 
  return (MPFR_IS_NAN(a)) ? !MPFR_IS_NAN(b) : 
45
 
    (MPFR_IS_NAN(b) || mpfr_cmp(a, b));
46
 
}
47
 
 
48
 
void
49
 
test3 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
50
 
{
51
 
  mpfr_t ref1, ref2, ref3;
52
 
  mpfr_t res1;
53
 
  int i;
54
 
 
55
 
#ifdef DEBUG
56
 
  printf("checking %s\n", foo);
57
 
#endif
58
 
  mpfr_init2 (ref1, prec);
59
 
  mpfr_init2 (ref2, prec);
60
 
  mpfr_init2 (ref3, prec);
61
 
  mpfr_init2 (res1, prec);
62
 
 
63
 
  /* for each variable, consider each of the following 6 possibilities:
64
 
     NaN, +Infinity, -Infinity, +0, -0 or a random number */
65
 
  for (i=0; i<36; i++) {
66
 
    if (i%6==0) mpfr_set_nan (ref2);
67
 
    if (i%6==1) mpfr_set_inf (ref2, 1);
68
 
    if (i%6==2) mpfr_set_inf (ref2, -1);
69
 
    if (i%6==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
70
 
    if (i%6==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
71
 
    if (i%6==5) mpfr_random (ref2);
72
 
 
73
 
    if (i/6==0) mpfr_set_nan (ref3);
74
 
    if (i/6==1) mpfr_set_inf (ref3, 1);
75
 
    if (i/6==2) mpfr_set_inf (ref3, -1);
76
 
    if (i/6==3) mpfr_set_d (ref3, 0.0, GMP_RNDN);
77
 
    if (i/6==4) mpfr_set_d (ref3, -0.0, GMP_RNDN);
78
 
    if (i/6==5) mpfr_random (ref3);
79
 
 
80
 
    /* reference call: foo(a, b, c) */
81
 
    testfunc (ref1, ref2, ref3, rnd);
82
 
 
83
 
    /* foo(a, a, c) */
84
 
    mpfr_set (res1, ref2, rnd); /* exact operation */
85
 
    testfunc (res1, res1, ref3, rnd);
86
 
 
87
 
    if (mpfr_compare (res1, ref1)) {
88
 
      fprintf (stderr, "Error for %s(a, a, c) for a=%e, c=%e\n", foo,
89
 
               mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));
90
 
      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
91
 
               mpfr_get_d1 (res1));
92
 
      exit (1);
93
 
    }
94
 
 
95
 
    /* foo(a, b, a) */
96
 
    mpfr_set (res1, ref3, rnd);
97
 
    testfunc (res1, ref2, res1, rnd);
98
 
    if (mpfr_compare (res1, ref1)) {
99
 
      fprintf (stderr, "Error for %s(a, b, a) for b=%e, a=%e\n", foo,
100
 
               mpfr_get_d1 (ref2), mpfr_get_d1 (ref3));
101
 
      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
102
 
               mpfr_get_d1 (res1));
103
 
      exit (1);
104
 
    }
105
 
 
106
 
    /* foo(a, a, a) */
107
 
    mpfr_set (ref3, ref2, rnd);
108
 
    testfunc (ref1, ref2, ref3, rnd);
109
 
    mpfr_set (res1, ref2, rnd);
110
 
    testfunc (res1, res1, res1, rnd);
111
 
 
112
 
   if (mpfr_compare (res1, ref1)) {
113
 
      fprintf (stderr, "Error for %s(a, a, a) for a=%e\n", foo,
114
 
               mpfr_get_d1 (ref2));
115
 
      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
116
 
               mpfr_get_d1 (res1));
117
 
      exit (1);
118
 
    }
119
 
  }
120
 
 
121
 
  mpfr_clear (ref1);
122
 
  mpfr_clear (ref2);
123
 
  mpfr_clear (ref3);
124
 
  mpfr_clear (res1);
125
 
}
126
 
 
127
 
void
128
 
test4 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
129
 
{
130
 
  mpfr_t ref, op1, op2, op3;
131
 
  mpfr_t res;
132
 
  int i, j, k;
133
 
 
134
 
#ifdef DEBUG
135
 
  printf("checking %s\n", foo);
136
 
#endif
137
 
  mpfr_init2 (ref, prec);
138
 
  mpfr_init2 (op1, prec);
139
 
  mpfr_init2 (op2, prec);
140
 
  mpfr_init2 (op3, prec);
141
 
  mpfr_init2 (res, prec);
142
 
 
143
 
  /* for each variable, consider each of the following 6 possibilities:
144
 
     NaN, +Infinity, -Infinity, +0, -0 or a random number */
145
 
 
146
 
  for (i=0; i<6; i++) 
147
 
    {
148
 
 
149
 
      MPFR_CLEAR_FLAGS(op1);
150
 
      if (i==0) mpfr_set_nan (op1);
151
 
      if (i==1) mpfr_set_inf (op1, 1);
152
 
      if (i==2) mpfr_set_inf (op1, -1);
153
 
      if (i==3) mpfr_set_d (op1, 0.0, GMP_RNDN);
154
 
      if (i==4) mpfr_set_d (op1, -0.0, GMP_RNDN);
155
 
      if (i==5) mpfr_random (op1);
156
 
      
157
 
      for (j=0; j<6; j++) 
158
 
        {
159
 
 
160
 
          MPFR_CLEAR_FLAGS(op2);
161
 
          if (j==0) mpfr_set_nan (op2);
162
 
          if (j==1) mpfr_set_inf (op2, 1);
163
 
          if (j==2) mpfr_set_inf (op2, -1);
164
 
          if (j==3) mpfr_set_d (op2, 0.0, GMP_RNDN);
165
 
          if (j==4) mpfr_set_d (op2, -0.0, GMP_RNDN);
166
 
          if (j==5) mpfr_random (op2);
167
 
 
168
 
          for (k=0; k<6; k++) 
169
 
            {
170
 
 
171
 
              MPFR_CLEAR_FLAGS(op3);
172
 
              if (k==0) mpfr_set_nan (op3);
173
 
              if (k==1) mpfr_set_inf (op3, 1);
174
 
              if (k==2) mpfr_set_inf (op3, -1);
175
 
              if (k==3) mpfr_set_d (op3, 0.0, GMP_RNDN);
176
 
              if (k==4) mpfr_set_d (op3, -0.0, GMP_RNDN);
177
 
              if (k==5) mpfr_random (op3);
178
 
 
179
 
              /* reference call: foo(s, a, b, c) */
180
 
              testfunc (ref, op1, op2, op3, rnd);
181
 
 
182
 
              /* foo(a, a, b, c) */
183
 
              mpfr_set (res, op1, rnd); /* exact operation */
184
 
              testfunc (res, res, op2, op3, rnd);
185
 
 
186
 
              if (mpfr_compare (res, ref)) 
187
 
              {
188
 
                fprintf (stderr, 
189
 
                         "Error for %s(a, a, b, c) for a=%e, b=%e, c=%e\n", 
190
 
                         foo,
191
 
                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
192
 
                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
193
 
                         mpfr_get_d1 (res));
194
 
                exit (1);
195
 
              }
196
 
 
197
 
              /* foo(b, a, b, c) */
198
 
              mpfr_set (res, op2, rnd);
199
 
              testfunc (res, op1, res, op3, rnd);
200
 
 
201
 
             if (mpfr_compare (res, ref)) 
202
 
              {
203
 
                fprintf (stderr, 
204
 
                         "Error for %s(b, a, b, c) for a=%e, b=%e, c=%e\n", 
205
 
                         foo,
206
 
                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
207
 
                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
208
 
                         mpfr_get_d1 (res));
209
 
                exit (1);
210
 
              }
211
 
 
212
 
              /* foo(c, a, b, c) */
213
 
              mpfr_set (res, op3, rnd);
214
 
              testfunc (res, op1, op2, res, rnd);
215
 
 
216
 
             if (mpfr_compare (res, ref)) 
217
 
              {
218
 
                fprintf (stderr, 
219
 
                         "Error for %s(c, a, b, c) for a=%e, b=%e, c=%e\n",
220
 
                         foo,
221
 
                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
222
 
                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
223
 
                         mpfr_get_d1 (res));
224
 
                exit (1);
225
 
              }
226
 
 
227
 
              /* foo(a, a, a,c) */
228
 
             testfunc (ref, op1, op1, op3, rnd);
229
 
             mpfr_set (res, op1, rnd);
230
 
             testfunc (res, res, res, op3, rnd);
231
 
             if (mpfr_compare (res, ref)) 
232
 
              {
233
 
                fprintf (stderr, 
234
 
                         "Error for %s(a, a, a, c) for a=%e, a=%e, c=%e\n",
235
 
                         foo,
236
 
                         mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
237
 
                fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
238
 
                         mpfr_get_d1 (res));
239
 
                exit (1);
240
 
              }
241
 
 
242
 
              /* foo(a, a, b,a) */
243
 
              testfunc (ref, op1, op2, op1, rnd);
244
 
              mpfr_set (res, op1, rnd);
245
 
              testfunc (res, res, op2, res, rnd);
246
 
              if (mpfr_compare (res, ref)) 
247
 
               {
248
 
                 fprintf (stderr, 
249
 
                          "Error for %s(a, a, b, a) for a=%e, a=%e, c=%e\n",
250
 
                          foo,
251
 
                       mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
252
 
                 fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
253
 
                          mpfr_get_d1 (res));
254
 
                 exit (1);
255
 
               }
256
 
 
257
 
              /* foo(b, a, b, b) */
258
 
              testfunc (ref, op1, op2, op2, rnd);
259
 
              mpfr_set (res, op2, rnd);
260
 
              testfunc (res, op1, res, res, rnd);
261
 
              if (mpfr_compare (res, ref)) 
262
 
               {
263
 
                 fprintf (stderr, 
264
 
                          "Error for %s(b, a, b, b) for a=%e, a=%e, c=%e\n", 
265
 
                          foo,
266
 
                        mpfr_get_d1 (op1), mpfr_get_d1 (op2), mpfr_get_d1 (op3));
267
 
                 fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
268
 
                          mpfr_get_d1 (res));
269
 
                 exit (1);
270
 
               }
271
 
 
272
 
              /* foo (a, a, a, a) */
273
 
              testfunc (ref, op1, op1, op1 ,rnd);
274
 
              mpfr_set (res, op1, rnd);
275
 
              testfunc (res, res, res, res, rnd);
276
 
              if (mpfr_compare (res, ref)) 
277
 
               {
278
 
                 fprintf (stderr,
279
 
                          "Error for %s(a, a, a, a) for a=%e\n", foo,
280
 
                          mpfr_get_d1 (op1));
281
 
                 fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref),
282
 
                          mpfr_get_d1 (res));
283
 
                 exit (1);
284
 
               }
285
 
            }
286
 
        }
287
 
    }
288
 
 
289
 
  mpfr_clear (ref);
290
 
  mpfr_clear (op1);
291
 
  mpfr_clear (op2);
292
 
  mpfr_clear (op3);
293
 
  mpfr_clear (res);
294
 
 
295
 
}
296
 
 
297
 
void
298
 
test2ui (char *foo, mp_prec_t prec, mp_rnd_t rnd)
299
 
{
300
 
  mpfr_t ref1, ref2;
301
 
  unsigned int ref3;
302
 
  mp_limb_t c[1];
303
 
  mpfr_t res1;
304
 
  int i;
305
 
 
306
 
#ifdef DEBUG  
307
 
  printf("checking %s\n", foo);
308
 
#endif
309
 
  mpfr_init2 (ref1, prec);
310
 
  mpfr_init2 (ref2, prec);
311
 
  mpfr_init2 (res1, prec);
312
 
 
313
 
 
314
 
 
315
 
  /* ref2 can be NaN, +Inf, -Inf, +0, -0 or any number
316
 
     ref3 can be 0 or any number */
317
 
  for (i=0; i<12; i++)
318
 
    {
319
 
      if (i%6==0) mpfr_set_nan (ref2);
320
 
      if (i%6==1) mpfr_set_inf (ref2, 1);
321
 
      if (i%6==2) mpfr_set_inf (ref2, -1);
322
 
      if (i%6==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
323
 
      if (i%6==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
324
 
      if (i%6==5) mpfr_random (ref2);
325
 
 
326
 
      if (i/6==0) 
327
 
        ref3=0;
328
 
      else 
329
 
        {
330
 
          mpn_random (c, 1);
331
 
          ref3 = (unsigned int) c[0];
332
 
        }
333
 
 
334
 
      /* reference call: foo(a, b, c) */
335
 
      testfunc (ref1, ref2, ref3, rnd);
336
 
 
337
 
      /* foo(a, a, c) */
338
 
      mpfr_set (res1, ref2, rnd); /* exact operation */
339
 
      testfunc (res1, res1, ref3, rnd);
340
 
 
341
 
      if (mpfr_compare (res1, ref1))
342
 
        {
343
 
          fprintf (stderr, "Error for %s(a, a, c) for a=%e c=%u\n", foo,
344
 
               mpfr_get_d1 (ref2), ref3);
345
 
          fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
346
 
               mpfr_get_d1 (res1));
347
 
          exit (1);
348
 
        }
349
 
    }
350
 
 
351
 
  mpfr_clear (ref1);
352
 
  mpfr_clear (ref2);
353
 
  mpfr_clear (res1);
354
 
}
355
 
 
356
 
void
357
 
testui2 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
358
 
{
359
 
  mpfr_t ref1, ref3;
360
 
  unsigned int ref2;
361
 
  mp_limb_t c[1];
362
 
  mpfr_t res1;
363
 
  int i;
364
 
 
365
 
#ifdef DEBUG  
366
 
  printf("checking %s\n", foo);
367
 
#endif
368
 
  mpfr_init2 (ref1, prec);
369
 
  mpfr_init2 (ref3, prec);
370
 
  mpfr_init2 (res1, prec);
371
 
  mpfr_random (ref3);
372
 
  mpn_random (c, 1);
373
 
  ref2 = (unsigned int) c[0];
374
 
 
375
 
  for (i=0; i<12; i++) {
376
 
    if (i%6==0) mpfr_set_nan (ref3);
377
 
    if (i%6==1) mpfr_set_inf (ref3, 1);
378
 
    if (i%6==2) mpfr_set_inf (ref3, -1);
379
 
    if (i%6==3) mpfr_set_d (ref3, 0.0, GMP_RNDN);
380
 
    if (i%6==4) mpfr_set_d (ref3, -0.0, GMP_RNDN);
381
 
    if (i%6==5) mpfr_random (ref3);
382
 
 
383
 
    if (i/6==0) ref2=0;
384
 
    else {
385
 
      mpn_random (c, 1);
386
 
      ref2 = (unsigned int) c[0];
387
 
    }
388
 
 
389
 
    /* reference call: foo(a, b, c) */
390
 
    testfunc (ref1, ref2, ref3, rnd);
391
 
 
392
 
    /* foo(a, b, a) */
393
 
    mpfr_set (res1, ref3, rnd); /* exact operation */
394
 
    testfunc (res1, ref2, res1, rnd);
395
 
    if (mpfr_compare (res1, ref1)) {
396
 
      fprintf (stderr, "Error for %s(a, b, a) for b=%u a=%e\n", foo,
397
 
               ref2, mpfr_get_d1 (ref3));
398
 
      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
399
 
               mpfr_get_d1 (res1));
400
 
      exit (1);
401
 
    }
402
 
  }
403
 
 
404
 
  mpfr_clear (ref1);
405
 
  mpfr_clear (ref3);
406
 
  mpfr_clear (res1);
407
 
}
408
 
 
409
 
/* foo(mpfr_ptr, mpfr_srcptr, mp_rndt) */
410
 
void
411
 
test2 (char *foo, mp_prec_t prec, mp_rnd_t rnd)
412
 
{
413
 
  mpfr_t ref1, ref2;
414
 
  mpfr_t res1;
415
 
  int i;
416
 
 
417
 
#ifdef DEBUG  
418
 
  printf("checking %s\n", foo);
419
 
#endif
420
 
  mpfr_init2 (ref1, prec);
421
 
  mpfr_init2 (ref2, prec);
422
 
  mpfr_init2 (res1, prec);
423
 
  mpfr_random (ref2);
424
 
 
425
 
  for (i=0; i<6; i++) {
426
 
    if (i==0) mpfr_set_nan (ref2);
427
 
    if (i==1) mpfr_set_inf (ref2, 1);
428
 
    if (i==2) mpfr_set_inf (ref2, -1);
429
 
    if (i==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
430
 
    if (i==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
431
 
    if (i==5) mpfr_random (ref2);
432
 
 
433
 
    /* reference call: foo(a, b) */
434
 
    testfunc (ref1, ref2, rnd);
435
 
 
436
 
    /* foo(a, a) */
437
 
    mpfr_set (res1, ref2, rnd); /* exact operation */
438
 
    testfunc (res1, res1, rnd);
439
 
    if (mpfr_compare (res1, ref1)) {
440
 
      fprintf (stderr, "Error for %s(a, a) for a=%e\n", foo, mpfr_get_d1 (ref2));
441
 
      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
442
 
               mpfr_get_d1 (res1));
443
 
      exit (1);
444
 
    }
445
 
  }
446
 
 
447
 
  mpfr_clear (ref1);
448
 
  mpfr_clear (ref2);
449
 
  mpfr_clear (res1);
450
 
}
451
 
 
452
 
/* foo(mpfr_ptr, mpfr_srcptr) */
453
 
void
454
 
test2a (char *foo, mp_prec_t prec)
455
 
{
456
 
  mpfr_t ref1, ref2;
457
 
  mpfr_t res1;
458
 
  int i;
459
 
 
460
 
#ifdef DEBUG  
461
 
  printf("checking %s\n", foo);
462
 
#endif
463
 
  mpfr_init2 (ref1, prec);
464
 
  mpfr_init2 (ref2, prec);
465
 
  mpfr_init2 (res1, prec);
466
 
  mpfr_random (ref2);
467
 
 
468
 
  for (i=0; i<6; i++) {
469
 
    if (i==0) mpfr_set_nan (ref2);
470
 
    if (i==1) mpfr_set_inf (ref2, 1);
471
 
    if (i==2) mpfr_set_inf (ref2, -1);
472
 
    if (i==3) mpfr_set_d (ref2, 0.0, GMP_RNDN);
473
 
    if (i==4) mpfr_set_d (ref2, -0.0, GMP_RNDN);
474
 
    if (i==5) mpfr_random (ref2);
475
 
 
476
 
    /* reference call: foo(a, b) */
477
 
    testfunc (ref1, ref2);
478
 
 
479
 
    /* foo(a, a) */
480
 
    mpfr_set (res1, ref2, GMP_RNDN); /* exact operation */
481
 
    testfunc (res1, res1);
482
 
    if (mpfr_compare (res1, ref1)) {
483
 
      fprintf (stderr, "Error for %s(a, a) for a=%e\n", foo, mpfr_get_d1 (ref2));
484
 
      fprintf (stderr, "expected %e, got %e\n", mpfr_get_d1 (ref1),
485
 
               mpfr_get_d1 (res1));
486
 
      exit (1);
487
 
    }
488
 
  }
489
 
 
490
 
  mpfr_clear (ref1);
491
 
  mpfr_clear (ref2);
492
 
  mpfr_clear (res1);
493
 
}
494
 
 
495
 
/* one operand, two results */
496
 
void
497
 
test3a (char *foo, mp_prec_t prec, mp_rnd_t rnd)
498
 
{
499
 
  mpfr_t ref1, ref2, ref3;
500
 
  mpfr_t res1, res2;
501
 
  int i;
502
 
 
503
 
#ifdef DEBUG  
504
 
  printf("checking %s\n", foo);
505
 
#endif
506
 
  mpfr_init2 (ref1, prec);
507
 
  mpfr_init2 (ref2, prec);
508
 
  mpfr_init2 (ref3, prec);
509
 
  mpfr_init2 (res1, prec);
510
 
  mpfr_init2 (res2, prec);
511
 
  mpfr_random (ref3);
512
 
 
513
 
  for (i=0; i<6; i++) {
514
 
    if (i==0) mpfr_set_nan (ref3);
515
 
    if (i==1) mpfr_set_inf (ref3, 1);
516
 
    if (i==2) mpfr_set_inf (ref3, -1);
517
 
    if (i==3) mpfr_set_d (ref3, 0.0, GMP_RNDN);
518
 
    if (i==4) mpfr_set_d (ref3, -0.0, GMP_RNDN);
519
 
    if (i==5) mpfr_random (ref3);
520
 
 
521
 
     /* reference call: foo(a, b, c) */
522
 
     testfunc (ref1, ref2, ref3, rnd);
523
 
 
524
 
     /* foo(a, b, a) */
525
 
     mpfr_set (res1, ref3, rnd); /* exact operation */
526
 
     testfunc (res1, res2, res1, rnd);
527
 
     if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2)) {
528
 
       fprintf (stderr, "Error for %s(a, b, a) for a=%e\n", foo, mpfr_get_d1 (ref3));
529
 
       fprintf (stderr, "expected (%e,%e), got (%e,%e)\n", mpfr_get_d1 (ref1),
530
 
                mpfr_get_d1 (ref2), mpfr_get_d1 (res1), mpfr_get_d1 (res2));
531
 
       exit (1);
532
 
     }
533
 
 
534
 
     /* foo(a, b, b) */
535
 
     mpfr_set (res2, ref3, rnd); /* exact operation */
536
 
     testfunc (res1, res2, res2, rnd);
537
 
     if (mpfr_compare (res1, ref1) || mpfr_compare (res2, ref2)) {
538
 
       fprintf (stderr, "Error for %s(a, b, b) for b=%e\n", foo, mpfr_get_d1 (ref3));
539
 
       fprintf (stderr, "expected (%e,%e), got (%e,%e)\n", mpfr_get_d1 (ref1),
540
 
                mpfr_get_d1 (ref2), mpfr_get_d1 (res1), mpfr_get_d1 (res2));
541
 
       exit (1);
542
 
     }
543
 
  }
544
 
 
545
 
  mpfr_clear (ref1);
546
 
  mpfr_clear (ref2);
547
 
  mpfr_clear (ref3);
548
 
  mpfr_clear (res1);
549
 
  mpfr_clear (res2);
550
 
}
551
 
 
552
 
int
553
 
main (void)
554
 
{
555
 
  testfunc = (fct_t) mpfr_add; test3 ("mpfr_add", 53, GMP_RNDN);
556
 
  testfunc = (fct_t) mpfr_add_ui; test2ui ("mpfr_add_ui", 53, GMP_RNDN);
557
 
  testfunc = (fct_t) mpfr_agm; test3 ("mpfr_agm", 53, GMP_RNDN);
558
 
  testfunc = (fct_t) mpfr_ceil; test2 ("mpfr_ceil", 53, GMP_RNDN);
559
 
  testfunc = (fct_t) mpfr_div; test3 ("mpfr_div", 53, GMP_RNDN);
560
 
  testfunc = (fct_t) mpfr_div_2exp; test2ui ("mpfr_div_2exp", 53, GMP_RNDN);
561
 
  testfunc = (fct_t) mpfr_div_ui; test2ui ("mpfr_div_ui", 53, GMP_RNDN);
562
 
  testfunc = (fct_t) mpfr_exp; test2 ("mpfr_exp", 53, GMP_RNDN);
563
 
  testfunc = (fct_t) mpfr_floor; test2 ("mpfr_floor", 53, GMP_RNDN);
564
 
  testfunc = (fct_t) mpfr_log; test2 ("mpfr_log", 53, GMP_RNDN);
565
 
  testfunc = (fct_t) mpfr_mul; test3 ("mpfr_mul", 53, GMP_RNDN);
566
 
  testfunc = (fct_t) mpfr_mul_2exp; test2ui ("mpfr_mul_2exp", 53, GMP_RNDN);
567
 
  testfunc = (fct_t) mpfr_mul_ui; test2ui ("mpfr_mul_ui", 53, GMP_RNDN);
568
 
  testfunc = (fct_t) mpfr_neg; test2 ("mpfr_neg", 53, GMP_RNDN);
569
 
  testfunc = (fct_t) mpfr_pow_ui; test2ui ("mpfr_pow_ui", 53, GMP_RNDN);
570
 
  testfunc = (fct_t) mpfr_reldiff; test3 ("mpfr_reldiff", 53, GMP_RNDN);
571
 
  testfunc = (fct_t) mpfr_sub; test3 ("mpfr_sub", 53, GMP_RNDN);
572
 
  testfunc = (fct_t) mpfr_sub_ui; test2ui ("mpfr_sub_ui", 53, GMP_RNDN);
573
 
  testfunc = (fct_t) mpfr_sqrt; test2 ("mpfr_sqrt", 53, GMP_RNDN);
574
 
  testfunc = (fct_t) mpfr_ui_div; testui2 ("mpfr_ui_div", 53, GMP_RNDN);
575
 
  testfunc = (fct_t) mpfr_ui_sub; testui2 ("mpfr_ui_sub", 53, GMP_RNDN);
576
 
  testfunc = (fct_t) mpfr_trunc; test2 ("mpfr_trunc", 53, GMP_RNDN);
577
 
  testfunc = (fct_t) mpfr_asin; test2 ("mpfr_asin", 53, GMP_RNDN);
578
 
  testfunc = (fct_t) mpfr_acos; test2 ("mpfr_acos", 53, GMP_RNDN);
579
 
  testfunc = (fct_t) mpfr_atan; test2 ("mpfr_atan", 53, GMP_RNDN);
580
 
  testfunc = (fct_t) mpfr_sinh; test2 ("mpfr_sinh", 53, GMP_RNDN);
581
 
  testfunc = (fct_t) mpfr_cosh; test2 ("mpfr_cosh", 53, GMP_RNDN);
582
 
  testfunc = (fct_t) mpfr_tanh; test2 ("mpfr_tanh", 53, GMP_RNDN);
583
 
  testfunc = (fct_t) mpfr_asinh; test2 ("mpfr_asinh", 53, GMP_RNDN);
584
 
  testfunc = (fct_t) mpfr_acosh; test2 ("mpfr_acosh", 53, GMP_RNDN);
585
 
  testfunc = (fct_t) mpfr_atanh; test2 ("mpfr_atanh", 53, GMP_RNDN);
586
 
  testfunc = (fct_t) mpfr_exp2; test2 ("mpfr_exp2", 53, GMP_RNDN);
587
 
  testfunc = (fct_t) mpfr_cos; test2 ("mpfr_cos", 53, GMP_RNDN);
588
 
  testfunc = (fct_t) mpfr_sin; test2 ("mpfr_sin", 53, GMP_RNDN);
589
 
  testfunc = (fct_t) mpfr_tan; test2 ("mpfr_tan", 53, GMP_RNDN);
590
 
  testfunc = (fct_t) mpfr_log10; test2 ("mpfr_log10", 53, GMP_RNDN);
591
 
  testfunc = (fct_t) mpfr_log2; test2 ("mpfr_log2", 53, GMP_RNDN);
592
 
  testfunc = (fct_t) mpfr_pow; test3 ("mpfr_pow", 53, GMP_RNDN);
593
 
  testfunc = (fct_t) mpfr_fma; test4 ("mpfr_fma", 53, GMP_RNDN);
594
 
  return 0;
595
 
}