Annotation of OpenXM_contrib/gmp/mpfr/tests/tset_f.c, Revision 1.1.1.1
1.1 ohara 1: /* Test file for mpfr_set_f.
2:
3: Copyright 1999, 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 <time.h>
25: #include "gmp.h"
26: #include "mpfr.h"
27: #include "mpfr-test.h"
28:
29: int
30: main (void)
31: {
32: mpfr_t x, u;
33: mpf_t y, z;
34: unsigned long k, pr;
35:
36: mpf_init(y);
37: mpf_init(z);
38:
39: mpf_set_d (y, 0.0);
40:
41: /* check prototype of mpfr_init_set_f */
42: mpfr_init_set_f (x, y, GMP_RNDN);
43: mpfr_set_prec (x, 100);
44: mpfr_set_f (x, y, GMP_RNDN);
45:
46: SEED_RAND (time(NULL));
47: mpf_random2(y, 10, 0);
48: mpfr_set_f(x, y, LONG_RAND() & 3);
49:
50: /* bug found by Jean-Pierre Merlet */
51: mpfr_set_prec(x, 256);
52: mpf_set_prec(y, 256);
53: mpfr_init2(u, 256);
54: mpfr_set_str(u,
55: "7.f10872b020c49ba5e353f7ced916872b020c49ba5e353f7ced916872b020c498@2",
56: 16, GMP_RNDN);
57: mpf_set_str(y, "2033.033", 10);
58: mpfr_set_f(x, y, GMP_RNDN);
59: if (mpfr_cmp(x, u)) {
60: fprintf(stderr, "mpfr_set_f failed for y=2033.033\n"); exit(1);
61: }
62: mpf_set_str(y, "-2033.033", 10);
63: mpfr_set_f(x, y, GMP_RNDN);
64: mpfr_neg(u, u, GMP_RNDN);
65: if (mpfr_cmp(x, u)) {
66: fprintf(stderr, "mpfr_set_f failed for y=-2033.033\n"); exit(1);
67: }
68:
69: mpfr_clear(u);
70: mpfr_clear(x);
71:
72: for (k = 1; k <= 100000; k++)
73: {
74: pr = 2 + (LONG_RAND()&255);
75: mpf_set_prec (z, pr);
76: mpf_random2 (z, z->_mp_prec, 0);
77: mpfr_init2 (x, pr);
78: mpfr_set_f (x, z, 0);
79: mpfr_clear (x);
80: }
81: mpf_clear (y);
82: mpf_clear (z);
83:
84: return 0;
85: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>