Move Math::BigInt from ext/ to cpan/
[p5sagit/p5-mst-13.2.git] / cpan / Math-BigInt / t / bigintpm.inc
CommitLineData
6854fd01 1#include this file into another for subclass testing
2
3my $version = ${"$class\::VERSION"};
4
56d9de68 5use strict;
6
6854fd01 7##############################################################################
8# for testing inheritance of _swap
9
10package Math::Foo;
11
61f5c3f5 12use Math::BigInt lib => $main::CL;
6854fd01 13use vars qw/@ISA/;
14@ISA = (qw/Math::BigInt/);
15
16use overload
17# customized overload for sub, since original does not use swap there
18'-' => sub { my @a = ref($_[0])->_swap(@_);
19 $a[0]->bsub($a[1])};
20
21sub _swap
22 {
23 # a fake _swap, which reverses the params
24 my $self = shift; # for override in subclass
25 if ($_[2])
26 {
27 my $c = ref ($_[0] ) || 'Math::Foo';
28 return ( $_[0]->copy(), $_[1] );
29 }
30 else
31 {
32 return ( Math::Foo->new($_[1]), $_[0] );
33 }
34 }
35
36##############################################################################
37package main;
38
b3abae2a 39my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
6854fd01 40
b3abae2a 41my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
6854fd01 42
43while (<DATA>)
44 {
f7f86b73 45 $_ =~ s/[\n\r]//g; # remove newlines
6854fd01 46 next if /^#/; # skip comments
47 if (s/^&//)
48 {
61f5c3f5 49 $f = $_; next;
6854fd01 50 }
51 elsif (/^\$/)
52 {
61f5c3f5 53 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
6854fd01 54 }
61f5c3f5 55
56 @args = split(/:/,$_,99); $ans = pop(@args);
b3abae2a 57 $expected_class = $class;
58 if ($ans =~ /(.*?)=(.*)/)
59 {
60 $expected_class = $2; $ans = $1;
61 }
61f5c3f5 62 $try = "\$x = $class->new(\"$args[0]\");";
63 if ($f eq "bnorm")
6854fd01 64 {
61f5c3f5 65 $try = "\$x = $class->bnorm(\"$args[0]\");";
66 # some is_xxx tests
b3abae2a 67 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
56d9de68 68 $try .= "\$x->$f() || 0;";
61f5c3f5 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]');";
56d9de68 75 # some unary ops
b3abae2a 76 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
61f5c3f5 77 $try .= "\$x->$f();";
56d9de68 78 } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
79 $try .= "\$x->$f();";
61f5c3f5 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;';
91 $try .= '"$m,$e";';
50109ad0 92 }elsif ($f eq "bexp"){
93 $try .= "\$x->bexp();";
fdb4b05f 94 } elsif ($f eq "bpi"){
95 $try .= "$class\->bpi(\$x);";
61f5c3f5 96 } else {
56d9de68 97 # binary ops
61f5c3f5 98 $try .= "\$y = $class->new('$args[1]');";
99 if ($f eq "bcmp")
100 {
a0ac753d 101 $try .= '$x->bcmp($y);';
61f5c3f5 102 } elsif ($f eq "bround") {
6854fd01 103 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5 104 } elsif ($f eq "bacmp"){
105 $try .= '$x->bacmp($y);';
106 } elsif ($f eq "badd"){
107 $try .= '$x + $y;';
108 } elsif ($f eq "bsub"){
109 $try .= '$x - $y;';
110 } elsif ($f eq "bmul"){
111 $try .= '$x * $y;';
112 } elsif ($f eq "bdiv"){
113 $try .= '$x / $y;';
114 } elsif ($f eq "bdiv-list"){
115 $try .= 'join (",",$x->bdiv($y));';
027dc388 116 # overload via x=
61f5c3f5 117 } elsif ($f =~ /^.=$/){
118 $try .= "\$x $f \$y;";
027dc388 119 # overload via x
61f5c3f5 120 } elsif ($f =~ /^.$/){
121 $try .= "\$x $f \$y;";
122 } elsif ($f eq "bmod"){
123 $try .= '$x % $y;';
124 } elsif ($f eq "bgcd")
6854fd01 125 {
126 if (defined $args[2])
127 {
61f5c3f5 128 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 129 }
130 $try .= "$class\::bgcd(\$x, \$y";
131 $try .= ", \$z" if (defined $args[2]);
132 $try .= " );";
133 }
134 elsif ($f eq "blcm")
135 {
136 if (defined $args[2])
137 {
61f5c3f5 138 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 139 }
140 $try .= "$class\::blcm(\$x, \$y";
141 $try .= ", \$z" if (defined $args[2]);
142 $try .= " );";
143 }elsif ($f eq "blsft"){
144 if (defined $args[2])
145 {
146 $try .= "\$x->blsft(\$y,$args[2]);";
147 }
148 else
149 {
150 $try .= "\$x << \$y;";
151 }
152 }elsif ($f eq "brsft"){
153 if (defined $args[2])
154 {
155 $try .= "\$x->brsft(\$y,$args[2]);";
156 }
157 else
158 {
159 $try .= "\$x >> \$y;";
160 }
50109ad0 161 }elsif ($f eq "bnok"){
162 $try .= "\$x->bnok(\$y);";
990fb837 163 }elsif ($f eq "broot"){
164 $try .= "\$x->broot(\$y);";
091c87b1 165 }elsif ($f eq "blog"){
166 $try .= "\$x->blog(\$y);";
6854fd01 167 }elsif ($f eq "band"){
168 $try .= "\$x & \$y;";
169 }elsif ($f eq "bior"){
170 $try .= "\$x | \$y;";
171 }elsif ($f eq "bxor"){
172 $try .= "\$x ^ \$y;";
173 }elsif ($f eq "bpow"){
174 $try .= "\$x ** \$y;";
d614cd8b 175 } elsif( $f eq "bmodinv") {
176 $try .= "\$x->bmodinv(\$y);";
6854fd01 177 }elsif ($f eq "digit"){
56b9c951 178 $try .= "\$x->digit(\$y);";
30afc38d 179 }elsif ($f eq "batan2"){
180 $try .= "\$x->batan2(\$y);";
d614cd8b 181 } else {
80365507 182 # Functions with three arguments
d614cd8b 183 $try .= "\$z = $class->new(\"$args[2]\");";
184
d614cd8b 185 if( $f eq "bmodpow") {
186 $try .= "\$x->bmodpow(\$y,\$z);";
80365507 187 } elsif ($f eq "bmuladd"){
188 $try .= "\$x->bmuladd(\$y,\$z);";
d614cd8b 189 } else { warn "Unknown op '$f'"; }
190 }
61f5c3f5 191 } # end else all other ops
192
193 $ans1 = eval $try;
194 # convert hex/binary targets to decimal
195 if ($ans =~ /^(0x0x|0b0b)/)
196 {
197 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 198 }
61f5c3f5 199 if ($ans eq "")
200 {
201 ok_undef ($ans1);
202 }
203 else
204 {
205 # print "try: $try ans: $ans1 $ans\n";
206 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 207 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 208 }
61f5c3f5 209 # check internal state of number objects
210 is_valid($ans1,$f) if ref $ans1;
6854fd01 211 } # endwhile data tests
212close DATA;
213
214# test some more
215@a = ();
216for (my $i = 1; $i < 10; $i++)
217 {
218 push @a, $i;
219 }
220ok "@a", "1 2 3 4 5 6 7 8 9";
221
222# test whether self-multiplication works correctly (result is 2**64)
223$try = "\$x = $class->new('4294967296');";
224$try .= '$a = $x->bmul($x);';
225$ans1 = eval $try;
226print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
227# test self-pow
228$try = "\$x = $class->new(10);";
229$try .= '$a = $x->bpow($x);';
230$ans1 = eval $try;
231print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
232
07d34614 233###############################################################################
6854fd01 234# test whether op destroys args or not (should better not)
235
236$x = $class->new(3);
237$y = $class->new(4);
238$z = $x & $y;
239ok ($x,3);
240ok ($y,4);
241ok ($z,0);
242$z = $x | $y;
243ok ($x,3);
244ok ($y,4);
245ok ($z,7);
246$x = $class->new(1);
247$y = $class->new(2);
248$z = $x | $y;
249ok ($x,1);
250ok ($y,2);
251ok ($z,3);
252
253$x = $class->new(5);
254$y = $class->new(4);
255$z = $x ^ $y;
256ok ($x,5);
257ok ($y,4);
258ok ($z,1);
259
260$x = $class->new(-5); $y = -$x;
261ok ($x, -5);
262
263$x = $class->new(-5); $y = abs($x);
264ok ($x, -5);
265
07d34614 266$x = $class->new(8);
267$y = $class->new(-1);
268$z = $class->new(5033);
269my $u = $x->copy()->bmodpow($y,$z);
270ok ($u,4404);
271ok ($y,-1);
272ok ($z,5033);
273
274$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
275$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
276
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);
282
283$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
284$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
285$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
286$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
287$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
288
289$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
290$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
291$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
292$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
293$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
294
295###############################################################################
6854fd01 296# check whether overloading cmp works
297$try = "\$x = $class->new(0);";
298$try .= "\$y = 10;";
299$try .= "'false' if \$x ne \$y;";
300$ans = eval $try;
301print "# For '$try'\n" if (!ok "$ans" , "false" );
302
303# we cant test for working cmpt with other objects here, we would need a dummy
304# object with stringify overload for this. see Math::String tests as example
305
306###############################################################################
6854fd01 307# check reversed order of arguments
027dc388 308
6854fd01 309$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
310$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
311print "# For '$try'\n" if (!ok "$ans" , "ok" );
312
313$try = "\$x = $class->new(10); \$x = 2 * \$x;";
314$try .= "'ok' if \$x == 20;"; $ans = eval $try;
315print "# For '$try'\n" if (!ok "$ans" , "ok" );
316
317$try = "\$x = $class->new(10); \$x = 2 + \$x;";
318$try .= "'ok' if \$x == 12;"; $ans = eval $try;
319print "# For '$try'\n" if (!ok "$ans" , "ok" );
320
321$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
322$try .= "'ok' if \$x == -8;"; $ans = eval $try;
323print "# For '$try'\n" if (!ok "$ans" , "ok" );
324
325$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
326$try .= "'ok' if \$x == 2;"; $ans = eval $try;
327print "# For '$try'\n" if (!ok "$ans" , "ok" );
328
027dc388 329$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
330$try .= "'ok' if \$x == 2;"; $ans = eval $try;
331print "# For '$try'\n" if (!ok "$ans" , "ok" );
332
333$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
334$try .= "'ok' if \$x == 4;"; $ans = eval $try;
335print "# For '$try'\n" if (!ok "$ans" , "ok" );
336
337$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
338$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
339print "# For '$try'\n" if (!ok "$ans" , "ok" );
340
341$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
342$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
343print "# For '$try'\n" if (!ok "$ans" , "ok" );
344
6854fd01 345###############################################################################
346# check badd(4,5) form
347
348$try = "\$x = $class\->badd(4,5);";
349$try .= "'ok' if \$x == 9;";
350$ans = eval $try;
351print "# For '$try'\n" if (!ok "$ans" , "ok" );
352
353###############################################################################
354# check undefs: NOT DONE YET
355
356###############################################################################
357# bool
358
f9a08e12 359$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
360$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 361
362###############################################################################
363# objectify()
364
365@args = Math::BigInt::objectify(2,4,5);
366ok (scalar @args,3); # $class, 4, 5
56b9c951 367ok ($args[0] =~ /^Math::BigInt/);
6854fd01 368ok ($args[1],4);
369ok ($args[2],5);
370
371@args = Math::BigInt::objectify(0,4,5);
372ok (scalar @args,3); # $class, 4, 5
56b9c951 373ok ($args[0] =~ /^Math::BigInt/);
6854fd01 374ok ($args[1],4);
375ok ($args[2],5);
376
377@args = Math::BigInt::objectify(2,4,5);
378ok (scalar @args,3); # $class, 4, 5
56b9c951 379ok ($args[0] =~ /^Math::BigInt/);
6854fd01 380ok ($args[1],4);
381ok ($args[2],5);
382
383@args = Math::BigInt::objectify(2,4,5,6,7);
384ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 385ok ($args[0] =~ /^Math::BigInt/);
6854fd01 386ok ($args[1],4); ok (ref($args[1]),$args[0]);
387ok ($args[2],5); ok (ref($args[2]),$args[0]);
388ok ($args[3],6); ok (ref($args[3]),'');
389ok ($args[4],7); ok (ref($args[4]),'');
390
391@args = Math::BigInt::objectify(2,$class,4,5,6,7);
392ok (scalar @args,5); # $class, 4, 5, 6, 7
393ok ($args[0],$class);
394ok ($args[1],4); ok (ref($args[1]),$args[0]);
395ok ($args[2],5); ok (ref($args[2]),$args[0]);
396ok ($args[3],6); ok (ref($args[3]),'');
397ok ($args[4],7); ok (ref($args[4]),'');
398
399###############################################################################
f9a08e12 400# test whether an opp calls objectify properly or not (or at least does what
401# it should do given non-objects, w/ or w/o objectify())
402
403ok ($class->new(123)->badd(123),246);
404ok ($class->badd(123,321),444);
405ok ($class->badd(123,$class->new(321)),444);
406
407ok ($class->new(123)->bsub(122),1);
408ok ($class->bsub(321,123),198);
409ok ($class->bsub(321,$class->new(123)),198);
410
411ok ($class->new(123)->bmul(123),15129);
412ok ($class->bmul(123,123),15129);
413ok ($class->bmul(123,$class->new(123)),15129);
414
415ok ($class->new(15129)->bdiv(123),123);
416ok ($class->bdiv(15129,123),123);
417ok ($class->bdiv(15129,$class->new(123)),123);
418
419ok ($class->new(15131)->bmod(123),2);
420ok ($class->bmod(15131,123),2);
421ok ($class->bmod(15131,$class->new(123)),2);
422
423ok ($class->new(2)->bpow(16),65536);
424ok ($class->bpow(2,16),65536);
425ok ($class->bpow(2,$class->new(16)),65536);
426
427ok ($class->new(2**15)->brsft(1),2**14);
428ok ($class->brsft(2**15,1),2**14);
429ok ($class->brsft(2**15,$class->new(1)),2**14);
430
431ok ($class->new(2**13)->blsft(1),2**14);
432ok ($class->blsft(2**13,1),2**14);
433ok ($class->blsft(2**13,$class->new(1)),2**14);
434
435###############################################################################
6854fd01 436# test for floating-point input (other tests in bnorm() below)
437
438$z = 1050000000000000; # may be int on systems with 64bit?
439$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
440$z = 1e+129; # definitely a float (may fail on UTS)
441# don't compare to $z, since some Perl versions stringify $z into something
442# like '1.e+129' or something equally ugly
443$x = $class->new($z); ok ($x->bsstr(),'1e+129');
444
445###############################################################################
56d9de68 446# test for whitespace inlcuding newlines to be handled correctly
447
448# ok ($Math::BigInt::strict,1); # the default
449
450foreach my $c (
451 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
452 {
453 my $m = $class->new($c);
454 ok ($class->new("$c"),$m);
455 ok ($class->new(" $c"),$m);
456 ok ($class->new("$c "),$m);
457 ok ($class->new(" $c "),$m);
458 ok ($class->new("\n$c"),$m);
459 ok ($class->new("$c\n"),$m);
460 ok ($class->new("\n$c\n"),$m);
461 ok ($class->new(" \n$c\n"),$m);
462 ok ($class->new(" \n$c \n"),$m);
463 ok ($class->new(" \n$c\n "),$m);
464 ok ($class->new(" \n$c\n1"),'NaN');
465 ok ($class->new("1 \n$c\n1"),'NaN');
466 }
467
468###############################################################################
6854fd01 469# prime number tests, also test for **= and length()
470# found on: http://www.utm.edu/research/primes/notes/by_year.html
471
472# ((2^148)-1)/17
473$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
474ok ($x,"20988936657440586486151264256610222593863921");
475ok ($x->length(),length "20988936657440586486151264256610222593863921");
476
477# MM7 = 2^127-1
478$x = $class->new(2); $x **= 127; $x--;
479ok ($x,"170141183460469231731687303715884105727");
480
481$x = $class->new('215960156869840440586892398248');
482($x,$y) = $x->length();
483ok ($x,30); ok ($y,0);
484
485$x = $class->new('1_000_000_000_000');
486($x,$y) = $x->length();
487ok ($x,13); ok ($y,0);
488
2d2b2744 489# test <<=, >>=
490$x = $class->new('2');
491my $y = $class->new('18');
492ok ($x <<= $y, 2 << 18);
493ok ($x, 2 << 18);
494ok ($x >>= $y, 2);
495ok ($x, 2);
496
6854fd01 497# I am afraid the following is not yet possible due to slowness
498# Also, testing for 2 meg output is a bit hard ;)
499#$x = $class->new(2); $x **= 6972593; $x--;
500
501# 593573509*2^332162+1 has exactly 1,000,000 digits
502# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
503#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
504#ok ($x->length(),1_000_000);
505
506###############################################################################
507# inheritance and overriding of _swap
508
509$x = Math::Foo->new(5);
510$x = $x - 8; # 8 - 5 instead of 5-8
511ok ($x,3);
512ok (ref($x),'Math::Foo');
513
514$x = Math::Foo->new(5);
515$x = 8 - $x; # 5 - 8 instead of 8 - 5
516ok ($x,-3);
517ok (ref($x),'Math::Foo');
518
519###############################################################################
520# Test whether +inf eq inf
521# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
522# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
523# like 1e100000 crash on some platforms. So simple test for the string 'inf'
524$x = $class->new('+inf'); ok ($x,'inf');
525
526###############################################################################
527###############################################################################
56d9de68 528# the followin tests only make sense with Math::BigInt::Calc or BareCalc or
529# FastCalc
6854fd01 530
56d9de68 531exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01 532
533###############################################################################
534# check proper length of internal arrays
535
394e6ffb 536my $bl = $CL->_base_len();
6854fd01 537my $BASE = '9' x $bl;
538my $MAX = $BASE;
539$BASE++;
540
541$x = $class->new($MAX); is_valid($x); # f.i. 9999
542$x += 1; ok ($x,$BASE); is_valid($x); # 10000
543$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
544
545###############################################################################
546# check numify
547
548$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
549$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 550
551# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
552$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 553$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
554$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
555ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
556
557###############################################################################
558# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
559
394e6ffb 560$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
561if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
562
563$x = $class->new($BASE+3); $x++;
564if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 565
394e6ffb 566# test for +0 instead of int():
567$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 568
569###############################################################################
56b9c951 570# test bug that $class->digit($string) did not work
571
572ok ($class->digit(123,2),1);
573
574###############################################################################
6854fd01 575# bug in sub where number with at least 6 trailing zeros after any op failed
576
394e6ffb 577$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 578ok ($z, 100000);
579ok ($x, 23456);
580
581###############################################################################
582# bug in shortcut in mul()
583
61f5c3f5 584# construct a number with a zero-hole of BASE_LEN_SMALL
585{
586 my @bl = $CL->_base_len(); my $bl = $bl[4];
587
588 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
589 $y = '1' x (2*$bl);
590 $x = $class->new($x)->bmul($y);
591 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
592 $y = ''; my $d = '';
593 for (my $i = 1; $i <= $bl; $i++)
594 {
595 $y .= $i; $d = $i.$d;
596 }
597 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
598 ok ($x,$y);
599
6854fd01 600
f9a08e12 601 #############################################################################
602 # see if mul shortcut for small numbers works
394e6ffb 603
f9a08e12 604 $x = '9' x $bl;
605 $x = $class->new($x);
606 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
607 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
608}
61f5c3f5 609
394e6ffb 610###############################################################################
6854fd01 611# bug with rest "-0" in div, causing further div()s to fail
612
394e6ffb 613$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 614
61f5c3f5 615ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 616
79c55733 617###############################################################################
f9a08e12 618# bug in $x->bmod($y)
07d34614 619
f9a08e12 620# if $x < 0 and $y > 0
07d34614 621$x = $class->new('-629'); ok ($x->bmod(5033),4404);
622
623###############################################################################
56b9c951 624# bone/binf etc as plain calls (Lite failed them)
625
626ok ($class->bzero(),0);
627ok ($class->bone(),1);
628ok ($class->bone('+'),1);
629ok ($class->bone('-'),-1);
630ok ($class->bnan(),'NaN');
631ok ($class->binf(),'inf');
632ok ($class->binf('+'),'inf');
633ok ($class->binf('-'),'-inf');
634ok ($class->binf('-inf'),'-inf');
635
636###############################################################################
990fb837 637# is_one('-')
638
639ok ($class->new(1)->is_one('-'),0);
640ok ($class->new(-1)->is_one('-'),1);
641ok ($class->new(1)->is_one(),1);
642ok ($class->new(-1)->is_one(),0);
643
644###############################################################################
0ac635f7 645# [perl #30609] bug with $x -= $x not being 0, but 2*$x
03874afe 646
647$x = $class->new(3); $x -= $x; ok ($x, 0);
648$x = $class->new(-3); $x -= $x; ok ($x, 0);
649$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
650$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
651$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
652
653$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
654$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
655$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
656$x = $class->new(3); $x += $x; ok ($x, 6);
657$x = $class->new(-3); $x += $x; ok ($x, -6);
658
659$x = $class->new(3); $x *= $x; ok ($x, 9);
660$x = $class->new(-3); $x *= $x; ok ($x, 9);
661$x = $class->new(3); $x /= $x; ok ($x, 1);
662$x = $class->new(-3); $x /= $x; ok ($x, 1);
663$x = $class->new(3); $x %= $x; ok ($x, 0);
664$x = $class->new(-3); $x %= $x; ok ($x, 0);
665
666###############################################################################
61f5c3f5 667# all tests done
6854fd01 668
6691;
670
671###############################################################################
61f5c3f5 672###############################################################################
6854fd01 673# Perl 5.005 does not like ok ($x,undef)
674
675sub ok_undef
676 {
677 my $x = shift;
678
679 ok (1,1) and return if !defined $x;
680 ok ($x,'undef');
681 }
682
683###############################################################################
684# sub to check validity of a BigInt internally, to ensure that no op leaves a
685# number object in an invalid state (f.i. "-0")
686
687sub is_valid
688 {
689 my ($x,$f) = @_;
690
691 my $e = 0; # error?
6854fd01 692
56b9c951 693 # allow the check to pass for all Lite, and all MBI and subclasses
694 # ok as reference?
695 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 696
56b9c951 697 if (ref($x) ne 'Math::BigInt::Lite')
698 {
699 # has ok sign?
700 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
701 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
702
703 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
704 $e = $CALC->_check($x->{value}) if $e eq '0';
705 }
6854fd01 706
707 # test done, see if error did crop up
708 ok (1,1), return if ($e eq '0');
709
027dc388 710 ok (1,$e." after op '$f'");
6854fd01 711 }
712
713__DATA__
027dc388 714&.=
7151234:-345:1234-345
716&+=
7171:2:3
718-1:-2:-3
719&-=
7201:2:-1
721-1:-2:1
722&*=
7232:3:6
724-1:5:-5
725&%=
726100:3:1
7278:9:8
07d34614 728-629:5033:4404
027dc388 729&/=
730100:3:33
731-8:2:-4
732&|=
7332:1:3
734&&=
7355:7:5
736&^=
7375:7:2
091c87b1 738&blog
739NaNlog:2:NaN
740122:NaNlog:NaN
741NaNlog1:NaNlog:NaN
742122:inf:NaN
743inf:122:NaN
744122:-inf:NaN
745-inf:122:NaN
746-inf:-inf:NaN
747inf:inf:NaN
7480:4:NaN
749-21:4:NaN
75021:-21:NaN
751# normal results
7521024:2:10
75381:3:4
754# 3.01.. truncate
75582:3:4
756# 3.9... truncate
75780:3:3
75815625:5:6
75915626:5:6
76015624:5:5
8df1e0a2 7611000:10:3
76210000:10:4
763100000:10:5
7641000000:10:6
76510000000:10:7
766100000000:10:8
7678916100448256:12:12
7688916100448257:12:12
7698916100448255:12:11
7702251799813685248:8:17
77172057594037927936:2:56
772144115188075855872:2:57
773288230376151711744:2:58
774576460752303423488:2:59
7754096:2:12
7761329227995784915872903807060280344576:2:120
091c87b1 777# $x == $base => result 1
7783:3:1
779# $x < $base => result 0 ($base ** 0 <= $x)
7803:4:0
781# $x == 1 => result 0
7821:5:0
6854fd01 783&is_negative
7840:0
785-1:1
7861:0
787+inf:0
788-inf:1
789NaNneg:0
790&is_positive
b68b7ab1 7910:0
6854fd01 792-1:0
7931:1
794+inf:1
795-inf:0
796NaNneg:0
b3abae2a 797&is_int
798-inf:0
799+inf:0
800NaNis_int:0
8011:1
8020:1
803123e12:1
6854fd01 804&is_odd
805abc:0
8060:0
8071:1
8083:1
809-1:1
810-3:1
81110000001:1
81210000002:0
8132:0
b3abae2a 814120:0
815121:1
6854fd01 816&is_even
817abc:0
8180:1
8191:0
8203:0
821-1:0
822-3:0
82310000001:0
82410000002:1
8252:1
b3abae2a 826120:1
827121:0
6854fd01 828&bacmp
829+0:-0:0
830+0:+1:-1
831-1:+1:0
832+1:-1:0
833-1:+2:-1
834+2:-1:1
835-123456789:+987654321:-1
836+123456789:-987654321:-1
837+987654321:+123456789:1
838-987654321:+123456789:1
839-123:+4567889:-1
840# NaNs
841acmpNaN:123:
842123:acmpNaN:
843acmpNaN:acmpNaN:
844# infinity
845+inf:+inf:0
846-inf:-inf:0
847+inf:-inf:0
848-inf:+inf:0
849+inf:123:1
850-inf:123:1
851+inf:-123:1
852-inf:-123:1
ef9466ea 853123:-inf:-1
854-123:inf:-1
855-123:-inf:-1
856123:inf:-1
6854fd01 857# return undef
858+inf:NaN:
859NaN:inf:
860-inf:NaN:
861NaN:-inf:
862&bnorm
aef458a0 8630e999:0
8640e-999:0
865-0e999:0
866-0e-999:0
6854fd01 867123:123
868# binary input
8690babc:NaN
8700b123:NaN
8710b0:0
872-0b0:0
873-0b1:-1
8740b0001:1
8750b001:1
8760b011:3
8770b101:5
61f5c3f5 8780b1001:9
8790b10001:17
8800b100001:33
8810b1000001:65
8820b10000001:129
8830b100000001:257
8840b1000000001:513
8850b10000000001:1025
8860b100000000001:2049
8870b1000000000001:4097
8880b10000000000001:8193
8890b100000000000001:16385
8900b1000000000000001:32769
8910b10000000000000001:65537
8920b100000000000000001:131073
8930b1000000000000000001:262145
8940b10000000000000000001:524289
8950b100000000000000000001:1048577
8960b1000000000000000000001:2097153
8970b10000000000000000000001:4194305
8980b100000000000000000000001:8388609
8990b1000000000000000000000001:16777217
9000b10000000000000000000000001:33554433
9010b100000000000000000000000001:67108865
9020b1000000000000000000000000001:134217729
9030b10000000000000000000000000001:268435457
9040b100000000000000000000000000001:536870913
9050b1000000000000000000000000000001:1073741825
9060b10000000000000000000000000000001:2147483649
9070b100000000000000000000000000000001:4294967297
9080b1000000000000000000000000000000001:8589934593
9090b10000000000000000000000000000000001:17179869185
6854fd01 9100b_101:NaN
9110b1_0_1:5
394e6ffb 9120b0_0_0_1:1
6854fd01 913# hex input
914-0x0:0
9150xabcdefgh:NaN
9160x1234:4660
9170xabcdef:11259375
918-0xABCDEF:-11259375
919-0x1234:-4660
9200x12345678:305419896
9210x1_2_3_4_56_78:305419896
394e6ffb 9220xa_b_c_d_e_f:11259375
6854fd01 9230x_123:NaN
61f5c3f5 9240x9:9
9250x11:17
9260x21:33
9270x41:65
9280x81:129
9290x101:257
9300x201:513
9310x401:1025
9320x801:2049
9330x1001:4097
9340x2001:8193
9350x4001:16385
9360x8001:32769
9370x10001:65537
9380x20001:131073
9390x40001:262145
9400x80001:524289
9410x100001:1048577
9420x200001:2097153
9430x400001:4194305
9440x800001:8388609
9450x1000001:16777217
9460x2000001:33554433
9470x4000001:67108865
9480x8000001:134217729
9490x10000001:268435457
9500x20000001:536870913
9510x40000001:1073741825
9520x80000001:2147483649
9530x100000001:4294967297
9540x200000001:8589934593
9550x400000001:17179869185
9560x800000001:34359738369
2d2b2744 957# bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex()
9580x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
6854fd01 959# inf input
960inf:inf
961+inf:inf
962-inf:-inf
9630inf:NaN
027dc388 964# abnormal input
6854fd01 965:NaN
966abc:NaN
967 1 a:NaN
9681bcd2:NaN
96911111b:NaN
970+1z:NaN
971-1z:NaN
027dc388 972# only one underscore between two digits
973_123:NaN
974_123_:NaN
975123_:NaN
9761__23:NaN
9771E1__2:NaN
9781_E12:NaN
9791E_12:NaN
9801_E_12:NaN
981+_1E12:NaN
982+0_1E2:100
983+0_0_1E2:100
984-0_0_1E2:-100
985-0_0_1E+0_0_2:-100
986E1:NaN
987E23:NaN
9881.23E1:NaN
9891.23E-1:NaN
0ac635f7 990# bug with two E's in number being valid
027dc388 9911e2e3:NaN
9921e2r:NaN
9931e2.0:NaN
0ac635f7 994# bug with two '.' in number being valid
07d34614 9951.2.2:NaN
9961.2.3e1:NaN
997-1.2.3:NaN
998-1.2.3e-4:NaN
9991.2e3.4:NaN
10001.2e-3.4:NaN
10011.2.3.4:NaN
10021.2.t:NaN
10031..2:NaN
10041..2e1:NaN
10051..2e1..1:NaN
100612e1..1:NaN
1007..2:NaN
1008.-2:NaN
61f5c3f5 1009# leading zeros
1010012:12
10110123:123
101201234:1234
1013012345:12345
10140123456:123456
101501234567:1234567
1016012345678:12345678
10170123456789:123456789
101801234567891:1234567891
1019012345678912:12345678912
10200123456789123:123456789123
102101234567891234:1234567891234
2d2b2744 1022# some inputs that result in zero
10230e0:0
1024+0e0:0
1025+0e+0:0
1026-0e+0:0
10270e-0:0
1028-0e-0:0
1029+0e-0:0
1030000:0
103100e2:0
103200e02:0
1033000e002:0
1034000e1230:0
103500e-3:0
103600e+3:0
103700e-03:0
103800e+03:0
1039-000:0
1040-00e2:0
1041-00e02:0
1042-000e002:0
1043-000e1230:0
1044-00e-3:0
1045-00e+3:0
1046-00e-03:0
1047-00e+03:0
027dc388 1048# normal input
6854fd01 10490:0
1050+0:0
1051+00:0
1052+000:0
1053000000000000000000:0
1054-0:0
1055-0000:0
1056+1:1
1057+01:1
1058+001:1
1059+00000100000:100000
1060123456789:123456789
1061-1:-1
1062-01:-1
1063-001:-1
1064-123456789:-123456789
1065-00000100000:-100000
10661_2_3:123
6854fd01 106710000000000E-1_0:1
10681E2:100
10691E1:10
10701E0:1
6854fd01 10711.23E2:123
6854fd01 1072100E-1:10
1073# floating point input
027dc388 1074# .2e2:20
10751.E3:1000
6854fd01 10761.01E2:101
10771010E-1:101
1078-1010E0:-1010
1079-1010E1:-10100
027dc388 10801234.00:1234
1081# non-integer numbers
6854fd01 1082-1010E-2:NaN
1083-1.01E+1:NaN
1084-1.01E-1:NaN
6854fd01 1085&bnan
10861:NaN
10872:NaN
1088abc:NaN
1089&bone
61f5c3f5 10902:+:1
6854fd01 10912:-:-1
1092boneNaN:-:-1
61f5c3f5 1093boneNaN:+:1
10942:abc:1
10953::1
6854fd01 1096&binf
10971:+:inf
10982:-:-inf
10993:abc:inf
027dc388 1100&is_nan
1101123:0
1102abc:1
1103NaN:1
1104-123:0
6854fd01 1105&is_inf
1106+inf::1
1107-inf::1
1108abc::0
11091::0
1110NaN::0
1111-1::0
1112+inf:-:0
1113+inf:+:1
1114-inf:-:1
1115-inf:+:0
79c55733 1116-inf:-inf:1
1117-inf:+inf:0
1118+inf:-inf:0
1119+inf:+inf:1
6854fd01 1120# it must be exactly /^[+-]inf$/
1121+infinity::0
1122-infinity::0
1123&blsft
1124abc:abc:NaN
61f5c3f5 1125+2:+2:8
1126+1:+32:4294967296
1127+1:+48:281474976710656
6854fd01 1128+8:-2:NaN
1129# excercise base 10
1130+12345:4:10:123450000
1131-1234:0:10:-1234
61f5c3f5 1132+1234:0:10:1234
6854fd01 1133+2:2:10:200
1134+12:2:10:1200
1135+1234:-3:10:NaN
11361234567890123:12:10:1234567890123000000000000
b3abae2a 1137-3:1:2:-6
1138-5:1:2:-10
1139-2:1:2:-4
1140-102533203:1:2:-205066406
6854fd01 1141&brsft
1142abc:abc:NaN
61f5c3f5 1143+8:+2:2
1144+4294967296:+32:1
1145+281474976710656:+48:1
6854fd01 1146+2:-2:NaN
1147# excercise base 10
1148-1234:0:10:-1234
61f5c3f5 1149+1234:0:10:1234
6854fd01 1150+200:2:10:2
1151+1234:3:10:1
1152+1234:2:10:12
1153+1234:-3:10:NaN
1154310000:4:10:31
115512300000:5:10:123
11561230000000000:10:10:123
115709876123456789067890:12:10:9876123
11581234561234567890123:13:10:123456
b3abae2a 1159820265627:1:2:410132813
1160# test shifting negative numbers in base 2
1161-15:1:2:-8
1162-14:1:2:-7
1163-13:1:2:-7
1164-12:1:2:-6
1165-11:1:2:-6
1166-10:1:2:-5
1167-9:1:2:-5
1168-8:1:2:-4
1169-7:1:2:-4
1170-6:1:2:-3
1171-5:1:2:-3
1172-4:1:2:-2
1173-3:1:2:-2
1174-2:1:2:-1
1175-1:1:2:-1
1176-1640531254:2:2:-410132814
1177-1640531254:1:2:-820265627
1178-820265627:1:2:-410132814
1179-205066405:1:2:-102533203
6854fd01 1180&bsstr
56d9de68 1181+inf:inf
1182-inf:-inf
6854fd01 11831e+34:1e+34
1184123.456E3:123456e+0
1185100:1e+2
56d9de68 1186bsstrabc:NaN
1187-5:-5e+0
1188-100:-1e+2
1189&numify
1190numifyabc:NaN
1191+inf:inf
1192-inf:-inf
11935:5
1194-5:-5
1195100:100
1196-100:-100
6854fd01 1197&bneg
1198bnegNaN:NaN
1199+inf:-inf
1200-inf:inf
1201abd:NaN
61f5c3f5 12020:0
12031:-1
1204-1:1
6854fd01 1205+123456789:-123456789
61f5c3f5 1206-123456789:123456789
6854fd01 1207&babs
1208babsNaN:NaN
1209+inf:inf
1210-inf:inf
61f5c3f5 12110:0
12121:1
1213-1:1
1214+123456789:123456789
1215-123456789:123456789
6854fd01 1216&bcmp
1217bcmpNaN:bcmpNaN:
61f5c3f5 1218bcmpNaN:0:
12190:bcmpNaN:
12200:0:0
1221-1:0:-1
12220:-1:1
12231:0:1
12240:1:-1
1225-1:1:-1
12261:-1:1
6854fd01 1227-1:-1:0
61f5c3f5 12281:1:0
1229123:123:0
1230123:12:1
123112:123:-1
6854fd01 1232-123:-123:0
1233-123:-12:-1
1234-12:-123:1
61f5c3f5 1235123:124:-1
1236124:123:1
6854fd01 1237-123:-124:1
1238-124:-123:-1
61f5c3f5 1239100:5:1
1240-123456789:987654321:-1
6854fd01 1241+123456789:-987654321:1
61f5c3f5 1242-987654321:123456789:-1
6854fd01 1243-inf:5432112345:-1
1244+inf:5432112345:1
1245-inf:-5432112345:-1
1246+inf:-5432112345:1
1247+inf:+inf:0
1248-inf:-inf:0
1249+inf:-inf:1
1250-inf:+inf:-1
12515:inf:-1
12525:inf:-1
1253-5:-inf:1
1254-5:-inf:1
1255# return undef
1256+inf:NaN:
1257NaN:inf:
1258-inf:NaN:
1259NaN:-inf:
1260&binc
1261abc:NaN
1262+inf:inf
1263-inf:-inf
61f5c3f5 1264+0:1
1265+1:2
1266-1:0
6854fd01 1267&bdec
1268abc:NaN
1269+inf:inf
1270-inf:-inf
1271+0:-1
61f5c3f5 1272+1:0
6854fd01 1273-1:-2
1274&badd
1275abc:abc:NaN
61f5c3f5 1276abc:0:NaN
6854fd01 1277+0:abc:NaN
b3abae2a 1278+inf:-inf:NaN
1279-inf:+inf:NaN
6854fd01 1280+inf:+inf:inf
1281-inf:-inf:-inf
1282baddNaN:+inf:NaN
1283baddNaN:+inf:NaN
1284+inf:baddNaN:NaN
1285-inf:baddNaN:NaN
61f5c3f5 12860:0:0
12871:0:1
12880:1:1
12891:1:2
1290-1:0:-1
12910:-1:-1
6854fd01 1292-1:-1:-2
61f5c3f5 1293-1:+1:0
1294+1:-1:0
1295+9:+1:10
1296+99:+1:100
1297+999:+1:1000
1298+9999:+1:10000
1299+99999:+1:100000
1300+999999:+1:1000000
1301+9999999:+1:10000000
1302+99999999:+1:100000000
1303+999999999:+1:1000000000
1304+9999999999:+1:10000000000
1305+99999999999:+1:100000000000
1306+10:-1:9
1307+100:-1:99
1308+1000:-1:999
1309+10000:-1:9999
1310+100000:-1:99999
1311+1000000:-1:999999
1312+10000000:-1:9999999
1313+100000000:-1:99999999
1314+1000000000:-1:999999999
1315+10000000000:-1:9999999999
1316+123456789:987654321:1111111110
1317-123456789:987654321:864197532
6854fd01 1318-123456789:-987654321:-1111111110
1319+123456789:-987654321:-864197532
56b9c951 1320-1:10001:10000
1321-1:100001:100000
1322-1:1000001:1000000
1323-1:10000001:10000000
1324-1:100000001:100000000
1325-1:1000000001:1000000000
1326-1:10000000001:10000000000
1327-1:100000000001:100000000000
1328-1:1000000000001:1000000000000
1329-1:10000000000001:10000000000000
1330-1:-10001:-10002
1331-1:-100001:-100002
1332-1:-1000001:-1000002
1333-1:-10000001:-10000002
1334-1:-100000001:-100000002
1335-1:-1000000001:-1000000002
1336-1:-10000000001:-10000000002
1337-1:-100000000001:-100000000002
1338-1:-1000000000001:-1000000000002
1339-1:-10000000000001:-10000000000002
6854fd01 1340&bsub
1341abc:abc:NaN
1342abc:+0:NaN
1343+0:abc:NaN
1344+inf:-inf:inf
1345-inf:+inf:-inf
b3abae2a 1346+inf:+inf:NaN
1347-inf:-inf:NaN
61f5c3f5 1348+0:+0:0
1349+1:+0:1
6854fd01 1350+0:+1:-1
61f5c3f5 1351+1:+1:0
6854fd01 1352-1:+0:-1
61f5c3f5 1353+0:-1:1
1354-1:-1:0
6854fd01 1355-1:+1:-2
61f5c3f5 1356+1:-1:2
1357+9:+1:8
1358+99:+1:98
1359+999:+1:998
1360+9999:+1:9998
1361+99999:+1:99998
1362+999999:+1:999998
1363+9999999:+1:9999998
1364+99999999:+1:99999998
1365+999999999:+1:999999998
1366+9999999999:+1:9999999998
1367+99999999999:+1:99999999998
1368+10:-1:11
1369+100:-1:101
1370+1000:-1:1001
1371+10000:-1:10001
1372+100000:-1:100001
1373+1000000:-1:1000001
1374+10000000:-1:10000001
1375+100000000:-1:100000001
1376+1000000000:-1:1000000001
1377+10000000000:-1:10000000001
6854fd01 1378+123456789:+987654321:-864197532
1379-123456789:+987654321:-1111111110
61f5c3f5 1380-123456789:-987654321:864197532
1381+123456789:-987654321:1111111110
56b9c951 138210001:1:10000
1383100001:1:100000
13841000001:1:1000000
138510000001:1:10000000
1386100000001:1:100000000
13871000000001:1:1000000000
138810000000001:1:10000000000
1389100000000001:1:100000000000
13901000000000001:1:1000000000000
139110000000000001:1:10000000000000
139210001:-1:10002
1393100001:-1:100002
13941000001:-1:1000002
139510000001:-1:10000002
1396100000001:-1:100000002
13971000000001:-1:1000000002
139810000000001:-1:10000000002
1399100000000001:-1:100000000002
14001000000000001:-1:1000000000002
140110000000000001:-1:10000000000002
80365507 1402&bmuladd
1403abc:abc:0:NaN
1404abc:+0:0:NaN
1405+0:abc:0:NaN
1406+0:0:abc:NaN
1407NaNmul:+inf:0:NaN
1408NaNmul:-inf:0:NaN
1409-inf:NaNmul:0:NaN
1410+inf:NaNmul:0:NaN
1411+inf:+inf:0:inf
1412+inf:-inf:0:-inf
1413-inf:+inf:0:-inf
1414-inf:-inf:0:inf
1415+0:+0:0:0
1416+0:+1:0:0
1417+1:+0:0:0
1418+0:-1:0:0
1419-1:+0:0:0
1420123456789123456789:0:0:0
14210:123456789123456789:0:0
1422-1:-1:0:1
1423-1:-1:0:1
1424-1:+1:0:-1
1425+1:-1:0:-1
1426+1:+1:0:1
1427+2:+3:0:6
1428-2:+3:0:-6
1429+2:-3:0:-6
1430-2:-3:0:6
1431111:111:0:12321
143210101:10101:0:102030201
14331001001:1001001:0:1002003002001
1434100010001:100010001:0:10002000300020001
143510000100001:10000100001:0:100002000030000200001
143611111111111:9:0:99999999999
143722222222222:9:0:199999999998
143833333333333:9:0:299999999997
143944444444444:9:0:399999999996
144055555555555:9:0:499999999995
144166666666666:9:0:599999999994
144277777777777:9:0:699999999993
144388888888888:9:0:799999999992
144499999999999:9:0:899999999991
144511111111111:9:1:100000000000
144622222222222:9:1:199999999999
144733333333333:9:1:299999999998
144844444444444:9:1:399999999997
144955555555555:9:1:499999999996
145066666666666:9:1:599999999995
145177777777777:9:1:699999999994
145288888888888:9:1:799999999993
145399999999999:9:1:899999999992
1454-3:-4:-5:7
14553:-4:-5:-17
1456-3:4:-5:-17
14573:4:-5:7
1458-3:4:5:-7
14593:-4:5:-7
14609999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890
14612:3:12345678901234567890:12345678901234567896
6854fd01 1462&bmul
1463abc:abc:NaN
1464abc:+0:NaN
1465+0:abc:NaN
1466NaNmul:+inf:NaN
1467NaNmul:-inf:NaN
1468-inf:NaNmul:NaN
1469+inf:NaNmul:NaN
1470+inf:+inf:inf
1471+inf:-inf:-inf
1472-inf:+inf:-inf
1473-inf:-inf:inf
61f5c3f5 1474+0:+0:0
1475+0:+1:0
1476+1:+0:0
1477+0:-1:0
1478-1:+0:0
1479123456789123456789:0:0
14800:123456789123456789:0
1481-1:-1:1
6854fd01 1482-1:+1:-1
1483+1:-1:-1
61f5c3f5 1484+1:+1:1
1485+2:+3:6
6854fd01 1486-2:+3:-6
1487+2:-3:-6
61f5c3f5 1488-2:-3:6
1489111:111:12321
149010101:10101:102030201
14911001001:1001001:1002003002001
1492100010001:100010001:10002000300020001
149310000100001:10000100001:100002000030000200001
149411111111111:9:99999999999
149522222222222:9:199999999998
149633333333333:9:299999999997
149744444444444:9:399999999996
149855555555555:9:499999999995
149966666666666:9:599999999994
150077777777777:9:699999999993
150188888888888:9:799999999992
150299999999999:9:899999999991
1503+25:+25:625
1504+12345:+12345:152399025
1505+99999:+11111:1111088889
6854fd01 15069999:10000:99990000
150799999:100000:9999900000
1508999999:1000000:999999000000
15099999999:10000000:99999990000000
151099999999:100000000:9999999900000000
1511999999999:1000000000:999999999000000000
15129999999999:10000000000:99999999990000000000
151399999999999:100000000000:9999999999900000000000
1514999999999999:1000000000000:999999999999000000000000
15159999999999999:10000000000000:99999999999990000000000000
151699999999999999:100000000000000:9999999999999900000000000000
1517999999999999999:1000000000000000:999999999999999000000000000000
15189999999999999999:10000000000000000:99999999999999990000000000000000
151999999999999999999:100000000000000000:9999999999999999900000000000000000
1520999999999999999999:1000000000000000000:999999999999999999000000000000000000
15219999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1522&bdiv-list
1523100:20:5,0
15244095:4095:1,0
1525-4095:-4095:1,0
15264095:-4095:-1,0
1527-4095:4095:-1,0
1528123:2:61,1
b3abae2a 15299:5:1,4
15309:4:2,1
6854fd01 1531# inf handling and general remainder
15325:8:0,5
15330:8:0,0
153411:2:5,1
153511:-2:-5,-1
1536-11:2:-5,1
1537# see table in documentation in MBI
15380:inf:0,0
15390:-inf:0,0
15405:inf:0,5
15415:-inf:0,5
1542-5:inf:0,-5
1543-5:-inf:0,-5
1544inf:5:inf,0
1545-inf:5:-inf,0
1546inf:-5:-inf,0
1547-inf:-5:inf,0
15485:5:1,0
1549-5:-5:1,0
b3abae2a 1550inf:inf:NaN,NaN
1551-inf:-inf:NaN,NaN
1552-inf:inf:NaN,NaN
1553inf:-inf:NaN,NaN
6854fd01 15548:0:inf,8
1555inf:0:inf,inf
1556# exceptions to reminder rule
1557-8:0:-inf,-8
1558-inf:0:-inf,-inf
15590:0:NaN,NaN
990fb837 1560# test the shortcut in Calc if @$x == @$yorg
15611234567812345678:123456712345678:10,688888898
156212345671234567:1234561234567:10,58888897
1563123456123456:12345123456:10,4888896
15641234512345:123412345:10,388895
15651234567890999999999:1234567890:1000000000,999999999
15661234567890000000000:1234567890:1000000000,0
15671234567890999999999:9876543210:124999998,9503086419
15681234567890000000000:9876543210:124999998,8503086420
156996969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
7596a890 1570# bug in v1.76
15711267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
b68b7ab1 1572# excercise shortcut for numbers of the same length in div
1573999999999999999999999999999999999:999999999999999999999999999999999:1,0
1574999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1575999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1576999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1577999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1578999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1579999999999999999999999999999999999:333333333333333333333333333333333:3,0
1580999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1581999999999999999999999999999999999:111111111111111111111111111111111:9,0
15829999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
15839999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
15849999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
15859999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
15869999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
15879999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
15889999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
15899999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
15909999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
15919999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
15929999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
6854fd01 1593&bdiv
1594abc:abc:NaN
61f5c3f5 1595abc:1:NaN
15961:abc:NaN
15970:0:NaN
6854fd01 1598# inf handling (see table in doc)
15990:inf:0
16000:-inf:0
16015:inf:0
16025:-inf:0
1603-5:inf:0
1604-5:-inf:0
1605inf:5:inf
1606-inf:5:-inf
1607inf:-5:-inf
1608-inf:-5:inf
16095:5:1
1610-5:-5:1
b3abae2a 1611inf:inf:NaN
1612-inf:-inf:NaN
1613-inf:inf:NaN
1614inf:-inf:NaN
6854fd01 16158:0:inf
1616inf:0:inf
1617-8:0:-inf
1618-inf:0:-inf
16190:0:NaN
162011:2:5
1621-11:-2:5
1622-11:2:-5
162311:-2:-5
61f5c3f5 16240:1:0
16250:-1:0
16261:1:1
1627-1:-1:1
16281:-1:-1
1629-1:1:-1
16301:2:0
16312:1:2
16321:26:0
16331000000000:9:111111111
16342000000000:9:222222222
16353000000000:9:333333333
16364000000000:9:444444444
16375000000000:9:555555555
16386000000000:9:666666666
16397000000000:9:777777777
16408000000000:9:888888888
16419000000000:9:1000000000
164235500000:113:314159
164371000000:226:314159
1644106500000:339:314159
16451000000000:3:333333333
1646+10:+5:2
1647+100:+4:25
1648+1000:+8:125
1649+10000:+16:625
1650999999999999:9:111111111111
1651999999999999:99:10101010101
1652999999999999:999:1001001001
1653999999999999:9999:100010001
1654999999999999999:99999:10000100001
1655+1111088889:99999:11111
6854fd01 1656-5:-3:1
1657-5:3:-1
16584:3:1
16594:-3:-1
16601:3:0
16611:-3:0
1662-2:-3:0
1663-2:3:0
16648:3:2
1665-8:3:-2
166614:-3:-4
1667-14:3:-4
1668-14:-3:4
166914:3:4
1670# bug in Calc with '99999' vs $BASE-1
167110000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1672# test the shortcut in Calc if @$x == @$yorg
16731234567812345678:123456712345678:10
167412345671234567:1234561234567:10
1675123456123456:12345123456:10
16761234512345:123412345:10
16771234567890999999999:1234567890:1000000000
16781234567890000000000:1234567890:1000000000
16791234567890999999999:9876543210:124999998
16801234567890000000000:9876543210:124999998
168196969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1682# bug up to v0.35 in Calc (--$q one too many)
168384696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
168484696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
168584696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
168684696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
b68b7ab1 1687# excercise shortcut for numbers of the same length in div
1688999999999999999999999999999999999:999999999999999999999999999999999:1
1689999999999999999999999999999999999:888888888888888888888888888888888:1
1690999999999999999999999999999999999:777777777777777777777777777777777:1
1691999999999999999999999999999999999:666666666666666666666666666666666:1
1692999999999999999999999999999999999:555555555555555555555555555555555:1
1693999999999999999999999999999999999:444444444444444444444444444444444:2
1694999999999999999999999999999999999:333333333333333333333333333333333:3
1695999999999999999999999999999999999:222222222222222222222222222222222:4
1696999999999999999999999999999999999:111111111111111111111111111111111:9
16979999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
16989999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
16999999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
17009999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
17019999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
17029999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
17039999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
17049999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
17059999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
17069999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
17079999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
a87115f0 1708# bug with shortcut in Calc 0.44
1709949418181818187070707070707070707070:181818181853535353535353535353535353:5
07d34614 1710&bmodinv
1711# format: number:modulus:result
1712# bmodinv Data errors
1713abc:abc:NaN
1714abc:5:NaN
17155:abc:NaN
1716# bmodinv Expected Results from normal use
17171:5:1
17183:5:2
1719-2:5:2
17208:5033:4404
56d9de68 17211234567891:13:6
1722-1234567891:13:7
07d34614 1723324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1724## bmodinv Error cases / useless use of function
07d34614 17253:-5:NaN
1726inf:5:NaN
1ddff52a 17275:inf:NaN
1728-inf:5:NaN
17295:-inf:NaN
07d34614 1730&bmodpow
1731# format: number:exponent:modulus:result
1732# bmodpow Data errors
1733abc:abc:abc:NaN
17345:abc:abc:NaN
1735abc:5:abc:NaN
1736abc:abc:5:NaN
17375:5:abc:NaN
17385:abc:5:NaN
1739abc:5:5:NaN
1740# bmodpow Expected results
17410:0:2:1
17421:0:2:1
17430:0:1:0
17448:7:5032:3840
17458:-1:5033:4404
174698436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1747# bmodpow Error cases
17488:8:-5:NaN
17498:-1:16:NaN
1750inf:5:13:NaN
17515:inf:13:NaN
6854fd01 1752&bmod
1753# inf handling, see table in doc
17540:inf:0
17550:-inf:0
17565:inf:5
17575:-inf:5
1758-5:inf:-5
1759-5:-inf:-5
1760inf:5:0
1761-inf:5:0
1762inf:-5:0
1763-inf:-5:0
17645:5:0
1765-5:-5:0
b3abae2a 1766inf:inf:NaN
1767-inf:-inf:NaN
1768-inf:inf:NaN
1769inf:-inf:NaN
6854fd01 17708:0:8
1771inf:0:inf
1772# exceptions to reminder rule
1773-inf:0:-inf
1774-8:0:-8
17750:0:NaN
1776abc:abc:NaN
61f5c3f5 1777abc:1:abc:NaN
17781:abc:NaN
17790:0:NaN
17800:1:0
17811:0:1
17820:-1:0
1783-1:0:-1
17841:1:0
1785-1:-1:0
17861:-1:0
1787-1:1:0
17881:2:1
17892:1:0
17901000000000:9:1
17912000000000:9:2
17923000000000:9:3
17934000000000:9:4
17945000000000:9:5
17956000000000:9:6
17967000000000:9:7
17978000000000:9:8
17989000000000:9:0
179935500000:113:33
180071000000:226:66
1801106500000:339:99
18021000000000:3:1
180310:5:0
1804100:4:0
18051000:8:0
180610000:16:0
1807999999999999:9:0
1808999999999999:99:0
1809999999999999:999:0
1810999999999999:9999:0
1811999999999999999:99999:0
1812-9:+5:1
6854fd01 1813+9:-5:-1
1814-9:-5:-4
1815-5:3:1
1816-2:3:1
18174:3:1
18181:3:1
1819-5:-3:-2
1820-2:-3:-2
18214:-3:-2
18221:-3:-2
18234095:4095:0
027dc388 1824100041000510123:3:0
1825152403346:12345:4321
b3abae2a 18269:5:4
28df3e88 1827# test shortcuts in Calc
1828# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
18291234:9:1
1830123456:9:3
183112345678:9:0
18321234567891:9:1
1833123456789123:9:6
183412345678912345:9:6
18351234567891234567:9:1
1836123456789123456789:9:0
18371234:10:4
1838123456:10:6
183912345678:10:8
18401234567891:10:1
1841123456789123:10:3
184212345678912345:10:5
18431234567891234567:10:7
1844123456789123456789:10:9
18451234:113:104
1846123456:113:60
184712345678:113:89
18481234567891:113:64
1849123456789123:113:95
185012345678912345:113:53
18511234567891234567:113:56
1852123456789123456789:113:39
07d34614 1853# bug in bmod() not modifying the variable in place
1854-629:5033:4404
aef458a0 1855# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1856# when X == X and X was big
1857111111111111111111111111111111:111111111111111111111111111111:0
185812345678901234567890:12345678901234567890:0
6854fd01 1859&bgcd
9b924220 1860inf:12:NaN
1861-inf:12:NaN
186212:inf:NaN
186312:-inf:NaN
1864inf:inf:NaN
1865inf:-inf:NaN
1866-inf:-inf:NaN
6854fd01 1867abc:abc:NaN
1868abc:+0:NaN
1869+0:abc:NaN
61f5c3f5 1870+0:+0:0
1871+0:+1:1
1872+1:+0:1
1873+1:+1:1
1874+2:+3:1
1875+3:+2:1
1876-3:+2:1
9b924220 1877-3:-2:1
1878-144:-60:12
1879144:-60:12
1880144:60:12
61f5c3f5 1881100:625:25
18824096:81:1
18831034:804:2
188427:90:56:1
188527:90:54:9
6854fd01 1886&blcm
1887abc:abc:NaN
1888abc:+0:NaN
1889+0:abc:NaN
1890+0:+0:NaN
61f5c3f5 1891+1:+0:0
1892+0:+1:0
1893+27:+90:270
1894+1034:+804:415668
6854fd01 1895&band
1896abc:abc:NaN
1897abc:0:NaN
18980:abc:NaN
18991:2:0
19003:2:2
61f5c3f5 1901+8:+2:0
1902+281474976710656:0:0
1903+281474976710656:1:0
1904+281474976710656:+281474976710656:281474976710656
9b924220 1905281474976710656:-1:281474976710656
6854fd01 1906-2:-3:-4
1907-1:-1:-1
1908-6:-6:-6
1909-7:-4:-8
1910-7:4:0
1911-4:7:4
9b924220 1912# negative argument is bitwise shorter than positive [perl #26559]
191330:-3:28
1914123:-1:123
394e6ffb 1915# equal arguments are treated special, so also do some test with unequal ones
19160xFFFF:0xFFFF:0x0xFFFF
19170xFFFFFF:0xFFFFFF:0x0xFFFFFF
19180xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
19190xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19200xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19210xF0F0:0xF0F0:0x0xF0F0
19220x0F0F:0x0F0F:0x0x0F0F
19230xF0F0F0:0xF0F0F0:0x0xF0F0F0
19240x0F0F0F:0x0F0F0F:0x0x0F0F0F
19250xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19260x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19270xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19280x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19290xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19300x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19310x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1932&bior
1933abc:abc:NaN
1934abc:0:NaN
19350:abc:NaN
19361:2:3
61f5c3f5 1937+8:+2:10
1938+281474976710656:0:281474976710656
1939+281474976710656:1:281474976710657
1940+281474976710656:281474976710656:281474976710656
6854fd01 1941-2:-3:-1
1942-1:-1:-1
1943-6:-6:-6
1944-7:4:-3
1945-4:7:-1
9b924220 1946+281474976710656:-1:-1
194730:-3:-1
194830:-4:-2
1949300:-76:-68
1950-76:300:-68
394e6ffb 1951# equal arguments are treated special, so also do some test with unequal ones
19520xFFFF:0xFFFF:0x0xFFFF
19530xFFFFFF:0xFFFFFF:0x0xFFFFFF
19540xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
19550xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19560xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19570:0xFFFF:0x0xFFFF
19580:0xFFFFFF:0x0xFFFFFF
19590:0xFFFFFFFF:0x0xFFFFFFFF
19600:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19610:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19620xFFFF:0:0x0xFFFF
19630xFFFFFF:0:0x0xFFFFFF
19640xFFFFFFFF:0:0x0xFFFFFFFF
19650xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19660xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19670xF0F0:0xF0F0:0x0xF0F0
19680x0F0F:0x0F0F:0x0x0F0F
19690xF0F0:0x0F0F:0x0xFFFF
19700xF0F0F0:0xF0F0F0:0x0xF0F0F0
19710x0F0F0F:0x0F0F0F:0x0x0F0F0F
19720x0F0F0F:0xF0F0F0:0x0xFFFFFF
19730xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19740x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19750x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19760xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19770x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19780x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19790xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19800x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19810x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
19820x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1983&bxor
1984abc:abc:NaN
1985abc:0:NaN
19860:abc:NaN
19871:2:3
61f5c3f5 1988+8:+2:10
1989+281474976710656:0:281474976710656
1990+281474976710656:1:281474976710657
1991+281474976710656:281474976710656:0
6854fd01 1992-2:-3:3
1993-1:-1:0
1994-6:-6:0
1995-7:4:-3
1996-4:7:-5
19974:-7:-3
1998-4:-7:5
9b924220 199930:-3:-29
200030:-4:-30
2001300:-76:-360
2002-76:300:-360
394e6ffb 2003# equal arguments are treated special, so also do some test with unequal ones
20040xFFFF:0xFFFF:0
20050xFFFFFF:0xFFFFFF:0
20060xFFFFFFFF:0xFFFFFFFF:0
20070xFFFFFFFFFF:0xFFFFFFFFFF:0
20080xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
20090:0xFFFF:0x0xFFFF
20100:0xFFFFFF:0x0xFFFFFF
20110:0xFFFFFFFF:0x0xFFFFFFFF
20120:0xFFFFFFFFFF:0x0xFFFFFFFFFF
20130:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
20140xFFFF:0:0x0xFFFF
20150xFFFFFF:0:0x0xFFFFFF
20160xFFFFFFFF:0:0x0xFFFFFFFF
20170xFFFFFFFFFF:0:0x0xFFFFFFFFFF
20180xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
20190xF0F0:0xF0F0:0
20200x0F0F:0x0F0F:0
20210xF0F0:0x0F0F:0x0xFFFF
20220xF0F0F0:0xF0F0F0:0
20230x0F0F0F:0x0F0F0F:0
20240x0F0F0F:0xF0F0F0:0x0xFFFFFF
20250xF0F0F0F0:0xF0F0F0F0:0
20260x0F0F0F0F:0x0F0F0F0F:0
20270x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
20280xF0F0F0F0F0:0xF0F0F0F0F0:0
20290x0F0F0F0F0F:0x0F0F0F0F0F:0
20300x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
20310xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
20320x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
20330x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 2034&bnot
2035abc:NaN
2036+0:-1
2037+8:-9
2038+281474976710656:-281474976710657
2039-1:0
2040-2:1
2041-12:11
2042&digit
20430:0:0
204412:0:2
204512:1:1
2046123:0:3
2047123:1:2
2048123:2:1
2049123:-1:1
2050123:-2:2
2051123:-3:3
2052123456:0:6
2053123456:1:5
2054123456:2:4
2055123456:3:3
2056123456:4:2
2057123456:5:1
2058123456:-1:1
2059123456:-2:2
2060123456:-3:3
2061100000:-3:0
2062100000:0:0
2063100000:1:0
2064&mantissa
2065abc:NaN
20661e4:1
20672e0:2
2068123:123
2069-1:-1
2070-2:-2
2071+inf:inf
2072-inf:-inf
2073&exponent
2074abc:NaN
20751e4:4
20762e0:0
2077123:0
2078-1:0
2079-2:0
20800:1
2081+inf:inf
2082-inf:inf
2083&parts
2084abc:NaN,NaN
20851e4:1,4
20862e0:2,0
2087123:123,0
2088-1:-1,0
2089-2:-2,0
20900:0,1
2091+inf:inf,inf
2092-inf:-inf,inf
b3abae2a 2093&bfac
2094-1:NaN
2095NaNfac:NaN
b282a552 2096+inf:inf
b3abae2a 2097-inf:NaN
20980:1
20991:1
21002:2
21013:6
21024:24
21035:120
21046:720
990fb837 21057:5040
21068:40320
21079:362880
b3abae2a 210810:3628800
210911:39916800
211012:479001600
50109ad0 211120:2432902008176640000
211222:1124000727777607680000
211369:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
6854fd01 2114&bpow
2115abc:12:NaN
211612:abc:NaN
21170:0:1
21180:1:0
21190:2:0
9b924220 21200:-1:inf
21210:-2:inf
6854fd01 21221:0:1
21231:1:1
21241:2:1
21251:3:1
21261:-1:1
21271:-2:1
21281:-3:1
21292:0:1
21302:1:2
21312:2:4
21322:3:8
21333:3:27
2d2b2744 2134-2:2:4
2135-2:3:-8
2136-2:4:16
2137-2:5:-32
6854fd01 21382:-1:NaN
2139-2:-1:NaN
21402:-2:NaN
2141-2:-2:NaN
2d2b2744 2142# inf tests
6854fd01 2143+inf:1234500012:inf
2d2b2744 2144-inf:1234500012:inf
2145-inf:1234500013:-inf
6854fd01 2146+inf:-12345000123:inf
2147-inf:-12345000123:-inf
2d2b2744 2148# -inf * -inf = inf
2149-inf:2:inf
2150-inf:0:NaN
2151-inf:-1:0
2152-inf:inf:NaN
21532:inf:inf
21542:-inf:0
21550:inf:0
21560:-inf:inf
2157-1:-inf:NaN
2158-1:inf:NaN
2159-2:inf:NaN
2160-2:-inf:0
2161NaN:inf:NaN
2162NaN:-inf:NaN
2163-inf:NaN:NaN
2164inf:NaN:NaN
2165inf:-inf:NaN
21661:inf:1
21671:-inf:1
6854fd01 2168# 1 ** -x => 1 / (1 ** x)
2169-1:0:1
2170-2:0:1
2171-1:1:-1
2172-1:2:1
2173-1:3:-1
2174-1:4:1
2175-1:5:-1
2176-1:-1:-1
2177-1:-2:1
2178-1:-3:-1
2179-1:-4:1
218010:2:100
218110:3:1000
218210:4:10000
218310:5:100000
218410:6:1000000
218510:7:10000000
218610:8:100000000
218710:9:1000000000
218810:20:100000000000000000000
2189123456:2:15241383936
9b924220 2190-2:2:4
2191-2:3:-8
2192-2:4:16
2193-2:5:-32
2194-3:2:9
2195-3:3:-27
2196-3:4:81
2197-3:5:-243
6854fd01 2198&length
2199100:3
220010:2
22011:1
22020:1
220312345:5
220410000000000000000:17
2205-123:3
2206215960156869840440586892398248:30
990fb837 2207&broot
2208# sqrt()
2209+0:2:0
2210+1:2:1
2211-1:2:NaN
2212# -$x ** (1/2) => -$y, but not in froot()
2213-123:2:NaN
2214+inf:2:inf
2215-inf:2:NaN
22162:2:1
2217-2:2:NaN
22184:2:2
22199:2:3
222016:2:4
2221100:2:10
2222123:2:11
222315241:2:123
2224144:2:12
222512:2:3
22260.49:2:0
22270.0049:2:0
2228# invalid ones
22291:NaN:NaN
2230-1:NaN:NaN
22310:NaN:NaN
2232-inf:NaN:NaN
2233+inf:NaN:NaN
2234NaN:0:NaN
2235NaN:2:NaN
2236NaN:inf:NaN
2237NaN:inf:NaN
223812:-inf:NaN
223912:inf:NaN
2240+0:0:NaN
2241+1:0:NaN
2242-1:0:NaN
2243-2:0:NaN
2244-123.45:0:NaN
2245+inf:0:NaN
224612:1:12
2247-12:1:NaN
22488:-1:NaN
2249-8:-1:NaN
2250# cubic root
22518:3:2
2252-8:3:NaN
2253# fourths root
c38b2de2 225416:4:2
225581:4:3
3a427a11 2256# 2 ** 64
c38b2de2 225718446744073709551616:4:65536
225818446744073709551616:8:256
225918446744073709551616:16:16
226018446744073709551616:32:4
226118446744073709551616:64:2
226218446744073709551616:128:1
3a427a11 2263# 213 ** 15
226484274086103068221283760416414557757:15:213
50109ad0 2265# see t/bigroot.t for more tests
6854fd01 2266&bsqrt
394e6ffb 2267145:12
6854fd01 2268144:12
394e6ffb 2269143:11
6854fd01 227016:4
394e6ffb 2271170:13
2272169:13
2273168:12
6854fd01 22744:2
394e6ffb 22753:1
6854fd01 22762:1
394e6ffb 22779:3
6854fd01 227812:3
2279256:16
2280100000000:10000
22814000000000000:2000000
394e6ffb 2282152399026:12345
2283152399025:12345
2284152399024:12344
3a427a11 2285# 2 ** 64 => 2 ** 32
228618446744073709551616:4294967296
228784274086103068221283760416414557757:290299993288095377
6854fd01 22881:1
22890:0
2290-2:NaN
394e6ffb 2291-123:NaN
6854fd01 2292Nan:NaN
990fb837 2293+inf:inf
2294-inf:NaN
50109ad0 2295# see t/biglog.t for more tests
2296&bexp
2297NaN:NaN
2298inf:inf
22991:2
23002:7
30afc38d 2301&batan2
2302NaN:1:10:NaN
2303NaN:NaN:10:NaN
23041:NaN:10:NaN
2305inf:1:14:1
2306-inf:1:14:-1
0dceeee6 23070:-inf:14:3
2308-1:-inf:14:-3
23091:-inf:14:3
23100:inf:14:0
2311inf:-inf:14:2
2312-inf:-inf:14:-2
2313# +- 0.78....
2314inf:+inf:14:0
2315-inf:+inf:14:0
30afc38d 23161:5:13:0
23171:5:14:0
23180:0:10:0
23190:1:14:0
23200:2:14:0
23211:0:14:1
23225:0:14:1
2323-1:0:11:-1
2324-2:0:77:-1
23252:0:77:1
2326-1:5:14:0
23271:5:14:0
2328-1:8:14:0
23291:8:14:0
2330-1:1:14:0
fdb4b05f 2331&bpi
233277:3
2333+0:3
233411:3
50109ad0 2335# see t/bignok.t for more tests
2336&bnok
2337+inf:10:inf
2338NaN:NaN:NaN
2339NaN:1:NaN
23401:NaN:NaN
23411:1:1
2342# k > n
23431:2:0
23442:3:0
2345# k < 0
23461:-2:0
2347# 7 over 3 = 35
23487:3:35
23497:6:1
2350100:90:17310309456440
2351100:95:75287520
6854fd01 2352&bround
2353$round_mode('trunc')
23540:12:0
2355NaNbround:12:NaN
2356+inf:12:inf
2357-inf:12:-inf
23581234:0:1234
23591234:2:1200
2360123456:4:123400
2361123456:5:123450
2362123456:6:123456
61f5c3f5 2363+10123456789:5:10123000000
6854fd01 2364-10123456789:5:-10123000000
61f5c3f5 2365+10123456789:9:10123456700
6854fd01 2366-10123456789:9:-10123456700
61f5c3f5 2367+101234500:6:101234000
6854fd01 2368-101234500:6:-101234000
61f5c3f5 2369#+101234500:-4:101234000
6854fd01 2370#-101234500:-4:-101234000
2371$round_mode('zero')
61f5c3f5 2372+20123456789:5:20123000000
6854fd01 2373-20123456789:5:-20123000000
61f5c3f5 2374+20123456789:9:20123456800
6854fd01 2375-20123456789:9:-20123456800
61f5c3f5 2376+201234500:6:201234000
6854fd01 2377-201234500:6:-201234000
61f5c3f5 2378#+201234500:-4:201234000
6854fd01 2379#-201234500:-4:-201234000
2380+12345000:4:12340000
2381-12345000:4:-12340000
2382$round_mode('+inf')
61f5c3f5 2383+30123456789:5:30123000000
6854fd01 2384-30123456789:5:-30123000000
61f5c3f5 2385+30123456789:9:30123456800
6854fd01 2386-30123456789:9:-30123456800
61f5c3f5 2387+301234500:6:301235000
6854fd01 2388-301234500:6:-301234000
61f5c3f5 2389#+301234500:-4:301235000
6854fd01 2390#-301234500:-4:-301234000
2391+12345000:4:12350000
2392-12345000:4:-12340000
2393$round_mode('-inf')
61f5c3f5 2394+40123456789:5:40123000000
6854fd01 2395-40123456789:5:-40123000000
61f5c3f5 2396+40123456789:9:40123456800
6854fd01 2397-40123456789:9:-40123456800
61f5c3f5 2398+401234500:6:401234000
2399+401234500:6:401234000
6854fd01 2400#-401234500:-4:-401235000
2401#-401234500:-4:-401235000
2402+12345000:4:12340000
2403-12345000:4:-12350000
2404$round_mode('odd')
61f5c3f5 2405+50123456789:5:50123000000
6854fd01 2406-50123456789:5:-50123000000
61f5c3f5 2407+50123456789:9:50123456800
6854fd01 2408-50123456789:9:-50123456800
61f5c3f5 2409+501234500:6:501235000
6854fd01 2410-501234500:6:-501235000
61f5c3f5 2411#+501234500:-4:501235000
6854fd01 2412#-501234500:-4:-501235000
2413+12345000:4:12350000
2414-12345000:4:-12350000
2415$round_mode('even')
61f5c3f5 2416+60123456789:5:60123000000
6854fd01 2417-60123456789:5:-60123000000
61f5c3f5 2418+60123456789:9:60123456800
6854fd01 2419-60123456789:9:-60123456800
61f5c3f5 2420+601234500:6:601234000
6854fd01 2421-601234500:6:-601234000
61f5c3f5 2422#+601234500:-4:601234000
6854fd01 2423#-601234500:-4:-601234000
2424#-601234500:-9:0
2425#-501234500:-9:0
2426#-601234500:-8:0
2427#-501234500:-8:0
2428+1234567:7:1234567
2429+1234567:6:1234570
2430+12345000:4:12340000
2431-12345000:4:-12340000
7b29e1e6 2432$round_mode('common')
2433+60123456789:5:60123000000
2434+60123199999:5:60123000000
2435+60123299999:5:60123000000
2436+60123399999:5:60123000000
2437+60123499999:5:60123000000
2438+60123500000:5:60124000000
2439+60123600000:5:60124000000
2440+60123700000:5:60124000000
2441+60123800000:5:60124000000
2442+60123900000:5:60124000000
2443-60123456789:5:-60123000000
2444-60123199999:5:-60123000000
2445-60123299999:5:-60123000000
2446-60123399999:5:-60123000000
2447-60123499999:5:-60123000000
2448-60123500000:5:-60124000000
2449-60123600000:5:-60124000000
2450-60123700000:5:-60124000000
2451-60123800000:5:-60124000000
2452-60123900000:5:-60124000000
6854fd01 2453&is_zero
24540:1
2455NaNzero:0
2456+inf:0
2457-inf:0
2458123:0
2459-1:0
24601:0
2461&is_one
24620:0
2463NaNone:0
2464+inf:0
2465-inf:0
24661:1
24672:0
2468-1:0
2469-2:0
2470# floor and ceil tests are pretty pointless in integer space...but play safe
2471&bfloor
24720:0
2473NaNfloor:NaN
2474+inf:inf
2475-inf:-inf
2476-1:-1
2477-2:-2
24782:2
24793:3
2480abc:NaN
2481&bceil
2482NaNceil:NaN
2483+inf:inf
2484-inf:-inf
24850:0
2486-1:-1
2487-2:-2
24882:2
24893:3
2490abc:NaN
2491&as_hex
2492128:0x80
2493-128:-0x80
24940:0x0
2495-0:0x0
24961:0x1
24970x123456789123456789:0x123456789123456789
2498+inf:inf
2499-inf:-inf
2500NaNas_hex:NaN
2501&as_bin
2502128:0b10000000
2503-128:-0b10000000
25040:0b0
2505-0:0b0
25061:0b1
25070b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 25080x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2509+inf:inf
2510-inf:-inf
2511NaNas_bin:NaN