Upgrade to Math::BigInt 1.41.
[p5sagit/p5-mst-13.2.git] / lib / Math / BigInt / t / bigintpm.t
1 #!/usr/bin/perl -w
2
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
11   plan tests => 1424;
12   }
13 my $version = '1.40';   # for $VERSION tests, match current release (by hand!)
14
15 ##############################################################################
16 # for testing inheritance of _swap
17
18 package Math::Foo;
19
20 use Math::BigInt;
21 #use Math::BigInt lib => 'BitVect';     # for testing
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;
47
48 use Math::BigInt;
49 #use Math::BigInt lib => 'BitVect';     # for testing
50
51 my $CALC = Math::BigInt::_core_lib(); ok ($CALC,'Math::BigInt::Calc');
52
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;';
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;';
84     } elsif ($f eq "is_negative") {
85       $try .= '$x->is_negative()+0;';
86     } elsif ($f eq "is_positive") {
87       $try .= '$x->is_positive()+0;';
88     } elsif ($f eq "is_inf") {
89       $try .= "\$x->is_inf('$args[1]')+0;";
90     } elsif ($f eq "binf") {
91       $try .= "\$x->binf('$args[1]');";
92     } elsif ($f eq "bone") {
93       $try .= "\$x->bone('$args[1]');";
94     } elsif ($f eq "bnan") {
95       $try .= "\$x->bnan();";
96     } elsif ($f eq "bfloor") {
97       $try .= '$x->bfloor();';
98     } elsif ($f eq "bceil") {
99       $try .= '$x->bceil();';
100     } elsif ($f eq "bsstr") {
101       $try .= '$x->bsstr();';
102     } elsif ($f eq "bneg") {
103       $try .= '$x->bneg();';
104     } elsif ($f eq "babs") {
105       $try .= '$x->babs();';
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();";
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 {
126       $try .= "\$y = new Math::BigInt ('$args[1]');";
127       if ($f eq "bcmp"){
128         $try .= '$x <=> $y;';
129       }elsif ($f eq "bround") {
130       $try .= "$round_mode; \$x->bround(\$y);";
131       }elsif ($f eq "bacmp"){
132         $try .= "\$x->bacmp(\$y);";
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;";
141       }elsif ($f eq "bdiv-list"){
142         $try .= 'join (",",$x->bdiv($y));';
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
207     is_valid($ans1,$f) if ref $ans1; 
208     }
209   } # endwhile data tests
210 close DATA;
211
212 # XXX Tels 06/29/2001 following tests never fail or do not work :( !?
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";';
217 $ans1 = eval $try;
218 ok_undef ( $_ );                # should result in error!
219
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;
224 ok ( $ans1, "1427247692705959881058285969449495136382746624");
225
226 # test wether Math::BigInt::Small via use works (w/ dff. spellings of calc)
227 #$try = "use Math::BigInt ($version,'lib','Small');";
228 #$try .= ' $x = 2**10; $x = "$x";';
229 #$ans1 = eval $try;
230 #ok ( $ans1, "1024");
231 #$try = "use Math::BigInt ($version,'LiB','Math::BigInt::Small');";
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
236 #$try = "use Math::BigInt ($version,'LIB');";
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
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
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
256 # test whether self-multiplication works correctly (result is 2**64)
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);
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);
266
267 # test whether op destroys args or not (should better not)
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 ###############################################################################
367 # the followin tests only make sense with Math::BigInt::Calc
368
369 ###############################################################################
370 # check proper length of internal arrays
371
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); 
375
376 ###############################################################################
377 # check numify
378
379 my $BASE = int(1e5);            # should access Math::BigInt::Calc::BASE
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 ###############################################################################
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 ###############################################################################
425 # bug with rest "-0" in div, causing further div()s to fail
426
427 $x = Math::BigInt->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
428
429 ok ($y,'0','not -0');   # not '-0'
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 ###############################################################################
479 # test for floating-point input (other tests in bnorm() below)
480
481 $z = 1050000000000000;          # may be int on systems with 64bit?
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);
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
503 # 593573509*2^332162+1 has exactly 1,000,000 digits
504 # takes about 24 mins on 300 Mhz, so cannot be done yet ;)
505 #$x = Math::BigInt->new(2); $x **= 332162; $x *= "593573509"; $x++;
506 #ok ($x->length(),1_000_000);
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 ###############################################################################
522 # Test whether +inf eq inf
523 # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
524 # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
525 # like 1e100000 crash on some platforms. So simple test for 'inf'
526 $x = Math::BigInt->new('+inf'); ok ($x,'inf');
527
528 ###############################################################################
529 # all tests done
530
531 ###############################################################################
532 # Perl 5.005 does not like ok ($x,undef)
533
534 sub ok_undef
535   {
536   my $x = shift;
537
538   ok (1,1) and return if !defined $x;
539   ok ($x,'undef');
540   }
541
542 ###############################################################################
543 # sub to check validity of a BigInt internally, to ensure that no op leaves a
544 # number object in an invalid state (f.i. "-0")
545
546 sub is_valid
547   {
548   my ($x,$f) = @_;
549
550   my $e = 0;                    # error?
551   # ok as reference? 
552   $e = 'Not a reference to Math::BigInt' if !ref($x);
553
554   # has ok sign?
555   $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
556    if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
557
558   $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
559   $e = $CALC->_check($x->{value}) if $e eq '0';
560
561   # test done, see if error did crop up
562   ok (1,1), return if ($e eq '0');
563
564   ok (1,$e." op '$f'");
565   }
566
567 __END__
568 &is_negative
569 0:0
570 -1:1
571 1:0
572 +inf:0
573 -inf:1
574 NaNneg:0
575 &is_positive
576 0:1
577 -1:0
578 1:1
579 +inf:1
580 -inf:0
581 NaNneg:0
582 &is_odd
583 abc:0
584 0:0
585 1:1
586 3:1
587 -1:1
588 -3:1
589 10000001:1
590 10000002:0
591 2:0
592 &is_even
593 abc:0
594 0:1
595 1:0
596 3:0
597 -1:0
598 -3:0
599 10000001:0
600 10000002:1
601 2:1
602 &bacmp
603 +0:-0:0
604 +0:+1:-1
605 -1:+1:0
606 +1:-1:0
607 -1:+2:-1
608 +2:-1:1
609 -123456789:+987654321:-1
610 +123456789:-987654321:-1
611 +987654321:+123456789:1
612 -987654321:+123456789:1
613 -123:+4567889:-1
614 # NaNs
615 acmpNaN:123:
616 123:acmpNaN:
617 acmpNaN:acmpNaN:
618 # infinity
619 +inf:+inf:0
620 -inf:-inf:0
621 +inf:-inf:0
622 -inf:+inf:0
623 +inf:123:1
624 -inf:123:1
625 +inf:-123:1
626 -inf:-123:1
627 # return undef
628 +inf:NaN:
629 NaN:inf:
630 -inf:NaN:
631 NaN:-inf:
632 &bnorm
633 123:123
634 # binary input
635 0babc:NaN
636 0b123:NaN
637 0b0:0
638 -0b0:0
639 -0b1:-1
640 0b0001:1
641 0b001:1
642 0b011:3
643 0b101:5
644 0b1000000000000000000000000000000:1073741824
645 0b_101:NaN
646 0b1_0_1:5
647 # hex input
648 -0x0:0
649 0xabcdefgh:NaN
650 0x1234:4660
651 0xabcdef:11259375
652 -0xABCDEF:-11259375
653 -0x1234:-4660
654 0x12345678:305419896
655 0x1_2_3_4_56_78:305419896
656 0x_123:NaN
657 # inf input
658 +inf:inf
659 -inf:-inf
660 0inf:NaN
661 # normal input
662 :NaN
663 abc:NaN
664    1 a:NaN
665 1bcd2:NaN
666 11111b:NaN
667 +1z:NaN
668 -1z:NaN
669 0:0
670 +0:0
671 +00:0
672 +000:0
673 000000000000000000:0
674 -0:0
675 -0000:0
676 +1:1
677 +01:1
678 +001:1
679 +00000100000:100000
680 123456789:123456789
681 -1:-1
682 -01:-1
683 -001:-1
684 -123456789:-123456789
685 -00000100000:-100000
686 1_2_3:123
687 _123:NaN
688 _123_:NaN
689 _123_:NaN
690 1__23:NaN
691 10000000000E-1_0:1
692 1E2:100
693 1E1:10
694 1E0:1
695 E1:NaN
696 E23:NaN
697 1.23E2:123
698 1.23E1:NaN
699 1.23E-1:NaN
700 100E-1:10
701 # floating point input
702 1.01E2:101
703 1010E-1:101
704 -1010E0:-1010
705 -1010E1:-10100
706 -1010E-2:NaN
707 -1.01E+1:NaN
708 -1.01E-1:NaN
709 1234.00:1234
710 &bnan
711 1:NaN
712 2:NaN
713 abc:NaN
714 &bone
715 2:+:+1
716 2:-:-1
717 boneNaN:-:-1
718 boneNaN:+:+1
719 2:abc:+1
720 3::+1
721 &binf
722 1:+:inf
723 2:-:-inf
724 3:abc:inf
725 &is_inf
726 +inf::1
727 -inf::1
728 abc::0
729 1::0
730 NaN::0
731 -1::0
732 +inf:-:0
733 +inf:+:1
734 -inf:-:1
735 -inf:+:0
736 # it must be exactly /^[+-]inf$/
737 +infinity::0
738 -infinity::0
739 &blsft
740 abc:abc:NaN
741 +2:+2:+8
742 +1:+32:+4294967296
743 +1:+48:+281474976710656
744 +8:-2:NaN
745 # excercise base 10
746 +12345:4:10:123450000
747 -1234:0:10:-1234
748 +1234:0:10:+1234
749 +2:2:10:200
750 +12:2:10:1200
751 +1234:-3:10:NaN
752 1234567890123:12:10:1234567890123000000000000
753 &brsft
754 abc:abc:NaN
755 +8:+2:+2
756 +4294967296:+32:+1
757 +281474976710656:+48:+1
758 +2:-2:NaN
759 # excercise base 10
760 -1234:0:10:-1234
761 +1234:0:10:+1234
762 +200:2:10:2
763 +1234:3:10:1
764 +1234:2:10:12
765 +1234:-3:10:NaN
766 310000:4:10:31
767 12300000:5:10:123
768 1230000000000:10:10:123
769 09876123456789067890:12:10:9876123
770 1234561234567890123:13:10:123456
771 &bsstr
772 1e+34:1e+34
773 123.456E3:123456e+0
774 100:1e+2
775 abc:NaN
776 &bneg
777 bnegNaN:NaN
778 +inf:-inf
779 -inf:inf
780 abd:NaN
781 +0:+0
782 +1:-1
783 -1:+1
784 +123456789:-123456789
785 -123456789:+123456789
786 &babs
787 babsNaN:NaN
788 +inf:inf
789 -inf:inf
790 +0:+0
791 +1:+1
792 -1:+1
793 +123456789:+123456789
794 -123456789:+123456789
795 &bcmp
796 bcmpNaN:bcmpNaN:
797 bcmpNaN:+0:
798 +0:bcmpNaN:
799 +0:+0:0
800 -1:+0:-1
801 +0:-1:1
802 +1:+0:1
803 +0:+1:-1
804 -1:+1:-1
805 +1:-1:1
806 -1:-1:0
807 +1:+1:0
808 +123:+123:0
809 +123:+12:1
810 +12:+123:-1
811 -123:-123:0
812 -123:-12:-1
813 -12:-123:1
814 +123:+124:-1
815 +124:+123:1
816 -123:-124:1
817 -124:-123:-1
818 +100:+5:1
819 -123456789:+987654321:-1
820 +123456789:-987654321:1
821 -987654321:+123456789:-1
822 -inf:5432112345:-1
823 +inf:5432112345:1
824 -inf:-5432112345:-1
825 +inf:-5432112345:1
826 +inf:+inf:0
827 -inf:-inf:0
828 +inf:-inf:1
829 -inf:+inf:-1
830 # return undef
831 +inf:NaN:
832 NaN:inf:
833 -inf:NaN:
834 NaN:-inf:
835 &binc
836 abc:NaN
837 +inf:inf
838 -inf:-inf
839 +0:+1
840 +1:+2
841 -1:+0
842 &bdec
843 abc:NaN
844 +inf:inf
845 -inf:-inf
846 +0:-1
847 +1:+0
848 -1:-2
849 &badd
850 abc:abc:NaN
851 abc:+0:NaN
852 +0:abc:NaN
853 +inf:-inf:0
854 -inf:+inf:0
855 +inf:+inf:inf
856 -inf:-inf:-inf
857 baddNaN:+inf:NaN
858 baddNaN:+inf:NaN
859 +inf:baddNaN:NaN
860 -inf:baddNaN:NaN
861 +0:+0:+0
862 +1:+0:+1
863 +0:+1:+1
864 +1:+1:+2
865 -1:+0:-1
866 +0:-1:-1
867 -1:-1:-2
868 -1:+1:+0
869 +1:-1:+0
870 +9:+1:+10
871 +99:+1:+100
872 +999:+1:+1000
873 +9999:+1:+10000
874 +99999:+1:+100000
875 +999999:+1:+1000000
876 +9999999:+1:+10000000
877 +99999999:+1:+100000000
878 +999999999:+1:+1000000000
879 +9999999999:+1:+10000000000
880 +99999999999:+1:+100000000000
881 +10:-1:+9
882 +100:-1:+99
883 +1000:-1:+999
884 +10000:-1:+9999
885 +100000:-1:+99999
886 +1000000:-1:+999999
887 +10000000:-1:+9999999
888 +100000000:-1:+99999999
889 +1000000000:-1:+999999999
890 +10000000000:-1:+9999999999
891 +123456789:+987654321:+1111111110
892 -123456789:+987654321:+864197532
893 -123456789:-987654321:-1111111110
894 +123456789:-987654321:-864197532
895 &bsub
896 abc:abc:NaN
897 abc:+0:NaN
898 +0:abc:NaN
899 +inf:-inf:inf
900 -inf:+inf:-inf
901 +inf:+inf:0
902 -inf:-inf:0
903 +0:+0:+0
904 +1:+0:+1
905 +0:+1:-1
906 +1:+1:+0
907 -1:+0:-1
908 +0:-1:+1
909 -1:-1:+0
910 -1:+1:-2
911 +1:-1:+2
912 +9:+1:+8
913 +99:+1:+98
914 +999:+1:+998
915 +9999:+1:+9998
916 +99999:+1:+99998
917 +999999:+1:+999998
918 +9999999:+1:+9999998
919 +99999999:+1:+99999998
920 +999999999:+1:+999999998
921 +9999999999:+1:+9999999998
922 +99999999999:+1:+99999999998
923 +10:-1:+11
924 +100:-1:+101
925 +1000:-1:+1001
926 +10000:-1:+10001
927 +100000:-1:+100001
928 +1000000:-1:+1000001
929 +10000000:-1:+10000001
930 +100000000:-1:+100000001
931 +1000000000:-1:+1000000001
932 +10000000000:-1:+10000000001
933 +123456789:+987654321:-864197532
934 -123456789:+987654321:-1111111110
935 -123456789:-987654321:+864197532
936 +123456789:-987654321:+1111111110
937 &bmul
938 abc:abc:NaN
939 abc:+0:NaN
940 +0:abc:NaN
941 NaNmul:+inf:NaN
942 NaNmul:-inf:NaN
943 -inf:NaNmul:NaN
944 +inf:NaNmul:NaN
945 +inf:+inf:inf
946 +inf:-inf:-inf
947 -inf:+inf:-inf
948 -inf:-inf:inf
949 +0:+0:+0
950 +0:+1:+0
951 +1:+0:+0
952 +0:-1:+0
953 -1:+0:+0
954 +123456789123456789:+0:+0
955 +0:+123456789123456789:+0
956 -1:-1:+1
957 -1:+1:-1
958 +1:-1:-1
959 +1:+1:+1
960 +2:+3:+6
961 -2:+3:-6
962 +2:-3:-6
963 -2:-3:+6
964 +111:+111:+12321
965 +10101:+10101:+102030201
966 +1001001:+1001001:+1002003002001
967 +100010001:+100010001:+10002000300020001
968 +10000100001:+10000100001:+100002000030000200001
969 +11111111111:+9:+99999999999
970 +22222222222:+9:+199999999998
971 +33333333333:+9:+299999999997
972 +44444444444:+9:+399999999996
973 +55555555555:+9:+499999999995
974 +66666666666:+9:+599999999994
975 +77777777777:+9:+699999999993
976 +88888888888:+9:+799999999992
977 +99999999999:+9:+899999999991
978 +25:+25:+625
979 +12345:+12345:+152399025
980 +99999:+11111:+1111088889
981 &bdiv-list
982 100:20:5,0
983 4095:4095:1,0
984 -4095:-4095:1,0
985 4095:-4095:-1,0
986 -4095:4095:-1,0
987 &bdiv
988 abc:abc:NaN
989 abc:+1:abc:NaN
990 +1:abc:NaN
991 +0:+0:NaN
992 +5:0:inf
993 -5:0:-inf
994 +1:+0:inf
995 +0:+1:+0
996 +0:-1:+0
997 -1:+0:-inf
998 +1:+1:+1
999 -1:-1:+1
1000 +1:-1:-1
1001 -1:+1:-1
1002 +1:+2:+0
1003 +2:+1:+2
1004 +1:+26:+0
1005 +1000000000:+9:+111111111
1006 +2000000000:+9:+222222222
1007 +3000000000:+9:+333333333
1008 +4000000000:+9:+444444444
1009 +5000000000:+9:+555555555
1010 +6000000000:+9:+666666666
1011 +7000000000:+9:+777777777
1012 +8000000000:+9:+888888888
1013 +9000000000:+9:+1000000000
1014 +35500000:+113:+314159
1015 +71000000:+226:+314159
1016 +106500000:+339:+314159
1017 +1000000000:+3:+333333333
1018 +10:+5:+2
1019 +100:+4:+25
1020 +1000:+8:+125
1021 +10000:+16:+625
1022 +999999999999:+9:+111111111111
1023 +999999999999:+99:+10101010101
1024 +999999999999:+999:+1001001001
1025 +999999999999:+9999:+100010001
1026 +999999999999999:+99999:+10000100001
1027 +1111088889:+99999:+11111
1028 -5:-3:1
1029 4:3:1
1030 1:3:0
1031 -2:-3:0
1032 -2:3:-1
1033 1:-3:-1
1034 -5:3:-2
1035 4:-3:-2
1036 123:+inf:0
1037 123:-inf:0
1038 &bmod
1039 abc:abc:NaN
1040 abc:+1:abc:NaN
1041 +1:abc:NaN
1042 +0:+0:NaN
1043 +0:+1:+0
1044 +1:+0:NaN
1045 +0:-1:+0
1046 -1:+0:NaN
1047 +1:+1:+0
1048 -1:-1:+0
1049 +1:-1:+0
1050 -1:+1:+0
1051 +1:+2:+1
1052 +2:+1:+0
1053 +1000000000:+9:+1
1054 +2000000000:+9:+2
1055 +3000000000:+9:+3
1056 +4000000000:+9:+4
1057 +5000000000:+9:+5
1058 +6000000000:+9:+6
1059 +7000000000:+9:+7
1060 +8000000000:+9:+8
1061 +9000000000:+9:+0
1062 +35500000:+113:+33
1063 +71000000:+226:+66
1064 +106500000:+339:+99
1065 +1000000000:+3:+1
1066 +10:+5:+0
1067 +100:+4:+0
1068 +1000:+8:+0
1069 +10000:+16:+0
1070 +999999999999:+9:+0
1071 +999999999999:+99:+0
1072 +999999999999:+999:+0
1073 +999999999999:+9999:+0
1074 +999999999999999:+99999:+0
1075 -9:+5:+1
1076 +9:-5:-1
1077 -9:-5:-4
1078 -5:3:1
1079 -2:3:1
1080 4:3:1
1081 1:3:1
1082 -5:-3:-2
1083 -2:-3:-2
1084 4:-3:-2
1085 1:-3:-2
1086 4095:4095:0
1087 &bgcd
1088 abc:abc:NaN
1089 abc:+0:NaN
1090 +0:abc:NaN
1091 +0:+0:+0
1092 +0:+1:+1
1093 +1:+0:+1
1094 +1:+1:+1
1095 +2:+3:+1
1096 +3:+2:+1
1097 -3:+2:+1
1098 +100:+625:+25
1099 +4096:+81:+1
1100 +1034:+804:+2
1101 +27:+90:+56:+1
1102 +27:+90:+54:+9
1103 &blcm
1104 abc:abc:NaN
1105 abc:+0:NaN
1106 +0:abc:NaN
1107 +0:+0:NaN
1108 +1:+0:+0
1109 +0:+1:+0
1110 +27:+90:+270
1111 +1034:+804:+415668
1112 &band
1113 abc:abc:NaN
1114 abc:0:NaN
1115 0:abc:NaN
1116 1:2:0
1117 3:2:2
1118 +8:+2:+0
1119 +281474976710656:+0:+0
1120 +281474976710656:+1:+0
1121 +281474976710656:+281474976710656:+281474976710656
1122 -2:-3:-4
1123 -1:-1:-1
1124 -6:-6:-6
1125 -7:-4:-8
1126 -7:4:0
1127 -4:7:4
1128 &bior
1129 abc:abc:NaN
1130 abc:0:NaN
1131 0:abc:NaN
1132 1:2:3
1133 +8:+2:+10
1134 +281474976710656:+0:+281474976710656
1135 +281474976710656:+1:+281474976710657
1136 +281474976710656:+281474976710656:+281474976710656
1137 -2:-3:-1
1138 -1:-1:-1
1139 -6:-6:-6
1140 -7:4:-3
1141 -4:7:-1
1142 &bxor
1143 abc:abc:NaN
1144 abc:0:NaN
1145 0:abc:NaN
1146 1:2:3
1147 +8:+2:+10
1148 +281474976710656:+0:+281474976710656
1149 +281474976710656:+1:+281474976710657
1150 +281474976710656:+281474976710656:+0
1151 -2:-3:3
1152 -1:-1:0
1153 -6:-6:0
1154 -7:4:-3
1155 -4:7:-5
1156 4:-7:-3
1157 -4:-7:5
1158 &bnot
1159 abc:NaN
1160 +0:-1
1161 +8:-9
1162 +281474976710656:-281474976710657
1163 -1:0
1164 -2:1
1165 -12:11
1166 &digit
1167 0:0:0
1168 12:0:2
1169 12:1:1
1170 123:0:3
1171 123:1:2
1172 123:2:1
1173 123:-1:1
1174 123:-2:2
1175 123:-3:3
1176 123456:0:6
1177 123456:1:5
1178 123456:2:4
1179 123456:3:3
1180 123456:4:2
1181 123456:5:1
1182 123456:-1:1
1183 123456:-2:2
1184 123456:-3:3
1185 100000:-3:0
1186 100000:0:0
1187 100000:1:0
1188 &mantissa
1189 abc:NaN
1190 1e4:1
1191 2e0:2
1192 123:123
1193 -1:-1
1194 -2:-2
1195 &exponent
1196 abc:NaN
1197 1e4:4
1198 2e0:0
1199 123:0
1200 -1:0
1201 -2:0
1202 0:1
1203 &parts
1204 abc:NaN,NaN
1205 1e4:1,4
1206 2e0:2,0
1207 123:123,0
1208 -1:-1,0
1209 -2:-2,0
1210 0:0,1
1211 &bpow
1212 abc:12:NaN
1213 12:abc:NaN
1214 0:0:1
1215 0:1:0
1216 0:2:0
1217 0:-1:NaN
1218 0:-2:NaN
1219 1:0:1
1220 1:1:1
1221 1:2:1
1222 1:3:1
1223 1:-1:1
1224 1:-2:1
1225 1:-3:1
1226 2:0:1
1227 2:1:2
1228 2:2:4
1229 2:3:8
1230 3:3:27
1231 2:-1:NaN
1232 -2:-1:NaN
1233 2:-2:NaN
1234 -2:-2:NaN
1235 +inf:1234500012:inf
1236 -inf:1234500012:-inf
1237 +inf:-12345000123:inf
1238 -inf:-12345000123:-inf
1239 # 1 ** -x => 1 / (1 ** x)
1240 -1:0:1
1241 -2:0:1
1242 -1:1:-1
1243 -1:2:1
1244 -1:3:-1
1245 -1:4:1
1246 -1:5:-1
1247 -1:-1:-1
1248 -1:-2:1
1249 -1:-3:-1
1250 -1:-4:1
1251 10:2:100
1252 10:3:1000
1253 10:4:10000
1254 10:5:100000
1255 10:6:1000000
1256 10:7:10000000
1257 10:8:100000000
1258 10:9:1000000000
1259 10:20:100000000000000000000
1260 123456:2:15241383936
1261 &length
1262 100:3
1263 10:2
1264 1:1
1265 0:1
1266 12345:5
1267 10000000000000000:17
1268 -123:3
1269 &bsqrt
1270 144:12
1271 16:4
1272 4:2
1273 2:1
1274 12:3
1275 256:16
1276 100000000:10000
1277 4000000000000:2000000
1278 1:1
1279 0:0
1280 -2:NaN
1281 Nan:NaN
1282 &bround
1283 $round_mode('trunc')
1284 0:12:0
1285 NaNbround:12:NaN
1286 +inf:12:inf
1287 -inf:12:-inf
1288 1234:0:1234
1289 1234:2:1200
1290 123456:4:123400
1291 123456:5:123450
1292 123456:6:123456
1293 +10123456789:5:+10123000000
1294 -10123456789:5:-10123000000
1295 +10123456789:9:+10123456700
1296 -10123456789:9:-10123456700
1297 +101234500:6:+101234000
1298 -101234500:6:-101234000
1299 #+101234500:-4:+101234000
1300 #-101234500:-4:-101234000
1301 $round_mode('zero')
1302 +20123456789:5:+20123000000
1303 -20123456789:5:-20123000000
1304 +20123456789:9:+20123456800
1305 -20123456789:9:-20123456800
1306 +201234500:6:+201234000
1307 -201234500:6:-201234000
1308 #+201234500:-4:+201234000
1309 #-201234500:-4:-201234000
1310 +12345000:4:12340000
1311 -12345000:4:-12340000
1312 $round_mode('+inf')
1313 +30123456789:5:+30123000000
1314 -30123456789:5:-30123000000
1315 +30123456789:9:+30123456800
1316 -30123456789:9:-30123456800
1317 +301234500:6:+301235000
1318 -301234500:6:-301234000
1319 #+301234500:-4:+301235000
1320 #-301234500:-4:-301234000
1321 +12345000:4:12350000
1322 -12345000:4:-12340000
1323 $round_mode('-inf')
1324 +40123456789:5:+40123000000
1325 -40123456789:5:-40123000000
1326 +40123456789:9:+40123456800
1327 -40123456789:9:-40123456800
1328 +401234500:6:+401234000
1329 +401234500:6:+401234000
1330 #-401234500:-4:-401235000
1331 #-401234500:-4:-401235000
1332 +12345000:4:12340000
1333 -12345000:4:-12350000
1334 $round_mode('odd')
1335 +50123456789:5:+50123000000
1336 -50123456789:5:-50123000000
1337 +50123456789:9:+50123456800
1338 -50123456789:9:-50123456800
1339 +501234500:6:+501235000
1340 -501234500:6:-501235000
1341 #+501234500:-4:+501235000
1342 #-501234500:-4:-501235000
1343 +12345000:4:12350000
1344 -12345000:4:-12350000
1345 $round_mode('even')
1346 +60123456789:5:+60123000000
1347 -60123456789:5:-60123000000
1348 +60123456789:9:+60123456800
1349 -60123456789:9:-60123456800
1350 +601234500:6:+601234000
1351 -601234500:6:-601234000
1352 #+601234500:-4:+601234000
1353 #-601234500:-4:-601234000
1354 #-601234500:-9:0
1355 #-501234500:-9:0
1356 #-601234500:-8:0
1357 #-501234500:-8:0
1358 +1234567:7:1234567
1359 +1234567:6:1234570
1360 +12345000:4:12340000
1361 -12345000:4:-12340000
1362 &is_zero
1363 0:1
1364 NaNzero:0
1365 +inf:0
1366 -inf:0
1367 123:0
1368 -1:0
1369 1:0
1370 &is_one
1371 0:0
1372 NaNone:0
1373 +inf:0
1374 -inf:0
1375 1:1
1376 2:0
1377 -1:0
1378 -2:0
1379 # floor and ceil tests are pretty pointless in integer space...but play safe
1380 &bfloor
1381 0:0
1382 NaNfloor:NaN
1383 +inf:inf
1384 -inf:-inf
1385 -1:-1
1386 -2:-2
1387 2:2
1388 3:3
1389 abc:NaN
1390 &bceil
1391 NaNceil:NaN
1392 +inf:inf
1393 -inf:-inf
1394 0:0
1395 -1:-1
1396 -2:-2
1397 2:2
1398 3:3
1399 abc:NaN