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 ###############################################################################
631 ###############################################################################
632 ###############################################################################
633 # Perl 5.005 does not like ok ($x,undef)
639 ok (1,1) and return if !defined $x;
643 ###############################################################################
644 # sub to check validity of a BigInt internally, to ensure that no op leaves a
645 # number object in an invalid state (f.i. "-0")
653 # allow the check to pass for all Lite, and all MBI and subclasses
655 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
657 if (ref($x) ne 'Math::BigInt::Lite')
660 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
661 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
663 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
664 $e = $CALC->_check($x->{value}) if $e eq '0';
667 # test done, see if error did crop up
668 ok (1,1), return if ($e eq '0');
670 ok (1,$e." after op '$f'");
730 2251799813685248:8:17
731 72057594037927936:2:56
732 144115188075855872:2:57
733 288230376151711744:2:58
734 576460752303423488:2:59
736 1329227995784915872903807060280344576:2:120
737 # $x == $base => result 1
739 # $x < $base => result 0 ($base ** 0 <= $x)
741 # $x == 1 => result 0
795 -123456789:+987654321:-1
796 +123456789:-987654321:-1
797 +987654321:+123456789:1
798 -987654321:+123456789:1
844 0b10000000000001:8193
845 0b100000000000001:16385
846 0b1000000000000001:32769
847 0b10000000000000001:65537
848 0b100000000000000001:131073
849 0b1000000000000000001:262145
850 0b10000000000000000001:524289
851 0b100000000000000000001:1048577
852 0b1000000000000000000001:2097153
853 0b10000000000000000000001:4194305
854 0b100000000000000000000001:8388609
855 0b1000000000000000000000001:16777217
856 0b10000000000000000000000001:33554433
857 0b100000000000000000000000001:67108865
858 0b1000000000000000000000000001:134217729
859 0b10000000000000000000000000001:268435457
860 0b100000000000000000000000000001:536870913
861 0b1000000000000000000000000000001:1073741825
862 0b10000000000000000000000000000001:2147483649
863 0b100000000000000000000000000000001:4294967297
864 0b1000000000000000000000000000000001:8589934593
865 0b10000000000000000000000000000000001:17179869185
877 0x1_2_3_4_56_78:305419896
878 0xa_b_c_d_e_f:11259375
907 0x40000001:1073741825
908 0x80000001:2147483649
909 0x100000001:4294967297
910 0x200000001:8589934593
911 0x400000001:17179869185
912 0x800000001:34359738369
926 # only one underscore between two digits
944 # bug with two E's in number beeing valid
948 # bug with two '.' in number beeing valid
972 01234567891:1234567891
973 012345678912:12345678912
974 0123456789123:123456789123
975 01234567891234:1234567891234
992 -123456789:-123456789
1001 # floating point input
1009 # non-integer numbers
1048 # it must be exactly /^[+-]inf$/
1055 +1:+48:281474976710656
1058 +12345:4:10:123450000
1064 1234567890123:12:10:1234567890123000000000000
1068 -102533203:1:2:-205066406
1073 +281474976710656:+48:1
1084 1230000000000:10:10:123
1085 09876123456789067890:12:10:9876123
1086 1234561234567890123:13:10:123456
1087 820265627:1:2:410132813
1088 # test shifting negative numbers in base 2
1104 -1640531254:2:2:-410132814
1105 -1640531254:1:2:-820265627
1106 -820265627:1:2:-410132814
1107 -205066405:1:2:-102533203
1133 +123456789:-123456789
1134 -123456789:123456789
1142 +123456789:123456789
1143 -123456789:123456789
1168 -123456789:987654321:-1
1169 +123456789:-987654321:1
1170 -987654321:123456789:-1
1229 +9999999:+1:10000000
1230 +99999999:+1:100000000
1231 +999999999:+1:1000000000
1232 +9999999999:+1:10000000000
1233 +99999999999:+1:100000000000
1240 +10000000:-1:9999999
1241 +100000000:-1:99999999
1242 +1000000000:-1:999999999
1243 +10000000000:-1:9999999999
1244 +123456789:987654321:1111111110
1245 -123456789:987654321:864197532
1246 -123456789:-987654321:-1111111110
1247 +123456789:-987654321:-864197532
1251 -1:10000001:10000000
1252 -1:100000001:100000000
1253 -1:1000000001:1000000000
1254 -1:10000000001:10000000000
1255 -1:100000000001:100000000000
1256 -1:1000000000001:1000000000000
1257 -1:10000000000001:10000000000000
1260 -1:-1000001:-1000002
1261 -1:-10000001:-10000002
1262 -1:-100000001:-100000002
1263 -1:-1000000001:-1000000002
1264 -1:-10000000001:-10000000002
1265 -1:-100000000001:-100000000002
1266 -1:-1000000000001:-1000000000002
1267 -1:-10000000000001:-10000000000002
1292 +99999999:+1:99999998
1293 +999999999:+1:999999998
1294 +9999999999:+1:9999999998
1295 +99999999999:+1:99999999998
1302 +10000000:-1:10000001
1303 +100000000:-1:100000001
1304 +1000000000:-1:1000000001
1305 +10000000000:-1:10000000001
1306 +123456789:+987654321:-864197532
1307 -123456789:+987654321:-1111111110
1308 -123456789:-987654321:864197532
1309 +123456789:-987654321:1111111110
1314 100000001:1:100000000
1315 1000000001:1:1000000000
1316 10000000001:1:10000000000
1317 100000000001:1:100000000000
1318 1000000000001:1:1000000000000
1319 10000000000001:1:10000000000000
1323 10000001:-1:10000002
1324 100000001:-1:100000002
1325 1000000001:-1:1000000002
1326 10000000001:-1:10000000002
1327 100000000001:-1:100000000002
1328 1000000000001:-1:1000000000002
1329 10000000000001:-1:10000000000002
1347 123456789123456789:0:0
1348 0:123456789123456789:0
1358 10101:10101:102030201
1359 1001001:1001001:1002003002001
1360 100010001:100010001:10002000300020001
1361 10000100001:10000100001:100002000030000200001
1362 11111111111:9:99999999999
1363 22222222222:9:199999999998
1364 33333333333:9:299999999997
1365 44444444444:9:399999999996
1366 55555555555:9:499999999995
1367 66666666666:9:599999999994
1368 77777777777:9:699999999993
1369 88888888888:9:799999999992
1370 99999999999:9:899999999991
1372 +12345:+12345:152399025
1373 +99999:+11111:1111088889
1375 99999:100000:9999900000
1376 999999:1000000:999999000000
1377 9999999:10000000:99999990000000
1378 99999999:100000000:9999999900000000
1379 999999999:1000000000:999999999000000000
1380 9999999999:10000000000:99999999990000000000
1381 99999999999:100000000000:9999999999900000000000
1382 999999999999:1000000000000:999999999999000000000000
1383 9999999999999:10000000000000:99999999999990000000000000
1384 99999999999999:100000000000000:9999999999999900000000000000
1385 999999999999999:1000000000000000:999999999999999000000000000000
1386 9999999999999999:10000000000000000:99999999999999990000000000000000
1387 99999999999999999:100000000000000000:9999999999999999900000000000000000
1388 999999999999999999:1000000000000000000:999999999999999999000000000000000000
1389 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1399 # inf handling and general remainder
1405 # see table in documentation in MBI
1424 # exceptions to reminder rule
1428 # test the shortcut in Calc if @$x == @$yorg
1429 1234567812345678:123456712345678:10,688888898
1430 12345671234567:1234561234567:10,58888897
1431 123456123456:12345123456:10,4888896
1432 1234512345:123412345:10,388895
1433 1234567890999999999:1234567890:1000000000,999999999
1434 1234567890000000000:1234567890:1000000000,0
1435 1234567890999999999:9876543210:124999998,9503086419
1436 1234567890000000000:9876543210:124999998,8503086420
1437 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
1443 # inf handling (see table in doc)
1478 1000000000:9:111111111
1479 2000000000:9:222222222
1480 3000000000:9:333333333
1481 4000000000:9:444444444
1482 5000000000:9:555555555
1483 6000000000:9:666666666
1484 7000000000:9:777777777
1485 8000000000:9:888888888
1486 9000000000:9:1000000000
1489 106500000:339:314159
1490 1000000000:3:333333333
1495 999999999999:9:111111111111
1496 999999999999:99:10101010101
1497 999999999999:999:1001001001
1498 999999999999:9999:100010001
1499 999999999999999:99999:10000100001
1500 +1111088889:99999:11111
1515 # bug in Calc with '99999' vs $BASE-1
1516 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1517 # test the shortcut in Calc if @$x == @$yorg
1518 1234567812345678:123456712345678:10
1519 12345671234567:1234561234567:10
1520 123456123456:12345123456:10
1521 1234512345:123412345:10
1522 1234567890999999999:1234567890:1000000000
1523 1234567890000000000:1234567890:1000000000
1524 1234567890999999999:9876543210:124999998
1525 1234567890000000000:9876543210:124999998
1526 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
1527 # bug up to v0.35 in Calc (--$q one too many)
1528 84696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
1529 84696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
1530 84696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
1531 84696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
1533 # format: number:modulus:result
1534 # bmodinv Data errors
1538 # bmodinv Expected Results from normal use
1545 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
1546 ## bmodinv Error cases / useless use of function
1553 # format: number:exponent:modulus:result
1554 # bmodpow Data errors
1562 # bmodpow Expected results
1568 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1569 # bmodpow Error cases
1575 # inf handling, see table in doc
1594 # exceptions to reminder rule
1633 999999999999999:99999:0
1647 152403346:12345:4321
1649 # test shortcuts in Calc
1650 # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
1657 1234567891234567:9:1
1658 123456789123456789:9:0
1665 1234567891234567:10:7
1666 123456789123456789:10:9
1672 12345678912345:113:53
1673 1234567891234567:113:56
1674 123456789123456789:113:39
1675 # bug in bmod() not modifying the variable in place
1677 # bug in bmod() in Calc in the _div_use_div() shortcut code path,
1678 # when X == X and X was big
1679 111111111111111111111111111111:111111111111111111111111111111:0
1680 12345678901234567890:12345678901234567890:0
1713 +281474976710656:0:0
1714 +281474976710656:1:0
1715 +281474976710656:+281474976710656:281474976710656
1722 # equal arguments are treated special, so also do some test with unequal ones
1723 0xFFFF:0xFFFF:0x0xFFFF
1724 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1725 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1726 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1727 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1728 0xF0F0:0xF0F0:0x0xF0F0
1729 0x0F0F:0x0F0F:0x0x0F0F
1730 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1731 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1732 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1733 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1734 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1735 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1736 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1737 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1738 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1745 +281474976710656:0:281474976710656
1746 +281474976710656:1:281474976710657
1747 +281474976710656:281474976710656:281474976710656
1753 # equal arguments are treated special, so also do some test with unequal ones
1754 0xFFFF:0xFFFF:0x0xFFFF
1755 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1756 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1757 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1758 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1760 0:0xFFFFFF:0x0xFFFFFF
1761 0:0xFFFFFFFF:0x0xFFFFFFFF
1762 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1763 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1765 0xFFFFFF:0:0x0xFFFFFF
1766 0xFFFFFFFF:0:0x0xFFFFFFFF
1767 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1768 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1769 0xF0F0:0xF0F0:0x0xF0F0
1770 0x0F0F:0x0F0F:0x0x0F0F
1771 0xF0F0:0x0F0F:0x0xFFFF
1772 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1773 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1774 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1775 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1776 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1777 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1778 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1779 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1780 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1781 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1782 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1783 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1784 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1791 +281474976710656:0:281474976710656
1792 +281474976710656:1:281474976710657
1793 +281474976710656:281474976710656:0
1801 # equal arguments are treated special, so also do some test with unequal ones
1804 0xFFFFFFFF:0xFFFFFFFF:0
1805 0xFFFFFFFFFF:0xFFFFFFFFFF:0
1806 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
1808 0:0xFFFFFF:0x0xFFFFFF
1809 0:0xFFFFFFFF:0x0xFFFFFFFF
1810 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1811 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1813 0xFFFFFF:0:0x0xFFFFFF
1814 0xFFFFFFFF:0:0x0xFFFFFFFF
1815 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1816 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1819 0xF0F0:0x0F0F:0x0xFFFF
1822 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1823 0xF0F0F0F0:0xF0F0F0F0:0
1824 0x0F0F0F0F:0x0F0F0F0F:0
1825 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1826 0xF0F0F0F0F0:0xF0F0F0F0F0:0
1827 0x0F0F0F0F0F:0x0F0F0F0F0F:0
1828 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1829 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
1830 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
1831 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1836 +281474976710656:-281474976710657
1934 -inf:1234500012:-inf
1935 +inf:-12345000123:inf
1936 -inf:-12345000123:-inf
1937 # 1 ** -x => 1 / (1 ** x)
1957 10:20:100000000000000000000
1958 123456:2:15241383936
1965 10000000000000000:17
1967 215960156869840440586892398248:30
1973 # -$x ** (1/2) => -$y, but not in froot()
2018 18446744073709551616:4:65536
2019 18446744073709551616:8:256
2020 18446744073709551616:16:16
2021 18446744073709551616:32:4
2022 18446744073709551616:64:2
2023 18446744073709551616:128:1
2025 84274086103068221283760416414557757:15:213
2026 # see t/bigroot for more tests
2042 4000000000000:2000000
2046 # 2 ** 64 => 2 ** 32
2047 18446744073709551616:4294967296
2048 84274086103068221283760416414557757:290299993288095377
2057 $round_mode('trunc')
2067 +10123456789:5:10123000000
2068 -10123456789:5:-10123000000
2069 +10123456789:9:10123456700
2070 -10123456789:9:-10123456700
2071 +101234500:6:101234000
2072 -101234500:6:-101234000
2073 #+101234500:-4:101234000
2074 #-101234500:-4:-101234000
2076 +20123456789:5:20123000000
2077 -20123456789:5:-20123000000
2078 +20123456789:9:20123456800
2079 -20123456789:9:-20123456800
2080 +201234500:6:201234000
2081 -201234500:6:-201234000
2082 #+201234500:-4:201234000
2083 #-201234500:-4:-201234000
2084 +12345000:4:12340000
2085 -12345000:4:-12340000
2087 +30123456789:5:30123000000
2088 -30123456789:5:-30123000000
2089 +30123456789:9:30123456800
2090 -30123456789:9:-30123456800
2091 +301234500:6:301235000
2092 -301234500:6:-301234000
2093 #+301234500:-4:301235000
2094 #-301234500:-4:-301234000
2095 +12345000:4:12350000
2096 -12345000:4:-12340000
2098 +40123456789:5:40123000000
2099 -40123456789:5:-40123000000
2100 +40123456789:9:40123456800
2101 -40123456789:9:-40123456800
2102 +401234500:6:401234000
2103 +401234500:6:401234000
2104 #-401234500:-4:-401235000
2105 #-401234500:-4:-401235000
2106 +12345000:4:12340000
2107 -12345000:4:-12350000
2109 +50123456789:5:50123000000
2110 -50123456789:5:-50123000000
2111 +50123456789:9:50123456800
2112 -50123456789:9:-50123456800
2113 +501234500:6:501235000
2114 -501234500:6:-501235000
2115 #+501234500:-4:501235000
2116 #-501234500:-4:-501235000
2117 +12345000:4:12350000
2118 -12345000:4:-12350000
2120 +60123456789:5:60123000000
2121 -60123456789:5:-60123000000
2122 +60123456789:9:60123456800
2123 -60123456789:9:-60123456800
2124 +601234500:6:601234000
2125 -601234500:6:-601234000
2126 #+601234500:-4:601234000
2127 #-601234500:-4:-601234000
2134 +12345000:4:12340000
2135 -12345000:4:-12340000
2153 # floor and ceil tests are pretty pointless in integer space...but play safe
2180 0x123456789123456789:0x123456789123456789
2190 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
2191 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001