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 "blog"){
160 $try .= "\$x->blog(\$y);";
161 }elsif ($f eq "band"){
162 $try .= "\$x & \$y;";
163 }elsif ($f eq "bior"){
164 $try .= "\$x | \$y;";
165 }elsif ($f eq "bxor"){
166 $try .= "\$x ^ \$y;";
167 }elsif ($f eq "bpow"){
168 $try .= "\$x ** \$y;";
169 } elsif( $f eq "bmodinv") {
170 $try .= "\$x->bmodinv(\$y);";
171 }elsif ($f eq "digit"){
172 $try .= "\$x->digit(\$y);";
174 $try .= "\$z = $class->new(\"$args[2]\");";
176 # Functions with three arguments
177 if( $f eq "bmodpow") {
178 $try .= "\$x->bmodpow(\$y,\$z);";
179 } else { warn "Unknown op '$f'"; }
181 } # end else all other ops
184 # convert hex/binary targets to decimal
185 if ($ans =~ /^(0x0x|0b0b)/)
187 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
195 # print "try: $try ans: $ans1 $ans\n";
196 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
197 ok (ref($ans),$expected_class) if $expected_class ne $class;
199 # check internal state of number objects
200 is_valid($ans1,$f) if ref $ans1;
201 } # endwhile data tests
206 for (my $i = 1; $i < 10; $i++)
210 ok "@a", "1 2 3 4 5 6 7 8 9";
212 # test whether self-multiplication works correctly (result is 2**64)
213 $try = "\$x = $class->new('4294967296');";
214 $try .= '$a = $x->bmul($x);';
216 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
218 $try = "\$x = $class->new(10);";
219 $try .= '$a = $x->bpow($x);';
221 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
223 ###############################################################################
224 # test whether op destroys args or not (should better not)
250 $x = $class->new(-5); $y = -$x;
253 $x = $class->new(-5); $y = abs($x);
257 $y = $class->new(-1);
258 $z = $class->new(5033);
259 my $u = $x->copy()->bmodpow($y,$z);
264 $x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
265 $x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
267 $x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
268 $x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
269 $x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
270 $x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
271 $x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
273 $x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
274 $x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
275 $x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
276 $x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
277 $x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
279 $x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
280 $x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
281 $x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
282 $x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
283 $x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
285 ###############################################################################
286 # check whether overloading cmp works
287 $try = "\$x = $class->new(0);";
289 $try .= "'false' if \$x ne \$y;";
291 print "# For '$try'\n" if (!ok "$ans" , "false" );
293 # we cant test for working cmpt with other objects here, we would need a dummy
294 # object with stringify overload for this. see Math::String tests as example
296 ###############################################################################
297 # check reversed order of arguments
299 $try = "\$x = $class->new(10); \$x = 2 ** \$x;";
300 $try .= "'ok' if \$x == 1024;"; $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 == 20;"; $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 == 12;"; $ans = eval $try;
309 print "# For '$try'\n" if (!ok "$ans" , "ok" );
311 $try = "\$x = $class\->new(10); \$x = 2 - \$x;";
312 $try .= "'ok' if \$x == -8;"; $ans = eval $try;
313 print "# For '$try'\n" if (!ok "$ans" , "ok" );
315 $try = "\$x = $class\->new(10); \$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(3); \$x = 20 % \$x;";
320 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
321 print "# For '$try'\n" if (!ok "$ans" , "ok" );
323 $try = "\$x = $class\->new(7); \$x = 20 & \$x;";
324 $try .= "'ok' if \$x == 4;"; $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 $try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
332 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
333 print "# For '$try'\n" if (!ok "$ans" , "ok" );
335 ###############################################################################
336 # check badd(4,5) form
338 $try = "\$x = $class\->badd(4,5);";
339 $try .= "'ok' if \$x == 9;";
341 print "# For '$try'\n" if (!ok "$ans" , "ok" );
343 ###############################################################################
344 # check undefs: NOT DONE YET
346 ###############################################################################
349 $x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
350 $x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
352 ###############################################################################
355 @args = Math::BigInt::objectify(2,4,5);
356 ok (scalar @args,3); # $class, 4, 5
357 ok ($args[0] =~ /^Math::BigInt/);
361 @args = Math::BigInt::objectify(0,4,5);
362 ok (scalar @args,3); # $class, 4, 5
363 ok ($args[0] =~ /^Math::BigInt/);
367 @args = Math::BigInt::objectify(2,4,5);
368 ok (scalar @args,3); # $class, 4, 5
369 ok ($args[0] =~ /^Math::BigInt/);
373 @args = Math::BigInt::objectify(2,4,5,6,7);
374 ok (scalar @args,5); # $class, 4, 5, 6, 7
375 ok ($args[0] =~ /^Math::BigInt/);
376 ok ($args[1],4); ok (ref($args[1]),$args[0]);
377 ok ($args[2],5); ok (ref($args[2]),$args[0]);
378 ok ($args[3],6); ok (ref($args[3]),'');
379 ok ($args[4],7); ok (ref($args[4]),'');
381 @args = Math::BigInt::objectify(2,$class,4,5,6,7);
382 ok (scalar @args,5); # $class, 4, 5, 6, 7
383 ok ($args[0],$class);
384 ok ($args[1],4); ok (ref($args[1]),$args[0]);
385 ok ($args[2],5); ok (ref($args[2]),$args[0]);
386 ok ($args[3],6); ok (ref($args[3]),'');
387 ok ($args[4],7); ok (ref($args[4]),'');
389 ###############################################################################
390 # test whether an opp calls objectify properly or not (or at least does what
391 # it should do given non-objects, w/ or w/o objectify())
393 ok ($class->new(123)->badd(123),246);
394 ok ($class->badd(123,321),444);
395 ok ($class->badd(123,$class->new(321)),444);
397 ok ($class->new(123)->bsub(122),1);
398 ok ($class->bsub(321,123),198);
399 ok ($class->bsub(321,$class->new(123)),198);
401 ok ($class->new(123)->bmul(123),15129);
402 ok ($class->bmul(123,123),15129);
403 ok ($class->bmul(123,$class->new(123)),15129);
405 ok ($class->new(15129)->bdiv(123),123);
406 ok ($class->bdiv(15129,123),123);
407 ok ($class->bdiv(15129,$class->new(123)),123);
409 ok ($class->new(15131)->bmod(123),2);
410 ok ($class->bmod(15131,123),2);
411 ok ($class->bmod(15131,$class->new(123)),2);
413 ok ($class->new(2)->bpow(16),65536);
414 ok ($class->bpow(2,16),65536);
415 ok ($class->bpow(2,$class->new(16)),65536);
417 ok ($class->new(2**15)->brsft(1),2**14);
418 ok ($class->brsft(2**15,1),2**14);
419 ok ($class->brsft(2**15,$class->new(1)),2**14);
421 ok ($class->new(2**13)->blsft(1),2**14);
422 ok ($class->blsft(2**13,1),2**14);
423 ok ($class->blsft(2**13,$class->new(1)),2**14);
425 ###############################################################################
426 # test for floating-point input (other tests in bnorm() below)
428 $z = 1050000000000000; # may be int on systems with 64bit?
429 $x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
430 $z = 1e+129; # definitely a float (may fail on UTS)
431 # don't compare to $z, since some Perl versions stringify $z into something
432 # like '1.e+129' or something equally ugly
433 $x = $class->new($z); ok ($x->bsstr(),'1e+129');
435 ###############################################################################
436 # test for whitespace inlcuding newlines to be handled correctly
438 # ok ($Math::BigInt::strict,1); # the default
441 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
443 my $m = $class->new($c);
444 ok ($class->new("$c"),$m);
445 ok ($class->new(" $c"),$m);
446 ok ($class->new("$c "),$m);
447 ok ($class->new(" $c "),$m);
448 ok ($class->new("\n$c"),$m);
449 ok ($class->new("$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 \n"),$m);
453 ok ($class->new(" \n$c\n "),$m);
454 ok ($class->new(" \n$c\n1"),'NaN');
455 ok ($class->new("1 \n$c\n1"),'NaN');
458 ###############################################################################
459 # prime number tests, also test for **= and length()
460 # found on: http://www.utm.edu/research/primes/notes/by_year.html
463 $x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
464 ok ($x,"20988936657440586486151264256610222593863921");
465 ok ($x->length(),length "20988936657440586486151264256610222593863921");
468 $x = $class->new(2); $x **= 127; $x--;
469 ok ($x,"170141183460469231731687303715884105727");
471 $x = $class->new('215960156869840440586892398248');
472 ($x,$y) = $x->length();
473 ok ($x,30); ok ($y,0);
475 $x = $class->new('1_000_000_000_000');
476 ($x,$y) = $x->length();
477 ok ($x,13); ok ($y,0);
479 # I am afraid the following is not yet possible due to slowness
480 # Also, testing for 2 meg output is a bit hard ;)
481 #$x = $class->new(2); $x **= 6972593; $x--;
483 # 593573509*2^332162+1 has exactly 1,000,000 digits
484 # takes about 24 mins on 300 Mhz, so cannot be done yet ;)
485 #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
486 #ok ($x->length(),1_000_000);
488 ###############################################################################
489 # inheritance and overriding of _swap
491 $x = Math::Foo->new(5);
492 $x = $x - 8; # 8 - 5 instead of 5-8
494 ok (ref($x),'Math::Foo');
496 $x = Math::Foo->new(5);
497 $x = 8 - $x; # 5 - 8 instead of 8 - 5
499 ok (ref($x),'Math::Foo');
501 ###############################################################################
502 # Test whether +inf eq inf
503 # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
504 # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
505 # like 1e100000 crash on some platforms. So simple test for the string 'inf'
506 $x = $class->new('+inf'); ok ($x,'inf');
508 ###############################################################################
509 ###############################################################################
510 # the followin tests only make sense with Math::BigInt::Calc or BareCalc or
513 exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
515 ###############################################################################
516 # check proper length of internal arrays
518 my $bl = $CL->_base_len();
519 my $BASE = '9' x $bl;
523 $x = $class->new($MAX); is_valid($x); # f.i. 9999
524 $x += 1; ok ($x,$BASE); is_valid($x); # 10000
525 $x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
527 ###############################################################################
530 $x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
531 $x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
533 # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
534 $x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
535 $x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
536 $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
537 ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
539 ###############################################################################
540 # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
542 $x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
543 if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
545 $x = $class->new($BASE+3); $x++;
546 if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
548 # test for +0 instead of int():
549 $x = $class->new($MAX); ok ($x->length(), length($MAX));
551 ###############################################################################
552 # test bug that $class->digit($string) did not work
554 ok ($class->digit(123,2),1);
556 ###############################################################################
557 # bug in sub where number with at least 6 trailing zeros after any op failed
559 $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
563 ###############################################################################
564 # bug in shortcut in mul()
566 # construct a number with a zero-hole of BASE_LEN_SMALL
568 my @bl = $CL->_base_len(); my $bl = $bl[4];
570 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
572 $x = $class->new($x)->bmul($y);
573 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
575 for (my $i = 1; $i <= $bl; $i++)
577 $y .= $i; $d = $i.$d;
579 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
583 #############################################################################
584 # see if mul shortcut for small numbers works
587 $x = $class->new($x);
588 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
589 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
592 ###############################################################################
593 # bug with rest "-0" in div, causing further div()s to fail
595 $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
597 ok ($y,'0'); is_valid($y); # $y not '-0'
599 ###############################################################################
600 # bug in $x->bmod($y)
602 # if $x < 0 and $y > 0
603 $x = $class->new('-629'); ok ($x->bmod(5033),4404);
605 ###############################################################################
606 # bone/binf etc as plain calls (Lite failed them)
608 ok ($class->bzero(),0);
609 ok ($class->bone(),1);
610 ok ($class->bone('+'),1);
611 ok ($class->bone('-'),-1);
612 ok ($class->bnan(),'NaN');
613 ok ($class->binf(),'inf');
614 ok ($class->binf('+'),'inf');
615 ok ($class->binf('-'),'-inf');
616 ok ($class->binf('-inf'),'-inf');
618 ###############################################################################
621 ok ($class->new(1)->is_one('-'),0);
622 ok ($class->new(-1)->is_one('-'),1);
623 ok ($class->new(1)->is_one(),1);
624 ok ($class->new(-1)->is_one(),0);
626 ###############################################################################
627 # [perl #30609] bug with $x -= $x not beeing 0, but 2*$x
629 $x = $class->new(3); $x -= $x; ok ($x, 0);
630 $x = $class->new(-3); $x -= $x; ok ($x, 0);
631 $x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
632 $x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
633 $x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
635 $x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
636 $x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
637 $x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
638 $x = $class->new(3); $x += $x; ok ($x, 6);
639 $x = $class->new(-3); $x += $x; ok ($x, -6);
641 $x = $class->new(3); $x *= $x; ok ($x, 9);
642 $x = $class->new(-3); $x *= $x; ok ($x, 9);
643 $x = $class->new(3); $x /= $x; ok ($x, 1);
644 $x = $class->new(-3); $x /= $x; ok ($x, 1);
645 $x = $class->new(3); $x %= $x; ok ($x, 0);
646 $x = $class->new(-3); $x %= $x; ok ($x, 0);
648 ###############################################################################
653 ###############################################################################
654 ###############################################################################
655 # Perl 5.005 does not like ok ($x,undef)
661 ok (1,1) and return if !defined $x;
665 ###############################################################################
666 # sub to check validity of a BigInt internally, to ensure that no op leaves a
667 # number object in an invalid state (f.i. "-0")
675 # allow the check to pass for all Lite, and all MBI and subclasses
677 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
679 if (ref($x) ne 'Math::BigInt::Lite')
682 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
683 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
685 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
686 $e = $CALC->_check($x->{value}) if $e eq '0';
689 # test done, see if error did crop up
690 ok (1,1), return if ($e eq '0');
692 ok (1,$e." after op '$f'");
752 2251799813685248:8:17
753 72057594037927936:2:56
754 144115188075855872:2:57
755 288230376151711744:2:58
756 576460752303423488:2:59
758 1329227995784915872903807060280344576:2:120
759 # $x == $base => result 1
761 # $x < $base => result 0 ($base ** 0 <= $x)
763 # $x == 1 => result 0
817 -123456789:+987654321:-1
818 +123456789:-987654321:-1
819 +987654321:+123456789:1
820 -987654321:+123456789:1
870 0b10000000000001:8193
871 0b100000000000001:16385
872 0b1000000000000001:32769
873 0b10000000000000001:65537
874 0b100000000000000001:131073
875 0b1000000000000000001:262145
876 0b10000000000000000001:524289
877 0b100000000000000000001:1048577
878 0b1000000000000000000001:2097153
879 0b10000000000000000000001:4194305
880 0b100000000000000000000001:8388609
881 0b1000000000000000000000001:16777217
882 0b10000000000000000000000001:33554433
883 0b100000000000000000000000001:67108865
884 0b1000000000000000000000000001:134217729
885 0b10000000000000000000000000001:268435457
886 0b100000000000000000000000000001:536870913
887 0b1000000000000000000000000000001:1073741825
888 0b10000000000000000000000000000001:2147483649
889 0b100000000000000000000000000000001:4294967297
890 0b1000000000000000000000000000000001:8589934593
891 0b10000000000000000000000000000000001:17179869185
903 0x1_2_3_4_56_78:305419896
904 0xa_b_c_d_e_f:11259375
933 0x40000001:1073741825
934 0x80000001:2147483649
935 0x100000001:4294967297
936 0x200000001:8589934593
937 0x400000001:17179869185
938 0x800000001:34359738369
952 # only one underscore between two digits
970 # bug with two E's in number beeing valid
974 # bug with two '.' in number beeing valid
998 01234567891:1234567891
999 012345678912:12345678912
1000 0123456789123:123456789123
1001 01234567891234:1234567891234
1007 000000000000000000:0
1018 -123456789:-123456789
1019 -00000100000:-100000
1027 # floating point input
1035 # non-integer numbers
1074 # it must be exactly /^[+-]inf$/
1081 +1:+48:281474976710656
1084 +12345:4:10:123450000
1090 1234567890123:12:10:1234567890123000000000000
1094 -102533203:1:2:-205066406
1099 +281474976710656:+48:1
1110 1230000000000:10:10:123
1111 09876123456789067890:12:10:9876123
1112 1234561234567890123:13:10:123456
1113 820265627:1:2:410132813
1114 # test shifting negative numbers in base 2
1130 -1640531254:2:2:-410132814
1131 -1640531254:1:2:-820265627
1132 -820265627:1:2:-410132814
1133 -205066405:1:2:-102533203
1159 +123456789:-123456789
1160 -123456789:123456789
1168 +123456789:123456789
1169 -123456789:123456789
1194 -123456789:987654321:-1
1195 +123456789:-987654321:1
1196 -987654321:123456789:-1
1255 +9999999:+1:10000000
1256 +99999999:+1:100000000
1257 +999999999:+1:1000000000
1258 +9999999999:+1:10000000000
1259 +99999999999:+1:100000000000
1266 +10000000:-1:9999999
1267 +100000000:-1:99999999
1268 +1000000000:-1:999999999
1269 +10000000000:-1:9999999999
1270 +123456789:987654321:1111111110
1271 -123456789:987654321:864197532
1272 -123456789:-987654321:-1111111110
1273 +123456789:-987654321:-864197532
1277 -1:10000001:10000000
1278 -1:100000001:100000000
1279 -1:1000000001:1000000000
1280 -1:10000000001:10000000000
1281 -1:100000000001:100000000000
1282 -1:1000000000001:1000000000000
1283 -1:10000000000001:10000000000000
1286 -1:-1000001:-1000002
1287 -1:-10000001:-10000002
1288 -1:-100000001:-100000002
1289 -1:-1000000001:-1000000002
1290 -1:-10000000001:-10000000002
1291 -1:-100000000001:-100000000002
1292 -1:-1000000000001:-1000000000002
1293 -1:-10000000000001:-10000000000002
1318 +99999999:+1:99999998
1319 +999999999:+1:999999998
1320 +9999999999:+1:9999999998
1321 +99999999999:+1:99999999998
1328 +10000000:-1:10000001
1329 +100000000:-1:100000001
1330 +1000000000:-1:1000000001
1331 +10000000000:-1:10000000001
1332 +123456789:+987654321:-864197532
1333 -123456789:+987654321:-1111111110
1334 -123456789:-987654321:864197532
1335 +123456789:-987654321:1111111110
1340 100000001:1:100000000
1341 1000000001:1:1000000000
1342 10000000001:1:10000000000
1343 100000000001:1:100000000000
1344 1000000000001:1:1000000000000
1345 10000000000001:1:10000000000000
1349 10000001:-1:10000002
1350 100000001:-1:100000002
1351 1000000001:-1:1000000002
1352 10000000001:-1:10000000002
1353 100000000001:-1:100000000002
1354 1000000000001:-1:1000000000002
1355 10000000000001:-1:10000000000002
1373 123456789123456789:0:0
1374 0:123456789123456789:0
1384 10101:10101:102030201
1385 1001001:1001001:1002003002001
1386 100010001:100010001:10002000300020001
1387 10000100001:10000100001:100002000030000200001
1388 11111111111:9:99999999999
1389 22222222222:9:199999999998
1390 33333333333:9:299999999997
1391 44444444444:9:399999999996
1392 55555555555:9:499999999995
1393 66666666666:9:599999999994
1394 77777777777:9:699999999993
1395 88888888888:9:799999999992
1396 99999999999:9:899999999991
1398 +12345:+12345:152399025
1399 +99999:+11111:1111088889
1401 99999:100000:9999900000
1402 999999:1000000:999999000000
1403 9999999:10000000:99999990000000
1404 99999999:100000000:9999999900000000
1405 999999999:1000000000:999999999000000000
1406 9999999999:10000000000:99999999990000000000
1407 99999999999:100000000000:9999999999900000000000
1408 999999999999:1000000000000:999999999999000000000000
1409 9999999999999:10000000000000:99999999999990000000000000
1410 99999999999999:100000000000000:9999999999999900000000000000
1411 999999999999999:1000000000000000:999999999999999000000000000000
1412 9999999999999999:10000000000000000:99999999999999990000000000000000
1413 99999999999999999:100000000000000000:9999999999999999900000000000000000
1414 999999999999999999:1000000000000000000:999999999999999999000000000000000000
1415 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1425 # inf handling and general remainder
1431 # see table in documentation in MBI
1450 # exceptions to reminder rule
1454 # test the shortcut in Calc if @$x == @$yorg
1455 1234567812345678:123456712345678:10,688888898
1456 12345671234567:1234561234567:10,58888897
1457 123456123456:12345123456:10,4888896
1458 1234512345:123412345:10,388895
1459 1234567890999999999:1234567890:1000000000,999999999
1460 1234567890000000000:1234567890:1000000000,0
1461 1234567890999999999:9876543210:124999998,9503086419
1462 1234567890000000000:9876543210:124999998,8503086420
1463 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
1469 # inf handling (see table in doc)
1504 1000000000:9:111111111
1505 2000000000:9:222222222
1506 3000000000:9:333333333
1507 4000000000:9:444444444
1508 5000000000:9:555555555
1509 6000000000:9:666666666
1510 7000000000:9:777777777
1511 8000000000:9:888888888
1512 9000000000:9:1000000000
1515 106500000:339:314159
1516 1000000000:3:333333333
1521 999999999999:9:111111111111
1522 999999999999:99:10101010101
1523 999999999999:999:1001001001
1524 999999999999:9999:100010001
1525 999999999999999:99999:10000100001
1526 +1111088889:99999:11111
1541 # bug in Calc with '99999' vs $BASE-1
1542 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1543 # test the shortcut in Calc if @$x == @$yorg
1544 1234567812345678:123456712345678:10
1545 12345671234567:1234561234567:10
1546 123456123456:12345123456:10
1547 1234512345:123412345:10
1548 1234567890999999999:1234567890:1000000000
1549 1234567890000000000:1234567890:1000000000
1550 1234567890999999999:9876543210:124999998
1551 1234567890000000000:9876543210:124999998
1552 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
1553 # bug up to v0.35 in Calc (--$q one too many)
1554 84696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
1555 84696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
1556 84696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
1557 84696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
1559 # format: number:modulus:result
1560 # bmodinv Data errors
1564 # bmodinv Expected Results from normal use
1571 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
1572 ## bmodinv Error cases / useless use of function
1579 # format: number:exponent:modulus:result
1580 # bmodpow Data errors
1588 # bmodpow Expected results
1594 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1595 # bmodpow Error cases
1601 # inf handling, see table in doc
1620 # exceptions to reminder rule
1659 999999999999999:99999:0
1673 152403346:12345:4321
1675 # test shortcuts in Calc
1676 # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
1683 1234567891234567:9:1
1684 123456789123456789:9:0
1691 1234567891234567:10:7
1692 123456789123456789:10:9
1698 12345678912345:113:53
1699 1234567891234567:113:56
1700 123456789123456789:113:39
1701 # bug in bmod() not modifying the variable in place
1703 # bug in bmod() in Calc in the _div_use_div() shortcut code path,
1704 # when X == X and X was big
1705 111111111111111111111111111111:111111111111111111111111111111:0
1706 12345678901234567890:12345678901234567890:0
1750 +281474976710656:0:0
1751 +281474976710656:1:0
1752 +281474976710656:+281474976710656:281474976710656
1753 281474976710656:-1:281474976710656
1760 # negative argument is bitwise shorter than positive [perl #26559]
1763 # equal arguments are treated special, so also do some test with unequal ones
1764 0xFFFF:0xFFFF:0x0xFFFF
1765 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1766 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1767 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1768 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1769 0xF0F0:0xF0F0:0x0xF0F0
1770 0x0F0F:0x0F0F:0x0x0F0F
1771 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1772 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1773 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1774 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1775 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1776 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1777 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1778 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1779 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1786 +281474976710656:0:281474976710656
1787 +281474976710656:1:281474976710657
1788 +281474976710656:281474976710656:281474976710656
1794 +281474976710656:-1:-1
1799 # equal arguments are treated special, so also do some test with unequal ones
1800 0xFFFF:0xFFFF:0x0xFFFF
1801 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1802 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1803 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1804 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1806 0:0xFFFFFF:0x0xFFFFFF
1807 0:0xFFFFFFFF:0x0xFFFFFFFF
1808 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1809 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1811 0xFFFFFF:0:0x0xFFFFFF
1812 0xFFFFFFFF:0:0x0xFFFFFFFF
1813 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1814 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1815 0xF0F0:0xF0F0:0x0xF0F0
1816 0x0F0F:0x0F0F:0x0x0F0F
1817 0xF0F0:0x0F0F:0x0xFFFF
1818 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1819 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1820 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1821 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1822 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1823 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1824 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1825 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1826 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1827 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1828 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1829 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1830 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1837 +281474976710656:0:281474976710656
1838 +281474976710656:1:281474976710657
1839 +281474976710656:281474976710656:0
1851 # equal arguments are treated special, so also do some test with unequal ones
1854 0xFFFFFFFF:0xFFFFFFFF:0
1855 0xFFFFFFFFFF:0xFFFFFFFFFF:0
1856 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
1858 0:0xFFFFFF:0x0xFFFFFF
1859 0:0xFFFFFFFF:0x0xFFFFFFFF
1860 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1861 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1863 0xFFFFFF:0:0x0xFFFFFF
1864 0xFFFFFFFF:0:0x0xFFFFFFFF
1865 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1866 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1869 0xF0F0:0x0F0F:0x0xFFFF
1872 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1873 0xF0F0F0F0:0xF0F0F0F0:0
1874 0x0F0F0F0F:0x0F0F0F0F:0
1875 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1876 0xF0F0F0F0F0:0xF0F0F0F0F0:0
1877 0x0F0F0F0F0F:0x0F0F0F0F0F:0
1878 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1879 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
1880 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
1881 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1886 +281474976710656:-281474976710657
1984 -inf:1234500012:-inf
1985 +inf:-12345000123:inf
1986 -inf:-12345000123:-inf
1987 # 1 ** -x => 1 / (1 ** x)
2007 10:20:100000000000000000000
2008 123456:2:15241383936
2023 10000000000000000:17
2025 215960156869840440586892398248:30
2031 # -$x ** (1/2) => -$y, but not in froot()
2076 18446744073709551616:4:65536
2077 18446744073709551616:8:256
2078 18446744073709551616:16:16
2079 18446744073709551616:32:4
2080 18446744073709551616:64:2
2081 18446744073709551616:128:1
2083 84274086103068221283760416414557757:15:213
2084 # see t/bigroot for more tests
2100 4000000000000:2000000
2104 # 2 ** 64 => 2 ** 32
2105 18446744073709551616:4294967296
2106 84274086103068221283760416414557757:290299993288095377
2115 $round_mode('trunc')
2125 +10123456789:5:10123000000
2126 -10123456789:5:-10123000000
2127 +10123456789:9:10123456700
2128 -10123456789:9:-10123456700
2129 +101234500:6:101234000
2130 -101234500:6:-101234000
2131 #+101234500:-4:101234000
2132 #-101234500:-4:-101234000
2134 +20123456789:5:20123000000
2135 -20123456789:5:-20123000000
2136 +20123456789:9:20123456800
2137 -20123456789:9:-20123456800
2138 +201234500:6:201234000
2139 -201234500:6:-201234000
2140 #+201234500:-4:201234000
2141 #-201234500:-4:-201234000
2142 +12345000:4:12340000
2143 -12345000:4:-12340000
2145 +30123456789:5:30123000000
2146 -30123456789:5:-30123000000
2147 +30123456789:9:30123456800
2148 -30123456789:9:-30123456800
2149 +301234500:6:301235000
2150 -301234500:6:-301234000
2151 #+301234500:-4:301235000
2152 #-301234500:-4:-301234000
2153 +12345000:4:12350000
2154 -12345000:4:-12340000
2156 +40123456789:5:40123000000
2157 -40123456789:5:-40123000000
2158 +40123456789:9:40123456800
2159 -40123456789:9:-40123456800
2160 +401234500:6:401234000
2161 +401234500:6:401234000
2162 #-401234500:-4:-401235000
2163 #-401234500:-4:-401235000
2164 +12345000:4:12340000
2165 -12345000:4:-12350000
2167 +50123456789:5:50123000000
2168 -50123456789:5:-50123000000
2169 +50123456789:9:50123456800
2170 -50123456789:9:-50123456800
2171 +501234500:6:501235000
2172 -501234500:6:-501235000
2173 #+501234500:-4:501235000
2174 #-501234500:-4:-501235000
2175 +12345000:4:12350000
2176 -12345000:4:-12350000
2178 +60123456789:5:60123000000
2179 -60123456789:5:-60123000000
2180 +60123456789:9:60123456800
2181 -60123456789:9:-60123456800
2182 +601234500:6:601234000
2183 -601234500:6:-601234000
2184 #+601234500:-4:601234000
2185 #-601234500:-4:-601234000
2192 +12345000:4:12340000
2193 -12345000:4:-12340000
2211 # floor and ceil tests are pretty pointless in integer space...but play safe
2238 0x123456789123456789:0x123456789123456789
2248 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
2249 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001