3 Copyright 2000, 2001 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
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 3 of the License, or (at your
10 option) any later version.
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.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
27 main (int argc, char **argv)
29 #if GMP_NAIL_BITS == 0
39 { -2, "0", 16, "0", "1" },
40 { -2, "1", 16, "1", "1" },
41 { -2, "1@1", 16, "2", "1" },
42 { -2, "1@2", 16, "4", "1" },
43 { -2, "1@3", 16, "8", "1" },
45 { -2, "1@30", 16, "40000000", "1" },
46 { -2, "1@31", 16, "80000000", "1" },
47 { -2, "1@32", 16, "100000000", "1" },
48 { -2, "1@33", 16, "200000000", "1" },
49 { -2, "1@34", 16, "400000000", "1" },
51 { -2, "1@62", 16, "4000000000000000", "1" },
52 { -2, "1@63", 16, "8000000000000000", "1" },
53 { -2, "1@64", 16, "10000000000000000", "1" },
54 { -2, "1@65", 16, "20000000000000000", "1" },
55 { -2, "1@66", 16, "40000000000000000", "1" },
57 { -2, "1@126", 16, "40000000000000000000000000000000", "1" },
58 { -2, "1@127", 16, "80000000000000000000000000000000", "1" },
59 { -2, "1@128", 16, "100000000000000000000000000000000", "1" },
60 { -2, "1@129", 16, "200000000000000000000000000000000", "1" },
61 { -2, "1@130", 16, "400000000000000000000000000000000", "1" },
63 { -2, "1@-1", 16, "1", "2" },
64 { -2, "1@-2", 16, "1", "4" },
65 { -2, "1@-3", 16, "1", "8" },
67 { -2, "1@-30", 16, "1", "40000000" },
68 { -2, "1@-31", 16, "1", "80000000" },
69 { -2, "1@-32", 16, "1", "100000000" },
70 { -2, "1@-33", 16, "1", "200000000" },
71 { -2, "1@-34", 16, "1", "400000000" },
73 { -2, "1@-62", 16, "1", "4000000000000000" },
74 { -2, "1@-63", 16, "1", "8000000000000000" },
75 { -2, "1@-64", 16, "1", "10000000000000000" },
76 { -2, "1@-65", 16, "1", "20000000000000000" },
77 { -2, "1@-66", 16, "1", "40000000000000000" },
79 { -2, "1@-126", 16, "1", "40000000000000000000000000000000" },
80 { -2, "1@-127", 16, "1", "80000000000000000000000000000000" },
81 { -2, "1@-128", 16, "1", "100000000000000000000000000000000" },
82 { -2, "1@-129", 16, "1", "200000000000000000000000000000000" },
83 { -2, "1@-130", 16, "1", "400000000000000000000000000000000" },
85 { -2, "1@-30", 16, "1", "40000000" },
86 { -2, "1@-31", 16, "1", "80000000" },
87 { -2, "1@-32", 16, "1", "100000000" },
88 { -2, "1@-33", 16, "1", "200000000" },
89 { -2, "1@-34", 16, "1", "400000000" },
91 { -2, "11@-62", 16, "3", "4000000000000000" },
92 { -2, "11@-63", 16, "3", "8000000000000000" },
93 { -2, "11@-64", 16, "3", "10000000000000000" },
94 { -2, "11@-65", 16, "3", "20000000000000000" },
95 { -2, "11@-66", 16, "3", "40000000000000000" },
97 { 16, "80000000.00000001", 16, "8000000000000001", "100000000" },
98 { 16, "80000000.00000008", 16, "1000000000000001", "20000000" },
99 { 16, "80000000.8", 16, "100000001", "2" },
105 mpz_t want_num, want_den;
110 mpf_init2 (f, 1024L);
115 for (i = 0; i < numberof (data); i++)
117 for (neg = 0; neg <= 1; neg++)
119 mpf_set_str_or_abort (f, data[i].f, data[i].f_base);
120 mpz_set_str_or_abort (want_num, data[i].want_num, data[i].z_base);
121 mpz_set_str_or_abort (want_den, data[i].want_den, data[i].z_base);
126 mpz_neg (want_num, want_num);
130 MPQ_CHECK_FORMAT (got);
132 if (mpz_cmp (mpq_numref(got), want_num) != 0
133 || mpz_cmp (mpq_denref(got), want_den) != 0)
135 printf ("wrong at data[%d]\n", i);
136 printf (" f_base %d, z_base %d\n",
137 data[i].f_base, data[i].z_base);
139 printf (" f \"%s\" hex ", data[i].f);
140 mpf_out_str (stdout, 16, 0, f);
143 printf (" want num 0x");
144 mpz_out_str (stdout, 16, want_num);
146 printf (" want den 0x");
147 mpz_out_str (stdout, 16, want_den);
150 printf (" got num 0x");
151 mpz_out_str (stdout, 16, mpq_numref(got));
153 printf (" got den 0x");
154 mpz_out_str (stdout, 16, mpq_denref(got));
164 mpz_clear (want_num);
165 mpz_clear (want_den);