Annotation of OpenXM_contrib/gmp/mpf/tests/t-dm2exp.c, Revision 1.1.1.2
1.1 maekawa 1: /* Test mpf_div, mpf_div_2exp, mpf_mul_2exp.
2:
1.1.1.2 ! maekawa 3: Copyright (C) 1996, 2000 Free Software Foundation, Inc.
1.1 maekawa 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
1.1.1.2 ! maekawa 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
1.1 maekawa 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
1.1.1.2 ! maekawa 14: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
1.1 maekawa 15: License for more details.
16:
1.1.1.2 ! maekawa 17: You should have received a copy of the GNU Lesser General Public License
1.1 maekawa 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 "gmp.h"
24: #include "gmp-impl.h"
25: #include "urandom.h"
26:
27: #ifndef SIZE
28: #define SIZE 16
29: #endif
30:
31: main (argc, argv)
32: int argc;
33: char **argv;
34: {
35: int reps = 500000;
36: int i;
1.1.1.2 ! maekawa 37: mpf_t u, v, w1, w2, w3;
1.1 maekawa 38: mp_size_t bprec = 100;
39: mpf_t rerr, limit_rerr;
1.1.1.2 ! maekawa 40: mp_size_t un;
! 41: mp_exp_t ue;
1.1 maekawa 42:
43: if (argc > 1)
44: {
45: reps = strtol (argv[1], 0, 0);
46: if (argc > 2)
47: bprec = strtol (argv[2], 0, 0);
48: }
49:
50: mpf_set_default_prec (bprec);
51:
52: mpf_init (rerr);
53: mpf_init (limit_rerr);
54:
55: mpf_init (u);
56: mpf_init (v);
57: mpf_init (w1);
58: mpf_init (w2);
1.1.1.2 ! maekawa 59: mpf_init (w3);
1.1 maekawa 60:
61: for (i = 0; i < reps; i++)
62: {
1.1.1.2 ! maekawa 63: unsigned long int res_prec;
1.1 maekawa 64: unsigned long int pow2;
65:
66: res_prec = urandom () % (bprec + 100);
67: mpf_set_prec (w1, res_prec);
68: mpf_set_prec (w2, res_prec);
1.1.1.2 ! maekawa 69: mpf_set_prec (w3, res_prec);
1.1 maekawa 70:
71: mpf_set_ui (limit_rerr, 1);
72: mpf_div_2exp (limit_rerr, limit_rerr, res_prec);
73:
74: pow2 = urandom () % 0x10000;
75: mpf_set_ui (v, 1);
76: mpf_mul_2exp (v, v, pow2);
77:
1.1.1.2 ! maekawa 78: un = urandom () % (2 * SIZE) - SIZE;
! 79: ue = urandom () % SIZE;
! 80: mpf_random2 (u, un, ue);
! 81:
1.1 maekawa 82: mpf_div_2exp (w1, u, pow2);
83: mpf_div (w2, u, v);
84: mpf_reldiff (rerr, w1, w2);
85: if (mpf_cmp (rerr, limit_rerr) > 0)
86: {
87: printf ("ERROR in mpf_div or mpf_div_2exp after %d tests\n", i);
88: printf (" u = "); mpf_dump (u);
89: printf (" v = "); mpf_dump (v);
90: printf (" w1 = "); mpf_dump (w1);
91: printf (" w2 = "); mpf_dump (w2);
1.1.1.2 ! maekawa 92: abort ();
! 93: }
! 94: mpf_mul_2exp (w3, w1, pow2);
! 95: mpf_reldiff (rerr, u, w3);
! 96: if (mpf_cmp (rerr, limit_rerr) > 0)
! 97: {
! 98: printf ("ERROR in mpf_mul_2exp after %d tests\n", i);
! 99: printf (" u = "); mpf_dump (u);
! 100: printf (" v = "); mpf_dump (v);
! 101: printf (" w1 = "); mpf_dump (w1);
! 102: printf (" w3 = "); mpf_dump (w3);
1.1 maekawa 103: abort ();
104: }
105: }
106:
107: exit (0);
108: }
109:
110: oo (x)
111: mpf_t x;
112: {
113: mp_size_t i;
114: printf (" exp = %ld\n", x->_mp_exp);
115: printf ("size = %d\n", x->_mp_size);
116: for (i = ABS (x->_mp_size) - 1; i >= 0; i--)
117: printf ("%08lX ", x->_mp_d[i]);
118: printf ("\n");
119: mpf_dump (x);
120: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>