Commit | Line | Data |
58cde26e |
1 | #!/usr/bin/perl -w |
748a9306 |
2 | |
58cde26e |
3 | use strict; |
4 | use Test; |
5 | |
6 | BEGIN |
7 | { |
8 | $| = 1; |
9 | # chdir 't' if -d 't'; |
10 | unshift @INC, '../lib'; # for running manually |
574bacfe |
11 | plan tests => 1424; |
58cde26e |
12 | } |
574bacfe |
13 | my $version = '1.40'; # for $VERSION tests, match current release (by hand!) |
58cde26e |
14 | |
15 | ############################################################################## |
16 | # for testing inheritance of _swap |
17 | |
18 | package Math::Foo; |
19 | |
20 | use Math::BigInt; |
574bacfe |
21 | #use Math::BigInt lib => 'BitVect'; # for testing |
58cde26e |
22 | use vars qw/@ISA/; |
23 | @ISA = (qw/Math::BigInt/); |
24 | |
25 | use overload |
26 | # customized overload for sub, since original does not use swap there |
27 | '-' => sub { my @a = ref($_[0])->_swap(@_); |
28 | $a[0]->bsub($a[1])}; |
29 | |
30 | sub _swap |
31 | { |
32 | # a fake _swap, which reverses the params |
33 | my $self = shift; # for override in subclass |
34 | if ($_[2]) |
35 | { |
36 | my $c = ref ($_[0] ) || 'Math::Foo'; |
37 | return ( $_[0]->copy(), $_[1] ); |
38 | } |
39 | else |
40 | { |
41 | return ( Math::Foo->new($_[1]), $_[0] ); |
42 | } |
43 | } |
44 | |
45 | ############################################################################## |
46 | package main; |
d1f8c7a4 |
47 | |
748a9306 |
48 | use Math::BigInt; |
0716bf9b |
49 | #use Math::BigInt lib => 'BitVect'; # for testing |
0716bf9b |
50 | |
574bacfe |
51 | my $CALC = Math::BigInt::_core_lib(); ok ($CALC,'Math::BigInt::Calc'); |
748a9306 |
52 | |
58cde26e |
53 | my (@args,$f,$try,$x,$y,$z,$a,$exp,$ans,$ans1,@a,$m,$e,$round_mode); |
54 | |
55 | while (<DATA>) |
56 | { |
57 | chop; |
58 | next if /^#/; # skip comments |
59 | if (s/^&//) |
60 | { |
61 | $f = $_; |
62 | } |
63 | elsif (/^\$/) |
64 | { |
65 | $round_mode = $_; |
66 | $round_mode =~ s/^\$/Math::BigInt->/; |
67 | # print "$round_mode\n"; |
68 | } |
69 | else |
70 | { |
71 | @args = split(/:/,$_,99); |
72 | $ans = pop(@args); |
73 | $try = "\$x = Math::BigInt->new(\"$args[0]\");"; |
74 | if ($f eq "bnorm"){ |
75 | # $try .= '$x+0;'; |
58cde26e |
76 | } elsif ($f eq "is_zero") { |
77 | $try .= '$x->is_zero()+0;'; |
78 | } elsif ($f eq "is_one") { |
79 | $try .= '$x->is_one()+0;'; |
80 | } elsif ($f eq "is_odd") { |
81 | $try .= '$x->is_odd()+0;'; |
82 | } elsif ($f eq "is_even") { |
83 | $try .= '$x->is_even()+0;'; |
574bacfe |
84 | } elsif ($f eq "is_negative") { |
85 | $try .= '$x->is_negative()+0;'; |
86 | } elsif ($f eq "is_positive") { |
87 | $try .= '$x->is_positive()+0;'; |
0716bf9b |
88 | } elsif ($f eq "is_inf") { |
89 | $try .= "\$x->is_inf('$args[1]')+0;"; |
58cde26e |
90 | } elsif ($f eq "binf") { |
91 | $try .= "\$x->binf('$args[1]');"; |
574bacfe |
92 | } elsif ($f eq "bone") { |
93 | $try .= "\$x->bone('$args[1]');"; |
94 | } elsif ($f eq "bnan") { |
95 | $try .= "\$x->bnan();"; |
58cde26e |
96 | } elsif ($f eq "bfloor") { |
97 | $try .= '$x->bfloor();'; |
98 | } elsif ($f eq "bceil") { |
99 | $try .= '$x->bceil();'; |
58cde26e |
100 | } elsif ($f eq "bsstr") { |
101 | $try .= '$x->bsstr();'; |
102 | } elsif ($f eq "bneg") { |
574bacfe |
103 | $try .= '$x->bneg();'; |
58cde26e |
104 | } elsif ($f eq "babs") { |
574bacfe |
105 | $try .= '$x->babs();'; |
58cde26e |
106 | } elsif ($f eq "binc") { |
107 | $try .= '++$x;'; |
108 | } elsif ($f eq "bdec") { |
109 | $try .= '--$x;'; |
110 | }elsif ($f eq "bnot") { |
111 | $try .= '~$x;'; |
112 | }elsif ($f eq "bsqrt") { |
113 | $try .= '$x->bsqrt();'; |
114 | }elsif ($f eq "length") { |
115 | $try .= "\$x->length();"; |
58cde26e |
116 | }elsif ($f eq "exponent"){ |
117 | $try .= '$x = $x->exponent()->bstr();'; |
118 | }elsif ($f eq "mantissa"){ |
119 | $try .= '$x = $x->mantissa()->bstr();'; |
120 | }elsif ($f eq "parts"){ |
121 | $try .= "(\$m,\$e) = \$x->parts();"; |
122 | $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;'; |
123 | $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;'; |
124 | $try .= '"$m,$e";'; |
125 | } else { |
0716bf9b |
126 | $try .= "\$y = new Math::BigInt ('$args[1]');"; |
58cde26e |
127 | if ($f eq "bcmp"){ |
128 | $try .= '$x <=> $y;'; |
0716bf9b |
129 | }elsif ($f eq "bround") { |
130 | $try .= "$round_mode; \$x->bround(\$y);"; |
58cde26e |
131 | }elsif ($f eq "bacmp"){ |
0716bf9b |
132 | $try .= "\$x->bacmp(\$y);"; |
58cde26e |
133 | }elsif ($f eq "badd"){ |
134 | $try .= "\$x + \$y;"; |
135 | }elsif ($f eq "bsub"){ |
136 | $try .= "\$x - \$y;"; |
137 | }elsif ($f eq "bmul"){ |
138 | $try .= "\$x * \$y;"; |
139 | }elsif ($f eq "bdiv"){ |
140 | $try .= "\$x / \$y;"; |
574bacfe |
141 | }elsif ($f eq "bdiv-list"){ |
142 | $try .= 'join (",",$x->bdiv($y));'; |
58cde26e |
143 | }elsif ($f eq "bmod"){ |
144 | $try .= "\$x % \$y;"; |
145 | }elsif ($f eq "bgcd") |
146 | { |
147 | if (defined $args[2]) |
148 | { |
149 | $try .= " \$z = new Math::BigInt \"$args[2]\"; "; |
150 | } |
151 | $try .= "Math::BigInt::bgcd(\$x, \$y"; |
152 | $try .= ", \$z" if (defined $args[2]); |
153 | $try .= " );"; |
154 | } |
155 | elsif ($f eq "blcm") |
156 | { |
157 | if (defined $args[2]) |
158 | { |
159 | $try .= " \$z = new Math::BigInt \"$args[2]\"; "; |
160 | } |
161 | $try .= "Math::BigInt::blcm(\$x, \$y"; |
162 | $try .= ", \$z" if (defined $args[2]); |
163 | $try .= " );"; |
164 | }elsif ($f eq "blsft"){ |
165 | if (defined $args[2]) |
166 | { |
167 | $try .= "\$x->blsft(\$y,$args[2]);"; |
168 | } |
169 | else |
170 | { |
171 | $try .= "\$x << \$y;"; |
172 | } |
173 | }elsif ($f eq "brsft"){ |
174 | if (defined $args[2]) |
175 | { |
176 | $try .= "\$x->brsft(\$y,$args[2]);"; |
177 | } |
178 | else |
179 | { |
180 | $try .= "\$x >> \$y;"; |
181 | } |
182 | }elsif ($f eq "band"){ |
183 | $try .= "\$x & \$y;"; |
184 | }elsif ($f eq "bior"){ |
185 | $try .= "\$x | \$y;"; |
186 | }elsif ($f eq "bxor"){ |
187 | $try .= "\$x ^ \$y;"; |
188 | }elsif ($f eq "bpow"){ |
189 | $try .= "\$x ** \$y;"; |
190 | }elsif ($f eq "digit"){ |
191 | $try = "\$x = Math::BigInt->new(\"$args[0]\"); \$x->digit($args[1]);"; |
192 | } else { warn "Unknown op '$f'"; } |
193 | } |
194 | # print "trying $try\n"; |
195 | $ans1 = eval $try; |
196 | $ans =~ s/^[+]([0-9])/$1/; # remove leading '+' |
197 | if ($ans eq "") |
198 | { |
199 | ok_undef ($ans1); |
200 | } |
201 | else |
202 | { |
203 | #print "try: $try ans: $ans1 $ans\n"; |
204 | print "# Tried: '$try'\n" if !ok ($ans1, $ans); |
205 | } |
206 | # check internal state of number objects |
0716bf9b |
207 | is_valid($ans1,$f) if ref $ans1; |
58cde26e |
208 | } |
209 | } # endwhile data tests |
210 | close DATA; |
211 | |
574bacfe |
212 | # XXX Tels 06/29/2001 following tests never fail or do not work :( !? |
0716bf9b |
213 | |
214 | # test whether use Math::BigInt qw/version/ works |
215 | $try = "use Math::BigInt ($version.'1');"; |
216 | $try .= ' $x = Math::BigInt->new(123); $x = "$x";'; |
58cde26e |
217 | $ans1 = eval $try; |
0716bf9b |
218 | ok_undef ( $_ ); # should result in error! |
58cde26e |
219 | |
0716bf9b |
220 | # test whether constant works or not, also test for qw($version) |
221 | $try = "use Math::BigInt ($version,'babs',':constant');"; |
222 | $try .= ' $x = 2**150; babs($x); $x = "$x";'; |
223 | $ans1 = eval $try; |
58cde26e |
224 | ok ( $ans1, "1427247692705959881058285969449495136382746624"); |
225 | |
0716bf9b |
226 | # test wether Math::BigInt::Small via use works (w/ dff. spellings of calc) |
574bacfe |
227 | #$try = "use Math::BigInt ($version,'lib','Small');"; |
0716bf9b |
228 | #$try .= ' $x = 2**10; $x = "$x";'; |
229 | #$ans1 = eval $try; |
230 | #ok ( $ans1, "1024"); |
574bacfe |
231 | #$try = "use Math::BigInt ($version,'LiB','Math::BigInt::Small');"; |
0716bf9b |
232 | #$try .= ' $x = 2**10; $x = "$x";'; |
233 | #$ans1 = eval $try; |
234 | #ok ( $ans1, "1024"); |
235 | # test wether calc => undef (array element not existing) works |
574bacfe |
236 | #$try = "use Math::BigInt ($version,'LIB');"; |
0716bf9b |
237 | #$try = "require Math::BigInt; Math::BigInt::import($version,'CALC');"; |
238 | #$try .= ' $x = Math::BigInt->new(2)**10; $x = "$x";'; |
239 | #$ans1 = eval $try; |
240 | #ok ( $ans1, 1024); |
241 | |
574bacfe |
242 | # test whether fallback to calc works |
243 | $try = "use Math::BigInt ($version,'lib','foo, bar , ');"; |
244 | $try .= ' Math::BigInt::_core_lib();'; |
245 | $ans1 = eval $try; |
246 | ok ( $ans1, "Math::BigInt::Calc"); |
247 | |
58cde26e |
248 | # test some more |
249 | @a = (); |
250 | for (my $i = 1; $i < 10; $i++) |
251 | { |
252 | push @a, $i; |
253 | } |
254 | ok "@a", "1 2 3 4 5 6 7 8 9"; |
255 | |
574bacfe |
256 | # test whether self-multiplication works correctly (result is 2**64) |
58cde26e |
257 | $try = '$x = new Math::BigInt "+4294967296";'; |
258 | $try .= '$a = $x->bmul($x);'; |
259 | $ans1 = eval $try; |
260 | print "# Tried: '$try'\n" if !ok ($ans1, Math::BigInt->new(2) ** 64); |
574bacfe |
261 | # test self-pow |
262 | $try = '$x = Math::BigInt->new(10);'; |
263 | $try .= '$a = $x->bpow($x);'; |
264 | $ans1 = eval $try; |
265 | print "# Tried: '$try'\n" if !ok ($ans1, Math::BigInt->new(10) ** 10); |
58cde26e |
266 | |
0716bf9b |
267 | # test whether op destroys args or not (should better not) |
58cde26e |
268 | |
269 | $x = new Math::BigInt (3); |
270 | $y = new Math::BigInt (4); |
271 | $z = $x & $y; |
272 | ok ($x,3); |
273 | ok ($y,4); |
274 | ok ($z,0); |
275 | $z = $x | $y; |
276 | ok ($x,3); |
277 | ok ($y,4); |
278 | ok ($z,7); |
279 | $x = new Math::BigInt (1); |
280 | $y = new Math::BigInt (2); |
281 | $z = $x | $y; |
282 | ok ($x,1); |
283 | ok ($y,2); |
284 | ok ($z,3); |
285 | |
286 | $x = new Math::BigInt (5); |
287 | $y = new Math::BigInt (4); |
288 | $z = $x ^ $y; |
289 | ok ($x,5); |
290 | ok ($y,4); |
291 | ok ($z,1); |
292 | |
293 | $x = new Math::BigInt (-5); $y = -$x; |
294 | ok ($x, -5); |
295 | |
296 | $x = new Math::BigInt (-5); $y = abs($x); |
297 | ok ($x, -5); |
298 | |
299 | # check whether overloading cmp works |
300 | $try = "\$x = Math::BigInt->new(0);"; |
301 | $try .= "\$y = 10;"; |
302 | $try .= "'false' if \$x ne \$y;"; |
303 | $ans = eval $try; |
304 | print "# For '$try'\n" if (!ok "$ans" , "false" ); |
305 | |
306 | # we cant test for working cmpt with other objects here, we would need a dummy |
307 | # object with stringify overload for this. see Math::String tests |
308 | |
309 | ############################################################################### |
310 | # check shortcuts |
311 | $try = "\$x = Math::BigInt->new(1); \$x += 9;"; |
312 | $try .= "'ok' if \$x == 10;"; |
313 | $ans = eval $try; |
314 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
315 | |
316 | $try = "\$x = Math::BigInt->new(1); \$x -= 9;"; |
317 | $try .= "'ok' if \$x == -8;"; |
318 | $ans = eval $try; |
319 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
320 | |
321 | $try = "\$x = Math::BigInt->new(1); \$x *= 9;"; |
322 | $try .= "'ok' if \$x == 9;"; |
323 | $ans = eval $try; |
324 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
325 | |
326 | $try = "\$x = Math::BigInt->new(10); \$x /= 2;"; |
327 | $try .= "'ok' if \$x == 5;"; |
328 | $ans = eval $try; |
329 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
330 | |
331 | ############################################################################### |
332 | # check reversed order of arguments |
333 | $try = "\$x = Math::BigInt->new(10); \$x = 2 ** \$x;"; |
334 | $try .= "'ok' if \$x == 1024;"; $ans = eval $try; |
335 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
336 | |
337 | $try = "\$x = Math::BigInt->new(10); \$x = 2 * \$x;"; |
338 | $try .= "'ok' if \$x == 20;"; $ans = eval $try; |
339 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
340 | |
341 | $try = "\$x = Math::BigInt->new(10); \$x = 2 + \$x;"; |
342 | $try .= "'ok' if \$x == 12;"; $ans = eval $try; |
343 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
344 | |
345 | $try = "\$x = Math::BigInt->new(10); \$x = 2 - \$x;"; |
346 | $try .= "'ok' if \$x == -8;"; $ans = eval $try; |
347 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
348 | |
349 | $try = "\$x = Math::BigInt->new(10); \$x = 20 / \$x;"; |
350 | $try .= "'ok' if \$x == 2;"; $ans = eval $try; |
351 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
352 | |
353 | ############################################################################### |
354 | # check badd(4,5) form |
355 | |
356 | $try = "\$x = Math::BigInt::badd(4,5);"; |
357 | $try .= "'ok' if \$x == 9;"; |
358 | $ans = eval $try; |
359 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
360 | |
361 | $try = "\$x = Math::BigInt->badd(4,5);"; |
362 | $try .= "'ok' if \$x == 9;"; |
363 | $ans = eval $try; |
364 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
365 | |
366 | ############################################################################### |
574bacfe |
367 | # the followin tests only make sense with Math::BigInt::Calc |
368 | |
369 | ############################################################################### |
58cde26e |
370 | # check proper length of internal arrays |
371 | |
0716bf9b |
372 | $x = Math::BigInt->new(99999); is_valid($x); |
373 | $x += 1; ok ($x,100000); is_valid($x); |
374 | $x -= 1; ok ($x,99999); is_valid($x); |
58cde26e |
375 | |
376 | ############################################################################### |
574bacfe |
377 | # check numify |
58cde26e |
378 | |
0716bf9b |
379 | my $BASE = int(1e5); # should access Math::BigInt::Calc::BASE |
58cde26e |
380 | $x = Math::BigInt->new($BASE-1); ok ($x->numify(),$BASE-1); |
381 | $x = Math::BigInt->new(-($BASE-1)); ok ($x->numify(),-($BASE-1)); |
382 | $x = Math::BigInt->new($BASE); ok ($x->numify(),$BASE); |
383 | $x = Math::BigInt->new(-$BASE); ok ($x->numify(),-$BASE); |
384 | $x = Math::BigInt->new( -($BASE*$BASE*1+$BASE*1+1) ); |
385 | ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); |
386 | |
387 | ############################################################################### |
388 | # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1 |
389 | |
390 | $x = Math::BigInt->new(99998); $x++; $x++; $x++; $x++; |
391 | if ($x > 100000) { ok (1,1) } else { ok ("$x < 100000","$x > 100000"); } |
392 | |
393 | $x = Math::BigInt->new(100003); $x++; |
394 | $y = Math::BigInt->new(1000000); |
395 | if ($x < 1000000) { ok (1,1) } else { ok ("$x > 1000000","$x < 1000000"); } |
396 | |
397 | ############################################################################### |
398 | # bug in sub where number with at least 6 trailing zeros after any op failed |
399 | |
400 | $x = Math::BigInt->new(123456); $z = Math::BigInt->new(10000); $z *= 10; |
401 | $x -= $z; |
402 | ok ($z, 100000); |
403 | ok ($x, 23456); |
404 | |
405 | ############################################################################### |
574bacfe |
406 | # bug in shortcut in mul() |
407 | |
408 | # construct a number with a zero-hole of BASE_LEN |
409 | my $bl = Math::BigInt::Calc::_base_len(); |
410 | $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl; |
411 | $y = '1' x (2*$bl); |
412 | #print "$x * $y\n"; |
413 | $x = Math::BigInt->new($x)->bmul($y); |
414 | # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl |
415 | $y = ''; my $d = ''; |
416 | for (my $i = 1; $i <= $bl; $i++) |
417 | { |
418 | $y .= $i; $d = $i.$d; |
419 | } |
420 | #print "$y $d\n"; |
421 | $y .= $bl x (3*$bl-1) . $d . '0' x $bl; |
422 | ok ($x,$y); |
423 | |
424 | ############################################################################### |
58cde26e |
425 | # bug with rest "-0" in div, causing further div()s to fail |
426 | |
0716bf9b |
427 | $x = Math::BigInt->new('-322056000'); ($x,$y) = $x->bdiv('-12882240'); |
58cde26e |
428 | |
0716bf9b |
429 | ok ($y,'0','not -0'); # not '-0' |
58cde26e |
430 | is_valid($y); |
431 | |
432 | ############################################################################### |
433 | # check undefs: NOT DONE YET |
434 | |
435 | ############################################################################### |
436 | # bool |
437 | |
438 | $x = Math::BigInt->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') } |
439 | $x = Math::BigInt->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') } |
440 | |
441 | ############################################################################### |
442 | # objectify() |
443 | |
444 | @args = Math::BigInt::objectify(2,4,5); |
445 | ok (scalar @args,3); # 'Math::BigInt', 4, 5 |
446 | ok ($args[0],'Math::BigInt'); |
447 | ok ($args[1],4); |
448 | ok ($args[2],5); |
449 | |
450 | @args = Math::BigInt::objectify(0,4,5); |
451 | ok (scalar @args,3); # 'Math::BigInt', 4, 5 |
452 | ok ($args[0],'Math::BigInt'); |
453 | ok ($args[1],4); |
454 | ok ($args[2],5); |
455 | |
456 | @args = Math::BigInt::objectify(2,4,5); |
457 | ok (scalar @args,3); # 'Math::BigInt', 4, 5 |
458 | ok ($args[0],'Math::BigInt'); |
459 | ok ($args[1],4); |
460 | ok ($args[2],5); |
461 | |
462 | @args = Math::BigInt::objectify(2,4,5,6,7); |
463 | ok (scalar @args,5); # 'Math::BigInt', 4, 5, 6, 7 |
464 | ok ($args[0],'Math::BigInt'); |
465 | ok ($args[1],4); ok (ref($args[1]),$args[0]); |
466 | ok ($args[2],5); ok (ref($args[2]),$args[0]); |
467 | ok ($args[3],6); ok (ref($args[3]),''); |
468 | ok ($args[4],7); ok (ref($args[4]),''); |
469 | |
470 | @args = Math::BigInt::objectify(2,'Math::BigInt',4,5,6,7); |
471 | ok (scalar @args,5); # 'Math::BigInt', 4, 5, 6, 7 |
472 | ok ($args[0],'Math::BigInt'); |
473 | ok ($args[1],4); ok (ref($args[1]),$args[0]); |
474 | ok ($args[2],5); ok (ref($args[2]),$args[0]); |
475 | ok ($args[3],6); ok (ref($args[3]),''); |
476 | ok ($args[4],7); ok (ref($args[4]),''); |
477 | |
478 | ############################################################################### |
b22b3e31 |
479 | # test for floating-point input (other tests in bnorm() below) |
58cde26e |
480 | |
481 | $z = 1050000000000000; # may be int on systems with 64bit? |
0716bf9b |
482 | $x = Math::BigInt->new($z); ok ($x->bsstr(),'105e+13'); # not 1.03e+15 |
483 | $z = 1e+129; # definitely a float (may fail on UTS) |
484 | $x = Math::BigInt->new($z); ok ($x->bsstr(),$z); |
58cde26e |
485 | |
486 | ############################################################################### |
487 | # prime number tests, also test for **= and length() |
488 | # found on: http://www.utm.edu/research/primes/notes/by_year.html |
489 | |
490 | # ((2^148)-1)/17 |
491 | $x = Math::BigInt->new(2); $x **= 148; $x++; $x = $x / 17; |
492 | ok ($x,"20988936657440586486151264256610222593863921"); |
493 | ok ($x->length(),length "20988936657440586486151264256610222593863921"); |
494 | |
495 | # MM7 = 2^127-1 |
496 | $x = Math::BigInt->new(2); $x **= 127; $x--; |
497 | ok ($x,"170141183460469231731687303715884105727"); |
498 | |
499 | # I am afraid the following is not yet possible due to slowness |
500 | # Also, testing for 2 meg output is a bit hard ;) |
501 | #$x = new Math::BigInt(2); $x **= 6972593; $x--; |
502 | |
0716bf9b |
503 | # 593573509*2^332162+1 has exactly 1,000,000 digits |
b22b3e31 |
504 | # takes about 24 mins on 300 Mhz, so cannot be done yet ;) |
58cde26e |
505 | #$x = Math::BigInt->new(2); $x **= 332162; $x *= "593573509"; $x++; |
0716bf9b |
506 | #ok ($x->length(),1_000_000); |
58cde26e |
507 | |
508 | ############################################################################### |
509 | # inheritance and overriding of _swap |
510 | |
511 | $x = Math::Foo->new(5); |
512 | $x = $x - 8; # 8 - 5 instead of 5-8 |
513 | ok ($x,3); |
514 | ok (ref($x),'Math::Foo'); |
515 | |
516 | $x = Math::Foo->new(5); |
517 | $x = 8 - $x; # 5 - 8 instead of 8 - 5 |
518 | ok ($x,-3); |
519 | ok (ref($x),'Math::Foo'); |
520 | |
521 | ############################################################################### |
574bacfe |
522 | # test whether +inf eq inf |
523 | |
524 | $y = 1e1000000; # create inf, since bareword inf does not work |
525 | $x = Math::BigInt->new('+inf'); ok ($x,$y); |
526 | |
527 | ############################################################################### |
58cde26e |
528 | # all tests done |
529 | |
58cde26e |
530 | ############################################################################### |
531 | # Perl 5.005 does not like ok ($x,undef) |
532 | |
533 | sub ok_undef |
534 | { |
535 | my $x = shift; |
536 | |
537 | ok (1,1) and return if !defined $x; |
538 | ok ($x,'undef'); |
539 | } |
540 | |
541 | ############################################################################### |
542 | # sub to check validity of a BigInt internally, to ensure that no op leaves a |
543 | # number object in an invalid state (f.i. "-0") |
544 | |
545 | sub is_valid |
546 | { |
0716bf9b |
547 | my ($x,$f) = @_; |
58cde26e |
548 | |
0716bf9b |
549 | my $e = 0; # error? |
58cde26e |
550 | # ok as reference? |
0716bf9b |
551 | $e = 'Not a reference to Math::BigInt' if !ref($x); |
58cde26e |
552 | |
553 | # has ok sign? |
0716bf9b |
554 | $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'" |
555 | if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/; |
58cde26e |
556 | |
0716bf9b |
557 | $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0; |
558 | $e = $CALC->_check($x->{value}) if $e eq '0'; |
58cde26e |
559 | |
0716bf9b |
560 | # test done, see if error did crop up |
561 | ok (1,1), return if ($e eq '0'); |
58cde26e |
562 | |
0716bf9b |
563 | ok (1,$e." op '$f'"); |
a99f8827 |
564 | } |
58cde26e |
565 | |
748a9306 |
566 | __END__ |
574bacfe |
567 | &is_negative |
568 | 0:0 |
569 | -1:1 |
570 | 1:0 |
571 | +inf:0 |
572 | -inf:1 |
573 | NaNneg:0 |
574 | &is_positive |
575 | 0:1 |
576 | -1:0 |
577 | 1:1 |
578 | +inf:1 |
579 | -inf:0 |
580 | NaNneg:0 |
0716bf9b |
581 | &is_odd |
582 | abc:0 |
583 | 0:0 |
584 | 1:1 |
585 | 3:1 |
586 | -1:1 |
587 | -3:1 |
588 | 10000001:1 |
589 | 10000002:0 |
590 | 2:0 |
591 | &is_even |
592 | abc:0 |
593 | 0:1 |
594 | 1:0 |
595 | 3:0 |
596 | -1:0 |
597 | -3:0 |
598 | 10000001:0 |
599 | 10000002:1 |
600 | 2:1 |
601 | &bacmp |
602 | +0:-0:0 |
603 | +0:+1:-1 |
604 | -1:+1:0 |
605 | +1:-1:0 |
606 | -1:+2:-1 |
607 | +2:-1:1 |
608 | -123456789:+987654321:-1 |
609 | +123456789:-987654321:-1 |
610 | +987654321:+123456789:1 |
611 | -987654321:+123456789:1 |
612 | -123:+4567889:-1 |
574bacfe |
613 | # NaNs |
614 | acmpNaN:123: |
615 | 123:acmpNaN: |
616 | acmpNaN:acmpNaN: |
617 | # infinity |
618 | +inf:+inf:0 |
619 | -inf:-inf:0 |
620 | +inf:-inf:0 |
621 | -inf:+inf:0 |
622 | +inf:123:1 |
623 | -inf:123:1 |
624 | +inf:-123:1 |
625 | -inf:-123:1 |
626 | # return undef |
627 | +inf:NaN: |
628 | NaN:inf: |
629 | -inf:NaN: |
630 | NaN:-inf: |
748a9306 |
631 | &bnorm |
0716bf9b |
632 | 123:123 |
58cde26e |
633 | # binary input |
634 | 0babc:NaN |
635 | 0b123:NaN |
636 | 0b0:0 |
637 | -0b0:0 |
638 | -0b1:-1 |
639 | 0b0001:1 |
640 | 0b001:1 |
641 | 0b011:3 |
642 | 0b101:5 |
643 | 0b1000000000000000000000000000000:1073741824 |
574bacfe |
644 | 0b_101:NaN |
645 | 0b1_0_1:5 |
58cde26e |
646 | # hex input |
647 | -0x0:0 |
648 | 0xabcdefgh:NaN |
649 | 0x1234:4660 |
650 | 0xabcdef:11259375 |
651 | -0xABCDEF:-11259375 |
652 | -0x1234:-4660 |
653 | 0x12345678:305419896 |
574bacfe |
654 | 0x1_2_3_4_56_78:305419896 |
655 | 0x_123:NaN |
58cde26e |
656 | # inf input |
574bacfe |
657 | +inf:inf |
58cde26e |
658 | -inf:-inf |
659 | 0inf:NaN |
660 | # normal input |
661 | :NaN |
748a9306 |
662 | abc:NaN |
663 | 1 a:NaN |
664 | 1bcd2:NaN |
665 | 11111b:NaN |
666 | +1z:NaN |
667 | -1z:NaN |
58cde26e |
668 | 0:0 |
669 | +0:0 |
670 | +00:0 |
671 | +000:0 |
672 | 000000000000000000:0 |
673 | -0:0 |
674 | -0000:0 |
675 | +1:1 |
676 | +01:1 |
677 | +001:1 |
678 | +00000100000:100000 |
679 | 123456789:123456789 |
748a9306 |
680 | -1:-1 |
681 | -01:-1 |
682 | -001:-1 |
683 | -123456789:-123456789 |
684 | -00000100000:-100000 |
58cde26e |
685 | 1_2_3:123 |
686 | _123:NaN |
687 | _123_:NaN |
688 | _123_:NaN |
689 | 1__23:NaN |
690 | 10000000000E-1_0:1 |
691 | 1E2:100 |
692 | 1E1:10 |
693 | 1E0:1 |
694 | E1:NaN |
695 | E23:NaN |
696 | 1.23E2:123 |
697 | 1.23E1:NaN |
698 | 1.23E-1:NaN |
699 | 100E-1:10 |
700 | # floating point input |
701 | 1.01E2:101 |
702 | 1010E-1:101 |
703 | -1010E0:-1010 |
704 | -1010E1:-10100 |
705 | -1010E-2:NaN |
706 | -1.01E+1:NaN |
707 | -1.01E-1:NaN |
574bacfe |
708 | 1234.00:1234 |
709 | &bnan |
710 | 1:NaN |
711 | 2:NaN |
712 | abc:NaN |
713 | &bone |
714 | 2:+:+1 |
715 | 2:-:-1 |
716 | boneNaN:-:-1 |
717 | boneNaN:+:+1 |
718 | 2:abc:+1 |
719 | 3::+1 |
58cde26e |
720 | &binf |
574bacfe |
721 | 1:+:inf |
58cde26e |
722 | 2:-:-inf |
574bacfe |
723 | 3:abc:inf |
58cde26e |
724 | &is_inf |
725 | +inf::1 |
726 | -inf::1 |
727 | abc::0 |
728 | 1::0 |
729 | NaN::0 |
730 | -1::0 |
731 | +inf:-:0 |
732 | +inf:+:1 |
733 | -inf:-:1 |
734 | -inf:+:0 |
0716bf9b |
735 | # it must be exactly /^[+-]inf$/ |
736 | +infinity::0 |
737 | -infinity::0 |
58cde26e |
738 | &blsft |
739 | abc:abc:NaN |
740 | +2:+2:+8 |
741 | +1:+32:+4294967296 |
742 | +1:+48:+281474976710656 |
743 | +8:-2:NaN |
744 | # excercise base 10 |
745 | +12345:4:10:123450000 |
746 | -1234:0:10:-1234 |
747 | +1234:0:10:+1234 |
748 | +2:2:10:200 |
749 | +12:2:10:1200 |
750 | +1234:-3:10:NaN |
751 | 1234567890123:12:10:1234567890123000000000000 |
752 | &brsft |
753 | abc:abc:NaN |
754 | +8:+2:+2 |
755 | +4294967296:+32:+1 |
756 | +281474976710656:+48:+1 |
757 | +2:-2:NaN |
758 | # excercise base 10 |
759 | -1234:0:10:-1234 |
760 | +1234:0:10:+1234 |
761 | +200:2:10:2 |
762 | +1234:3:10:1 |
763 | +1234:2:10:12 |
764 | +1234:-3:10:NaN |
765 | 310000:4:10:31 |
766 | 12300000:5:10:123 |
767 | 1230000000000:10:10:123 |
768 | 09876123456789067890:12:10:9876123 |
769 | 1234561234567890123:13:10:123456 |
770 | &bsstr |
771 | 1e+34:1e+34 |
772 | 123.456E3:123456e+0 |
773 | 100:1e+2 |
774 | abc:NaN |
748a9306 |
775 | &bneg |
574bacfe |
776 | bnegNaN:NaN |
777 | +inf:-inf |
778 | -inf:inf |
748a9306 |
779 | abd:NaN |
780 | +0:+0 |
781 | +1:-1 |
782 | -1:+1 |
783 | +123456789:-123456789 |
784 | -123456789:+123456789 |
785 | &babs |
574bacfe |
786 | babsNaN:NaN |
787 | +inf:inf |
788 | -inf:inf |
748a9306 |
789 | +0:+0 |
790 | +1:+1 |
791 | -1:+1 |
792 | +123456789:+123456789 |
793 | -123456789:+123456789 |
794 | &bcmp |
574bacfe |
795 | bcmpNaN:bcmpNaN: |
796 | bcmpNaN:+0: |
797 | +0:bcmpNaN: |
5d7098d5 |
798 | +0:+0:0 |
748a9306 |
799 | -1:+0:-1 |
5d7098d5 |
800 | +0:-1:1 |
801 | +1:+0:1 |
748a9306 |
802 | +0:+1:-1 |
803 | -1:+1:-1 |
5d7098d5 |
804 | +1:-1:1 |
805 | -1:-1:0 |
806 | +1:+1:0 |
807 | +123:+123:0 |
808 | +123:+12:1 |
748a9306 |
809 | +12:+123:-1 |
5d7098d5 |
810 | -123:-123:0 |
748a9306 |
811 | -123:-12:-1 |
5d7098d5 |
812 | -12:-123:1 |
748a9306 |
813 | +123:+124:-1 |
5d7098d5 |
814 | +124:+123:1 |
815 | -123:-124:1 |
748a9306 |
816 | -124:-123:-1 |
5d7098d5 |
817 | +100:+5:1 |
58cde26e |
818 | -123456789:+987654321:-1 |
819 | +123456789:-987654321:1 |
820 | -987654321:+123456789:-1 |
0716bf9b |
821 | -inf:5432112345:-1 |
822 | +inf:5432112345:1 |
823 | -inf:-5432112345:-1 |
824 | +inf:-5432112345:1 |
825 | +inf:+inf:0 |
826 | -inf:-inf:0 |
574bacfe |
827 | +inf:-inf:1 |
828 | -inf:+inf:-1 |
0716bf9b |
829 | # return undef |
830 | +inf:NaN: |
574bacfe |
831 | NaN:inf: |
0716bf9b |
832 | -inf:NaN: |
833 | NaN:-inf: |
58cde26e |
834 | &binc |
835 | abc:NaN |
574bacfe |
836 | +inf:inf |
837 | -inf:-inf |
58cde26e |
838 | +0:+1 |
839 | +1:+2 |
840 | -1:+0 |
841 | &bdec |
842 | abc:NaN |
574bacfe |
843 | +inf:inf |
844 | -inf:-inf |
58cde26e |
845 | +0:-1 |
846 | +1:+0 |
847 | -1:-2 |
748a9306 |
848 | &badd |
849 | abc:abc:NaN |
850 | abc:+0:NaN |
851 | +0:abc:NaN |
574bacfe |
852 | +inf:-inf:0 |
853 | -inf:+inf:0 |
854 | +inf:+inf:inf |
855 | -inf:-inf:-inf |
856 | baddNaN:+inf:NaN |
857 | baddNaN:+inf:NaN |
858 | +inf:baddNaN:NaN |
859 | -inf:baddNaN:NaN |
748a9306 |
860 | +0:+0:+0 |
861 | +1:+0:+1 |
862 | +0:+1:+1 |
863 | +1:+1:+2 |
864 | -1:+0:-1 |
865 | +0:-1:-1 |
866 | -1:-1:-2 |
867 | -1:+1:+0 |
868 | +1:-1:+0 |
869 | +9:+1:+10 |
870 | +99:+1:+100 |
871 | +999:+1:+1000 |
872 | +9999:+1:+10000 |
873 | +99999:+1:+100000 |
874 | +999999:+1:+1000000 |
875 | +9999999:+1:+10000000 |
876 | +99999999:+1:+100000000 |
877 | +999999999:+1:+1000000000 |
878 | +9999999999:+1:+10000000000 |
879 | +99999999999:+1:+100000000000 |
880 | +10:-1:+9 |
881 | +100:-1:+99 |
882 | +1000:-1:+999 |
883 | +10000:-1:+9999 |
884 | +100000:-1:+99999 |
885 | +1000000:-1:+999999 |
886 | +10000000:-1:+9999999 |
887 | +100000000:-1:+99999999 |
888 | +1000000000:-1:+999999999 |
889 | +10000000000:-1:+9999999999 |
890 | +123456789:+987654321:+1111111110 |
891 | -123456789:+987654321:+864197532 |
892 | -123456789:-987654321:-1111111110 |
893 | +123456789:-987654321:-864197532 |
894 | &bsub |
895 | abc:abc:NaN |
896 | abc:+0:NaN |
897 | +0:abc:NaN |
574bacfe |
898 | +inf:-inf:inf |
899 | -inf:+inf:-inf |
900 | +inf:+inf:0 |
901 | -inf:-inf:0 |
748a9306 |
902 | +0:+0:+0 |
903 | +1:+0:+1 |
904 | +0:+1:-1 |
905 | +1:+1:+0 |
906 | -1:+0:-1 |
907 | +0:-1:+1 |
908 | -1:-1:+0 |
909 | -1:+1:-2 |
910 | +1:-1:+2 |
911 | +9:+1:+8 |
912 | +99:+1:+98 |
913 | +999:+1:+998 |
914 | +9999:+1:+9998 |
915 | +99999:+1:+99998 |
916 | +999999:+1:+999998 |
917 | +9999999:+1:+9999998 |
918 | +99999999:+1:+99999998 |
919 | +999999999:+1:+999999998 |
920 | +9999999999:+1:+9999999998 |
921 | +99999999999:+1:+99999999998 |
922 | +10:-1:+11 |
923 | +100:-1:+101 |
924 | +1000:-1:+1001 |
925 | +10000:-1:+10001 |
926 | +100000:-1:+100001 |
927 | +1000000:-1:+1000001 |
928 | +10000000:-1:+10000001 |
929 | +100000000:-1:+100000001 |
930 | +1000000000:-1:+1000000001 |
931 | +10000000000:-1:+10000000001 |
932 | +123456789:+987654321:-864197532 |
933 | -123456789:+987654321:-1111111110 |
934 | -123456789:-987654321:+864197532 |
935 | +123456789:-987654321:+1111111110 |
936 | &bmul |
937 | abc:abc:NaN |
938 | abc:+0:NaN |
939 | +0:abc:NaN |
574bacfe |
940 | NaNmul:+inf:NaN |
941 | NaNmul:-inf:NaN |
942 | -inf:NaNmul:NaN |
943 | +inf:NaNmul:NaN |
944 | +inf:+inf:inf |
945 | +inf:-inf:-inf |
946 | -inf:+inf:-inf |
947 | -inf:-inf:inf |
748a9306 |
948 | +0:+0:+0 |
949 | +0:+1:+0 |
950 | +1:+0:+0 |
951 | +0:-1:+0 |
952 | -1:+0:+0 |
953 | +123456789123456789:+0:+0 |
954 | +0:+123456789123456789:+0 |
955 | -1:-1:+1 |
956 | -1:+1:-1 |
957 | +1:-1:-1 |
958 | +1:+1:+1 |
959 | +2:+3:+6 |
960 | -2:+3:-6 |
961 | +2:-3:-6 |
962 | -2:-3:+6 |
963 | +111:+111:+12321 |
964 | +10101:+10101:+102030201 |
965 | +1001001:+1001001:+1002003002001 |
966 | +100010001:+100010001:+10002000300020001 |
967 | +10000100001:+10000100001:+100002000030000200001 |
968 | +11111111111:+9:+99999999999 |
969 | +22222222222:+9:+199999999998 |
970 | +33333333333:+9:+299999999997 |
971 | +44444444444:+9:+399999999996 |
972 | +55555555555:+9:+499999999995 |
973 | +66666666666:+9:+599999999994 |
974 | +77777777777:+9:+699999999993 |
975 | +88888888888:+9:+799999999992 |
976 | +99999999999:+9:+899999999991 |
58cde26e |
977 | +25:+25:+625 |
978 | +12345:+12345:+152399025 |
979 | +99999:+11111:+1111088889 |
574bacfe |
980 | &bdiv-list |
981 | 100:20:5,0 |
982 | 4095:4095:1,0 |
983 | -4095:-4095:1,0 |
984 | 4095:-4095:-1,0 |
985 | -4095:4095:-1,0 |
748a9306 |
986 | &bdiv |
987 | abc:abc:NaN |
988 | abc:+1:abc:NaN |
989 | +1:abc:NaN |
990 | +0:+0:NaN |
574bacfe |
991 | +5:0:inf |
992 | -5:0:-inf |
993 | +1:+0:inf |
748a9306 |
994 | +0:+1:+0 |
748a9306 |
995 | +0:-1:+0 |
574bacfe |
996 | -1:+0:-inf |
748a9306 |
997 | +1:+1:+1 |
998 | -1:-1:+1 |
999 | +1:-1:-1 |
1000 | -1:+1:-1 |
1001 | +1:+2:+0 |
1002 | +2:+1:+2 |
58cde26e |
1003 | +1:+26:+0 |
748a9306 |
1004 | +1000000000:+9:+111111111 |
1005 | +2000000000:+9:+222222222 |
1006 | +3000000000:+9:+333333333 |
1007 | +4000000000:+9:+444444444 |
1008 | +5000000000:+9:+555555555 |
1009 | +6000000000:+9:+666666666 |
1010 | +7000000000:+9:+777777777 |
1011 | +8000000000:+9:+888888888 |
1012 | +9000000000:+9:+1000000000 |
1013 | +35500000:+113:+314159 |
1014 | +71000000:+226:+314159 |
1015 | +106500000:+339:+314159 |
1016 | +1000000000:+3:+333333333 |
1017 | +10:+5:+2 |
1018 | +100:+4:+25 |
1019 | +1000:+8:+125 |
1020 | +10000:+16:+625 |
1021 | +999999999999:+9:+111111111111 |
1022 | +999999999999:+99:+10101010101 |
1023 | +999999999999:+999:+1001001001 |
1024 | +999999999999:+9999:+100010001 |
1025 | +999999999999999:+99999:+10000100001 |
58cde26e |
1026 | +1111088889:+99999:+11111 |
1027 | -5:-3:1 |
1028 | 4:3:1 |
1029 | 1:3:0 |
1030 | -2:-3:0 |
1031 | -2:3:-1 |
1032 | 1:-3:-1 |
1033 | -5:3:-2 |
1034 | 4:-3:-2 |
574bacfe |
1035 | 123:+inf:0 |
1036 | 123:-inf:0 |
748a9306 |
1037 | &bmod |
1038 | abc:abc:NaN |
1039 | abc:+1:abc:NaN |
1040 | +1:abc:NaN |
1041 | +0:+0:NaN |
1042 | +0:+1:+0 |
1043 | +1:+0:NaN |
1044 | +0:-1:+0 |
1045 | -1:+0:NaN |
1046 | +1:+1:+0 |
1047 | -1:-1:+0 |
1048 | +1:-1:+0 |
1049 | -1:+1:+0 |
1050 | +1:+2:+1 |
1051 | +2:+1:+0 |
1052 | +1000000000:+9:+1 |
1053 | +2000000000:+9:+2 |
1054 | +3000000000:+9:+3 |
1055 | +4000000000:+9:+4 |
1056 | +5000000000:+9:+5 |
1057 | +6000000000:+9:+6 |
1058 | +7000000000:+9:+7 |
1059 | +8000000000:+9:+8 |
1060 | +9000000000:+9:+0 |
1061 | +35500000:+113:+33 |
1062 | +71000000:+226:+66 |
1063 | +106500000:+339:+99 |
1064 | +1000000000:+3:+1 |
1065 | +10:+5:+0 |
1066 | +100:+4:+0 |
1067 | +1000:+8:+0 |
1068 | +10000:+16:+0 |
1069 | +999999999999:+9:+0 |
1070 | +999999999999:+99:+0 |
1071 | +999999999999:+999:+0 |
1072 | +999999999999:+9999:+0 |
1073 | +999999999999999:+99999:+0 |
58cde26e |
1074 | -9:+5:+1 |
1075 | +9:-5:-1 |
1076 | -9:-5:-4 |
1077 | -5:3:1 |
1078 | -2:3:1 |
1079 | 4:3:1 |
1080 | 1:3:1 |
1081 | -5:-3:-2 |
1082 | -2:-3:-2 |
1083 | 4:-3:-2 |
1084 | 1:-3:-2 |
574bacfe |
1085 | 4095:4095:0 |
748a9306 |
1086 | &bgcd |
1087 | abc:abc:NaN |
1088 | abc:+0:NaN |
1089 | +0:abc:NaN |
1090 | +0:+0:+0 |
1091 | +0:+1:+1 |
1092 | +1:+0:+1 |
1093 | +1:+1:+1 |
1094 | +2:+3:+1 |
1095 | +3:+2:+1 |
58cde26e |
1096 | -3:+2:+1 |
748a9306 |
1097 | +100:+625:+25 |
1098 | +4096:+81:+1 |
58cde26e |
1099 | +1034:+804:+2 |
1100 | +27:+90:+56:+1 |
1101 | +27:+90:+54:+9 |
1102 | &blcm |
e16b8f49 |
1103 | abc:abc:NaN |
58cde26e |
1104 | abc:+0:NaN |
1105 | +0:abc:NaN |
1106 | +0:+0:NaN |
1107 | +1:+0:+0 |
1108 | +0:+1:+0 |
1109 | +27:+90:+270 |
1110 | +1034:+804:+415668 |
e16b8f49 |
1111 | &band |
1112 | abc:abc:NaN |
58cde26e |
1113 | abc:0:NaN |
1114 | 0:abc:NaN |
0716bf9b |
1115 | 1:2:0 |
1116 | 3:2:2 |
e16b8f49 |
1117 | +8:+2:+0 |
1118 | +281474976710656:+0:+0 |
1119 | +281474976710656:+1:+0 |
1120 | +281474976710656:+281474976710656:+281474976710656 |
574bacfe |
1121 | -2:-3:-4 |
1122 | -1:-1:-1 |
1123 | -6:-6:-6 |
1124 | -7:-4:-8 |
1125 | -7:4:0 |
1126 | -4:7:4 |
e16b8f49 |
1127 | &bior |
1128 | abc:abc:NaN |
58cde26e |
1129 | abc:0:NaN |
1130 | 0:abc:NaN |
0716bf9b |
1131 | 1:2:3 |
e16b8f49 |
1132 | +8:+2:+10 |
1133 | +281474976710656:+0:+281474976710656 |
1134 | +281474976710656:+1:+281474976710657 |
1135 | +281474976710656:+281474976710656:+281474976710656 |
574bacfe |
1136 | -2:-3:-1 |
1137 | -1:-1:-1 |
1138 | -6:-6:-6 |
1139 | -7:4:-3 |
1140 | -4:7:-1 |
e16b8f49 |
1141 | &bxor |
1142 | abc:abc:NaN |
58cde26e |
1143 | abc:0:NaN |
1144 | 0:abc:NaN |
0716bf9b |
1145 | 1:2:3 |
e16b8f49 |
1146 | +8:+2:+10 |
1147 | +281474976710656:+0:+281474976710656 |
1148 | +281474976710656:+1:+281474976710657 |
1149 | +281474976710656:+281474976710656:+0 |
574bacfe |
1150 | -2:-3:3 |
1151 | -1:-1:0 |
1152 | -6:-6:0 |
1153 | -7:4:-3 |
1154 | -4:7:-5 |
1155 | 4:-7:-3 |
1156 | -4:-7:5 |
e16b8f49 |
1157 | &bnot |
1158 | abc:NaN |
1159 | +0:-1 |
1160 | +8:-9 |
1161 | +281474976710656:-281474976710657 |
574bacfe |
1162 | -1:0 |
1163 | -2:1 |
1164 | -12:11 |
58cde26e |
1165 | &digit |
1166 | 0:0:0 |
1167 | 12:0:2 |
1168 | 12:1:1 |
1169 | 123:0:3 |
1170 | 123:1:2 |
1171 | 123:2:1 |
1172 | 123:-1:1 |
1173 | 123:-2:2 |
1174 | 123:-3:3 |
1175 | 123456:0:6 |
1176 | 123456:1:5 |
1177 | 123456:2:4 |
1178 | 123456:3:3 |
1179 | 123456:4:2 |
1180 | 123456:5:1 |
1181 | 123456:-1:1 |
1182 | 123456:-2:2 |
1183 | 123456:-3:3 |
1184 | 100000:-3:0 |
1185 | 100000:0:0 |
1186 | 100000:1:0 |
1187 | &mantissa |
1188 | abc:NaN |
1189 | 1e4:1 |
1190 | 2e0:2 |
1191 | 123:123 |
1192 | -1:-1 |
1193 | -2:-2 |
1194 | &exponent |
1195 | abc:NaN |
1196 | 1e4:4 |
1197 | 2e0:0 |
1198 | 123:0 |
1199 | -1:0 |
1200 | -2:0 |
1201 | 0:1 |
1202 | &parts |
1203 | abc:NaN,NaN |
1204 | 1e4:1,4 |
1205 | 2e0:2,0 |
1206 | 123:123,0 |
1207 | -1:-1,0 |
1208 | -2:-2,0 |
1209 | 0:0,1 |
1210 | &bpow |
0716bf9b |
1211 | abc:12:NaN |
1212 | 12:abc:NaN |
58cde26e |
1213 | 0:0:1 |
1214 | 0:1:0 |
1215 | 0:2:0 |
1216 | 0:-1:NaN |
1217 | 0:-2:NaN |
1218 | 1:0:1 |
1219 | 1:1:1 |
1220 | 1:2:1 |
1221 | 1:3:1 |
1222 | 1:-1:1 |
1223 | 1:-2:1 |
1224 | 1:-3:1 |
1225 | 2:0:1 |
1226 | 2:1:2 |
1227 | 2:2:4 |
1228 | 2:3:8 |
1229 | 3:3:27 |
1230 | 2:-1:NaN |
1231 | -2:-1:NaN |
1232 | 2:-2:NaN |
1233 | -2:-2:NaN |
574bacfe |
1234 | +inf:1234500012:inf |
0716bf9b |
1235 | -inf:1234500012:-inf |
574bacfe |
1236 | +inf:-12345000123:inf |
0716bf9b |
1237 | -inf:-12345000123:-inf |
58cde26e |
1238 | # 1 ** -x => 1 / (1 ** x) |
1239 | -1:0:1 |
1240 | -2:0:1 |
1241 | -1:1:-1 |
1242 | -1:2:1 |
1243 | -1:3:-1 |
1244 | -1:4:1 |
1245 | -1:5:-1 |
1246 | -1:-1:-1 |
1247 | -1:-2:1 |
1248 | -1:-3:-1 |
1249 | -1:-4:1 |
1250 | 10:2:100 |
1251 | 10:3:1000 |
1252 | 10:4:10000 |
1253 | 10:5:100000 |
1254 | 10:6:1000000 |
1255 | 10:7:10000000 |
1256 | 10:8:100000000 |
1257 | 10:9:1000000000 |
1258 | 10:20:100000000000000000000 |
1259 | 123456:2:15241383936 |
1260 | &length |
1261 | 100:3 |
1262 | 10:2 |
1263 | 1:1 |
1264 | 0:1 |
1265 | 12345:5 |
1266 | 10000000000000000:17 |
1267 | -123:3 |
1268 | &bsqrt |
1269 | 144:12 |
1270 | 16:4 |
1271 | 4:2 |
1272 | 2:1 |
1273 | 12:3 |
1274 | 256:16 |
1275 | 100000000:10000 |
1276 | 4000000000000:2000000 |
1277 | 1:1 |
1278 | 0:0 |
1279 | -2:NaN |
1280 | Nan:NaN |
1281 | &bround |
1282 | $round_mode('trunc') |
574bacfe |
1283 | 0:12:0 |
1284 | NaNbround:12:NaN |
1285 | +inf:12:inf |
1286 | -inf:12:-inf |
58cde26e |
1287 | 1234:0:1234 |
1288 | 1234:2:1200 |
1289 | 123456:4:123400 |
1290 | 123456:5:123450 |
1291 | 123456:6:123456 |
1292 | +10123456789:5:+10123000000 |
1293 | -10123456789:5:-10123000000 |
1294 | +10123456789:9:+10123456700 |
1295 | -10123456789:9:-10123456700 |
1296 | +101234500:6:+101234000 |
1297 | -101234500:6:-101234000 |
1298 | #+101234500:-4:+101234000 |
1299 | #-101234500:-4:-101234000 |
1300 | $round_mode('zero') |
1301 | +20123456789:5:+20123000000 |
1302 | -20123456789:5:-20123000000 |
1303 | +20123456789:9:+20123456800 |
1304 | -20123456789:9:-20123456800 |
1305 | +201234500:6:+201234000 |
1306 | -201234500:6:-201234000 |
1307 | #+201234500:-4:+201234000 |
1308 | #-201234500:-4:-201234000 |
1309 | +12345000:4:12340000 |
1310 | -12345000:4:-12340000 |
1311 | $round_mode('+inf') |
1312 | +30123456789:5:+30123000000 |
1313 | -30123456789:5:-30123000000 |
1314 | +30123456789:9:+30123456800 |
1315 | -30123456789:9:-30123456800 |
1316 | +301234500:6:+301235000 |
1317 | -301234500:6:-301234000 |
1318 | #+301234500:-4:+301235000 |
1319 | #-301234500:-4:-301234000 |
1320 | +12345000:4:12350000 |
1321 | -12345000:4:-12340000 |
1322 | $round_mode('-inf') |
1323 | +40123456789:5:+40123000000 |
1324 | -40123456789:5:-40123000000 |
1325 | +40123456789:9:+40123456800 |
1326 | -40123456789:9:-40123456800 |
1327 | +401234500:6:+401234000 |
1328 | +401234500:6:+401234000 |
1329 | #-401234500:-4:-401235000 |
1330 | #-401234500:-4:-401235000 |
1331 | +12345000:4:12340000 |
1332 | -12345000:4:-12350000 |
1333 | $round_mode('odd') |
1334 | +50123456789:5:+50123000000 |
1335 | -50123456789:5:-50123000000 |
1336 | +50123456789:9:+50123456800 |
1337 | -50123456789:9:-50123456800 |
1338 | +501234500:6:+501235000 |
1339 | -501234500:6:-501235000 |
1340 | #+501234500:-4:+501235000 |
1341 | #-501234500:-4:-501235000 |
1342 | +12345000:4:12350000 |
1343 | -12345000:4:-12350000 |
1344 | $round_mode('even') |
1345 | +60123456789:5:+60123000000 |
1346 | -60123456789:5:-60123000000 |
1347 | +60123456789:9:+60123456800 |
1348 | -60123456789:9:-60123456800 |
1349 | +601234500:6:+601234000 |
1350 | -601234500:6:-601234000 |
1351 | #+601234500:-4:+601234000 |
1352 | #-601234500:-4:-601234000 |
1353 | #-601234500:-9:0 |
1354 | #-501234500:-9:0 |
1355 | #-601234500:-8:0 |
1356 | #-501234500:-8:0 |
1357 | +1234567:7:1234567 |
1358 | +1234567:6:1234570 |
1359 | +12345000:4:12340000 |
1360 | -12345000:4:-12340000 |
58cde26e |
1361 | &is_zero |
1362 | 0:1 |
1363 | NaNzero:0 |
574bacfe |
1364 | +inf:0 |
1365 | -inf:0 |
58cde26e |
1366 | 123:0 |
1367 | -1:0 |
1368 | 1:0 |
58cde26e |
1369 | &is_one |
1370 | 0:0 |
574bacfe |
1371 | NaNone:0 |
1372 | +inf:0 |
1373 | -inf:0 |
58cde26e |
1374 | 1:1 |
1375 | 2:0 |
1376 | -1:0 |
1377 | -2:0 |
1378 | # floor and ceil tests are pretty pointless in integer space...but play safe |
1379 | &bfloor |
1380 | 0:0 |
574bacfe |
1381 | NaNfloor:NaN |
1382 | +inf:inf |
1383 | -inf:-inf |
f216259d |
1384 | -1:-1 |
58cde26e |
1385 | -2:-2 |
1386 | 2:2 |
1387 | 3:3 |
1388 | abc:NaN |
1389 | &bceil |
574bacfe |
1390 | NaNceil:NaN |
1391 | +inf:inf |
1392 | -inf:-inf |
58cde26e |
1393 | 0:0 |
1394 | -1:-1 |
1395 | -2:-2 |
1396 | 2:2 |
1397 | 3:3 |
1398 | abc:NaN |