Annotation of OpenXM_contrib/gmp/mpfr/tests/tpow.c, Revision 1.1.1.1
1.1 ohara 1: /* Test file for mpfr_pow and mpfr_pow_ui.
2:
3: Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
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: #include "mpfr-test.h"
28:
29: void check_pow_ui _PROTO ((void));
30: void check_inexact _PROTO ((mp_prec_t));
31:
32: void
33: check_pow_ui (void)
34: {
35: mpfr_t a, b;
36:
37: mpfr_init2 (a, 53);
38: mpfr_init2 (b, 53);
39:
40: /* check in-place operations */
41: mpfr_set_d (b, 0.6926773, GMP_RNDN);
42: mpfr_pow_ui (a, b, 10, GMP_RNDN);
43: mpfr_pow_ui (b, b, 10, GMP_RNDN);
44: if (mpfr_cmp (a, b)) {
45: fprintf (stderr, "Error for mpfr_pow_ui (b, b, ...)\n"); exit (1);
46: }
47:
48: /* check large exponents */
49: mpfr_set_d (b, 1, GMP_RNDN);
50: mpfr_pow_ui (a, b, 4294967295UL, GMP_RNDN);
51:
52: mpfr_set_inf (a, -1);
53: mpfr_pow_ui (a, a, 4049053855UL, GMP_RNDN);
54: if (!mpfr_inf_p (a) || (mpfr_sgn (a) >= 0))
55: {
56: fprintf (stderr, "Error for (-Inf)^4049053855\n");
57: exit (1);
58: }
59:
60: mpfr_set_inf (a, -1);
61: mpfr_pow_ui (a, a, (unsigned long) 30002752, GMP_RNDN);
62: if (!mpfr_inf_p (a) || (mpfr_sgn (a) <= 0))
63: {
64: fprintf (stderr, "Error for (-Inf)^30002752\n");
65: exit (1);
66: }
67:
68: mpfr_clear (a);
69: mpfr_clear (b);
70: }
71:
72: void
73: check_inexact (mp_prec_t p)
74: {
75: mpfr_t x, y, z, t;
76: unsigned long u;
77: mp_prec_t q;
78: int inexact, cmp;
79: mp_rnd_t rnd;
80:
81: mpfr_init2 (x, p);
82: mpfr_init (y);
83: mpfr_init (z);
84: mpfr_init (t);
85: mpfr_random (x);
86: u = LONG_RAND() % 2;
87: for (q=2; q<=p; q++)
88: for (rnd=0; rnd<4; rnd++)
89: {
90: mpfr_set_prec (y, q);
91: mpfr_set_prec (z, q + 10);
92: mpfr_set_prec (t, q);
93: inexact = mpfr_pow_ui (y, x, u, rnd);
94: cmp = mpfr_pow_ui (z, x, u, rnd);
95: if (mpfr_can_round (z, q + 10, rnd, rnd, q))
96: {
97: cmp = mpfr_set (t, z, rnd) || cmp;
98: if (mpfr_cmp (y, t))
99: {
100: fprintf (stderr, "results differ for u=%lu rnd=%s\n", u,
101: mpfr_print_rnd_mode(rnd));
102: printf ("x="); mpfr_print_binary (x); putchar ('\n');
103: printf ("y="); mpfr_print_binary (y); putchar ('\n');
104: printf ("t="); mpfr_print_binary (t); putchar ('\n');
105: printf ("z="); mpfr_print_binary (z); putchar ('\n');
106: exit (1);
107: }
108: if (((inexact == 0) && (cmp != 0)) ||
109: ((inexact != 0) && (cmp == 0)))
110: {
111: fprintf (stderr, "Wrong inexact flag for p=%u, q=%u, rnd=%s\n",
112: (unsigned) p, (unsigned) q, mpfr_print_rnd_mode (rnd));
113: printf ("expected %d, got %d\n", cmp, inexact);
114: printf ("u=%lu x=", u); mpfr_print_binary (x); putchar ('\n');
115: printf ("y="); mpfr_print_binary (y); putchar ('\n');
116: exit (1);
117: }
118: }
119: }
120:
121: mpfr_clear (x);
122: mpfr_clear (y);
123: mpfr_clear (z);
124: mpfr_clear (t);
125: }
126:
127: int
128: main (void)
129: {
130: mp_prec_t p;
131:
132: check_pow_ui ();
133:
134: for (p=2; p<100; p++)
135: check_inexact (p);
136:
137: return 0;
138: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>