This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
b229d7c67bafe863df3abd08c1f7424401f6abeb
[perl5.git] / t / lib / bigintpm.t
1 #!./perl
2
3 BEGIN { unshift @INC, './lib', '../lib';
4     require Config; import Config;
5 }
6 use Math::BigInt;
7
8 $test = 0;
9 $| = 1;
10 print "1..246\n";
11 while (<DATA>) {
12        chop;
13        if (s/^&//) {
14                $f = $_;
15        } else {
16                ++$test;
17                @args = split(/:/,$_,99);
18                $ans = pop(@args);
19                $try = "\$x = new Math::BigInt \"$args[0]\";";
20                if ($f eq "bnorm"){
21                    $try .= "\$x+0;";
22                } elsif ($f eq "bneg") {
23                    $try .= "-\$x;";
24                } elsif ($f eq "babs") {
25                    $try .= "abs \$x;";
26                } else {
27                    $try .= "\$y = new Math::BigInt \"$args[1]\";";
28                    if ($f eq bcmp){
29                        $try .= "\$x <=> \$y;";
30                    }elsif ($f eq badd){
31                        $try .= "\$x + \$y;";
32                    }elsif ($f eq bsub){
33                        $try .= "\$x - \$y;";
34                    }elsif ($f eq bmul){
35                        $try .= "\$x * \$y;";
36                    }elsif ($f eq bdiv){
37                        $try .= "\$x / \$y;";
38                    }elsif ($f eq bmod){
39                        $try .= "\$x % \$y;";
40                    }elsif ($f eq bgcd){
41                        $try .= "Math::BigInt::bgcd(\$x, \$y);";
42                    } else { warn "Unknown op"; }
43                }
44                #print ">>>",$try,"<<<\n";
45                $ans1 = eval $try;
46                if ("$ans1" eq $ans) { #bug!
47                        print "ok $test\n";
48                } else {
49                        print "not ok $test\n";
50                        print "# '$try' expected: '$ans' got: '$ans1'\n";
51                }
52        }
53
54 __END__
55 &bnorm
56 abc:NaN
57    1 a:NaN
58 1bcd2:NaN
59 11111b:NaN
60 +1z:NaN
61 -1z:NaN
62 0:+0
63 +0:+0
64 +00:+0
65 +0 0 0:+0
66 000000  0000000   00000:+0
67 -0:+0
68 -0000:+0
69 +1:+1
70 +01:+1
71 +001:+1
72 +00000100000:+100000
73 123456789:+123456789
74 -1:-1
75 -01:-1
76 -001:-1
77 -123456789:-123456789
78 -00000100000:-100000
79 &bneg
80 abd:NaN
81 +0:+0
82 +1:-1
83 -1:+1
84 +123456789:-123456789
85 -123456789:+123456789
86 &babs
87 abc:NaN
88 +0:+0
89 +1:+1
90 -1:+1
91 +123456789:+123456789
92 -123456789:+123456789
93 &bcmp
94 abc:abc:NaN
95 abc:+0:NaN
96 +0:abc:NaN
97 +0:+0:+0
98 -1:+0:-1
99 +0:-1:+1
100 +1:+0:+1
101 +0:+1:-1
102 -1:+1:-1
103 +1:-1:+1
104 -1:-1:+0
105 +1:+1:+0
106 +123:+123:+0
107 +123:+12:+1
108 +12:+123:-1
109 -123:-123:+0
110 -123:-12:-1
111 -12:-123:+1
112 +123:+124:-1
113 +124:+123:+1
114 -123:-124:+1
115 -124:-123:-1
116 &badd
117 abc:abc:NaN
118 abc:+0:NaN
119 +0:abc:NaN
120 +0:+0:+0
121 +1:+0:+1
122 +0:+1:+1
123 +1:+1:+2
124 -1:+0:-1
125 +0:-1:-1
126 -1:-1:-2
127 -1:+1:+0
128 +1:-1:+0
129 +9:+1:+10
130 +99:+1:+100
131 +999:+1:+1000
132 +9999:+1:+10000
133 +99999:+1:+100000
134 +999999:+1:+1000000
135 +9999999:+1:+10000000
136 +99999999:+1:+100000000
137 +999999999:+1:+1000000000
138 +9999999999:+1:+10000000000
139 +99999999999:+1:+100000000000
140 +10:-1:+9
141 +100:-1:+99
142 +1000:-1:+999
143 +10000:-1:+9999
144 +100000:-1:+99999
145 +1000000:-1:+999999
146 +10000000:-1:+9999999
147 +100000000:-1:+99999999
148 +1000000000:-1:+999999999
149 +10000000000:-1:+9999999999
150 +123456789:+987654321:+1111111110
151 -123456789:+987654321:+864197532
152 -123456789:-987654321:-1111111110
153 +123456789:-987654321:-864197532
154 &bsub
155 abc:abc:NaN
156 abc:+0:NaN
157 +0:abc:NaN
158 +0:+0:+0
159 +1:+0:+1
160 +0:+1:-1
161 +1:+1:+0
162 -1:+0:-1
163 +0:-1:+1
164 -1:-1:+0
165 -1:+1:-2
166 +1:-1:+2
167 +9:+1:+8
168 +99:+1:+98
169 +999:+1:+998
170 +9999:+1:+9998
171 +99999:+1:+99998
172 +999999:+1:+999998
173 +9999999:+1:+9999998
174 +99999999:+1:+99999998
175 +999999999:+1:+999999998
176 +9999999999:+1:+9999999998
177 +99999999999:+1:+99999999998
178 +10:-1:+11
179 +100:-1:+101
180 +1000:-1:+1001
181 +10000:-1:+10001
182 +100000:-1:+100001
183 +1000000:-1:+1000001
184 +10000000:-1:+10000001
185 +100000000:-1:+100000001
186 +1000000000:-1:+1000000001
187 +10000000000:-1:+10000000001
188 +123456789:+987654321:-864197532
189 -123456789:+987654321:-1111111110
190 -123456789:-987654321:+864197532
191 +123456789:-987654321:+1111111110
192 &bmul
193 abc:abc:NaN
194 abc:+0:NaN
195 +0:abc:NaN
196 +0:+0:+0
197 +0:+1:+0
198 +1:+0:+0
199 +0:-1:+0
200 -1:+0:+0
201 +123456789123456789:+0:+0
202 +0:+123456789123456789:+0
203 -1:-1:+1
204 -1:+1:-1
205 +1:-1:-1
206 +1:+1:+1
207 +2:+3:+6
208 -2:+3:-6
209 +2:-3:-6
210 -2:-3:+6
211 +111:+111:+12321
212 +10101:+10101:+102030201
213 +1001001:+1001001:+1002003002001
214 +100010001:+100010001:+10002000300020001
215 +10000100001:+10000100001:+100002000030000200001
216 +11111111111:+9:+99999999999
217 +22222222222:+9:+199999999998
218 +33333333333:+9:+299999999997
219 +44444444444:+9:+399999999996
220 +55555555555:+9:+499999999995
221 +66666666666:+9:+599999999994
222 +77777777777:+9:+699999999993
223 +88888888888:+9:+799999999992
224 +99999999999:+9:+899999999991
225 &bdiv
226 abc:abc:NaN
227 abc:+1:abc:NaN
228 +1:abc:NaN
229 +0:+0:NaN
230 +0:+1:+0
231 +1:+0:NaN
232 +0:-1:+0
233 -1:+0:NaN
234 +1:+1:+1
235 -1:-1:+1
236 +1:-1:-1
237 -1:+1:-1
238 +1:+2:+0
239 +2:+1:+2
240 +1000000000:+9:+111111111
241 +2000000000:+9:+222222222
242 +3000000000:+9:+333333333
243 +4000000000:+9:+444444444
244 +5000000000:+9:+555555555
245 +6000000000:+9:+666666666
246 +7000000000:+9:+777777777
247 +8000000000:+9:+888888888
248 +9000000000:+9:+1000000000
249 +35500000:+113:+314159
250 +71000000:+226:+314159
251 +106500000:+339:+314159
252 +1000000000:+3:+333333333
253 +10:+5:+2
254 +100:+4:+25
255 +1000:+8:+125
256 +10000:+16:+625
257 +999999999999:+9:+111111111111
258 +999999999999:+99:+10101010101
259 +999999999999:+999:+1001001001
260 +999999999999:+9999:+100010001
261 +999999999999999:+99999:+10000100001
262 &bmod
263 abc:abc:NaN
264 abc:+1:abc:NaN
265 +1:abc:NaN
266 +0:+0:NaN
267 +0:+1:+0
268 +1:+0:NaN
269 +0:-1:+0
270 -1:+0:NaN
271 +1:+1:+0
272 -1:-1:+0
273 +1:-1:+0
274 -1:+1:+0
275 +1:+2:+1
276 +2:+1:+0
277 +1000000000:+9:+1
278 +2000000000:+9:+2
279 +3000000000:+9:+3
280 +4000000000:+9:+4
281 +5000000000:+9:+5
282 +6000000000:+9:+6
283 +7000000000:+9:+7
284 +8000000000:+9:+8
285 +9000000000:+9:+0
286 +35500000:+113:+33
287 +71000000:+226:+66
288 +106500000:+339:+99
289 +1000000000:+3:+1
290 +10:+5:+0
291 +100:+4:+0
292 +1000:+8:+0
293 +10000:+16:+0
294 +999999999999:+9:+0
295 +999999999999:+99:+0
296 +999999999999:+999:+0
297 +999999999999:+9999:+0
298 +999999999999999:+99999:+0
299 &bgcd
300 abc:abc:NaN
301 abc:+0:NaN
302 +0:abc:NaN
303 +0:+0:+0
304 +0:+1:+1
305 +1:+0:+1
306 +1:+1:+1
307 +2:+3:+1
308 +3:+2:+1
309 +100:+625:+25
310 +4096:+81:+1