1 #include this file into another for subclass testing
3 my $version = ${"$class\::VERSION"};
7 ##############################################################################
8 # for testing inheritance of _swap
12 use Math::BigInt lib => $main::CL;
14 @ISA = (qw/Math::BigInt/);
17 # customized overload for sub, since original does not use swap there
18 '-' => sub { my @a = ref($_[0])->_swap(@_);
23 # a fake _swap, which reverses the params
24 my $self = shift; # for override in subclass
27 my $c = ref ($_[0] ) || 'Math::Foo';
28 return ( $_[0]->copy(), $_[1] );
32 return ( Math::Foo->new($_[1]), $_[0] );
36 ##############################################################################
39 my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
41 my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
46 next if /^#/; # skip comments
53 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
56 @args = split(/:/,$_,99); $ans = pop(@args);
57 $expected_class = $class;
58 if ($ans =~ /(.*?)=(.*)/)
60 $expected_class = $2; $ans = $1;
62 $try = "\$x = $class->new(\"$args[0]\");";
65 $try = "\$x = $class->bnorm(\"$args[0]\");";
67 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
68 $try .= "\$x->$f() || 0;";
69 } elsif ($f eq "is_inf") {
70 $try .= "\$x->is_inf('$args[1]');";
71 } elsif ($f eq "binf") {
72 $try .= "\$x->binf('$args[1]');";
73 } elsif ($f eq "bone") {
74 $try .= "\$x->bone('$args[1]');";
76 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
78 } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
80 } elsif ($f eq "exponent"){
81 # ->bstr() to see if an object is returned
82 $try .= '$x = $x->exponent()->bstr();';
83 } elsif ($f eq "mantissa"){
84 # ->bstr() to see if an object is returned
85 $try .= '$x = $x->mantissa()->bstr();';
86 } elsif ($f eq "parts"){
87 $try .= '($m,$e) = $x->parts();';
88 # ->bstr() to see if an object is returned
89 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
90 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
94 $try .= "\$y = $class->new('$args[1]');";
98 } elsif ($f eq "bround") {
99 $try .= "$round_mode; \$x->bround(\$y);";
100 } elsif ($f eq "bacmp"){
101 $try .= '$x->bacmp($y);';
102 } elsif ($f eq "badd"){
104 } elsif ($f eq "bsub"){
106 } elsif ($f eq "bmul"){
108 } elsif ($f eq "bdiv"){
110 } elsif ($f eq "bdiv-list"){
111 $try .= 'join (",",$x->bdiv($y));';
113 } elsif ($f =~ /^.=$/){
114 $try .= "\$x $f \$y;";
116 } elsif ($f =~ /^.$/){
117 $try .= "\$x $f \$y;";
118 } elsif ($f eq "bmod"){
120 } elsif ($f eq "bgcd")
122 if (defined $args[2])
124 $try .= " \$z = $class->new('$args[2]'); ";
126 $try .= "$class\::bgcd(\$x, \$y";
127 $try .= ", \$z" if (defined $args[2]);
132 if (defined $args[2])
134 $try .= " \$z = $class->new('$args[2]'); ";
136 $try .= "$class\::blcm(\$x, \$y";
137 $try .= ", \$z" if (defined $args[2]);
139 }elsif ($f eq "blsft"){
140 if (defined $args[2])
142 $try .= "\$x->blsft(\$y,$args[2]);";
146 $try .= "\$x << \$y;";
148 }elsif ($f eq "brsft"){
149 if (defined $args[2])
151 $try .= "\$x->brsft(\$y,$args[2]);";
155 $try .= "\$x >> \$y;";
157 }elsif ($f eq "band"){
158 $try .= "\$x & \$y;";
159 }elsif ($f eq "bior"){
160 $try .= "\$x | \$y;";
161 }elsif ($f eq "bxor"){
162 $try .= "\$x ^ \$y;";
163 }elsif ($f eq "bpow"){
164 $try .= "\$x ** \$y;";
165 } elsif( $f eq "bmodinv") {
166 $try .= "\$x->bmodinv(\$y);";
167 }elsif ($f eq "digit"){
168 $try .= "\$x->digit(\$y);";
170 $try .= "\$z = $class->new(\"$args[2]\");";
172 # Functions with three arguments
173 if( $f eq "bmodpow") {
174 $try .= "\$x->bmodpow(\$y,\$z);";
175 } else { warn "Unknown op '$f'"; }
177 } # end else all other ops
180 # convert hex/binary targets to decimal
181 if ($ans =~ /^(0x0x|0b0b)/)
183 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
191 # print "try: $try ans: $ans1 $ans\n";
192 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
193 ok (ref($ans),$expected_class) if $expected_class ne $class;
195 # check internal state of number objects
196 is_valid($ans1,$f) if ref $ans1;
197 } # endwhile data tests
202 for (my $i = 1; $i < 10; $i++)
206 ok "@a", "1 2 3 4 5 6 7 8 9";
208 # test whether self-multiplication works correctly (result is 2**64)
209 $try = "\$x = $class->new('4294967296');";
210 $try .= '$a = $x->bmul($x);';
212 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
214 $try = "\$x = $class->new(10);";
215 $try .= '$a = $x->bpow($x);';
217 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
219 ###############################################################################
220 # test whether op destroys args or not (should better not)
246 $x = $class->new(-5); $y = -$x;
249 $x = $class->new(-5); $y = abs($x);
253 $y = $class->new(-1);
254 $z = $class->new(5033);
255 my $u = $x->copy()->bmodpow($y,$z);
260 $x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
261 $x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
263 $x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
264 $x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
265 $x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
266 $x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
267 $x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
269 $x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
270 $x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
271 $x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
272 $x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
273 $x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
275 $x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
276 $x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
277 $x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
278 $x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
279 $x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
281 ###############################################################################
282 # check whether overloading cmp works
283 $try = "\$x = $class->new(0);";
285 $try .= "'false' if \$x ne \$y;";
287 print "# For '$try'\n" if (!ok "$ans" , "false" );
289 # we cant test for working cmpt with other objects here, we would need a dummy
290 # object with stringify overload for this. see Math::String tests as example
292 ###############################################################################
293 # check reversed order of arguments
295 $try = "\$x = $class->new(10); \$x = 2 ** \$x;";
296 $try .= "'ok' if \$x == 1024;"; $ans = eval $try;
297 print "# For '$try'\n" if (!ok "$ans" , "ok" );
299 $try = "\$x = $class->new(10); \$x = 2 * \$x;";
300 $try .= "'ok' if \$x == 20;"; $ans = eval $try;
301 print "# For '$try'\n" if (!ok "$ans" , "ok" );
303 $try = "\$x = $class->new(10); \$x = 2 + \$x;";
304 $try .= "'ok' if \$x == 12;"; $ans = eval $try;
305 print "# For '$try'\n" if (!ok "$ans" , "ok" );
307 $try = "\$x = $class\->new(10); \$x = 2 - \$x;";
308 $try .= "'ok' if \$x == -8;"; $ans = eval $try;
309 print "# For '$try'\n" if (!ok "$ans" , "ok" );
311 $try = "\$x = $class\->new(10); \$x = 20 / \$x;";
312 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
313 print "# For '$try'\n" if (!ok "$ans" , "ok" );
315 $try = "\$x = $class\->new(3); \$x = 20 % \$x;";
316 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
317 print "# For '$try'\n" if (!ok "$ans" , "ok" );
319 $try = "\$x = $class\->new(7); \$x = 20 & \$x;";
320 $try .= "'ok' if \$x == 4;"; $ans = eval $try;
321 print "# For '$try'\n" if (!ok "$ans" , "ok" );
323 $try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
324 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
325 print "# For '$try'\n" if (!ok "$ans" , "ok" );
327 $try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
328 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
329 print "# For '$try'\n" if (!ok "$ans" , "ok" );
331 ###############################################################################
332 # check badd(4,5) form
334 $try = "\$x = $class\->badd(4,5);";
335 $try .= "'ok' if \$x == 9;";
337 print "# For '$try'\n" if (!ok "$ans" , "ok" );
339 ###############################################################################
340 # check undefs: NOT DONE YET
342 ###############################################################################
345 $x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
346 $x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
348 ###############################################################################
351 @args = Math::BigInt::objectify(2,4,5);
352 ok (scalar @args,3); # $class, 4, 5
353 ok ($args[0] =~ /^Math::BigInt/);
357 @args = Math::BigInt::objectify(0,4,5);
358 ok (scalar @args,3); # $class, 4, 5
359 ok ($args[0] =~ /^Math::BigInt/);
363 @args = Math::BigInt::objectify(2,4,5);
364 ok (scalar @args,3); # $class, 4, 5
365 ok ($args[0] =~ /^Math::BigInt/);
369 @args = Math::BigInt::objectify(2,4,5,6,7);
370 ok (scalar @args,5); # $class, 4, 5, 6, 7
371 ok ($args[0] =~ /^Math::BigInt/);
372 ok ($args[1],4); ok (ref($args[1]),$args[0]);
373 ok ($args[2],5); ok (ref($args[2]),$args[0]);
374 ok ($args[3],6); ok (ref($args[3]),'');
375 ok ($args[4],7); ok (ref($args[4]),'');
377 @args = Math::BigInt::objectify(2,$class,4,5,6,7);
378 ok (scalar @args,5); # $class, 4, 5, 6, 7
379 ok ($args[0],$class);
380 ok ($args[1],4); ok (ref($args[1]),$args[0]);
381 ok ($args[2],5); ok (ref($args[2]),$args[0]);
382 ok ($args[3],6); ok (ref($args[3]),'');
383 ok ($args[4],7); ok (ref($args[4]),'');
385 ###############################################################################
386 # test whether an opp calls objectify properly or not (or at least does what
387 # it should do given non-objects, w/ or w/o objectify())
389 ok ($class->new(123)->badd(123),246);
390 ok ($class->badd(123,321),444);
391 ok ($class->badd(123,$class->new(321)),444);
393 ok ($class->new(123)->bsub(122),1);
394 ok ($class->bsub(321,123),198);
395 ok ($class->bsub(321,$class->new(123)),198);
397 ok ($class->new(123)->bmul(123),15129);
398 ok ($class->bmul(123,123),15129);
399 ok ($class->bmul(123,$class->new(123)),15129);
401 ok ($class->new(15129)->bdiv(123),123);
402 ok ($class->bdiv(15129,123),123);
403 ok ($class->bdiv(15129,$class->new(123)),123);
405 ok ($class->new(15131)->bmod(123),2);
406 ok ($class->bmod(15131,123),2);
407 ok ($class->bmod(15131,$class->new(123)),2);
409 ok ($class->new(2)->bpow(16),65536);
410 ok ($class->bpow(2,16),65536);
411 ok ($class->bpow(2,$class->new(16)),65536);
413 ok ($class->new(2**15)->brsft(1),2**14);
414 ok ($class->brsft(2**15,1),2**14);
415 ok ($class->brsft(2**15,$class->new(1)),2**14);
417 ok ($class->new(2**13)->blsft(1),2**14);
418 ok ($class->blsft(2**13,1),2**14);
419 ok ($class->blsft(2**13,$class->new(1)),2**14);
421 ###############################################################################
422 # test for floating-point input (other tests in bnorm() below)
424 $z = 1050000000000000; # may be int on systems with 64bit?
425 $x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
426 $z = 1e+129; # definitely a float (may fail on UTS)
427 # don't compare to $z, since some Perl versions stringify $z into something
428 # like '1.e+129' or something equally ugly
429 $x = $class->new($z); ok ($x->bsstr(),'1e+129');
431 ###############################################################################
432 # test for whitespace inlcuding newlines to be handled correctly
434 # ok ($Math::BigInt::strict,1); # the default
437 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
439 my $m = $class->new($c);
440 ok ($class->new("$c"),$m);
441 ok ($class->new(" $c"),$m);
442 ok ($class->new("$c "),$m);
443 ok ($class->new(" $c "),$m);
444 ok ($class->new("\n$c"),$m);
445 ok ($class->new("$c\n"),$m);
446 ok ($class->new("\n$c\n"),$m);
447 ok ($class->new(" \n$c\n"),$m);
448 ok ($class->new(" \n$c \n"),$m);
449 ok ($class->new(" \n$c\n "),$m);
450 ok ($class->new(" \n$c\n1"),'NaN');
451 ok ($class->new("1 \n$c\n1"),'NaN');
454 ###############################################################################
455 # prime number tests, also test for **= and length()
456 # found on: http://www.utm.edu/research/primes/notes/by_year.html
459 $x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
460 ok ($x,"20988936657440586486151264256610222593863921");
461 ok ($x->length(),length "20988936657440586486151264256610222593863921");
464 $x = $class->new(2); $x **= 127; $x--;
465 ok ($x,"170141183460469231731687303715884105727");
467 $x = $class->new('215960156869840440586892398248');
468 ($x,$y) = $x->length();
469 ok ($x,30); ok ($y,0);
471 $x = $class->new('1_000_000_000_000');
472 ($x,$y) = $x->length();
473 ok ($x,13); ok ($y,0);
475 # I am afraid the following is not yet possible due to slowness
476 # Also, testing for 2 meg output is a bit hard ;)
477 #$x = $class->new(2); $x **= 6972593; $x--;
479 # 593573509*2^332162+1 has exactly 1,000,000 digits
480 # takes about 24 mins on 300 Mhz, so cannot be done yet ;)
481 #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
482 #ok ($x->length(),1_000_000);
484 ###############################################################################
485 # inheritance and overriding of _swap
487 $x = Math::Foo->new(5);
488 $x = $x - 8; # 8 - 5 instead of 5-8
490 ok (ref($x),'Math::Foo');
492 $x = Math::Foo->new(5);
493 $x = 8 - $x; # 5 - 8 instead of 8 - 5
495 ok (ref($x),'Math::Foo');
497 ###############################################################################
498 # Test whether +inf eq inf
499 # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
500 # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
501 # like 1e100000 crash on some platforms. So simple test for the string 'inf'
502 $x = $class->new('+inf'); ok ($x,'inf');
504 ###############################################################################
505 ###############################################################################
506 # the followin tests only make sense with Math::BigInt::Calc or BareCalc or
509 exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
511 ###############################################################################
512 # check proper length of internal arrays
514 my $bl = $CL->_base_len();
515 my $BASE = '9' x $bl;
519 $x = $class->new($MAX); is_valid($x); # f.i. 9999
520 $x += 1; ok ($x,$BASE); is_valid($x); # 10000
521 $x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
523 ###############################################################################
526 $x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
527 $x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
529 # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
530 $x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
531 $x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
532 $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
533 ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
535 ###############################################################################
536 # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
538 $x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
539 if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
541 $x = $class->new($BASE+3); $x++;
542 if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
544 # test for +0 instead of int():
545 $x = $class->new($MAX); ok ($x->length(), length($MAX));
547 ###############################################################################
548 # test bug that $class->digit($string) did not work
550 ok ($class->digit(123,2),1);
552 ###############################################################################
553 # bug in sub where number with at least 6 trailing zeros after any op failed
555 $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
559 ###############################################################################
560 # bug in shortcut in mul()
562 # construct a number with a zero-hole of BASE_LEN_SMALL
564 my @bl = $CL->_base_len(); my $bl = $bl[4];
566 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
568 $x = $class->new($x)->bmul($y);
569 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
571 for (my $i = 1; $i <= $bl; $i++)
573 $y .= $i; $d = $i.$d;
575 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
579 #############################################################################
580 # see if mul shortcut for small numbers works
583 $x = $class->new($x);
584 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
585 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
588 ###############################################################################
589 # bug with rest "-0" in div, causing further div()s to fail
591 $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
593 ok ($y,'0'); is_valid($y); # $y not '-0'
595 ###############################################################################
596 # bug in $x->bmod($y)
598 # if $x < 0 and $y > 0
599 $x = $class->new('-629'); ok ($x->bmod(5033),4404);
601 ###############################################################################
602 # bone/binf etc as plain calls (Lite failed them)
604 ok ($class->bzero(),0);
605 ok ($class->bone(),1);
606 ok ($class->bone('+'),1);
607 ok ($class->bone('-'),-1);
608 ok ($class->bnan(),'NaN');
609 ok ($class->binf(),'inf');
610 ok ($class->binf('+'),'inf');
611 ok ($class->binf('-'),'-inf');
612 ok ($class->binf('-inf'),'-inf');
614 ###############################################################################
619 ###############################################################################
620 ###############################################################################
621 # Perl 5.005 does not like ok ($x,undef)
627 ok (1,1) and return if !defined $x;
631 ###############################################################################
632 # sub to check validity of a BigInt internally, to ensure that no op leaves a
633 # number object in an invalid state (f.i. "-0")
641 # allow the check to pass for all Lite, and all MBI and subclasses
643 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
645 if (ref($x) ne 'Math::BigInt::Lite')
648 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
649 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
651 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
652 $e = $CALC->_check($x->{value}) if $e eq '0';
655 # test done, see if error did crop up
656 ok (1,1), return if ($e eq '0');
658 ok (1,$e." after op '$f'");
738 -123456789:+987654321:-1
739 +123456789:-987654321:-1
740 +987654321:+123456789:1
741 -987654321:+123456789:1
783 0b10000000000001:8193
784 0b100000000000001:16385
785 0b1000000000000001:32769
786 0b10000000000000001:65537
787 0b100000000000000001:131073
788 0b1000000000000000001:262145
789 0b10000000000000000001:524289
790 0b100000000000000000001:1048577
791 0b1000000000000000000001:2097153
792 0b10000000000000000000001:4194305
793 0b100000000000000000000001:8388609
794 0b1000000000000000000000001:16777217
795 0b10000000000000000000000001:33554433
796 0b100000000000000000000000001:67108865
797 0b1000000000000000000000000001:134217729
798 0b10000000000000000000000000001:268435457
799 0b100000000000000000000000000001:536870913
800 0b1000000000000000000000000000001:1073741825
801 0b10000000000000000000000000000001:2147483649
802 0b100000000000000000000000000000001:4294967297
803 0b1000000000000000000000000000000001:8589934593
804 0b10000000000000000000000000000000001:17179869185
816 0x1_2_3_4_56_78:305419896
817 0xa_b_c_d_e_f:11259375
846 0x40000001:1073741825
847 0x80000001:2147483649
848 0x100000001:4294967297
849 0x200000001:8589934593
850 0x400000001:17179869185
851 0x800000001:34359738369
865 # only one underscore between two digits
883 # bug with two E's in number beeing valid
887 # bug with two '.' in number beeing valid
911 01234567891:1234567891
912 012345678912:12345678912
913 0123456789123:123456789123
914 01234567891234:1234567891234
931 -123456789:-123456789
940 # floating point input
948 # non-integer numbers
987 # it must be exactly /^[+-]inf$/
994 +1:+48:281474976710656
997 +12345:4:10:123450000
1003 1234567890123:12:10:1234567890123000000000000
1007 -102533203:1:2:-205066406
1012 +281474976710656:+48:1
1023 1230000000000:10:10:123
1024 09876123456789067890:12:10:9876123
1025 1234561234567890123:13:10:123456
1026 820265627:1:2:410132813
1027 # test shifting negative numbers in base 2
1043 -1640531254:2:2:-410132814
1044 -1640531254:1:2:-820265627
1045 -820265627:1:2:-410132814
1046 -205066405:1:2:-102533203
1072 +123456789:-123456789
1073 -123456789:123456789
1081 +123456789:123456789
1082 -123456789:123456789
1107 -123456789:987654321:-1
1108 +123456789:-987654321:1
1109 -987654321:123456789:-1
1168 +9999999:+1:10000000
1169 +99999999:+1:100000000
1170 +999999999:+1:1000000000
1171 +9999999999:+1:10000000000
1172 +99999999999:+1:100000000000
1179 +10000000:-1:9999999
1180 +100000000:-1:99999999
1181 +1000000000:-1:999999999
1182 +10000000000:-1:9999999999
1183 +123456789:987654321:1111111110
1184 -123456789:987654321:864197532
1185 -123456789:-987654321:-1111111110
1186 +123456789:-987654321:-864197532
1190 -1:10000001:10000000
1191 -1:100000001:100000000
1192 -1:1000000001:1000000000
1193 -1:10000000001:10000000000
1194 -1:100000000001:100000000000
1195 -1:1000000000001:1000000000000
1196 -1:10000000000001:10000000000000
1199 -1:-1000001:-1000002
1200 -1:-10000001:-10000002
1201 -1:-100000001:-100000002
1202 -1:-1000000001:-1000000002
1203 -1:-10000000001:-10000000002
1204 -1:-100000000001:-100000000002
1205 -1:-1000000000001:-1000000000002
1206 -1:-10000000000001:-10000000000002
1231 +99999999:+1:99999998
1232 +999999999:+1:999999998
1233 +9999999999:+1:9999999998
1234 +99999999999:+1:99999999998
1241 +10000000:-1:10000001
1242 +100000000:-1:100000001
1243 +1000000000:-1:1000000001
1244 +10000000000:-1:10000000001
1245 +123456789:+987654321:-864197532
1246 -123456789:+987654321:-1111111110
1247 -123456789:-987654321:864197532
1248 +123456789:-987654321:1111111110
1253 100000001:1:100000000
1254 1000000001:1:1000000000
1255 10000000001:1:10000000000
1256 100000000001:1:100000000000
1257 1000000000001:1:1000000000000
1258 10000000000001:1:10000000000000
1262 10000001:-1:10000002
1263 100000001:-1:100000002
1264 1000000001:-1:1000000002
1265 10000000001:-1:10000000002
1266 100000000001:-1:100000000002
1267 1000000000001:-1:1000000000002
1268 10000000000001:-1:10000000000002
1286 123456789123456789:0:0
1287 0:123456789123456789:0
1297 10101:10101:102030201
1298 1001001:1001001:1002003002001
1299 100010001:100010001:10002000300020001
1300 10000100001:10000100001:100002000030000200001
1301 11111111111:9:99999999999
1302 22222222222:9:199999999998
1303 33333333333:9:299999999997
1304 44444444444:9:399999999996
1305 55555555555:9:499999999995
1306 66666666666:9:599999999994
1307 77777777777:9:699999999993
1308 88888888888:9:799999999992
1309 99999999999:9:899999999991
1311 +12345:+12345:152399025
1312 +99999:+11111:1111088889
1314 99999:100000:9999900000
1315 999999:1000000:999999000000
1316 9999999:10000000:99999990000000
1317 99999999:100000000:9999999900000000
1318 999999999:1000000000:999999999000000000
1319 9999999999:10000000000:99999999990000000000
1320 99999999999:100000000000:9999999999900000000000
1321 999999999999:1000000000000:999999999999000000000000
1322 9999999999999:10000000000000:99999999999990000000000000
1323 99999999999999:100000000000000:9999999999999900000000000000
1324 999999999999999:1000000000000000:999999999999999000000000000000
1325 9999999999999999:10000000000000000:99999999999999990000000000000000
1326 99999999999999999:100000000000000000:9999999999999999900000000000000000
1327 999999999999999999:1000000000000000000:999999999999999999000000000000000000
1328 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1338 # inf handling and general remainder
1344 # see table in documentation in MBI
1363 # exceptions to reminder rule
1372 # inf handling (see table in doc)
1407 1000000000:9:111111111
1408 2000000000:9:222222222
1409 3000000000:9:333333333
1410 4000000000:9:444444444
1411 5000000000:9:555555555
1412 6000000000:9:666666666
1413 7000000000:9:777777777
1414 8000000000:9:888888888
1415 9000000000:9:1000000000
1418 106500000:339:314159
1419 1000000000:3:333333333
1424 999999999999:9:111111111111
1425 999999999999:99:10101010101
1426 999999999999:999:1001001001
1427 999999999999:9999:100010001
1428 999999999999999:99999:10000100001
1429 +1111088889:99999:11111
1444 # bug in Calc with '99999' vs $BASE-1
1445 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1447 # format: number:modulus:result
1448 # bmodinv Data errors
1452 # bmodinv Expected Results from normal use
1459 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
1460 ## bmodinv Error cases / useless use of function
1467 # format: number:exponent:modulus:result
1468 # bmodpow Data errors
1476 # bmodpow Expected results
1482 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1483 # bmodpow Error cases
1489 # inf handling, see table in doc
1508 # exceptions to reminder rule
1547 999999999999999:99999:0
1561 152403346:12345:4321
1563 # test shortcuts in Calc
1564 # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
1571 1234567891234567:9:1
1572 123456789123456789:9:0
1579 1234567891234567:10:7
1580 123456789123456789:10:9
1586 12345678912345:113:53
1587 1234567891234567:113:56
1588 123456789123456789:113:39
1589 # bug in bmod() not modifying the variable in place
1623 +281474976710656:0:0
1624 +281474976710656:1:0
1625 +281474976710656:+281474976710656:281474976710656
1632 # equal arguments are treated special, so also do some test with unequal ones
1633 0xFFFF:0xFFFF:0x0xFFFF
1634 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1635 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1636 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1637 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1638 0xF0F0:0xF0F0:0x0xF0F0
1639 0x0F0F:0x0F0F:0x0x0F0F
1640 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1641 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1642 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1643 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1644 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1645 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1646 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1647 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1648 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1655 +281474976710656:0:281474976710656
1656 +281474976710656:1:281474976710657
1657 +281474976710656:281474976710656:281474976710656
1663 # equal arguments are treated special, so also do some test with unequal ones
1664 0xFFFF:0xFFFF:0x0xFFFF
1665 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1666 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1667 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1668 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1670 0:0xFFFFFF:0x0xFFFFFF
1671 0:0xFFFFFFFF:0x0xFFFFFFFF
1672 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1673 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1675 0xFFFFFF:0:0x0xFFFFFF
1676 0xFFFFFFFF:0:0x0xFFFFFFFF
1677 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1678 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1679 0xF0F0:0xF0F0:0x0xF0F0
1680 0x0F0F:0x0F0F:0x0x0F0F
1681 0xF0F0:0x0F0F:0x0xFFFF
1682 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1683 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1684 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1685 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1686 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1687 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1688 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1689 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1690 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1691 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1692 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1693 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1694 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1701 +281474976710656:0:281474976710656
1702 +281474976710656:1:281474976710657
1703 +281474976710656:281474976710656:0
1711 # equal arguments are treated special, so also do some test with unequal ones
1714 0xFFFFFFFF:0xFFFFFFFF:0
1715 0xFFFFFFFFFF:0xFFFFFFFFFF:0
1716 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
1718 0:0xFFFFFF:0x0xFFFFFF
1719 0:0xFFFFFFFF:0x0xFFFFFFFF
1720 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1721 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1723 0xFFFFFF:0:0x0xFFFFFF
1724 0xFFFFFFFF:0:0x0xFFFFFFFF
1725 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1726 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1729 0xF0F0:0x0F0F:0x0xFFFF
1732 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1733 0xF0F0F0F0:0xF0F0F0F0:0
1734 0x0F0F0F0F:0x0F0F0F0F:0
1735 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1736 0xF0F0F0F0F0:0xF0F0F0F0F0:0
1737 0x0F0F0F0F0F:0x0F0F0F0F0F:0
1738 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1739 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
1740 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
1741 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1746 +281474976710656:-281474976710657
1841 -inf:1234500012:-inf
1842 +inf:-12345000123:inf
1843 -inf:-12345000123:-inf
1844 # 1 ** -x => 1 / (1 ** x)
1864 10:20:100000000000000000000
1865 123456:2:15241383936
1872 10000000000000000:17
1874 215960156869840440586892398248:30
1890 4000000000000:2000000
1901 $round_mode('trunc')
1911 +10123456789:5:10123000000
1912 -10123456789:5:-10123000000
1913 +10123456789:9:10123456700
1914 -10123456789:9:-10123456700
1915 +101234500:6:101234000
1916 -101234500:6:-101234000
1917 #+101234500:-4:101234000
1918 #-101234500:-4:-101234000
1920 +20123456789:5:20123000000
1921 -20123456789:5:-20123000000
1922 +20123456789:9:20123456800
1923 -20123456789:9:-20123456800
1924 +201234500:6:201234000
1925 -201234500:6:-201234000
1926 #+201234500:-4:201234000
1927 #-201234500:-4:-201234000
1928 +12345000:4:12340000
1929 -12345000:4:-12340000
1931 +30123456789:5:30123000000
1932 -30123456789:5:-30123000000
1933 +30123456789:9:30123456800
1934 -30123456789:9:-30123456800
1935 +301234500:6:301235000
1936 -301234500:6:-301234000
1937 #+301234500:-4:301235000
1938 #-301234500:-4:-301234000
1939 +12345000:4:12350000
1940 -12345000:4:-12340000
1942 +40123456789:5:40123000000
1943 -40123456789:5:-40123000000
1944 +40123456789:9:40123456800
1945 -40123456789:9:-40123456800
1946 +401234500:6:401234000
1947 +401234500:6:401234000
1948 #-401234500:-4:-401235000
1949 #-401234500:-4:-401235000
1950 +12345000:4:12340000
1951 -12345000:4:-12350000
1953 +50123456789:5:50123000000
1954 -50123456789:5:-50123000000
1955 +50123456789:9:50123456800
1956 -50123456789:9:-50123456800
1957 +501234500:6:501235000
1958 -501234500:6:-501235000
1959 #+501234500:-4:501235000
1960 #-501234500:-4:-501235000
1961 +12345000:4:12350000
1962 -12345000:4:-12350000
1964 +60123456789:5:60123000000
1965 -60123456789:5:-60123000000
1966 +60123456789:9:60123456800
1967 -60123456789:9:-60123456800
1968 +601234500:6:601234000
1969 -601234500:6:-601234000
1970 #+601234500:-4:601234000
1971 #-601234500:-4:-601234000
1978 +12345000:4:12340000
1979 -12345000:4:-12340000
1997 # floor and ceil tests are pretty pointless in integer space...but play safe
2024 0x123456789123456789:0x123456789123456789
2034 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
2035 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001