Annotation of OpenXM_contrib/gmp/mpfr/tests/tsqrt_ui.c, Revision 1.1.1.1
1.1 ohara 1: /* Test file for mpfr_sqrt_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 <math.h>
23: #include <stdio.h>
24: #include <stdlib.h>
25: #include <time.h>
26: #include "gmp.h"
27: #include "mpfr.h"
28: #include "mpfr-test.h"
29:
30: void check _PROTO((unsigned long, mp_rnd_t, double));
31:
32: int maxulp=0;
33:
34: void
35: check (unsigned long a, mp_rnd_t rnd_mode, double Q)
36: {
37: mpfr_t q; double Q2; int u, ck;
38:
39: mpfr_init2(q, 53);
40: #ifdef MPFR_HAVE_FESETROUND
41: mpfr_set_machine_rnd_mode(rnd_mode);
42: #endif
43: mpfr_sqrt_ui(q, a, rnd_mode);
44: ck = (Q >= 0.0);
45: if (!ck) Q = sqrt(1.0 * a);
46: Q2 = mpfr_get_d1 (q);
47: if (Q!=Q2 && (!isnan(Q) || !isnan(Q2))) {
48: u = ulp(Q2,Q);
49: if (ck) printf("mpfr_sqrt_ui failed");
50: else printf("mpfr_sqrt_ui differs from sqrt");
51: printf(" for a=%lu, rnd_mode=%s\n",
52: a, mpfr_print_rnd_mode(rnd_mode));
53: printf("sqrt gives %1.20e, mpfr_sqrt_ui gives %1.20e (%d ulp)\n",Q,Q2,u);
54: exit(1);
55: }
56: mpfr_clear(q);
57: }
58:
59: double five = 5.0;
60:
61: int
62: main (void)
63: {
64: #ifdef MPFR_HAVE_FESETROUND
65: int i;
66: unsigned long a;
67:
68: mpfr_test_init ();
69:
70: /* On Debian potato glibc 2.1.3-18, sqrt() doesn't seem to respect
71: fesetround. */
72: {
73: double a, b;
74: mpfr_set_machine_rnd_mode (GMP_RNDU);
75: a = sqrt (five);
76: mpfr_set_machine_rnd_mode (GMP_RNDD);
77: b = sqrt (five);
78: if (a == b)
79: {
80: printf ("Tests suppressed, mpfr_set_machine_rnd_mode doesn't affect sqrt()\n");
81: goto nogood;
82: }
83: }
84:
85: SEED_RAND (time(NULL));
86: for (i=0;i<1000000;i++)
87: {
88: a = LONG_RAND();
89: /* machine arithmetic must agree if a <= 2.0^53 */
90: if (1.0*a < 9007199254872064.0)
91: check(a, LONG_RAND() % 4, -1.0);
92: }
93: nogood:
94: #endif
95:
96: check (0, GMP_RNDN, 0.0);
97: check (2116118, GMP_RNDU, 1.45468828276026215e3);
98:
99: return 0;
100: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>