Annotation of OpenXM_contrib/gmp/tests/mpf/t-add.c, Revision 1.1
1.1 ! ohara 1: /* Test mpf_add.
! 2:
! 3: Copyright 1996, 2001 Free Software Foundation, Inc.
! 4:
! 5: This file is part of the GNU MP Library.
! 6:
! 7: The GNU MP 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 GNU MP 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 GNU MP 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:
! 25: #include "gmp.h"
! 26: #include "gmp-impl.h"
! 27: #include "tests.h"
! 28:
! 29: #ifndef SIZE
! 30: #define SIZE 16
! 31: #endif
! 32:
! 33: int
! 34: main (int argc, char **argv)
! 35: {
! 36: mp_size_t size;
! 37: mp_exp_t exp;
! 38: int reps = 100000;
! 39: int i;
! 40: mpf_t u, v, w, wref;
! 41: mp_size_t bprec = 100;
! 42: mpf_t rerr, max_rerr, limit_rerr;
! 43:
! 44: tests_start ();
! 45:
! 46: if (argc > 1)
! 47: {
! 48: reps = strtol (argv[1], 0, 0);
! 49: if (argc > 2)
! 50: bprec = strtol (argv[2], 0, 0);
! 51: }
! 52:
! 53: mpf_set_default_prec (bprec);
! 54:
! 55: mpf_init_set_ui (limit_rerr, 1);
! 56: mpf_div_2exp (limit_rerr, limit_rerr, bprec);
! 57: #if VERBOSE
! 58: mpf_dump (limit_rerr);
! 59: #endif
! 60: mpf_init (rerr);
! 61: mpf_init_set_ui (max_rerr, 0);
! 62:
! 63: mpf_init (u);
! 64: mpf_init (v);
! 65: mpf_init (w);
! 66: mpf_init (wref);
! 67: for (i = 0; i < reps; i++)
! 68: {
! 69: size = urandom () % (2 * SIZE) - SIZE;
! 70: exp = urandom () % SIZE;
! 71: mpf_random2 (u, size, exp);
! 72:
! 73: size = urandom () % (2 * SIZE) - SIZE;
! 74: exp = urandom () % SIZE;
! 75: mpf_random2 (v, size, exp);
! 76:
! 77: mpf_add (w, u, v);
! 78: refmpf_add (wref, u, v);
! 79:
! 80: mpf_reldiff (rerr, w, wref);
! 81: if (mpf_cmp (rerr, max_rerr) > 0)
! 82: {
! 83: mpf_set (max_rerr, rerr);
! 84: #if VERBOSE
! 85: mpf_dump (max_rerr);
! 86: #endif
! 87: if (mpf_cmp (rerr, limit_rerr) > 0)
! 88: {
! 89: printf ("ERROR after %d tests\n", i);
! 90: printf (" u = "); mpf_dump (u);
! 91: printf (" v = "); mpf_dump (v);
! 92: printf ("wref = "); mpf_dump (wref);
! 93: printf (" w = "); mpf_dump (w);
! 94: abort ();
! 95: }
! 96: }
! 97: }
! 98:
! 99: mpf_clear (limit_rerr);
! 100: mpf_clear (rerr);
! 101: mpf_clear (max_rerr);
! 102:
! 103: mpf_clear (u);
! 104: mpf_clear (v);
! 105: mpf_clear (w);
! 106: mpf_clear (wref);
! 107:
! 108: tests_end ();
! 109: exit (0);
! 110: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>