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