1 /* Test mpq_mul_2exp and mpq_div_2exp.
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/. */
41 { {"0","1"}, 0, {"0","1"} },
42 { {"0","1"}, 1, {"0","1"} },
43 { {"0","1"}, 2, {"0","1"} },
45 { {"1","1"}, 0, {"1","1"} },
46 { {"1","1"}, 1, {"2","1"} },
47 { {"1","1"}, 2, {"4","1"} },
48 { {"1","1"}, 3, {"8","1"} },
50 { {"1","1"}, 31, {"0x80000000","1"} },
51 { {"1","1"}, 32, {"0x100000000","1"} },
52 { {"1","1"}, 33, {"0x200000000","1"} },
53 { {"1","1"}, 63, {"0x8000000000000000","1"} },
54 { {"1","1"}, 64, {"0x10000000000000000","1"} },
55 { {"1","1"}, 65, {"0x20000000000000000","1"} },
56 { {"1","1"}, 95, {"0x800000000000000000000000","1"} },
57 { {"1","1"}, 96, {"0x1000000000000000000000000","1"} },
58 { {"1","1"}, 97, {"0x2000000000000000000000000","1"} },
59 { {"1","1"}, 127, {"0x80000000000000000000000000000000","1"} },
60 { {"1","1"}, 128, {"0x100000000000000000000000000000000","1"} },
61 { {"1","1"}, 129, {"0x200000000000000000000000000000000","1"} },
63 { {"1","2"}, 31, {"0x40000000","1"} },
64 { {"1","2"}, 32, {"0x80000000","1"} },
65 { {"1","2"}, 33, {"0x100000000","1"} },
66 { {"1","2"}, 63, {"0x4000000000000000","1"} },
67 { {"1","2"}, 64, {"0x8000000000000000","1"} },
68 { {"1","2"}, 65, {"0x10000000000000000","1"} },
69 { {"1","2"}, 95, {"0x400000000000000000000000","1"} },
70 { {"1","2"}, 96, {"0x800000000000000000000000","1"} },
71 { {"1","2"}, 97, {"0x1000000000000000000000000","1"} },
72 { {"1","2"}, 127, {"0x40000000000000000000000000000000","1"} },
73 { {"1","2"}, 128, {"0x80000000000000000000000000000000","1"} },
74 { {"1","2"}, 129, {"0x100000000000000000000000000000000","1"} },
76 { {"1","0x80000000"}, 30, {"1","2"} },
77 { {"1","0x80000000"}, 31, {"1","1"} },
78 { {"1","0x80000000"}, 32, {"2","1"} },
79 { {"1","0x80000000"}, 33, {"4","1"} },
80 { {"1","0x80000000"}, 62, {"0x80000000","1"} },
81 { {"1","0x80000000"}, 63, {"0x100000000","1"} },
82 { {"1","0x80000000"}, 64, {"0x200000000","1"} },
83 { {"1","0x80000000"}, 94, {"0x8000000000000000","1"} },
84 { {"1","0x80000000"}, 95, {"0x10000000000000000","1"} },
85 { {"1","0x80000000"}, 96, {"0x20000000000000000","1"} },
86 { {"1","0x80000000"}, 126, {"0x800000000000000000000000","1"} },
87 { {"1","0x80000000"}, 127, {"0x1000000000000000000000000","1"} },
88 { {"1","0x80000000"}, 128, {"0x2000000000000000000000000","1"} },
90 { {"1","0x100000000"}, 1, {"1","0x80000000"} },
91 { {"1","0x100000000"}, 2, {"1","0x40000000"} },
92 { {"1","0x100000000"}, 3, {"1","0x20000000"} },
94 { {"1","0x10000000000000000"}, 1, {"1","0x8000000000000000"} },
95 { {"1","0x10000000000000000"}, 2, {"1","0x4000000000000000"} },
96 { {"1","0x10000000000000000"}, 3, {"1","0x2000000000000000"} },
99 void (*fun) __GMP_PROTO ((mpq_ptr, mpq_srcptr, unsigned long));
100 const struct pair_t *p_start, *p_want;
102 mpq_t sep, got, want;
104 int i, muldiv, sign, overlap;
112 for (i = 0; i < numberof (data); i++)
114 for (muldiv = 0; muldiv < 2; muldiv++)
119 name = "mpq_mul_2exp";
120 p_start = &data[i].left;
121 p_want = &data[i].right;
126 name = "mpq_div_2exp";
127 p_start = &data[i].right;
128 p_want = &data[i].left;
131 for (sign = 0; sign <= 1; sign++)
133 mpz_set_str_or_abort (mpq_numref(want), p_want->num, 0);
134 mpz_set_str_or_abort (mpq_denref(want), p_want->den, 0);
136 mpq_neg (want, want);
138 for (overlap = 0; overlap <= 1; overlap++)
140 q = overlap ? got : sep;
142 /* initial garbage in "got" */
143 mpq_set_ui (got, 123L, 456L);
145 mpz_set_str_or_abort (mpq_numref(q), p_start->num, 0);
146 mpz_set_str_or_abort (mpq_denref(q), p_start->den, 0);
150 (*fun) (got, q, data[i].n);
151 MPQ_CHECK_FORMAT (got);
153 if (! mpq_equal (got, want))
155 printf ("%s wrong at data[%d], sign %d, overlap %d\n",
156 name, i, sign, overlap);
157 printf (" num \"%s\"\n", p_start->num);
158 printf (" den \"%s\"\n", p_start->den);
159 printf (" n %lu\n", data[i].n);
162 mpq_out_str (stdout, 16, got);
166 mpq_out_str (stdout, 16, want);