Annotation of OpenXM_contrib/gmp/tests/mpf/t-sqrt.c, Revision 1.1.1.1
1.1 ohara 1: /* Test mpf_sqrt, mpf_mul.
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 x, y, y2;
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 (x);
64: mpf_init (y);
65: mpf_init (y2);
66: for (i = 0; i < reps; i++)
67: {
68: size = urandom () % SIZE;
69: exp = urandom () % SIZE;
70: mpf_random2 (x, size, exp);
71:
72: mpf_sqrt (y, x);
73: mpf_mul (y2, y, y);
74:
75: mpf_reldiff (rerr, x, y2);
76: if (mpf_cmp (rerr, max_rerr) > 0)
77: {
78: mpf_set (max_rerr, rerr);
79: #if VERBOSE
80: mpf_dump (max_rerr);
81: #endif
82: if (mpf_cmp (rerr, limit_rerr) > 0)
83: {
84: printf ("ERROR after %d tests\n", i);
85: printf (" x = "); mpf_dump (x);
86: printf (" y = "); mpf_dump (y);
87: printf (" y2 = "); mpf_dump (y2);
88: abort ();
89: }
90: }
91: }
92:
93: mpf_clear (limit_rerr);
94: mpf_clear (rerr);
95: mpf_clear (max_rerr);
96:
97: mpf_clear (x);
98: mpf_clear (y);
99: mpf_clear (y2);
100:
101: tests_end ();
102: exit (0);
103: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>