Annotation of OpenXM_contrib/gmp/mpfr/tests/tatan.c, Revision 1.1.1.1
1.1 ohara 1: /* Test file for mpfr_arctan.
2:
3: Copyright 2001, 2002 Free Software Foundation.
4: Written by Paul Zimmermann, INRIA Lorraine.
5:
6: This file is part of the MPFR Library.
7:
8: The MPFR Library is free software; you can redistribute it and/or modify
9: it under the terms of the GNU Lesser General Public License as published by
10: the Free Software Foundation; either version 2.1 of the License, or (at your
11: option) any later version.
12:
13: The MPFR Library is distributed in the hope that it will be useful, but
14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15: or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16: License for more details.
17:
18: You should have received a copy of the GNU Lesser General Public License
19: along with the MPFR Library; see the file COPYING.LIB. If not, write to
20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
21: MA 02111-1307, USA. */
22:
23: #include <stdio.h>
24: #include <stdlib.h>
25: #include "gmp.h"
26: #include "mpfr.h"
27: #include "mpfr-test.h"
28:
29: void worst_cases _PROTO((void));
30: int mpfr_arctan_aux2 _PROTO((mpfr_ptr, mpfr_srcptr, mp_rnd_t));
31:
32: void
33: worst_cases (void)
34: {
35: mpfr_t x, y, z;
36:
37: mpfr_init2 (x, 53);
38: mpfr_init2 (y, 53);
39: mpfr_init2 (z, 53);
40:
41: mpfr_set_str_raw (x, "1.0000100110000001100111100011001110101110100111011101");
42: mpfr_set_str_raw (y, "1.1001101101110100101100110011011101101000011010111110e-1");
43: mpfr_atan (z, x, GMP_RNDN);
44: if (mpfr_cmp (y, z))
45: {
46: fprintf (stderr, "Error in mpfr_atan for prec=53, rnd=GMP_RNDN\n");
47: fprintf (stderr, "x=");
48: mpfr_out_str (stderr, 2, 0, x, GMP_RNDN);
49: fprintf (stderr, "\nexpected ");
50: mpfr_out_str (stderr, 2, 0, y, GMP_RNDN);
51: fprintf (stderr, "\ngot ");
52: mpfr_out_str (stderr, 2, 0, z, GMP_RNDN);
53: fprintf (stderr, "\n");
54: exit (1);
55: }
56:
57: mpfr_clear (x);
58: mpfr_clear (y);
59: mpfr_clear (z);
60: }
61:
62: int
63: main (int argc, char *argv[])
64: {
65: unsigned int prec, err, yprec, n, p0 = 2, p1 = 100, N = 10;
66: mp_rnd_t rnd;
67: mpfr_t x, y, z, t;
68:
69: worst_cases ();
70:
71: mpfr_init (x);
72: mpfr_init (y);
73: mpfr_init (z);
74: mpfr_init (t);
75:
76: /* tarctan prec - perform one random computation with precision prec */
77: if (argc >= 2)
78: {
79: p0 = p1 = atoi (argv[1]);
80: N = 1;
81: }
82:
83: for (prec = p0; prec <= p1; prec++)
84: {
85: mpfr_set_prec (x, prec);
86: mpfr_set_prec (z, prec);
87: mpfr_set_prec (t, prec);
88: yprec = prec + 10;
89:
90: for (n=0; n<N; n++)
91: {
92: mpfr_random (x);
93: rnd = random () % 4;
94: mpfr_set_prec (y, yprec);
95: mpfr_atan (y, x, rnd);
96: err = (rnd == GMP_RNDN) ? yprec + 1 : yprec;
97: if (mpfr_can_round (y, err, rnd, rnd, prec))
98: {
99: mpfr_set (t, y, rnd);
100: mpfr_atan (z, x, rnd);
101: if (mpfr_cmp (t, z))
102: {
103: printf ("results differ for x=");
104: mpfr_out_str (stdout, 2, prec, x, GMP_RNDN);
105: printf (" prec=%u rnd_mode=%s\n", prec,
106: mpfr_print_rnd_mode (rnd));
107: printf (" got ");
108: mpfr_out_str (stdout, 2, prec, z, GMP_RNDN);
109: putchar ('\n');
110: printf (" expected ");
111: mpfr_out_str (stdout, 2, prec, t, GMP_RNDN);
112: putchar ('\n');
113: printf (" approximation was ");
114: mpfr_print_binary (y);
115: putchar ('\n');
116: exit (1);
117: }
118: }
119: }
120: }
121:
122: mpfr_clear (x);
123: mpfr_clear (y);
124: mpfr_clear (z);
125: mpfr_clear (t);
126:
127: return 0;
128: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>