[BACK]Return to tgeneric.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpfr / tests

Annotation of OpenXM_contrib/gmp/mpfr/tests/tgeneric.c, Revision 1.1.1.1

1.1       ohara       1: /* Generic test file for functions with one mpfr_t argument.
                      2:
                      3: Copyright 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: void test_generic _PROTO((int, int, int));
                     23:
                     24: void
                     25: test_generic (int p0, int p1, int N)
                     26: {
                     27:   mp_prec_t prec, yprec;
                     28:   mpfr_t x, y, z, t;
                     29:   mp_rnd_t rnd;
                     30:   int inexact, compare, compare2;
                     31:   unsigned int n;
                     32:
                     33:   mpfr_init (x);
                     34:   mpfr_init (y);
                     35:   mpfr_init (z);
                     36:   mpfr_init (t);
                     37:
                     38:   /* generic test */
                     39:   for (prec = p0; prec <= p1; prec++)
                     40:     {
                     41:       mpfr_set_prec (x, prec);
                     42:       mpfr_set_prec (z, prec);
                     43:       mpfr_set_prec (t, prec);
                     44:       yprec = prec + 10;
                     45:
                     46:       for (n=0; n<N; n++)
                     47:        {
                     48: #if defined(RAND_FUNCTION)
                     49:          RAND_FUNCTION (x);
                     50: #else
                     51:          mpfr_random (x);
                     52: #endif
                     53:          rnd = random () % 4;
                     54:          mpfr_set_prec (y, yprec);
                     55:          compare = TEST_FUNCTION (y, x, rnd);
                     56:          if (mpfr_can_round (y, yprec, rnd, rnd, prec))
                     57:            {
                     58:              mpfr_set (t, y, rnd);
                     59:              inexact = TEST_FUNCTION (z, x, rnd);
                     60:              if (mpfr_cmp (t, z))
                     61:                {
                     62:                  printf ("results differ for x=");
                     63:                  mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
                     64:                  printf (" prec=%u rnd_mode=%s\n", (unsigned) prec,
                     65:                          mpfr_print_rnd_mode (rnd));
                     66:                  printf ("got      ");
                     67:                  mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
                     68:                  putchar ('\n');
                     69:                  printf ("expected ");
                     70:                  mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
                     71:                  putchar ('\n');
                     72:                  printf ("approx  ");
                     73:                  mpfr_print_binary (y);
                     74:                  putchar ('\n');
                     75:                  exit (1);
                     76:                }
                     77:              compare2 = mpfr_cmp (t, y);
                     78:              /* if rounding to nearest, cannot know the sign of t - f(x)
                     79:                 because of composed rounding: y = o(f(x)) and t = o(y) */
                     80:              if ((rnd != GMP_RNDN) && (compare * compare2 >= 0))
                     81:                compare = compare + compare2;
                     82:              else
                     83:                compare = inexact; /* cannot determine sign(t-f(x)) */
                     84:              if (((inexact == 0) && (compare != 0)) ||
                     85:                  ((inexact > 0) && (compare <= 0)) ||
                     86:                  ((inexact < 0) && (compare >= 0)))
                     87:                {
                     88:                  fprintf (stderr, "Wrong inexact flag for rnd=%s: expected %d, got %d\n",
                     89:                           mpfr_print_rnd_mode (rnd), compare, inexact);
                     90:                  printf ("x="); mpfr_print_binary (x); putchar ('\n');
                     91:                  printf ("y="); mpfr_print_binary (y); putchar ('\n');
                     92:                  printf ("t="); mpfr_print_binary (t); putchar ('\n');
                     93:                  exit (1);
                     94:                }
                     95:            }
                     96:        }
                     97:     }
                     98:
                     99:   mpfr_clear (x);
                    100:   mpfr_clear (y);
                    101:   mpfr_clear (z);
                    102:   mpfr_clear (t);
                    103: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>