threads 1.63
[p5sagit/p5-mst-13.2.git] / lib / 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 {
d614cd8b 45 chomp;
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);";
d614cd8b 179 } else {
80365507 180 # Functions with three arguments
d614cd8b 181 $try .= "\$z = $class->new(\"$args[2]\");";
182
d614cd8b 183 if( $f eq "bmodpow") {
184 $try .= "\$x->bmodpow(\$y,\$z);";
80365507 185 } elsif ($f eq "bmuladd"){
186 $try .= "\$x->bmuladd(\$y,\$z);";
d614cd8b 187 } else { warn "Unknown op '$f'"; }
188 }
61f5c3f5 189 } # end else all other ops
190
191 $ans1 = eval $try;
192 # convert hex/binary targets to decimal
193 if ($ans =~ /^(0x0x|0b0b)/)
194 {
195 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 196 }
61f5c3f5 197 if ($ans eq "")
198 {
199 ok_undef ($ans1);
200 }
201 else
202 {
203 # print "try: $try ans: $ans1 $ans\n";
204 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 205 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 206 }
61f5c3f5 207 # check internal state of number objects
208 is_valid($ans1,$f) if ref $ans1;
6854fd01 209 } # endwhile data tests
210close DATA;
211
212# test some more
213@a = ();
214for (my $i = 1; $i < 10; $i++)
215 {
216 push @a, $i;
217 }
218ok "@a", "1 2 3 4 5 6 7 8 9";
219
220# test whether self-multiplication works correctly (result is 2**64)
221$try = "\$x = $class->new('4294967296');";
222$try .= '$a = $x->bmul($x);';
223$ans1 = eval $try;
224print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
225# test self-pow
226$try = "\$x = $class->new(10);";
227$try .= '$a = $x->bpow($x);';
228$ans1 = eval $try;
229print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
230
07d34614 231###############################################################################
6854fd01 232# test whether op destroys args or not (should better not)
233
234$x = $class->new(3);
235$y = $class->new(4);
236$z = $x & $y;
237ok ($x,3);
238ok ($y,4);
239ok ($z,0);
240$z = $x | $y;
241ok ($x,3);
242ok ($y,4);
243ok ($z,7);
244$x = $class->new(1);
245$y = $class->new(2);
246$z = $x | $y;
247ok ($x,1);
248ok ($y,2);
249ok ($z,3);
250
251$x = $class->new(5);
252$y = $class->new(4);
253$z = $x ^ $y;
254ok ($x,5);
255ok ($y,4);
256ok ($z,1);
257
258$x = $class->new(-5); $y = -$x;
259ok ($x, -5);
260
261$x = $class->new(-5); $y = abs($x);
262ok ($x, -5);
263
07d34614 264$x = $class->new(8);
265$y = $class->new(-1);
266$z = $class->new(5033);
267my $u = $x->copy()->bmodpow($y,$z);
268ok ($u,4404);
269ok ($y,-1);
270ok ($z,5033);
271
272$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
273$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
274
275$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
276$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
277$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
278$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
279$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
280
281$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
282$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
283$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
284$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
285$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
286
287$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
288$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
289$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
290$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
291$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
292
293###############################################################################
6854fd01 294# check whether overloading cmp works
295$try = "\$x = $class->new(0);";
296$try .= "\$y = 10;";
297$try .= "'false' if \$x ne \$y;";
298$ans = eval $try;
299print "# For '$try'\n" if (!ok "$ans" , "false" );
300
301# we cant test for working cmpt with other objects here, we would need a dummy
302# object with stringify overload for this. see Math::String tests as example
303
304###############################################################################
6854fd01 305# check reversed order of arguments
027dc388 306
6854fd01 307$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
308$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
309print "# For '$try'\n" if (!ok "$ans" , "ok" );
310
311$try = "\$x = $class->new(10); \$x = 2 * \$x;";
312$try .= "'ok' if \$x == 20;"; $ans = eval $try;
313print "# For '$try'\n" if (!ok "$ans" , "ok" );
314
315$try = "\$x = $class->new(10); \$x = 2 + \$x;";
316$try .= "'ok' if \$x == 12;"; $ans = eval $try;
317print "# For '$try'\n" if (!ok "$ans" , "ok" );
318
319$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
320$try .= "'ok' if \$x == -8;"; $ans = eval $try;
321print "# For '$try'\n" if (!ok "$ans" , "ok" );
322
323$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
324$try .= "'ok' if \$x == 2;"; $ans = eval $try;
325print "# For '$try'\n" if (!ok "$ans" , "ok" );
326
027dc388 327$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
328$try .= "'ok' if \$x == 2;"; $ans = eval $try;
329print "# For '$try'\n" if (!ok "$ans" , "ok" );
330
331$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
332$try .= "'ok' if \$x == 4;"; $ans = eval $try;
333print "# For '$try'\n" if (!ok "$ans" , "ok" );
334
335$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
336$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
337print "# For '$try'\n" if (!ok "$ans" , "ok" );
338
339$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
340$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
341print "# For '$try'\n" if (!ok "$ans" , "ok" );
342
6854fd01 343###############################################################################
344# check badd(4,5) form
345
346$try = "\$x = $class\->badd(4,5);";
347$try .= "'ok' if \$x == 9;";
348$ans = eval $try;
349print "# For '$try'\n" if (!ok "$ans" , "ok" );
350
351###############################################################################
352# check undefs: NOT DONE YET
353
354###############################################################################
355# bool
356
f9a08e12 357$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
358$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 359
360###############################################################################
361# objectify()
362
363@args = Math::BigInt::objectify(2,4,5);
364ok (scalar @args,3); # $class, 4, 5
56b9c951 365ok ($args[0] =~ /^Math::BigInt/);
6854fd01 366ok ($args[1],4);
367ok ($args[2],5);
368
369@args = Math::BigInt::objectify(0,4,5);
370ok (scalar @args,3); # $class, 4, 5
56b9c951 371ok ($args[0] =~ /^Math::BigInt/);
6854fd01 372ok ($args[1],4);
373ok ($args[2],5);
374
375@args = Math::BigInt::objectify(2,4,5);
376ok (scalar @args,3); # $class, 4, 5
56b9c951 377ok ($args[0] =~ /^Math::BigInt/);
6854fd01 378ok ($args[1],4);
379ok ($args[2],5);
380
381@args = Math::BigInt::objectify(2,4,5,6,7);
382ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 383ok ($args[0] =~ /^Math::BigInt/);
6854fd01 384ok ($args[1],4); ok (ref($args[1]),$args[0]);
385ok ($args[2],5); ok (ref($args[2]),$args[0]);
386ok ($args[3],6); ok (ref($args[3]),'');
387ok ($args[4],7); ok (ref($args[4]),'');
388
389@args = Math::BigInt::objectify(2,$class,4,5,6,7);
390ok (scalar @args,5); # $class, 4, 5, 6, 7
391ok ($args[0],$class);
392ok ($args[1],4); ok (ref($args[1]),$args[0]);
393ok ($args[2],5); ok (ref($args[2]),$args[0]);
394ok ($args[3],6); ok (ref($args[3]),'');
395ok ($args[4],7); ok (ref($args[4]),'');
396
397###############################################################################
f9a08e12 398# test whether an opp calls objectify properly or not (or at least does what
399# it should do given non-objects, w/ or w/o objectify())
400
401ok ($class->new(123)->badd(123),246);
402ok ($class->badd(123,321),444);
403ok ($class->badd(123,$class->new(321)),444);
404
405ok ($class->new(123)->bsub(122),1);
406ok ($class->bsub(321,123),198);
407ok ($class->bsub(321,$class->new(123)),198);
408
409ok ($class->new(123)->bmul(123),15129);
410ok ($class->bmul(123,123),15129);
411ok ($class->bmul(123,$class->new(123)),15129);
412
413ok ($class->new(15129)->bdiv(123),123);
414ok ($class->bdiv(15129,123),123);
415ok ($class->bdiv(15129,$class->new(123)),123);
416
417ok ($class->new(15131)->bmod(123),2);
418ok ($class->bmod(15131,123),2);
419ok ($class->bmod(15131,$class->new(123)),2);
420
421ok ($class->new(2)->bpow(16),65536);
422ok ($class->bpow(2,16),65536);
423ok ($class->bpow(2,$class->new(16)),65536);
424
425ok ($class->new(2**15)->brsft(1),2**14);
426ok ($class->brsft(2**15,1),2**14);
427ok ($class->brsft(2**15,$class->new(1)),2**14);
428
429ok ($class->new(2**13)->blsft(1),2**14);
430ok ($class->blsft(2**13,1),2**14);
431ok ($class->blsft(2**13,$class->new(1)),2**14);
432
433###############################################################################
6854fd01 434# test for floating-point input (other tests in bnorm() below)
435
436$z = 1050000000000000; # may be int on systems with 64bit?
437$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
438$z = 1e+129; # definitely a float (may fail on UTS)
439# don't compare to $z, since some Perl versions stringify $z into something
440# like '1.e+129' or something equally ugly
441$x = $class->new($z); ok ($x->bsstr(),'1e+129');
442
443###############################################################################
56d9de68 444# test for whitespace inlcuding newlines to be handled correctly
445
446# ok ($Math::BigInt::strict,1); # the default
447
448foreach my $c (
449 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
450 {
451 my $m = $class->new($c);
452 ok ($class->new("$c"),$m);
453 ok ($class->new(" $c"),$m);
454 ok ($class->new("$c "),$m);
455 ok ($class->new(" $c "),$m);
456 ok ($class->new("\n$c"),$m);
457 ok ($class->new("$c\n"),$m);
458 ok ($class->new("\n$c\n"),$m);
459 ok ($class->new(" \n$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\n1"),'NaN');
463 ok ($class->new("1 \n$c\n1"),'NaN');
464 }
465
466###############################################################################
6854fd01 467# prime number tests, also test for **= and length()
468# found on: http://www.utm.edu/research/primes/notes/by_year.html
469
470# ((2^148)-1)/17
471$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
472ok ($x,"20988936657440586486151264256610222593863921");
473ok ($x->length(),length "20988936657440586486151264256610222593863921");
474
475# MM7 = 2^127-1
476$x = $class->new(2); $x **= 127; $x--;
477ok ($x,"170141183460469231731687303715884105727");
478
479$x = $class->new('215960156869840440586892398248');
480($x,$y) = $x->length();
481ok ($x,30); ok ($y,0);
482
483$x = $class->new('1_000_000_000_000');
484($x,$y) = $x->length();
485ok ($x,13); ok ($y,0);
486
2d2b2744 487# test <<=, >>=
488$x = $class->new('2');
489my $y = $class->new('18');
490ok ($x <<= $y, 2 << 18);
491ok ($x, 2 << 18);
492ok ($x >>= $y, 2);
493ok ($x, 2);
494
6854fd01 495# I am afraid the following is not yet possible due to slowness
496# Also, testing for 2 meg output is a bit hard ;)
497#$x = $class->new(2); $x **= 6972593; $x--;
498
499# 593573509*2^332162+1 has exactly 1,000,000 digits
500# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
501#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
502#ok ($x->length(),1_000_000);
503
504###############################################################################
505# inheritance and overriding of _swap
506
507$x = Math::Foo->new(5);
508$x = $x - 8; # 8 - 5 instead of 5-8
509ok ($x,3);
510ok (ref($x),'Math::Foo');
511
512$x = Math::Foo->new(5);
513$x = 8 - $x; # 5 - 8 instead of 8 - 5
514ok ($x,-3);
515ok (ref($x),'Math::Foo');
516
517###############################################################################
518# Test whether +inf eq inf
519# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
520# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
521# like 1e100000 crash on some platforms. So simple test for the string 'inf'
522$x = $class->new('+inf'); ok ($x,'inf');
523
524###############################################################################
525###############################################################################
56d9de68 526# the followin tests only make sense with Math::BigInt::Calc or BareCalc or
527# FastCalc
6854fd01 528
56d9de68 529exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01 530
531###############################################################################
532# check proper length of internal arrays
533
394e6ffb 534my $bl = $CL->_base_len();
6854fd01 535my $BASE = '9' x $bl;
536my $MAX = $BASE;
537$BASE++;
538
539$x = $class->new($MAX); is_valid($x); # f.i. 9999
540$x += 1; ok ($x,$BASE); is_valid($x); # 10000
541$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
542
543###############################################################################
544# check numify
545
546$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
547$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 548
549# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
550$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 551$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
552$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
553ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
554
555###############################################################################
556# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
557
394e6ffb 558$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
559if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
560
561$x = $class->new($BASE+3); $x++;
562if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 563
394e6ffb 564# test for +0 instead of int():
565$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 566
567###############################################################################
56b9c951 568# test bug that $class->digit($string) did not work
569
570ok ($class->digit(123,2),1);
571
572###############################################################################
6854fd01 573# bug in sub where number with at least 6 trailing zeros after any op failed
574
394e6ffb 575$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 576ok ($z, 100000);
577ok ($x, 23456);
578
579###############################################################################
580# bug in shortcut in mul()
581
61f5c3f5 582# construct a number with a zero-hole of BASE_LEN_SMALL
583{
584 my @bl = $CL->_base_len(); my $bl = $bl[4];
585
586 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
587 $y = '1' x (2*$bl);
588 $x = $class->new($x)->bmul($y);
589 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
590 $y = ''; my $d = '';
591 for (my $i = 1; $i <= $bl; $i++)
592 {
593 $y .= $i; $d = $i.$d;
594 }
595 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
596 ok ($x,$y);
597
6854fd01 598
f9a08e12 599 #############################################################################
600 # see if mul shortcut for small numbers works
394e6ffb 601
f9a08e12 602 $x = '9' x $bl;
603 $x = $class->new($x);
604 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
605 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
606}
61f5c3f5 607
394e6ffb 608###############################################################################
6854fd01 609# bug with rest "-0" in div, causing further div()s to fail
610
394e6ffb 611$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 612
61f5c3f5 613ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 614
79c55733 615###############################################################################
f9a08e12 616# bug in $x->bmod($y)
07d34614 617
f9a08e12 618# if $x < 0 and $y > 0
07d34614 619$x = $class->new('-629'); ok ($x->bmod(5033),4404);
620
621###############################################################################
56b9c951 622# bone/binf etc as plain calls (Lite failed them)
623
624ok ($class->bzero(),0);
625ok ($class->bone(),1);
626ok ($class->bone('+'),1);
627ok ($class->bone('-'),-1);
628ok ($class->bnan(),'NaN');
629ok ($class->binf(),'inf');
630ok ($class->binf('+'),'inf');
631ok ($class->binf('-'),'-inf');
632ok ($class->binf('-inf'),'-inf');
633
634###############################################################################
990fb837 635# is_one('-')
636
637ok ($class->new(1)->is_one('-'),0);
638ok ($class->new(-1)->is_one('-'),1);
639ok ($class->new(1)->is_one(),1);
640ok ($class->new(-1)->is_one(),0);
641
642###############################################################################
03874afe 643# [perl #30609] bug with $x -= $x not beeing 0, but 2*$x
644
645$x = $class->new(3); $x -= $x; ok ($x, 0);
646$x = $class->new(-3); $x -= $x; ok ($x, 0);
647$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
648$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
649$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
650
651$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
652$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
653$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
654$x = $class->new(3); $x += $x; ok ($x, 6);
655$x = $class->new(-3); $x += $x; ok ($x, -6);
656
657$x = $class->new(3); $x *= $x; ok ($x, 9);
658$x = $class->new(-3); $x *= $x; ok ($x, 9);
659$x = $class->new(3); $x /= $x; ok ($x, 1);
660$x = $class->new(-3); $x /= $x; ok ($x, 1);
661$x = $class->new(3); $x %= $x; ok ($x, 0);
662$x = $class->new(-3); $x %= $x; ok ($x, 0);
663
664###############################################################################
61f5c3f5 665# all tests done
6854fd01 666
6671;
668
669###############################################################################
61f5c3f5 670###############################################################################
6854fd01 671# Perl 5.005 does not like ok ($x,undef)
672
673sub ok_undef
674 {
675 my $x = shift;
676
677 ok (1,1) and return if !defined $x;
678 ok ($x,'undef');
679 }
680
681###############################################################################
682# sub to check validity of a BigInt internally, to ensure that no op leaves a
683# number object in an invalid state (f.i. "-0")
684
685sub is_valid
686 {
687 my ($x,$f) = @_;
688
689 my $e = 0; # error?
6854fd01 690
56b9c951 691 # allow the check to pass for all Lite, and all MBI and subclasses
692 # ok as reference?
693 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 694
56b9c951 695 if (ref($x) ne 'Math::BigInt::Lite')
696 {
697 # has ok sign?
698 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
699 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
700
701 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
702 $e = $CALC->_check($x->{value}) if $e eq '0';
703 }
6854fd01 704
705 # test done, see if error did crop up
706 ok (1,1), return if ($e eq '0');
707
027dc388 708 ok (1,$e." after op '$f'");
6854fd01 709 }
710
711__DATA__
027dc388 712&.=
7131234:-345:1234-345
714&+=
7151:2:3
716-1:-2:-3
717&-=
7181:2:-1
719-1:-2:1
720&*=
7212:3:6
722-1:5:-5
723&%=
724100:3:1
7258:9:8
07d34614 726-629:5033:4404
027dc388 727&/=
728100:3:33
729-8:2:-4
730&|=
7312:1:3
732&&=
7335:7:5
734&^=
7355:7:2
091c87b1 736&blog
737NaNlog:2:NaN
738122:NaNlog:NaN
739NaNlog1:NaNlog:NaN
740122:inf:NaN
741inf:122:NaN
742122:-inf:NaN
743-inf:122:NaN
744-inf:-inf:NaN
745inf:inf:NaN
7460:4:NaN
747-21:4:NaN
74821:-21:NaN
749# normal results
7501024:2:10
75181:3:4
752# 3.01.. truncate
75382:3:4
754# 3.9... truncate
75580:3:3
75615625:5:6
75715626:5:6
75815624:5:5
8df1e0a2 7591000:10:3
76010000:10:4
761100000:10:5
7621000000:10:6
76310000000:10:7
764100000000:10:8
7658916100448256:12:12
7668916100448257:12:12
7678916100448255:12:11
7682251799813685248:8:17
76972057594037927936:2:56
770144115188075855872:2:57
771288230376151711744:2:58
772576460752303423488:2:59
7734096:2:12
7741329227995784915872903807060280344576:2:120
091c87b1 775# $x == $base => result 1
7763:3:1
777# $x < $base => result 0 ($base ** 0 <= $x)
7783:4:0
779# $x == 1 => result 0
7801:5:0
6854fd01 781&is_negative
7820:0
783-1:1
7841:0
785+inf:0
786-inf:1
787NaNneg:0
788&is_positive
b68b7ab1 7890:0
6854fd01 790-1:0
7911:1
792+inf:1
793-inf:0
794NaNneg:0
b3abae2a 795&is_int
796-inf:0
797+inf:0
798NaNis_int:0
7991:1
8000:1
801123e12:1
6854fd01 802&is_odd
803abc:0
8040:0
8051:1
8063:1
807-1:1
808-3:1
80910000001:1
81010000002:0
8112:0
b3abae2a 812120:0
813121:1
6854fd01 814&is_even
815abc:0
8160:1
8171:0
8183:0
819-1:0
820-3:0
82110000001:0
82210000002:1
8232:1
b3abae2a 824120:1
825121:0
6854fd01 826&bacmp
827+0:-0:0
828+0:+1:-1
829-1:+1:0
830+1:-1:0
831-1:+2:-1
832+2:-1:1
833-123456789:+987654321:-1
834+123456789:-987654321:-1
835+987654321:+123456789:1
836-987654321:+123456789:1
837-123:+4567889:-1
838# NaNs
839acmpNaN:123:
840123:acmpNaN:
841acmpNaN:acmpNaN:
842# infinity
843+inf:+inf:0
844-inf:-inf:0
845+inf:-inf:0
846-inf:+inf:0
847+inf:123:1
848-inf:123:1
849+inf:-123:1
850-inf:-123:1
ef9466ea 851123:-inf:-1
852-123:inf:-1
853-123:-inf:-1
854123:inf:-1
6854fd01 855# return undef
856+inf:NaN:
857NaN:inf:
858-inf:NaN:
859NaN:-inf:
860&bnorm
aef458a0 8610e999:0
8620e-999:0
863-0e999:0
864-0e-999:0
6854fd01 865123:123
866# binary input
8670babc:NaN
8680b123:NaN
8690b0:0
870-0b0:0
871-0b1:-1
8720b0001:1
8730b001:1
8740b011:3
8750b101:5
61f5c3f5 8760b1001:9
8770b10001:17
8780b100001:33
8790b1000001:65
8800b10000001:129
8810b100000001:257
8820b1000000001:513
8830b10000000001:1025
8840b100000000001:2049
8850b1000000000001:4097
8860b10000000000001:8193
8870b100000000000001:16385
8880b1000000000000001:32769
8890b10000000000000001:65537
8900b100000000000000001:131073
8910b1000000000000000001:262145
8920b10000000000000000001:524289
8930b100000000000000000001:1048577
8940b1000000000000000000001:2097153
8950b10000000000000000000001:4194305
8960b100000000000000000000001:8388609
8970b1000000000000000000000001:16777217
8980b10000000000000000000000001:33554433
8990b100000000000000000000000001:67108865
9000b1000000000000000000000000001:134217729
9010b10000000000000000000000000001:268435457
9020b100000000000000000000000000001:536870913
9030b1000000000000000000000000000001:1073741825
9040b10000000000000000000000000000001:2147483649
9050b100000000000000000000000000000001:4294967297
9060b1000000000000000000000000000000001:8589934593
9070b10000000000000000000000000000000001:17179869185
6854fd01 9080b_101:NaN
9090b1_0_1:5
394e6ffb 9100b0_0_0_1:1
6854fd01 911# hex input
912-0x0:0
9130xabcdefgh:NaN
9140x1234:4660
9150xabcdef:11259375
916-0xABCDEF:-11259375
917-0x1234:-4660
9180x12345678:305419896
9190x1_2_3_4_56_78:305419896
394e6ffb 9200xa_b_c_d_e_f:11259375
6854fd01 9210x_123:NaN
61f5c3f5 9220x9:9
9230x11:17
9240x21:33
9250x41:65
9260x81:129
9270x101:257
9280x201:513
9290x401:1025
9300x801:2049
9310x1001:4097
9320x2001:8193
9330x4001:16385
9340x8001:32769
9350x10001:65537
9360x20001:131073
9370x40001:262145
9380x80001:524289
9390x100001:1048577
9400x200001:2097153
9410x400001:4194305
9420x800001:8388609
9430x1000001:16777217
9440x2000001:33554433
9450x4000001:67108865
9460x8000001:134217729
9470x10000001:268435457
9480x20000001:536870913
9490x40000001:1073741825
9500x80000001:2147483649
9510x100000001:4294967297
9520x200000001:8589934593
9530x400000001:17179869185
9540x800000001:34359738369
2d2b2744 955# bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex()
9560x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
6854fd01 957# inf input
958inf:inf
959+inf:inf
960-inf:-inf
9610inf:NaN
027dc388 962# abnormal input
6854fd01 963:NaN
964abc:NaN
965 1 a:NaN
9661bcd2:NaN
96711111b:NaN
968+1z:NaN
969-1z:NaN
027dc388 970# only one underscore between two digits
971_123:NaN
972_123_:NaN
973123_:NaN
9741__23:NaN
9751E1__2:NaN
9761_E12:NaN
9771E_12:NaN
9781_E_12:NaN
979+_1E12:NaN
980+0_1E2:100
981+0_0_1E2:100
982-0_0_1E2:-100
983-0_0_1E+0_0_2:-100
984E1:NaN
985E23:NaN
9861.23E1:NaN
9871.23E-1:NaN
988# bug with two E's in number beeing valid
9891e2e3:NaN
9901e2r:NaN
9911e2.0:NaN
07d34614 992# bug with two '.' in number beeing valid
9931.2.2:NaN
9941.2.3e1:NaN
995-1.2.3:NaN
996-1.2.3e-4:NaN
9971.2e3.4:NaN
9981.2e-3.4:NaN
9991.2.3.4:NaN
10001.2.t:NaN
10011..2:NaN
10021..2e1:NaN
10031..2e1..1:NaN
100412e1..1:NaN
1005..2:NaN
1006.-2:NaN
61f5c3f5 1007# leading zeros
1008012:12
10090123:123
101001234:1234
1011012345:12345
10120123456:123456
101301234567:1234567
1014012345678:12345678
10150123456789:123456789
101601234567891:1234567891
1017012345678912:12345678912
10180123456789123:123456789123
101901234567891234:1234567891234
2d2b2744 1020# some inputs that result in zero
10210e0:0
1022+0e0:0
1023+0e+0:0
1024-0e+0:0
10250e-0:0
1026-0e-0:0
1027+0e-0:0
1028000:0
102900e2:0
103000e02:0
1031000e002:0
1032000e1230:0
103300e-3:0
103400e+3:0
103500e-03:0
103600e+03:0
1037-000:0
1038-00e2:0
1039-00e02:0
1040-000e002:0
1041-000e1230:0
1042-00e-3:0
1043-00e+3:0
1044-00e-03:0
1045-00e+03:0
027dc388 1046# normal input
6854fd01 10470:0
1048+0:0
1049+00:0
1050+000:0
1051000000000000000000:0
1052-0:0
1053-0000:0
1054+1:1
1055+01:1
1056+001:1
1057+00000100000:100000
1058123456789:123456789
1059-1:-1
1060-01:-1
1061-001:-1
1062-123456789:-123456789
1063-00000100000:-100000
10641_2_3:123
6854fd01 106510000000000E-1_0:1
10661E2:100
10671E1:10
10681E0:1
6854fd01 10691.23E2:123
6854fd01 1070100E-1:10
1071# floating point input
027dc388 1072# .2e2:20
10731.E3:1000
6854fd01 10741.01E2:101
10751010E-1:101
1076-1010E0:-1010
1077-1010E1:-10100
027dc388 10781234.00:1234
1079# non-integer numbers
6854fd01 1080-1010E-2:NaN
1081-1.01E+1:NaN
1082-1.01E-1:NaN
6854fd01 1083&bnan
10841:NaN
10852:NaN
1086abc:NaN
1087&bone
61f5c3f5 10882:+:1
6854fd01 10892:-:-1
1090boneNaN:-:-1
61f5c3f5 1091boneNaN:+:1
10922:abc:1
10933::1
6854fd01 1094&binf
10951:+:inf
10962:-:-inf
10973:abc:inf
027dc388 1098&is_nan
1099123:0
1100abc:1
1101NaN:1
1102-123:0
6854fd01 1103&is_inf
1104+inf::1
1105-inf::1
1106abc::0
11071::0
1108NaN::0
1109-1::0
1110+inf:-:0
1111+inf:+:1
1112-inf:-:1
1113-inf:+:0
79c55733 1114-inf:-inf:1
1115-inf:+inf:0
1116+inf:-inf:0
1117+inf:+inf:1
6854fd01 1118# it must be exactly /^[+-]inf$/
1119+infinity::0
1120-infinity::0
1121&blsft
1122abc:abc:NaN
61f5c3f5 1123+2:+2:8
1124+1:+32:4294967296
1125+1:+48:281474976710656
6854fd01 1126+8:-2:NaN
1127# excercise base 10
1128+12345:4:10:123450000
1129-1234:0:10:-1234
61f5c3f5 1130+1234:0:10:1234
6854fd01 1131+2:2:10:200
1132+12:2:10:1200
1133+1234:-3:10:NaN
11341234567890123:12:10:1234567890123000000000000
b3abae2a 1135-3:1:2:-6
1136-5:1:2:-10
1137-2:1:2:-4
1138-102533203:1:2:-205066406
6854fd01 1139&brsft
1140abc:abc:NaN
61f5c3f5 1141+8:+2:2
1142+4294967296:+32:1
1143+281474976710656:+48:1
6854fd01 1144+2:-2:NaN
1145# excercise base 10
1146-1234:0:10:-1234
61f5c3f5 1147+1234:0:10:1234
6854fd01 1148+200:2:10:2
1149+1234:3:10:1
1150+1234:2:10:12
1151+1234:-3:10:NaN
1152310000:4:10:31
115312300000:5:10:123
11541230000000000:10:10:123
115509876123456789067890:12:10:9876123
11561234561234567890123:13:10:123456
b3abae2a 1157820265627:1:2:410132813
1158# test shifting negative numbers in base 2
1159-15:1:2:-8
1160-14:1:2:-7
1161-13:1:2:-7
1162-12:1:2:-6
1163-11:1:2:-6
1164-10:1:2:-5
1165-9:1:2:-5
1166-8:1:2:-4
1167-7:1:2:-4
1168-6:1:2:-3
1169-5:1:2:-3
1170-4:1:2:-2
1171-3:1:2:-2
1172-2:1:2:-1
1173-1:1:2:-1
1174-1640531254:2:2:-410132814
1175-1640531254:1:2:-820265627
1176-820265627:1:2:-410132814
1177-205066405:1:2:-102533203
6854fd01 1178&bsstr
56d9de68 1179+inf:inf
1180-inf:-inf
6854fd01 11811e+34:1e+34
1182123.456E3:123456e+0
1183100:1e+2
56d9de68 1184bsstrabc:NaN
1185-5:-5e+0
1186-100:-1e+2
1187&numify
1188numifyabc:NaN
1189+inf:inf
1190-inf:-inf
11915:5
1192-5:-5
1193100:100
1194-100:-100
6854fd01 1195&bneg
1196bnegNaN:NaN
1197+inf:-inf
1198-inf:inf
1199abd:NaN
61f5c3f5 12000:0
12011:-1
1202-1:1
6854fd01 1203+123456789:-123456789
61f5c3f5 1204-123456789:123456789
6854fd01 1205&babs
1206babsNaN:NaN
1207+inf:inf
1208-inf:inf
61f5c3f5 12090:0
12101:1
1211-1:1
1212+123456789:123456789
1213-123456789:123456789
6854fd01 1214&bcmp
1215bcmpNaN:bcmpNaN:
61f5c3f5 1216bcmpNaN:0:
12170:bcmpNaN:
12180:0:0
1219-1:0:-1
12200:-1:1
12211:0:1
12220:1:-1
1223-1:1:-1
12241:-1:1
6854fd01 1225-1:-1:0
61f5c3f5 12261:1:0
1227123:123:0
1228123:12:1
122912:123:-1
6854fd01 1230-123:-123:0
1231-123:-12:-1
1232-12:-123:1
61f5c3f5 1233123:124:-1
1234124:123:1
6854fd01 1235-123:-124:1
1236-124:-123:-1
61f5c3f5 1237100:5:1
1238-123456789:987654321:-1
6854fd01 1239+123456789:-987654321:1
61f5c3f5 1240-987654321:123456789:-1
6854fd01 1241-inf:5432112345:-1
1242+inf:5432112345:1
1243-inf:-5432112345:-1
1244+inf:-5432112345:1
1245+inf:+inf:0
1246-inf:-inf:0
1247+inf:-inf:1
1248-inf:+inf:-1
12495:inf:-1
12505:inf:-1
1251-5:-inf:1
1252-5:-inf:1
1253# return undef
1254+inf:NaN:
1255NaN:inf:
1256-inf:NaN:
1257NaN:-inf:
1258&binc
1259abc:NaN
1260+inf:inf
1261-inf:-inf
61f5c3f5 1262+0:1
1263+1:2
1264-1:0
6854fd01 1265&bdec
1266abc:NaN
1267+inf:inf
1268-inf:-inf
1269+0:-1
61f5c3f5 1270+1:0
6854fd01 1271-1:-2
1272&badd
1273abc:abc:NaN
61f5c3f5 1274abc:0:NaN
6854fd01 1275+0:abc:NaN
b3abae2a 1276+inf:-inf:NaN
1277-inf:+inf:NaN
6854fd01 1278+inf:+inf:inf
1279-inf:-inf:-inf
1280baddNaN:+inf:NaN
1281baddNaN:+inf:NaN
1282+inf:baddNaN:NaN
1283-inf:baddNaN:NaN
61f5c3f5 12840:0:0
12851:0:1
12860:1:1
12871:1:2
1288-1:0:-1
12890:-1:-1
6854fd01 1290-1:-1:-2
61f5c3f5 1291-1:+1:0
1292+1:-1:0
1293+9:+1:10
1294+99:+1:100
1295+999:+1:1000
1296+9999:+1:10000
1297+99999:+1:100000
1298+999999:+1:1000000
1299+9999999:+1:10000000
1300+99999999:+1:100000000
1301+999999999:+1:1000000000
1302+9999999999:+1:10000000000
1303+99999999999:+1:100000000000
1304+10:-1:9
1305+100:-1:99
1306+1000:-1:999
1307+10000:-1:9999
1308+100000:-1:99999
1309+1000000:-1:999999
1310+10000000:-1:9999999
1311+100000000:-1:99999999
1312+1000000000:-1:999999999
1313+10000000000:-1:9999999999
1314+123456789:987654321:1111111110
1315-123456789:987654321:864197532
6854fd01 1316-123456789:-987654321:-1111111110
1317+123456789:-987654321:-864197532
56b9c951 1318-1:10001:10000
1319-1:100001:100000
1320-1:1000001:1000000
1321-1:10000001:10000000
1322-1:100000001:100000000
1323-1:1000000001:1000000000
1324-1:10000000001:10000000000
1325-1:100000000001:100000000000
1326-1:1000000000001:1000000000000
1327-1:10000000000001:10000000000000
1328-1:-10001:-10002
1329-1:-100001:-100002
1330-1:-1000001:-1000002
1331-1:-10000001:-10000002
1332-1:-100000001:-100000002
1333-1:-1000000001:-1000000002
1334-1:-10000000001:-10000000002
1335-1:-100000000001:-100000000002
1336-1:-1000000000001:-1000000000002
1337-1:-10000000000001:-10000000000002
6854fd01 1338&bsub
1339abc:abc:NaN
1340abc:+0:NaN
1341+0:abc:NaN
1342+inf:-inf:inf
1343-inf:+inf:-inf
b3abae2a 1344+inf:+inf:NaN
1345-inf:-inf:NaN
61f5c3f5 1346+0:+0:0
1347+1:+0:1
6854fd01 1348+0:+1:-1
61f5c3f5 1349+1:+1:0
6854fd01 1350-1:+0:-1
61f5c3f5 1351+0:-1:1
1352-1:-1:0
6854fd01 1353-1:+1:-2
61f5c3f5 1354+1:-1:2
1355+9:+1:8
1356+99:+1:98
1357+999:+1:998
1358+9999:+1:9998
1359+99999:+1:99998
1360+999999:+1:999998
1361+9999999:+1:9999998
1362+99999999:+1:99999998
1363+999999999:+1:999999998
1364+9999999999:+1:9999999998
1365+99999999999:+1:99999999998
1366+10:-1:11
1367+100:-1:101
1368+1000:-1:1001
1369+10000:-1:10001
1370+100000:-1:100001
1371+1000000:-1:1000001
1372+10000000:-1:10000001
1373+100000000:-1:100000001
1374+1000000000:-1:1000000001
1375+10000000000:-1:10000000001
6854fd01 1376+123456789:+987654321:-864197532
1377-123456789:+987654321:-1111111110
61f5c3f5 1378-123456789:-987654321:864197532
1379+123456789:-987654321:1111111110
56b9c951 138010001:1:10000
1381100001:1:100000
13821000001:1:1000000
138310000001:1:10000000
1384100000001:1:100000000
13851000000001:1:1000000000
138610000000001:1:10000000000
1387100000000001:1:100000000000
13881000000000001:1:1000000000000
138910000000000001:1:10000000000000
139010001:-1:10002
1391100001:-1:100002
13921000001:-1:1000002
139310000001:-1:10000002
1394100000001:-1:100000002
13951000000001:-1:1000000002
139610000000001:-1:10000000002
1397100000000001:-1:100000000002
13981000000000001:-1:1000000000002
139910000000000001:-1:10000000000002
80365507 1400&bmuladd
1401abc:abc:0:NaN
1402abc:+0:0:NaN
1403+0:abc:0:NaN
1404+0:0:abc:NaN
1405NaNmul:+inf:0:NaN
1406NaNmul:-inf:0:NaN
1407-inf:NaNmul:0:NaN
1408+inf:NaNmul:0:NaN
1409+inf:+inf:0:inf
1410+inf:-inf:0:-inf
1411-inf:+inf:0:-inf
1412-inf:-inf:0:inf
1413+0:+0:0:0
1414+0:+1:0:0
1415+1:+0:0:0
1416+0:-1:0:0
1417-1:+0:0:0
1418123456789123456789:0:0:0
14190:123456789123456789:0:0
1420-1:-1:0:1
1421-1:-1:0:1
1422-1:+1:0:-1
1423+1:-1:0:-1
1424+1:+1:0:1
1425+2:+3:0:6
1426-2:+3:0:-6
1427+2:-3:0:-6
1428-2:-3:0:6
1429111:111:0:12321
143010101:10101:0:102030201
14311001001:1001001:0:1002003002001
1432100010001:100010001:0:10002000300020001
143310000100001:10000100001:0:100002000030000200001
143411111111111:9:0:99999999999
143522222222222:9:0:199999999998
143633333333333:9:0:299999999997
143744444444444:9:0:399999999996
143855555555555:9:0:499999999995
143966666666666:9:0:599999999994
144077777777777:9:0:699999999993
144188888888888:9:0:799999999992
144299999999999:9:0:899999999991
144311111111111:9:1:100000000000
144422222222222:9:1:199999999999
144533333333333:9:1:299999999998
144644444444444:9:1:399999999997
144755555555555:9:1:499999999996
144866666666666:9:1:599999999995
144977777777777:9:1:699999999994
145088888888888:9:1:799999999993
145199999999999:9:1:899999999992
1452-3:-4:-5:7
14533:-4:-5:-17
1454-3:4:-5:-17
14553:4:-5:7
1456-3:4:5:-7
14573:-4:5:-7
14589999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890
14592:3:12345678901234567890:12345678901234567896
6854fd01 1460&bmul
1461abc:abc:NaN
1462abc:+0:NaN
1463+0:abc:NaN
1464NaNmul:+inf:NaN
1465NaNmul:-inf:NaN
1466-inf:NaNmul:NaN
1467+inf:NaNmul:NaN
1468+inf:+inf:inf
1469+inf:-inf:-inf
1470-inf:+inf:-inf
1471-inf:-inf:inf
61f5c3f5 1472+0:+0:0
1473+0:+1:0
1474+1:+0:0
1475+0:-1:0
1476-1:+0:0
1477123456789123456789:0:0
14780:123456789123456789:0
1479-1:-1:1
6854fd01 1480-1:+1:-1
1481+1:-1:-1
61f5c3f5 1482+1:+1:1
1483+2:+3:6
6854fd01 1484-2:+3:-6
1485+2:-3:-6
61f5c3f5 1486-2:-3:6
1487111:111:12321
148810101:10101:102030201
14891001001:1001001:1002003002001
1490100010001:100010001:10002000300020001
149110000100001:10000100001:100002000030000200001
149211111111111:9:99999999999
149322222222222:9:199999999998
149433333333333:9:299999999997
149544444444444:9:399999999996
149655555555555:9:499999999995
149766666666666:9:599999999994
149877777777777:9:699999999993
149988888888888:9:799999999992
150099999999999:9:899999999991
1501+25:+25:625
1502+12345:+12345:152399025
1503+99999:+11111:1111088889
6854fd01 15049999:10000:99990000
150599999:100000:9999900000
1506999999:1000000:999999000000
15079999999:10000000:99999990000000
150899999999:100000000:9999999900000000
1509999999999:1000000000:999999999000000000
15109999999999:10000000000:99999999990000000000
151199999999999:100000000000:9999999999900000000000
1512999999999999:1000000000000:999999999999000000000000
15139999999999999:10000000000000:99999999999990000000000000
151499999999999999:100000000000000:9999999999999900000000000000
1515999999999999999:1000000000000000:999999999999999000000000000000
15169999999999999999:10000000000000000:99999999999999990000000000000000
151799999999999999999:100000000000000000:9999999999999999900000000000000000
1518999999999999999999:1000000000000000000:999999999999999999000000000000000000
15199999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1520&bdiv-list
1521100:20:5,0
15224095:4095:1,0
1523-4095:-4095:1,0
15244095:-4095:-1,0
1525-4095:4095:-1,0
1526123:2:61,1
b3abae2a 15279:5:1,4
15289:4:2,1
6854fd01 1529# inf handling and general remainder
15305:8:0,5
15310:8:0,0
153211:2:5,1
153311:-2:-5,-1
1534-11:2:-5,1
1535# see table in documentation in MBI
15360:inf:0,0
15370:-inf:0,0
15385:inf:0,5
15395:-inf:0,5
1540-5:inf:0,-5
1541-5:-inf:0,-5
1542inf:5:inf,0
1543-inf:5:-inf,0
1544inf:-5:-inf,0
1545-inf:-5:inf,0
15465:5:1,0
1547-5:-5:1,0
b3abae2a 1548inf:inf:NaN,NaN
1549-inf:-inf:NaN,NaN
1550-inf:inf:NaN,NaN
1551inf:-inf:NaN,NaN
6854fd01 15528:0:inf,8
1553inf:0:inf,inf
1554# exceptions to reminder rule
1555-8:0:-inf,-8
1556-inf:0:-inf,-inf
15570:0:NaN,NaN
990fb837 1558# test the shortcut in Calc if @$x == @$yorg
15591234567812345678:123456712345678:10,688888898
156012345671234567:1234561234567:10,58888897
1561123456123456:12345123456:10,4888896
15621234512345:123412345:10,388895
15631234567890999999999:1234567890:1000000000,999999999
15641234567890000000000:1234567890:1000000000,0
15651234567890999999999:9876543210:124999998,9503086419
15661234567890000000000:9876543210:124999998,8503086420
156796969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
7596a890 1568# bug in v1.76
15691267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
b68b7ab1 1570# excercise shortcut for numbers of the same length in div
1571999999999999999999999999999999999:999999999999999999999999999999999:1,0
1572999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1573999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1574999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1575999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1576999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1577999999999999999999999999999999999:333333333333333333333333333333333:3,0
1578999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1579999999999999999999999999999999999:111111111111111111111111111111111:9,0
15809999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
15819999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
15829999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
15839999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
15849999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
15859999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
15869999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
15879999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
15889999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
15899999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
15909999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
6854fd01 1591&bdiv
1592abc:abc:NaN
61f5c3f5 1593abc:1:NaN
15941:abc:NaN
15950:0:NaN
6854fd01 1596# inf handling (see table in doc)
15970:inf:0
15980:-inf:0
15995:inf:0
16005:-inf:0
1601-5:inf:0
1602-5:-inf:0
1603inf:5:inf
1604-inf:5:-inf
1605inf:-5:-inf
1606-inf:-5:inf
16075:5:1
1608-5:-5:1
b3abae2a 1609inf:inf:NaN
1610-inf:-inf:NaN
1611-inf:inf:NaN
1612inf:-inf:NaN
6854fd01 16138:0:inf
1614inf:0:inf
1615-8:0:-inf
1616-inf:0:-inf
16170:0:NaN
161811:2:5
1619-11:-2:5
1620-11:2:-5
162111:-2:-5
61f5c3f5 16220:1:0
16230:-1:0
16241:1:1
1625-1:-1:1
16261:-1:-1
1627-1:1:-1
16281:2:0
16292:1:2
16301:26:0
16311000000000:9:111111111
16322000000000:9:222222222
16333000000000:9:333333333
16344000000000:9:444444444
16355000000000:9:555555555
16366000000000:9:666666666
16377000000000:9:777777777
16388000000000:9:888888888
16399000000000:9:1000000000
164035500000:113:314159
164171000000:226:314159
1642106500000:339:314159
16431000000000:3:333333333
1644+10:+5:2
1645+100:+4:25
1646+1000:+8:125
1647+10000:+16:625
1648999999999999:9:111111111111
1649999999999999:99:10101010101
1650999999999999:999:1001001001
1651999999999999:9999:100010001
1652999999999999999:99999:10000100001
1653+1111088889:99999:11111
6854fd01 1654-5:-3:1
1655-5:3:-1
16564:3:1
16574:-3:-1
16581:3:0
16591:-3:0
1660-2:-3:0
1661-2:3:0
16628:3:2
1663-8:3:-2
166414:-3:-4
1665-14:3:-4
1666-14:-3:4
166714:3:4
1668# bug in Calc with '99999' vs $BASE-1
166910000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1670# test the shortcut in Calc if @$x == @$yorg
16711234567812345678:123456712345678:10
167212345671234567:1234561234567:10
1673123456123456:12345123456:10
16741234512345:123412345:10
16751234567890999999999:1234567890:1000000000
16761234567890000000000:1234567890:1000000000
16771234567890999999999:9876543210:124999998
16781234567890000000000:9876543210:124999998
167996969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1680# bug up to v0.35 in Calc (--$q one too many)
168184696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
168284696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
168384696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
168484696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
b68b7ab1 1685# excercise shortcut for numbers of the same length in div
1686999999999999999999999999999999999:999999999999999999999999999999999:1
1687999999999999999999999999999999999:888888888888888888888888888888888:1
1688999999999999999999999999999999999:777777777777777777777777777777777:1
1689999999999999999999999999999999999:666666666666666666666666666666666:1
1690999999999999999999999999999999999:555555555555555555555555555555555:1
1691999999999999999999999999999999999:444444444444444444444444444444444:2
1692999999999999999999999999999999999:333333333333333333333333333333333:3
1693999999999999999999999999999999999:222222222222222222222222222222222:4
1694999999999999999999999999999999999:111111111111111111111111111111111:9
16959999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
16969999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
16979999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
16989999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
16999999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
17009999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
17019999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
17029999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
17039999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
17049999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
17059999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
a87115f0 1706# bug with shortcut in Calc 0.44
1707949418181818187070707070707070707070:181818181853535353535353535353535353:5
07d34614 1708&bmodinv
1709# format: number:modulus:result
1710# bmodinv Data errors
1711abc:abc:NaN
1712abc:5:NaN
17135:abc:NaN
1714# bmodinv Expected Results from normal use
17151:5:1
17163:5:2
1717-2:5:2
17188:5033:4404
56d9de68 17191234567891:13:6
1720-1234567891:13:7
07d34614 1721324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1722## bmodinv Error cases / useless use of function
07d34614 17233:-5:NaN
1724inf:5:NaN
1ddff52a 17255:inf:NaN
1726-inf:5:NaN
17275:-inf:NaN
07d34614 1728&bmodpow
1729# format: number:exponent:modulus:result
1730# bmodpow Data errors
1731abc:abc:abc:NaN
17325:abc:abc:NaN
1733abc:5:abc:NaN
1734abc:abc:5:NaN
17355:5:abc:NaN
17365:abc:5:NaN
1737abc:5:5:NaN
1738# bmodpow Expected results
17390:0:2:1
17401:0:2:1
17410:0:1:0
17428:7:5032:3840
17438:-1:5033:4404
174498436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1745# bmodpow Error cases
17468:8:-5:NaN
17478:-1:16:NaN
1748inf:5:13:NaN
17495:inf:13:NaN
6854fd01 1750&bmod
1751# inf handling, see table in doc
17520:inf:0
17530:-inf:0
17545:inf:5
17555:-inf:5
1756-5:inf:-5
1757-5:-inf:-5
1758inf:5:0
1759-inf:5:0
1760inf:-5:0
1761-inf:-5:0
17625:5:0
1763-5:-5:0
b3abae2a 1764inf:inf:NaN
1765-inf:-inf:NaN
1766-inf:inf:NaN
1767inf:-inf:NaN
6854fd01 17688:0:8
1769inf:0:inf
1770# exceptions to reminder rule
1771-inf:0:-inf
1772-8:0:-8
17730:0:NaN
1774abc:abc:NaN
61f5c3f5 1775abc:1:abc:NaN
17761:abc:NaN
17770:0:NaN
17780:1:0
17791:0:1
17800:-1:0
1781-1:0:-1
17821:1:0
1783-1:-1:0
17841:-1:0
1785-1:1:0
17861:2:1
17872:1:0
17881000000000:9:1
17892000000000:9:2
17903000000000:9:3
17914000000000:9:4
17925000000000:9:5
17936000000000:9:6
17947000000000:9:7
17958000000000:9:8
17969000000000:9:0
179735500000:113:33
179871000000:226:66
1799106500000:339:99
18001000000000:3:1
180110:5:0
1802100:4:0
18031000:8:0
180410000:16:0
1805999999999999:9:0
1806999999999999:99:0
1807999999999999:999:0
1808999999999999:9999:0
1809999999999999999:99999:0
1810-9:+5:1
6854fd01 1811+9:-5:-1
1812-9:-5:-4
1813-5:3:1
1814-2:3:1
18154:3:1
18161:3:1
1817-5:-3:-2
1818-2:-3:-2
18194:-3:-2
18201:-3:-2
18214095:4095:0
027dc388 1822100041000510123:3:0
1823152403346:12345:4321
b3abae2a 18249:5:4
28df3e88 1825# test shortcuts in Calc
1826# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
18271234:9:1
1828123456:9:3
182912345678:9:0
18301234567891:9:1
1831123456789123:9:6
183212345678912345:9:6
18331234567891234567:9:1
1834123456789123456789:9:0
18351234:10:4
1836123456:10:6
183712345678:10:8
18381234567891:10:1
1839123456789123:10:3
184012345678912345:10:5
18411234567891234567:10:7
1842123456789123456789:10:9
18431234:113:104
1844123456:113:60
184512345678:113:89
18461234567891:113:64
1847123456789123:113:95
184812345678912345:113:53
18491234567891234567:113:56
1850123456789123456789:113:39
07d34614 1851# bug in bmod() not modifying the variable in place
1852-629:5033:4404
aef458a0 1853# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1854# when X == X and X was big
1855111111111111111111111111111111:111111111111111111111111111111:0
185612345678901234567890:12345678901234567890:0
6854fd01 1857&bgcd
9b924220 1858inf:12:NaN
1859-inf:12:NaN
186012:inf:NaN
186112:-inf:NaN
1862inf:inf:NaN
1863inf:-inf:NaN
1864-inf:-inf:NaN
6854fd01 1865abc:abc:NaN
1866abc:+0:NaN
1867+0:abc:NaN
61f5c3f5 1868+0:+0:0
1869+0:+1:1
1870+1:+0:1
1871+1:+1:1
1872+2:+3:1
1873+3:+2:1
1874-3:+2:1
9b924220 1875-3:-2:1
1876-144:-60:12
1877144:-60:12
1878144:60:12
61f5c3f5 1879100:625:25
18804096:81:1
18811034:804:2
188227:90:56:1
188327:90:54:9
6854fd01 1884&blcm
1885abc:abc:NaN
1886abc:+0:NaN
1887+0:abc:NaN
1888+0:+0:NaN
61f5c3f5 1889+1:+0:0
1890+0:+1:0
1891+27:+90:270
1892+1034:+804:415668
6854fd01 1893&band
1894abc:abc:NaN
1895abc:0:NaN
18960:abc:NaN
18971:2:0
18983:2:2
61f5c3f5 1899+8:+2:0
1900+281474976710656:0:0
1901+281474976710656:1:0
1902+281474976710656:+281474976710656:281474976710656
9b924220 1903281474976710656:-1:281474976710656
6854fd01 1904-2:-3:-4
1905-1:-1:-1
1906-6:-6:-6
1907-7:-4:-8
1908-7:4:0
1909-4:7:4
9b924220 1910# negative argument is bitwise shorter than positive [perl #26559]
191130:-3:28
1912123:-1:123
394e6ffb 1913# equal arguments are treated special, so also do some test with unequal ones
19140xFFFF:0xFFFF:0x0xFFFF
19150xFFFFFF:0xFFFFFF:0x0xFFFFFF
19160xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
19170xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19180xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19190xF0F0:0xF0F0:0x0xF0F0
19200x0F0F:0x0F0F:0x0x0F0F
19210xF0F0F0:0xF0F0F0:0x0xF0F0F0
19220x0F0F0F:0x0F0F0F:0x0x0F0F0F
19230xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19240x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19250xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19260x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19270xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19280x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19290x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1930&bior
1931abc:abc:NaN
1932abc:0:NaN
19330:abc:NaN
19341:2:3
61f5c3f5 1935+8:+2:10
1936+281474976710656:0:281474976710656
1937+281474976710656:1:281474976710657
1938+281474976710656:281474976710656:281474976710656
6854fd01 1939-2:-3:-1
1940-1:-1:-1
1941-6:-6:-6
1942-7:4:-3
1943-4:7:-1
9b924220 1944+281474976710656:-1:-1
194530:-3:-1
194630:-4:-2
1947300:-76:-68
1948-76:300:-68
394e6ffb 1949# equal arguments are treated special, so also do some test with unequal ones
19500xFFFF:0xFFFF:0x0xFFFF
19510xFFFFFF:0xFFFFFF:0x0xFFFFFF
19520xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
19530xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19540xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19550:0xFFFF:0x0xFFFF
19560:0xFFFFFF:0x0xFFFFFF
19570:0xFFFFFFFF:0x0xFFFFFFFF
19580:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19590:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19600xFFFF:0:0x0xFFFF
19610xFFFFFF:0:0x0xFFFFFF
19620xFFFFFFFF:0:0x0xFFFFFFFF
19630xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19640xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19650xF0F0:0xF0F0:0x0xF0F0
19660x0F0F:0x0F0F:0x0x0F0F
19670xF0F0:0x0F0F:0x0xFFFF
19680xF0F0F0:0xF0F0F0:0x0xF0F0F0
19690x0F0F0F:0x0F0F0F:0x0x0F0F0F
19700x0F0F0F:0xF0F0F0:0x0xFFFFFF
19710xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19720x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19730x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19740xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19750x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19760x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19770xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19780x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19790x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
19800x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1981&bxor
1982abc:abc:NaN
1983abc:0:NaN
19840:abc:NaN
19851:2:3
61f5c3f5 1986+8:+2:10
1987+281474976710656:0:281474976710656
1988+281474976710656:1:281474976710657
1989+281474976710656:281474976710656:0
6854fd01 1990-2:-3:3
1991-1:-1:0
1992-6:-6:0
1993-7:4:-3
1994-4:7:-5
19954:-7:-3
1996-4:-7:5
9b924220 199730:-3:-29
199830:-4:-30
1999300:-76:-360
2000-76:300:-360
394e6ffb 2001# equal arguments are treated special, so also do some test with unequal ones
20020xFFFF:0xFFFF:0
20030xFFFFFF:0xFFFFFF:0
20040xFFFFFFFF:0xFFFFFFFF:0
20050xFFFFFFFFFF:0xFFFFFFFFFF:0
20060xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
20070:0xFFFF:0x0xFFFF
20080:0xFFFFFF:0x0xFFFFFF
20090:0xFFFFFFFF:0x0xFFFFFFFF
20100:0xFFFFFFFFFF:0x0xFFFFFFFFFF
20110:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
20120xFFFF:0:0x0xFFFF
20130xFFFFFF:0:0x0xFFFFFF
20140xFFFFFFFF:0:0x0xFFFFFFFF
20150xFFFFFFFFFF:0:0x0xFFFFFFFFFF
20160xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
20170xF0F0:0xF0F0:0
20180x0F0F:0x0F0F:0
20190xF0F0:0x0F0F:0x0xFFFF
20200xF0F0F0:0xF0F0F0:0
20210x0F0F0F:0x0F0F0F:0
20220x0F0F0F:0xF0F0F0:0x0xFFFFFF
20230xF0F0F0F0:0xF0F0F0F0:0
20240x0F0F0F0F:0x0F0F0F0F:0
20250x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
20260xF0F0F0F0F0:0xF0F0F0F0F0:0
20270x0F0F0F0F0F:0x0F0F0F0F0F:0
20280x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
20290xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
20300x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
20310x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 2032&bnot
2033abc:NaN
2034+0:-1
2035+8:-9
2036+281474976710656:-281474976710657
2037-1:0
2038-2:1
2039-12:11
2040&digit
20410:0:0
204212:0:2
204312:1:1
2044123:0:3
2045123:1:2
2046123:2:1
2047123:-1:1
2048123:-2:2
2049123:-3:3
2050123456:0:6
2051123456:1:5
2052123456:2:4
2053123456:3:3
2054123456:4:2
2055123456:5:1
2056123456:-1:1
2057123456:-2:2
2058123456:-3:3
2059100000:-3:0
2060100000:0:0
2061100000:1:0
2062&mantissa
2063abc:NaN
20641e4:1
20652e0:2
2066123:123
2067-1:-1
2068-2:-2
2069+inf:inf
2070-inf:-inf
2071&exponent
2072abc:NaN
20731e4:4
20742e0:0
2075123:0
2076-1:0
2077-2:0
20780:1
2079+inf:inf
2080-inf:inf
2081&parts
2082abc:NaN,NaN
20831e4:1,4
20842e0:2,0
2085123:123,0
2086-1:-1,0
2087-2:-2,0
20880:0,1
2089+inf:inf,inf
2090-inf:-inf,inf
b3abae2a 2091&bfac
2092-1:NaN
2093NaNfac:NaN
b282a552 2094+inf:inf
b3abae2a 2095-inf:NaN
20960:1
20971:1
20982:2
20993:6
21004:24
21015:120
21026:720
990fb837 21037:5040
21048:40320
21059:362880
b3abae2a 210610:3628800
210711:39916800
210812:479001600
50109ad0 210920:2432902008176640000
211022:1124000727777607680000
211169:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
6854fd01 2112&bpow
2113abc:12:NaN
211412:abc:NaN
21150:0:1
21160:1:0
21170:2:0
9b924220 21180:-1:inf
21190:-2:inf
6854fd01 21201:0:1
21211:1:1
21221:2:1
21231:3:1
21241:-1:1
21251:-2:1
21261:-3:1
21272:0:1
21282:1:2
21292:2:4
21302:3:8
21313:3:27
2d2b2744 2132-2:2:4
2133-2:3:-8
2134-2:4:16
2135-2:5:-32
6854fd01 21362:-1:NaN
2137-2:-1:NaN
21382:-2:NaN
2139-2:-2:NaN
2d2b2744 2140# inf tests
6854fd01 2141+inf:1234500012:inf
2d2b2744 2142-inf:1234500012:inf
2143-inf:1234500013:-inf
6854fd01 2144+inf:-12345000123:inf
2145-inf:-12345000123:-inf
2d2b2744 2146# -inf * -inf = inf
2147-inf:2:inf
2148-inf:0:NaN
2149-inf:-1:0
2150-inf:inf:NaN
21512:inf:inf
21522:-inf:0
21530:inf:0
21540:-inf:inf
2155-1:-inf:NaN
2156-1:inf:NaN
2157-2:inf:NaN
2158-2:-inf:0
2159NaN:inf:NaN
2160NaN:-inf:NaN
2161-inf:NaN:NaN
2162inf:NaN:NaN
2163inf:-inf:NaN
21641:inf:1
21651:-inf:1
6854fd01 2166# 1 ** -x => 1 / (1 ** x)
2167-1:0:1
2168-2:0:1
2169-1:1:-1
2170-1:2:1
2171-1:3:-1
2172-1:4:1
2173-1:5:-1
2174-1:-1:-1
2175-1:-2:1
2176-1:-3:-1
2177-1:-4:1
217810:2:100
217910:3:1000
218010:4:10000
218110:5:100000
218210:6:1000000
218310:7:10000000
218410:8:100000000
218510:9:1000000000
218610:20:100000000000000000000
2187123456:2:15241383936
9b924220 2188-2:2:4
2189-2:3:-8
2190-2:4:16
2191-2:5:-32
2192-3:2:9
2193-3:3:-27
2194-3:4:81
2195-3:5:-243
6854fd01 2196&length
2197100:3
219810:2
21991:1
22000:1
220112345:5
220210000000000000000:17
2203-123:3
2204215960156869840440586892398248:30
990fb837 2205&broot
2206# sqrt()
2207+0:2:0
2208+1:2:1
2209-1:2:NaN
2210# -$x ** (1/2) => -$y, but not in froot()
2211-123:2:NaN
2212+inf:2:inf
2213-inf:2:NaN
22142:2:1
2215-2:2:NaN
22164:2:2
22179:2:3
221816:2:4
2219100:2:10
2220123:2:11
222115241:2:123
2222144:2:12
222312:2:3
22240.49:2:0
22250.0049:2:0
2226# invalid ones
22271:NaN:NaN
2228-1:NaN:NaN
22290:NaN:NaN
2230-inf:NaN:NaN
2231+inf:NaN:NaN
2232NaN:0:NaN
2233NaN:2:NaN
2234NaN:inf:NaN
2235NaN:inf:NaN
223612:-inf:NaN
223712:inf:NaN
2238+0:0:NaN
2239+1:0:NaN
2240-1:0:NaN
2241-2:0:NaN
2242-123.45:0:NaN
2243+inf:0:NaN
224412:1:12
2245-12:1:NaN
22468:-1:NaN
2247-8:-1:NaN
2248# cubic root
22498:3:2
2250-8:3:NaN
2251# fourths root
c38b2de2 225216:4:2
225381:4:3
3a427a11 2254# 2 ** 64
c38b2de2 225518446744073709551616:4:65536
225618446744073709551616:8:256
225718446744073709551616:16:16
225818446744073709551616:32:4
225918446744073709551616:64:2
226018446744073709551616:128:1
3a427a11 2261# 213 ** 15
226284274086103068221283760416414557757:15:213
50109ad0 2263# see t/bigroot.t for more tests
6854fd01 2264&bsqrt
394e6ffb 2265145:12
6854fd01 2266144:12
394e6ffb 2267143:11
6854fd01 226816:4
394e6ffb 2269170:13
2270169:13
2271168:12
6854fd01 22724:2
394e6ffb 22733:1
6854fd01 22742:1
394e6ffb 22759:3
6854fd01 227612:3
2277256:16
2278100000000:10000
22794000000000000:2000000
394e6ffb 2280152399026:12345
2281152399025:12345
2282152399024:12344
3a427a11 2283# 2 ** 64 => 2 ** 32
228418446744073709551616:4294967296
228584274086103068221283760416414557757:290299993288095377
6854fd01 22861:1
22870:0
2288-2:NaN
394e6ffb 2289-123:NaN
6854fd01 2290Nan:NaN
990fb837 2291+inf:inf
2292-inf:NaN
50109ad0 2293# see t/biglog.t for more tests
2294&bexp
2295NaN:NaN
2296inf:inf
22971:2
22982:7
fdb4b05f 2299&bpi
230077:3
2301+0:3
230211:3
50109ad0 2303# see t/bignok.t for more tests
2304&bnok
2305+inf:10:inf
2306NaN:NaN:NaN
2307NaN:1:NaN
23081:NaN:NaN
23091:1:1
2310# k > n
23111:2:0
23122:3:0
2313# k < 0
23141:-2:0
2315# 7 over 3 = 35
23167:3:35
23177:6:1
2318100:90:17310309456440
2319100:95:75287520
6854fd01 2320&bround
2321$round_mode('trunc')
23220:12:0
2323NaNbround:12:NaN
2324+inf:12:inf
2325-inf:12:-inf
23261234:0:1234
23271234:2:1200
2328123456:4:123400
2329123456:5:123450
2330123456:6:123456
61f5c3f5 2331+10123456789:5:10123000000
6854fd01 2332-10123456789:5:-10123000000
61f5c3f5 2333+10123456789:9:10123456700
6854fd01 2334-10123456789:9:-10123456700
61f5c3f5 2335+101234500:6:101234000
6854fd01 2336-101234500:6:-101234000
61f5c3f5 2337#+101234500:-4:101234000
6854fd01 2338#-101234500:-4:-101234000
2339$round_mode('zero')
61f5c3f5 2340+20123456789:5:20123000000
6854fd01 2341-20123456789:5:-20123000000
61f5c3f5 2342+20123456789:9:20123456800
6854fd01 2343-20123456789:9:-20123456800
61f5c3f5 2344+201234500:6:201234000
6854fd01 2345-201234500:6:-201234000
61f5c3f5 2346#+201234500:-4:201234000
6854fd01 2347#-201234500:-4:-201234000
2348+12345000:4:12340000
2349-12345000:4:-12340000
2350$round_mode('+inf')
61f5c3f5 2351+30123456789:5:30123000000
6854fd01 2352-30123456789:5:-30123000000
61f5c3f5 2353+30123456789:9:30123456800
6854fd01 2354-30123456789:9:-30123456800
61f5c3f5 2355+301234500:6:301235000
6854fd01 2356-301234500:6:-301234000
61f5c3f5 2357#+301234500:-4:301235000
6854fd01 2358#-301234500:-4:-301234000
2359+12345000:4:12350000
2360-12345000:4:-12340000
2361$round_mode('-inf')
61f5c3f5 2362+40123456789:5:40123000000
6854fd01 2363-40123456789:5:-40123000000
61f5c3f5 2364+40123456789:9:40123456800
6854fd01 2365-40123456789:9:-40123456800
61f5c3f5 2366+401234500:6:401234000
2367+401234500:6:401234000
6854fd01 2368#-401234500:-4:-401235000
2369#-401234500:-4:-401235000
2370+12345000:4:12340000
2371-12345000:4:-12350000
2372$round_mode('odd')
61f5c3f5 2373+50123456789:5:50123000000
6854fd01 2374-50123456789:5:-50123000000
61f5c3f5 2375+50123456789:9:50123456800
6854fd01 2376-50123456789:9:-50123456800
61f5c3f5 2377+501234500:6:501235000
6854fd01 2378-501234500:6:-501235000
61f5c3f5 2379#+501234500:-4:501235000
6854fd01 2380#-501234500:-4:-501235000
2381+12345000:4:12350000
2382-12345000:4:-12350000
2383$round_mode('even')
61f5c3f5 2384+60123456789:5:60123000000
6854fd01 2385-60123456789:5:-60123000000
61f5c3f5 2386+60123456789:9:60123456800
6854fd01 2387-60123456789:9:-60123456800
61f5c3f5 2388+601234500:6:601234000
6854fd01 2389-601234500:6:-601234000
61f5c3f5 2390#+601234500:-4:601234000
6854fd01 2391#-601234500:-4:-601234000
2392#-601234500:-9:0
2393#-501234500:-9:0
2394#-601234500:-8:0
2395#-501234500:-8:0
2396+1234567:7:1234567
2397+1234567:6:1234570
2398+12345000:4:12340000
2399-12345000:4:-12340000
7b29e1e6 2400$round_mode('common')
2401+60123456789:5:60123000000
2402+60123199999:5:60123000000
2403+60123299999:5:60123000000
2404+60123399999:5:60123000000
2405+60123499999:5:60123000000
2406+60123500000:5:60124000000
2407+60123600000:5:60124000000
2408+60123700000:5:60124000000
2409+60123800000:5:60124000000
2410+60123900000:5:60124000000
2411-60123456789:5:-60123000000
2412-60123199999:5:-60123000000
2413-60123299999:5:-60123000000
2414-60123399999:5:-60123000000
2415-60123499999:5:-60123000000
2416-60123500000:5:-60124000000
2417-60123600000:5:-60124000000
2418-60123700000:5:-60124000000
2419-60123800000:5:-60124000000
2420-60123900000:5:-60124000000
6854fd01 2421&is_zero
24220:1
2423NaNzero:0
2424+inf:0
2425-inf:0
2426123:0
2427-1:0
24281:0
2429&is_one
24300:0
2431NaNone:0
2432+inf:0
2433-inf:0
24341:1
24352:0
2436-1:0
2437-2:0
2438# floor and ceil tests are pretty pointless in integer space...but play safe
2439&bfloor
24400:0
2441NaNfloor:NaN
2442+inf:inf
2443-inf:-inf
2444-1:-1
2445-2:-2
24462:2
24473:3
2448abc:NaN
2449&bceil
2450NaNceil:NaN
2451+inf:inf
2452-inf:-inf
24530:0
2454-1:-1
2455-2:-2
24562:2
24573:3
2458abc:NaN
2459&as_hex
2460128:0x80
2461-128:-0x80
24620:0x0
2463-0:0x0
24641:0x1
24650x123456789123456789:0x123456789123456789
2466+inf:inf
2467-inf:-inf
2468NaNas_hex:NaN
2469&as_bin
2470128:0b10000000
2471-128:-0b10000000
24720:0b0
2473-0:0b0
24741:0b1
24750b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 24760x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2477+inf:inf
2478-inf:-inf
2479NaNas_bin:NaN