Annotation of OpenXM_contrib/gmp/tests/mpq/t-set_f.c, Revision 1.1.1.1
1.1 ohara 1: /* Test mpq_set_f.
2:
3: Copyright 2000, 2001 Free Software Foundation, Inc.
4:
5: This file is part of the GNU MP Library.
6:
7: The GNU MP 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 GNU MP 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 GNU MP 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 "gmp-impl.h"
26: #include "tests.h"
27:
28: int
29: main (int argc, char **argv)
30: {
31: #if GMP_NAIL_BITS == 0
32: static const struct {
33: int f_base;
34: const char *f;
35: int z_base;
36: const char *want_num;
37: const char *want_den;
38:
39: } data[] = {
40:
41: { -2, "0", 16, "0", "1" },
42: { -2, "1", 16, "1", "1" },
43: { -2, "1@1", 16, "2", "1" },
44: { -2, "1@2", 16, "4", "1" },
45: { -2, "1@3", 16, "8", "1" },
46:
47: { -2, "1@30", 16, "40000000", "1" },
48: { -2, "1@31", 16, "80000000", "1" },
49: { -2, "1@32", 16, "100000000", "1" },
50: { -2, "1@33", 16, "200000000", "1" },
51: { -2, "1@34", 16, "400000000", "1" },
52:
53: { -2, "1@62", 16, "4000000000000000", "1" },
54: { -2, "1@63", 16, "8000000000000000", "1" },
55: { -2, "1@64", 16, "10000000000000000", "1" },
56: { -2, "1@65", 16, "20000000000000000", "1" },
57: { -2, "1@66", 16, "40000000000000000", "1" },
58:
59: { -2, "1@126", 16, "40000000000000000000000000000000", "1" },
60: { -2, "1@127", 16, "80000000000000000000000000000000", "1" },
61: { -2, "1@128", 16, "100000000000000000000000000000000", "1" },
62: { -2, "1@129", 16, "200000000000000000000000000000000", "1" },
63: { -2, "1@130", 16, "400000000000000000000000000000000", "1" },
64:
65: { -2, "1@-1", 16, "1", "2" },
66: { -2, "1@-2", 16, "1", "4" },
67: { -2, "1@-3", 16, "1", "8" },
68:
69: { -2, "1@-30", 16, "1", "40000000" },
70: { -2, "1@-31", 16, "1", "80000000" },
71: { -2, "1@-32", 16, "1", "100000000" },
72: { -2, "1@-33", 16, "1", "200000000" },
73: { -2, "1@-34", 16, "1", "400000000" },
74:
75: { -2, "1@-62", 16, "1", "4000000000000000" },
76: { -2, "1@-63", 16, "1", "8000000000000000" },
77: { -2, "1@-64", 16, "1", "10000000000000000" },
78: { -2, "1@-65", 16, "1", "20000000000000000" },
79: { -2, "1@-66", 16, "1", "40000000000000000" },
80:
81: { -2, "1@-126", 16, "1", "40000000000000000000000000000000" },
82: { -2, "1@-127", 16, "1", "80000000000000000000000000000000" },
83: { -2, "1@-128", 16, "1", "100000000000000000000000000000000" },
84: { -2, "1@-129", 16, "1", "200000000000000000000000000000000" },
85: { -2, "1@-130", 16, "1", "400000000000000000000000000000000" },
86:
87: { -2, "1@-30", 16, "1", "40000000" },
88: { -2, "1@-31", 16, "1", "80000000" },
89: { -2, "1@-32", 16, "1", "100000000" },
90: { -2, "1@-33", 16, "1", "200000000" },
91: { -2, "1@-34", 16, "1", "400000000" },
92:
93: { -2, "11@-62", 16, "3", "4000000000000000" },
94: { -2, "11@-63", 16, "3", "8000000000000000" },
95: { -2, "11@-64", 16, "3", "10000000000000000" },
96: { -2, "11@-65", 16, "3", "20000000000000000" },
97: { -2, "11@-66", 16, "3", "40000000000000000" },
98:
99: { 16, "80000000.00000001", 16, "8000000000000001", "100000000" },
100: { 16, "80000000.00000008", 16, "1000000000000001", "20000000" },
101: { 16, "80000000.8", 16, "100000001", "2" },
102:
103: };
104:
105: mpf_t f;
106: mpq_t got;
107: mpz_t want_num, want_den;
108: int i, neg;
109:
110: tests_start ();
111:
112: mpf_init2 (f, 1024L);
113: mpq_init (got);
114: mpz_init (want_num);
115: mpz_init (want_den);
116:
117: for (i = 0; i < numberof (data); i++)
118: {
119: for (neg = 0; neg <= 1; neg++)
120: {
121: mpf_set_str_or_abort (f, data[i].f, data[i].f_base);
122: mpz_set_str_or_abort (want_num, data[i].want_num, data[i].z_base);
123: mpz_set_str_or_abort (want_den, data[i].want_den, data[i].z_base);
124:
125: if (neg)
126: {
127: mpf_neg (f, f);
128: mpz_neg (want_num, want_num);
129: }
130:
131: mpq_set_f (got, f);
132: MPQ_CHECK_FORMAT (got);
133:
134: if (mpz_cmp (mpq_numref(got), want_num) != 0
135: || mpz_cmp (mpq_denref(got), want_den) != 0)
136: {
137: printf ("wrong at data[%d]\n", i);
138: printf (" f_base %d, z_base %d\n",
139: data[i].f_base, data[i].z_base);
140:
141: printf (" f \"%s\" hex ", data[i].f);
142: mpf_out_str (stdout, 16, 0, f);
143: printf ("\n");
144:
145: printf (" want num 0x");
146: mpz_out_str (stdout, 16, want_num);
147: printf ("\n");
148: printf (" want den 0x");
149: mpz_out_str (stdout, 16, want_den);
150: printf ("\n");
151:
152: printf (" got num 0x");
153: mpz_out_str (stdout, 16, mpq_numref(got));
154: printf ("\n");
155: printf (" got den 0x");
156: mpz_out_str (stdout, 16, mpq_denref(got));
157: printf ("\n");
158:
159: abort ();
160: }
161: }
162: }
163:
164: mpf_clear (f);
165: mpq_clear (got);
166: mpz_clear (want_num);
167: mpz_clear (want_den);
168:
169: tests_end ();
170: #endif
171: exit (0);
172: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>