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