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 "broot"){
158 $try .= "\$x->broot(\$y);";
159 }elsif ($f eq "band"){
160 $try .= "\$x & \$y;";
161 }elsif ($f eq "bior"){
162 $try .= "\$x | \$y;";
163 }elsif ($f eq "bxor"){
164 $try .= "\$x ^ \$y;";
165 }elsif ($f eq "bpow"){
166 $try .= "\$x ** \$y;";
167 } elsif( $f eq "bmodinv") {
168 $try .= "\$x->bmodinv(\$y);";
169 }elsif ($f eq "digit"){
170 $try .= "\$x->digit(\$y);";
172 $try .= "\$z = $class->new(\"$args[2]\");";
174 # Functions with three arguments
175 if( $f eq "bmodpow") {
176 $try .= "\$x->bmodpow(\$y,\$z);";
177 } else { warn "Unknown op '$f'"; }
179 } # end else all other ops
182 # convert hex/binary targets to decimal
183 if ($ans =~ /^(0x0x|0b0b)/)
185 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
193 # print "try: $try ans: $ans1 $ans\n";
194 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
195 ok (ref($ans),$expected_class) if $expected_class ne $class;
197 # check internal state of number objects
198 is_valid($ans1,$f) if ref $ans1;
199 } # endwhile data tests
204 for (my $i = 1; $i < 10; $i++)
208 ok "@a", "1 2 3 4 5 6 7 8 9";
210 # test whether self-multiplication works correctly (result is 2**64)
211 $try = "\$x = $class->new('4294967296');";
212 $try .= '$a = $x->bmul($x);';
214 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
216 $try = "\$x = $class->new(10);";
217 $try .= '$a = $x->bpow($x);';
219 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
221 ###############################################################################
222 # test whether op destroys args or not (should better not)
248 $x = $class->new(-5); $y = -$x;
251 $x = $class->new(-5); $y = abs($x);
255 $y = $class->new(-1);
256 $z = $class->new(5033);
257 my $u = $x->copy()->bmodpow($y,$z);
262 $x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
263 $x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
265 $x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
266 $x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
267 $x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
268 $x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
269 $x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
271 $x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
272 $x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
273 $x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
274 $x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
275 $x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
277 $x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
278 $x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
279 $x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
280 $x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
281 $x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
283 ###############################################################################
284 # check whether overloading cmp works
285 $try = "\$x = $class->new(0);";
287 $try .= "'false' if \$x ne \$y;";
289 print "# For '$try'\n" if (!ok "$ans" , "false" );
291 # we cant test for working cmpt with other objects here, we would need a dummy
292 # object with stringify overload for this. see Math::String tests as example
294 ###############################################################################
295 # check reversed order of arguments
297 $try = "\$x = $class->new(10); \$x = 2 ** \$x;";
298 $try .= "'ok' if \$x == 1024;"; $ans = eval $try;
299 print "# For '$try'\n" if (!ok "$ans" , "ok" );
301 $try = "\$x = $class->new(10); \$x = 2 * \$x;";
302 $try .= "'ok' if \$x == 20;"; $ans = eval $try;
303 print "# For '$try'\n" if (!ok "$ans" , "ok" );
305 $try = "\$x = $class->new(10); \$x = 2 + \$x;";
306 $try .= "'ok' if \$x == 12;"; $ans = eval $try;
307 print "# For '$try'\n" if (!ok "$ans" , "ok" );
309 $try = "\$x = $class\->new(10); \$x = 2 - \$x;";
310 $try .= "'ok' if \$x == -8;"; $ans = eval $try;
311 print "# For '$try'\n" if (!ok "$ans" , "ok" );
313 $try = "\$x = $class\->new(10); \$x = 20 / \$x;";
314 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
315 print "# For '$try'\n" if (!ok "$ans" , "ok" );
317 $try = "\$x = $class\->new(3); \$x = 20 % \$x;";
318 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
319 print "# For '$try'\n" if (!ok "$ans" , "ok" );
321 $try = "\$x = $class\->new(7); \$x = 20 & \$x;";
322 $try .= "'ok' if \$x == 4;"; $ans = eval $try;
323 print "# For '$try'\n" if (!ok "$ans" , "ok" );
325 $try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
326 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
327 print "# For '$try'\n" if (!ok "$ans" , "ok" );
329 $try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
330 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
331 print "# For '$try'\n" if (!ok "$ans" , "ok" );
333 ###############################################################################
334 # check badd(4,5) form
336 $try = "\$x = $class\->badd(4,5);";
337 $try .= "'ok' if \$x == 9;";
339 print "# For '$try'\n" if (!ok "$ans" , "ok" );
341 ###############################################################################
342 # check undefs: NOT DONE YET
344 ###############################################################################
347 $x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
348 $x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
350 ###############################################################################
353 @args = Math::BigInt::objectify(2,4,5);
354 ok (scalar @args,3); # $class, 4, 5
355 ok ($args[0] =~ /^Math::BigInt/);
359 @args = Math::BigInt::objectify(0,4,5);
360 ok (scalar @args,3); # $class, 4, 5
361 ok ($args[0] =~ /^Math::BigInt/);
365 @args = Math::BigInt::objectify(2,4,5);
366 ok (scalar @args,3); # $class, 4, 5
367 ok ($args[0] =~ /^Math::BigInt/);
371 @args = Math::BigInt::objectify(2,4,5,6,7);
372 ok (scalar @args,5); # $class, 4, 5, 6, 7
373 ok ($args[0] =~ /^Math::BigInt/);
374 ok ($args[1],4); ok (ref($args[1]),$args[0]);
375 ok ($args[2],5); ok (ref($args[2]),$args[0]);
376 ok ($args[3],6); ok (ref($args[3]),'');
377 ok ($args[4],7); ok (ref($args[4]),'');
379 @args = Math::BigInt::objectify(2,$class,4,5,6,7);
380 ok (scalar @args,5); # $class, 4, 5, 6, 7
381 ok ($args[0],$class);
382 ok ($args[1],4); ok (ref($args[1]),$args[0]);
383 ok ($args[2],5); ok (ref($args[2]),$args[0]);
384 ok ($args[3],6); ok (ref($args[3]),'');
385 ok ($args[4],7); ok (ref($args[4]),'');
387 ###############################################################################
388 # test whether an opp calls objectify properly or not (or at least does what
389 # it should do given non-objects, w/ or w/o objectify())
391 ok ($class->new(123)->badd(123),246);
392 ok ($class->badd(123,321),444);
393 ok ($class->badd(123,$class->new(321)),444);
395 ok ($class->new(123)->bsub(122),1);
396 ok ($class->bsub(321,123),198);
397 ok ($class->bsub(321,$class->new(123)),198);
399 ok ($class->new(123)->bmul(123),15129);
400 ok ($class->bmul(123,123),15129);
401 ok ($class->bmul(123,$class->new(123)),15129);
403 ok ($class->new(15129)->bdiv(123),123);
404 ok ($class->bdiv(15129,123),123);
405 ok ($class->bdiv(15129,$class->new(123)),123);
407 ok ($class->new(15131)->bmod(123),2);
408 ok ($class->bmod(15131,123),2);
409 ok ($class->bmod(15131,$class->new(123)),2);
411 ok ($class->new(2)->bpow(16),65536);
412 ok ($class->bpow(2,16),65536);
413 ok ($class->bpow(2,$class->new(16)),65536);
415 ok ($class->new(2**15)->brsft(1),2**14);
416 ok ($class->brsft(2**15,1),2**14);
417 ok ($class->brsft(2**15,$class->new(1)),2**14);
419 ok ($class->new(2**13)->blsft(1),2**14);
420 ok ($class->blsft(2**13,1),2**14);
421 ok ($class->blsft(2**13,$class->new(1)),2**14);
423 ###############################################################################
424 # test for floating-point input (other tests in bnorm() below)
426 $z = 1050000000000000; # may be int on systems with 64bit?
427 $x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
428 $z = 1e+129; # definitely a float (may fail on UTS)
429 # don't compare to $z, since some Perl versions stringify $z into something
430 # like '1.e+129' or something equally ugly
431 $x = $class->new($z); ok ($x->bsstr(),'1e+129');
433 ###############################################################################
434 # test for whitespace inlcuding newlines to be handled correctly
436 # ok ($Math::BigInt::strict,1); # the default
439 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
441 my $m = $class->new($c);
442 ok ($class->new("$c"),$m);
443 ok ($class->new(" $c"),$m);
444 ok ($class->new("$c "),$m);
445 ok ($class->new(" $c "),$m);
446 ok ($class->new("\n$c"),$m);
447 ok ($class->new("$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 \n"),$m);
451 ok ($class->new(" \n$c\n "),$m);
452 ok ($class->new(" \n$c\n1"),'NaN');
453 ok ($class->new("1 \n$c\n1"),'NaN');
456 ###############################################################################
457 # prime number tests, also test for **= and length()
458 # found on: http://www.utm.edu/research/primes/notes/by_year.html
461 $x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
462 ok ($x,"20988936657440586486151264256610222593863921");
463 ok ($x->length(),length "20988936657440586486151264256610222593863921");
466 $x = $class->new(2); $x **= 127; $x--;
467 ok ($x,"170141183460469231731687303715884105727");
469 $x = $class->new('215960156869840440586892398248');
470 ($x,$y) = $x->length();
471 ok ($x,30); ok ($y,0);
473 $x = $class->new('1_000_000_000_000');
474 ($x,$y) = $x->length();
475 ok ($x,13); ok ($y,0);
477 # I am afraid the following is not yet possible due to slowness
478 # Also, testing for 2 meg output is a bit hard ;)
479 #$x = $class->new(2); $x **= 6972593; $x--;
481 # 593573509*2^332162+1 has exactly 1,000,000 digits
482 # takes about 24 mins on 300 Mhz, so cannot be done yet ;)
483 #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
484 #ok ($x->length(),1_000_000);
486 ###############################################################################
487 # inheritance and overriding of _swap
489 $x = Math::Foo->new(5);
490 $x = $x - 8; # 8 - 5 instead of 5-8
492 ok (ref($x),'Math::Foo');
494 $x = Math::Foo->new(5);
495 $x = 8 - $x; # 5 - 8 instead of 8 - 5
497 ok (ref($x),'Math::Foo');
499 ###############################################################################
500 # Test whether +inf eq inf
501 # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
502 # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
503 # like 1e100000 crash on some platforms. So simple test for the string 'inf'
504 $x = $class->new('+inf'); ok ($x,'inf');
506 ###############################################################################
507 ###############################################################################
508 # the followin tests only make sense with Math::BigInt::Calc or BareCalc or
511 exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
513 ###############################################################################
514 # check proper length of internal arrays
516 my $bl = $CL->_base_len();
517 my $BASE = '9' x $bl;
521 $x = $class->new($MAX); is_valid($x); # f.i. 9999
522 $x += 1; ok ($x,$BASE); is_valid($x); # 10000
523 $x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
525 ###############################################################################
528 $x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
529 $x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
531 # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
532 $x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
533 $x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
534 $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
535 ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
537 ###############################################################################
538 # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
540 $x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
541 if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
543 $x = $class->new($BASE+3); $x++;
544 if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
546 # test for +0 instead of int():
547 $x = $class->new($MAX); ok ($x->length(), length($MAX));
549 ###############################################################################
550 # test bug that $class->digit($string) did not work
552 ok ($class->digit(123,2),1);
554 ###############################################################################
555 # bug in sub where number with at least 6 trailing zeros after any op failed
557 $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
561 ###############################################################################
562 # bug in shortcut in mul()
564 # construct a number with a zero-hole of BASE_LEN_SMALL
566 my @bl = $CL->_base_len(); my $bl = $bl[4];
568 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
570 $x = $class->new($x)->bmul($y);
571 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
573 for (my $i = 1; $i <= $bl; $i++)
575 $y .= $i; $d = $i.$d;
577 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
581 #############################################################################
582 # see if mul shortcut for small numbers works
585 $x = $class->new($x);
586 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
587 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
590 ###############################################################################
591 # bug with rest "-0" in div, causing further div()s to fail
593 $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
595 ok ($y,'0'); is_valid($y); # $y not '-0'
597 ###############################################################################
598 # bug in $x->bmod($y)
600 # if $x < 0 and $y > 0
601 $x = $class->new('-629'); ok ($x->bmod(5033),4404);
603 ###############################################################################
604 # bone/binf etc as plain calls (Lite failed them)
606 ok ($class->bzero(),0);
607 ok ($class->bone(),1);
608 ok ($class->bone('+'),1);
609 ok ($class->bone('-'),-1);
610 ok ($class->bnan(),'NaN');
611 ok ($class->binf(),'inf');
612 ok ($class->binf('+'),'inf');
613 ok ($class->binf('-'),'-inf');
614 ok ($class->binf('-inf'),'-inf');
616 ###############################################################################
619 ok ($class->new(1)->is_one('-'),0);
620 ok ($class->new(-1)->is_one('-'),1);
621 ok ($class->new(1)->is_one(),1);
622 ok ($class->new(-1)->is_one(),0);
624 ###############################################################################
629 ###############################################################################
630 ###############################################################################
631 # Perl 5.005 does not like ok ($x,undef)
637 ok (1,1) and return if !defined $x;
641 ###############################################################################
642 # sub to check validity of a BigInt internally, to ensure that no op leaves a
643 # number object in an invalid state (f.i. "-0")
651 # allow the check to pass for all Lite, and all MBI and subclasses
653 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
655 if (ref($x) ne 'Math::BigInt::Lite')
658 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
659 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
661 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
662 $e = $CALC->_check($x->{value}) if $e eq '0';
665 # test done, see if error did crop up
666 ok (1,1), return if ($e eq '0');
668 ok (1,$e." after op '$f'");
748 -123456789:+987654321:-1
749 +123456789:-987654321:-1
750 +987654321:+123456789:1
751 -987654321:+123456789:1
797 0b10000000000001:8193
798 0b100000000000001:16385
799 0b1000000000000001:32769
800 0b10000000000000001:65537
801 0b100000000000000001:131073
802 0b1000000000000000001:262145
803 0b10000000000000000001:524289
804 0b100000000000000000001:1048577
805 0b1000000000000000000001:2097153
806 0b10000000000000000000001:4194305
807 0b100000000000000000000001:8388609
808 0b1000000000000000000000001:16777217
809 0b10000000000000000000000001:33554433
810 0b100000000000000000000000001:67108865
811 0b1000000000000000000000000001:134217729
812 0b10000000000000000000000000001:268435457
813 0b100000000000000000000000000001:536870913
814 0b1000000000000000000000000000001:1073741825
815 0b10000000000000000000000000000001:2147483649
816 0b100000000000000000000000000000001:4294967297
817 0b1000000000000000000000000000000001:8589934593
818 0b10000000000000000000000000000000001:17179869185
830 0x1_2_3_4_56_78:305419896
831 0xa_b_c_d_e_f:11259375
860 0x40000001:1073741825
861 0x80000001:2147483649
862 0x100000001:4294967297
863 0x200000001:8589934593
864 0x400000001:17179869185
865 0x800000001:34359738369
879 # only one underscore between two digits
897 # bug with two E's in number beeing valid
901 # bug with two '.' in number beeing valid
925 01234567891:1234567891
926 012345678912:12345678912
927 0123456789123:123456789123
928 01234567891234:1234567891234
945 -123456789:-123456789
954 # floating point input
962 # non-integer numbers
1001 # it must be exactly /^[+-]inf$/
1008 +1:+48:281474976710656
1011 +12345:4:10:123450000
1017 1234567890123:12:10:1234567890123000000000000
1021 -102533203:1:2:-205066406
1026 +281474976710656:+48:1
1037 1230000000000:10:10:123
1038 09876123456789067890:12:10:9876123
1039 1234561234567890123:13:10:123456
1040 820265627:1:2:410132813
1041 # test shifting negative numbers in base 2
1057 -1640531254:2:2:-410132814
1058 -1640531254:1:2:-820265627
1059 -820265627:1:2:-410132814
1060 -205066405:1:2:-102533203
1086 +123456789:-123456789
1087 -123456789:123456789
1095 +123456789:123456789
1096 -123456789:123456789
1121 -123456789:987654321:-1
1122 +123456789:-987654321:1
1123 -987654321:123456789:-1
1182 +9999999:+1:10000000
1183 +99999999:+1:100000000
1184 +999999999:+1:1000000000
1185 +9999999999:+1:10000000000
1186 +99999999999:+1:100000000000
1193 +10000000:-1:9999999
1194 +100000000:-1:99999999
1195 +1000000000:-1:999999999
1196 +10000000000:-1:9999999999
1197 +123456789:987654321:1111111110
1198 -123456789:987654321:864197532
1199 -123456789:-987654321:-1111111110
1200 +123456789:-987654321:-864197532
1204 -1:10000001:10000000
1205 -1:100000001:100000000
1206 -1:1000000001:1000000000
1207 -1:10000000001:10000000000
1208 -1:100000000001:100000000000
1209 -1:1000000000001:1000000000000
1210 -1:10000000000001:10000000000000
1213 -1:-1000001:-1000002
1214 -1:-10000001:-10000002
1215 -1:-100000001:-100000002
1216 -1:-1000000001:-1000000002
1217 -1:-10000000001:-10000000002
1218 -1:-100000000001:-100000000002
1219 -1:-1000000000001:-1000000000002
1220 -1:-10000000000001:-10000000000002
1245 +99999999:+1:99999998
1246 +999999999:+1:999999998
1247 +9999999999:+1:9999999998
1248 +99999999999:+1:99999999998
1255 +10000000:-1:10000001
1256 +100000000:-1:100000001
1257 +1000000000:-1:1000000001
1258 +10000000000:-1:10000000001
1259 +123456789:+987654321:-864197532
1260 -123456789:+987654321:-1111111110
1261 -123456789:-987654321:864197532
1262 +123456789:-987654321:1111111110
1267 100000001:1:100000000
1268 1000000001:1:1000000000
1269 10000000001:1:10000000000
1270 100000000001:1:100000000000
1271 1000000000001:1:1000000000000
1272 10000000000001:1:10000000000000
1276 10000001:-1:10000002
1277 100000001:-1:100000002
1278 1000000001:-1:1000000002
1279 10000000001:-1:10000000002
1280 100000000001:-1:100000000002
1281 1000000000001:-1:1000000000002
1282 10000000000001:-1:10000000000002
1300 123456789123456789:0:0
1301 0:123456789123456789:0
1311 10101:10101:102030201
1312 1001001:1001001:1002003002001
1313 100010001:100010001:10002000300020001
1314 10000100001:10000100001:100002000030000200001
1315 11111111111:9:99999999999
1316 22222222222:9:199999999998
1317 33333333333:9:299999999997
1318 44444444444:9:399999999996
1319 55555555555:9:499999999995
1320 66666666666:9:599999999994
1321 77777777777:9:699999999993
1322 88888888888:9:799999999992
1323 99999999999:9:899999999991
1325 +12345:+12345:152399025
1326 +99999:+11111:1111088889
1328 99999:100000:9999900000
1329 999999:1000000:999999000000
1330 9999999:10000000:99999990000000
1331 99999999:100000000:9999999900000000
1332 999999999:1000000000:999999999000000000
1333 9999999999:10000000000:99999999990000000000
1334 99999999999:100000000000:9999999999900000000000
1335 999999999999:1000000000000:999999999999000000000000
1336 9999999999999:10000000000000:99999999999990000000000000
1337 99999999999999:100000000000000:9999999999999900000000000000
1338 999999999999999:1000000000000000:999999999999999000000000000000
1339 9999999999999999:10000000000000000:99999999999999990000000000000000
1340 99999999999999999:100000000000000000:9999999999999999900000000000000000
1341 999999999999999999:1000000000000000000:999999999999999999000000000000000000
1342 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1352 # inf handling and general remainder
1358 # see table in documentation in MBI
1377 # exceptions to reminder rule
1381 # test the shortcut in Calc if @$x == @$yorg
1382 1234567812345678:123456712345678:10,688888898
1383 12345671234567:1234561234567:10,58888897
1384 123456123456:12345123456:10,4888896
1385 1234512345:123412345:10,388895
1386 1234567890999999999:1234567890:1000000000,999999999
1387 1234567890000000000:1234567890:1000000000,0
1388 1234567890999999999:9876543210:124999998,9503086419
1389 1234567890000000000:9876543210:124999998,8503086420
1390 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
1396 # inf handling (see table in doc)
1431 1000000000:9:111111111
1432 2000000000:9:222222222
1433 3000000000:9:333333333
1434 4000000000:9:444444444
1435 5000000000:9:555555555
1436 6000000000:9:666666666
1437 7000000000:9:777777777
1438 8000000000:9:888888888
1439 9000000000:9:1000000000
1442 106500000:339:314159
1443 1000000000:3:333333333
1448 999999999999:9:111111111111
1449 999999999999:99:10101010101
1450 999999999999:999:1001001001
1451 999999999999:9999:100010001
1452 999999999999999:99999:10000100001
1453 +1111088889:99999:11111
1468 # bug in Calc with '99999' vs $BASE-1
1469 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1470 # test the shortcut in Calc if @$x == @$yorg
1471 1234567812345678:123456712345678:10
1472 12345671234567:1234561234567:10
1473 123456123456:12345123456:10
1474 1234512345:123412345:10
1475 1234567890999999999:1234567890:1000000000
1476 1234567890000000000:1234567890:1000000000
1477 1234567890999999999:9876543210:124999998
1478 1234567890000000000:9876543210:124999998
1479 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
1480 # bug up to v0.35 in Calc (--$q one too many)
1481 84696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
1482 84696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
1483 84696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
1484 84696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
1486 # format: number:modulus:result
1487 # bmodinv Data errors
1491 # bmodinv Expected Results from normal use
1498 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
1499 ## bmodinv Error cases / useless use of function
1506 # format: number:exponent:modulus:result
1507 # bmodpow Data errors
1515 # bmodpow Expected results
1521 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1522 # bmodpow Error cases
1528 # inf handling, see table in doc
1547 # exceptions to reminder rule
1586 999999999999999:99999:0
1600 152403346:12345:4321
1602 # test shortcuts in Calc
1603 # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
1610 1234567891234567:9:1
1611 123456789123456789:9:0
1618 1234567891234567:10:7
1619 123456789123456789:10:9
1625 12345678912345:113:53
1626 1234567891234567:113:56
1627 123456789123456789:113:39
1628 # bug in bmod() not modifying the variable in place
1630 # bug in bmod() in Calc in the _div_use_div() shortcut code path,
1631 # when X == X and X was big
1632 111111111111111111111111111111:111111111111111111111111111111:0
1633 12345678901234567890:12345678901234567890:0
1666 +281474976710656:0:0
1667 +281474976710656:1:0
1668 +281474976710656:+281474976710656:281474976710656
1675 # equal arguments are treated special, so also do some test with unequal ones
1676 0xFFFF:0xFFFF:0x0xFFFF
1677 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1678 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1679 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1680 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1681 0xF0F0:0xF0F0:0x0xF0F0
1682 0x0F0F:0x0F0F:0x0x0F0F
1683 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1684 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1685 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1686 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1687 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1688 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1689 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1690 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1691 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1698 +281474976710656:0:281474976710656
1699 +281474976710656:1:281474976710657
1700 +281474976710656:281474976710656:281474976710656
1706 # equal arguments are treated special, so also do some test with unequal ones
1707 0xFFFF:0xFFFF:0x0xFFFF
1708 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1709 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1710 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1711 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1713 0:0xFFFFFF:0x0xFFFFFF
1714 0:0xFFFFFFFF:0x0xFFFFFFFF
1715 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1716 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1718 0xFFFFFF:0:0x0xFFFFFF
1719 0xFFFFFFFF:0:0x0xFFFFFFFF
1720 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1721 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1722 0xF0F0:0xF0F0:0x0xF0F0
1723 0x0F0F:0x0F0F:0x0x0F0F
1724 0xF0F0:0x0F0F:0x0xFFFF
1725 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1726 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1727 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1728 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1729 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1730 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1731 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1732 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1733 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1734 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1735 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1736 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1737 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1744 +281474976710656:0:281474976710656
1745 +281474976710656:1:281474976710657
1746 +281474976710656:281474976710656:0
1754 # equal arguments are treated special, so also do some test with unequal ones
1757 0xFFFFFFFF:0xFFFFFFFF:0
1758 0xFFFFFFFFFF:0xFFFFFFFFFF:0
1759 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
1761 0:0xFFFFFF:0x0xFFFFFF
1762 0:0xFFFFFFFF:0x0xFFFFFFFF
1763 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1764 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1766 0xFFFFFF:0:0x0xFFFFFF
1767 0xFFFFFFFF:0:0x0xFFFFFFFF
1768 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1769 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1772 0xF0F0:0x0F0F:0x0xFFFF
1775 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1776 0xF0F0F0F0:0xF0F0F0F0:0
1777 0x0F0F0F0F:0x0F0F0F0F:0
1778 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1779 0xF0F0F0F0F0:0xF0F0F0F0F0:0
1780 0x0F0F0F0F0F:0x0F0F0F0F0F:0
1781 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1782 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
1783 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
1784 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1789 +281474976710656:-281474976710657
1887 -inf:1234500012:-inf
1888 +inf:-12345000123:inf
1889 -inf:-12345000123:-inf
1890 # 1 ** -x => 1 / (1 ** x)
1910 10:20:100000000000000000000
1911 123456:2:15241383936
1918 10000000000000000:17
1920 215960156869840440586892398248:30
1926 # -$x ** (1/2) => -$y, but not in froot()
1971 18446744073709551616:4:65536
1972 18446744073709551616:8:256
1973 18446744073709551616:16:16
1974 18446744073709551616:32:4
1975 18446744073709551616:64:2
1976 18446744073709551616:128:1
1992 4000000000000:2000000
2004 $round_mode('trunc')
2014 +10123456789:5:10123000000
2015 -10123456789:5:-10123000000
2016 +10123456789:9:10123456700
2017 -10123456789:9:-10123456700
2018 +101234500:6:101234000
2019 -101234500:6:-101234000
2020 #+101234500:-4:101234000
2021 #-101234500:-4:-101234000
2023 +20123456789:5:20123000000
2024 -20123456789:5:-20123000000
2025 +20123456789:9:20123456800
2026 -20123456789:9:-20123456800
2027 +201234500:6:201234000
2028 -201234500:6:-201234000
2029 #+201234500:-4:201234000
2030 #-201234500:-4:-201234000
2031 +12345000:4:12340000
2032 -12345000:4:-12340000
2034 +30123456789:5:30123000000
2035 -30123456789:5:-30123000000
2036 +30123456789:9:30123456800
2037 -30123456789:9:-30123456800
2038 +301234500:6:301235000
2039 -301234500:6:-301234000
2040 #+301234500:-4:301235000
2041 #-301234500:-4:-301234000
2042 +12345000:4:12350000
2043 -12345000:4:-12340000
2045 +40123456789:5:40123000000
2046 -40123456789:5:-40123000000
2047 +40123456789:9:40123456800
2048 -40123456789:9:-40123456800
2049 +401234500:6:401234000
2050 +401234500:6:401234000
2051 #-401234500:-4:-401235000
2052 #-401234500:-4:-401235000
2053 +12345000:4:12340000
2054 -12345000:4:-12350000
2056 +50123456789:5:50123000000
2057 -50123456789:5:-50123000000
2058 +50123456789:9:50123456800
2059 -50123456789:9:-50123456800
2060 +501234500:6:501235000
2061 -501234500:6:-501235000
2062 #+501234500:-4:501235000
2063 #-501234500:-4:-501235000
2064 +12345000:4:12350000
2065 -12345000:4:-12350000
2067 +60123456789:5:60123000000
2068 -60123456789:5:-60123000000
2069 +60123456789:9:60123456800
2070 -60123456789:9:-60123456800
2071 +601234500:6:601234000
2072 -601234500:6:-601234000
2073 #+601234500:-4:601234000
2074 #-601234500:-4:-601234000
2081 +12345000:4:12340000
2082 -12345000:4:-12340000
2100 # floor and ceil tests are pretty pointless in integer space...but play safe
2127 0x123456789123456789:0x123456789123456789
2137 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
2138 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001