Annotation of OpenXM_contrib/gmp/mpfr/tests/ttan.c, Revision 1.1.1.1
1.1 ohara 1: /* Test file for mpfr_tan.
2:
3: Copyright 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 <math.h>
25: #include "gmp.h"
26: #include "mpfr.h"
27: #include "mpfr-impl.h"
28: #include "mpfr-test.h"
29:
30: void check53 _PROTO ((double, double, mp_rnd_t));
31:
32: void
33: check53 (double x, double tan_x, mp_rnd_t rnd_mode)
34: {
35: mpfr_t xx, s;
36:
37: mpfr_init2 (xx, 53);
38: mpfr_init2 (s, 53);
39: mpfr_set_d (xx, x, rnd_mode); /* should be exact */
40: mpfr_tan (s, xx, rnd_mode);
41: if (mpfr_get_d1 (s) != tan_x && (!isnan(tan_x) || !mpfr_nan_p(s))) {
42: fprintf (stderr, "mpfr_tan failed for x=%1.20e, rnd=%s\n", x,
43: mpfr_print_rnd_mode (rnd_mode));
44: fprintf (stderr, "mpfr_tan gives tan(x)=%1.20e, expected %1.20e\n",
45: mpfr_get_d1 (s), tan_x);
46: exit(1);
47: }
48: mpfr_clear (xx);
49: mpfr_clear (s);
50: }
51:
52: #define TEST_FUNCTION mpfr_tan
53: #include "tgeneric.c"
54:
55: int
56: main(int argc, char *argv[])
57: {
58: mpfr_t x;
59: unsigned int i;
60: unsigned int prec[10] = {14, 15, 19, 22, 23, 24, 25, 40, 41, 52};
61: unsigned int prec2[10] = {4, 5, 6, 19, 70, 95, 100, 106, 107, 108};
62:
63: #ifdef HAVE_INFS
64: check53 (DBL_NAN, DBL_NAN, GMP_RNDN);
65: check53 (DBL_POS_INF, DBL_NAN, GMP_RNDN);
66: check53 (DBL_NEG_INF, DBL_NAN, GMP_RNDN);
67: #endif
68:
69: mpfr_init (x);
70:
71: mpfr_set_prec (x, 2);
72: mpfr_set_d (x, 0.5, GMP_RNDN);
73: mpfr_tan (x, x, GMP_RNDD);
74: if (mpfr_get_d1 (x) != 0.5)
75: {
76: fprintf (stderr, "mpfr_tan(0.5, GMP_RNDD) failed\n");
77: fprintf (stderr, "expected 0.5, got %f\n", mpfr_get_d1 (x));
78: exit (1);
79: }
80:
81: /* check that tan(3*Pi/4) ~ -1 */
82: for (i=0; i<10; i++)
83: {
84: mpfr_set_prec (x, prec[i]);
85: mpfr_const_pi (x, GMP_RNDN);
86: mpfr_mul_ui (x, x, 3, GMP_RNDN);
87: mpfr_div_ui (x, x, 4, GMP_RNDN);
88: mpfr_tan (x, x, GMP_RNDN);
89: if (mpfr_cmp_si (x, -1))
90: {
91: fprintf (stderr, "tan(3*Pi/4) fails for prec=%u\n", prec[i]);
92: exit (1);
93: }
94: }
95:
96: /* check that tan(7*Pi/4) ~ -1 */
97: for (i=0; i<10; i++)
98: {
99: mpfr_set_prec (x, prec2[i]);
100: mpfr_const_pi (x, GMP_RNDN);
101: mpfr_mul_ui (x, x, 7, GMP_RNDN);
102: mpfr_div_ui (x, x, 4, GMP_RNDN);
103: mpfr_tan (x, x, GMP_RNDN);
104: if (mpfr_cmp_si (x, -1))
105: {
106: fprintf (stderr, "tan(3*Pi/4) fails for prec=%u\n", prec2[i]);
107: exit (1);
108: }
109: }
110:
111: mpfr_clear (x);
112:
113: test_generic (2, 100, 100);
114:
115: return 0;
116: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>