ANNOUNCE: Math-BigInt v1.62
[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";';
92 } else {
56d9de68 93 # binary ops
61f5c3f5 94 $try .= "\$y = $class->new('$args[1]');";
95 if ($f eq "bcmp")
96 {
97 $try .= '$x <=> $y;';
98 } elsif ($f eq "bround") {
6854fd01 99 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5 100 } elsif ($f eq "bacmp"){
101 $try .= '$x->bacmp($y);';
102 } elsif ($f eq "badd"){
103 $try .= '$x + $y;';
104 } elsif ($f eq "bsub"){
105 $try .= '$x - $y;';
106 } elsif ($f eq "bmul"){
107 $try .= '$x * $y;';
108 } elsif ($f eq "bdiv"){
109 $try .= '$x / $y;';
110 } elsif ($f eq "bdiv-list"){
111 $try .= 'join (",",$x->bdiv($y));';
027dc388 112 # overload via x=
61f5c3f5 113 } elsif ($f =~ /^.=$/){
114 $try .= "\$x $f \$y;";
027dc388 115 # overload via x
61f5c3f5 116 } elsif ($f =~ /^.$/){
117 $try .= "\$x $f \$y;";
118 } elsif ($f eq "bmod"){
119 $try .= '$x % $y;';
120 } elsif ($f eq "bgcd")
6854fd01 121 {
122 if (defined $args[2])
123 {
61f5c3f5 124 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 125 }
126 $try .= "$class\::bgcd(\$x, \$y";
127 $try .= ", \$z" if (defined $args[2]);
128 $try .= " );";
129 }
130 elsif ($f eq "blcm")
131 {
132 if (defined $args[2])
133 {
61f5c3f5 134 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 135 }
136 $try .= "$class\::blcm(\$x, \$y";
137 $try .= ", \$z" if (defined $args[2]);
138 $try .= " );";
139 }elsif ($f eq "blsft"){
140 if (defined $args[2])
141 {
142 $try .= "\$x->blsft(\$y,$args[2]);";
143 }
144 else
145 {
146 $try .= "\$x << \$y;";
147 }
148 }elsif ($f eq "brsft"){
149 if (defined $args[2])
150 {
151 $try .= "\$x->brsft(\$y,$args[2]);";
152 }
153 else
154 {
155 $try .= "\$x >> \$y;";
156 }
157 }elsif ($f eq "band"){
158 $try .= "\$x & \$y;";
159 }elsif ($f eq "bior"){
160 $try .= "\$x | \$y;";
161 }elsif ($f eq "bxor"){
162 $try .= "\$x ^ \$y;";
163 }elsif ($f eq "bpow"){
164 $try .= "\$x ** \$y;";
d614cd8b 165 } elsif( $f eq "bmodinv") {
166 $try .= "\$x->bmodinv(\$y);";
6854fd01 167 }elsif ($f eq "digit"){
56b9c951 168 $try .= "\$x->digit(\$y);";
d614cd8b 169 } else {
170 $try .= "\$z = $class->new(\"$args[2]\");";
171
172 # Functions with three arguments
173 if( $f eq "bmodpow") {
174 $try .= "\$x->bmodpow(\$y,\$z);";
175 } else { warn "Unknown op '$f'"; }
176 }
61f5c3f5 177 } # end else all other ops
178
179 $ans1 = eval $try;
180 # convert hex/binary targets to decimal
181 if ($ans =~ /^(0x0x|0b0b)/)
182 {
183 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 184 }
61f5c3f5 185 if ($ans eq "")
186 {
187 ok_undef ($ans1);
188 }
189 else
190 {
191 # print "try: $try ans: $ans1 $ans\n";
192 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 193 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 194 }
61f5c3f5 195 # check internal state of number objects
196 is_valid($ans1,$f) if ref $ans1;
6854fd01 197 } # endwhile data tests
198close DATA;
199
200# test some more
201@a = ();
202for (my $i = 1; $i < 10; $i++)
203 {
204 push @a, $i;
205 }
206ok "@a", "1 2 3 4 5 6 7 8 9";
207
208# test whether self-multiplication works correctly (result is 2**64)
209$try = "\$x = $class->new('4294967296');";
210$try .= '$a = $x->bmul($x);';
211$ans1 = eval $try;
212print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
213# test self-pow
214$try = "\$x = $class->new(10);";
215$try .= '$a = $x->bpow($x);';
216$ans1 = eval $try;
217print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
218
07d34614 219###############################################################################
6854fd01 220# test whether op destroys args or not (should better not)
221
222$x = $class->new(3);
223$y = $class->new(4);
224$z = $x & $y;
225ok ($x,3);
226ok ($y,4);
227ok ($z,0);
228$z = $x | $y;
229ok ($x,3);
230ok ($y,4);
231ok ($z,7);
232$x = $class->new(1);
233$y = $class->new(2);
234$z = $x | $y;
235ok ($x,1);
236ok ($y,2);
237ok ($z,3);
238
239$x = $class->new(5);
240$y = $class->new(4);
241$z = $x ^ $y;
242ok ($x,5);
243ok ($y,4);
244ok ($z,1);
245
246$x = $class->new(-5); $y = -$x;
247ok ($x, -5);
248
249$x = $class->new(-5); $y = abs($x);
250ok ($x, -5);
251
07d34614 252$x = $class->new(8);
253$y = $class->new(-1);
254$z = $class->new(5033);
255my $u = $x->copy()->bmodpow($y,$z);
256ok ($u,4404);
257ok ($y,-1);
258ok ($z,5033);
259
260$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
261$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
262
263$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
264$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
265$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
266$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
267$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
268
269$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
270$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
271$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
272$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
273$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
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###############################################################################
6854fd01 282# check whether overloading cmp works
283$try = "\$x = $class->new(0);";
284$try .= "\$y = 10;";
285$try .= "'false' if \$x ne \$y;";
286$ans = eval $try;
287print "# For '$try'\n" if (!ok "$ans" , "false" );
288
289# we cant test for working cmpt with other objects here, we would need a dummy
290# object with stringify overload for this. see Math::String tests as example
291
292###############################################################################
6854fd01 293# check reversed order of arguments
027dc388 294
6854fd01 295$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
296$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
297print "# For '$try'\n" if (!ok "$ans" , "ok" );
298
299$try = "\$x = $class->new(10); \$x = 2 * \$x;";
300$try .= "'ok' if \$x == 20;"; $ans = eval $try;
301print "# For '$try'\n" if (!ok "$ans" , "ok" );
302
303$try = "\$x = $class->new(10); \$x = 2 + \$x;";
304$try .= "'ok' if \$x == 12;"; $ans = eval $try;
305print "# For '$try'\n" if (!ok "$ans" , "ok" );
306
307$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
308$try .= "'ok' if \$x == -8;"; $ans = eval $try;
309print "# For '$try'\n" if (!ok "$ans" , "ok" );
310
311$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
312$try .= "'ok' if \$x == 2;"; $ans = eval $try;
313print "# For '$try'\n" if (!ok "$ans" , "ok" );
314
027dc388 315$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
316$try .= "'ok' if \$x == 2;"; $ans = eval $try;
317print "# For '$try'\n" if (!ok "$ans" , "ok" );
318
319$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
320$try .= "'ok' if \$x == 4;"; $ans = eval $try;
321print "# For '$try'\n" if (!ok "$ans" , "ok" );
322
323$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
324$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
325print "# For '$try'\n" if (!ok "$ans" , "ok" );
326
327$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
328$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
329print "# For '$try'\n" if (!ok "$ans" , "ok" );
330
6854fd01 331###############################################################################
332# check badd(4,5) form
333
334$try = "\$x = $class\->badd(4,5);";
335$try .= "'ok' if \$x == 9;";
336$ans = eval $try;
337print "# For '$try'\n" if (!ok "$ans" , "ok" );
338
339###############################################################################
340# check undefs: NOT DONE YET
341
342###############################################################################
343# bool
344
f9a08e12 345$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
346$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 347
348###############################################################################
349# objectify()
350
351@args = Math::BigInt::objectify(2,4,5);
352ok (scalar @args,3); # $class, 4, 5
56b9c951 353ok ($args[0] =~ /^Math::BigInt/);
6854fd01 354ok ($args[1],4);
355ok ($args[2],5);
356
357@args = Math::BigInt::objectify(0,4,5);
358ok (scalar @args,3); # $class, 4, 5
56b9c951 359ok ($args[0] =~ /^Math::BigInt/);
6854fd01 360ok ($args[1],4);
361ok ($args[2],5);
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(2,4,5,6,7);
370ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 371ok ($args[0] =~ /^Math::BigInt/);
6854fd01 372ok ($args[1],4); ok (ref($args[1]),$args[0]);
373ok ($args[2],5); ok (ref($args[2]),$args[0]);
374ok ($args[3],6); ok (ref($args[3]),'');
375ok ($args[4],7); ok (ref($args[4]),'');
376
377@args = Math::BigInt::objectify(2,$class,4,5,6,7);
378ok (scalar @args,5); # $class, 4, 5, 6, 7
379ok ($args[0],$class);
380ok ($args[1],4); ok (ref($args[1]),$args[0]);
381ok ($args[2],5); ok (ref($args[2]),$args[0]);
382ok ($args[3],6); ok (ref($args[3]),'');
383ok ($args[4],7); ok (ref($args[4]),'');
384
385###############################################################################
f9a08e12 386# test whether an opp calls objectify properly or not (or at least does what
387# it should do given non-objects, w/ or w/o objectify())
388
389ok ($class->new(123)->badd(123),246);
390ok ($class->badd(123,321),444);
391ok ($class->badd(123,$class->new(321)),444);
392
393ok ($class->new(123)->bsub(122),1);
394ok ($class->bsub(321,123),198);
395ok ($class->bsub(321,$class->new(123)),198);
396
397ok ($class->new(123)->bmul(123),15129);
398ok ($class->bmul(123,123),15129);
399ok ($class->bmul(123,$class->new(123)),15129);
400
401ok ($class->new(15129)->bdiv(123),123);
402ok ($class->bdiv(15129,123),123);
403ok ($class->bdiv(15129,$class->new(123)),123);
404
405ok ($class->new(15131)->bmod(123),2);
406ok ($class->bmod(15131,123),2);
407ok ($class->bmod(15131,$class->new(123)),2);
408
409ok ($class->new(2)->bpow(16),65536);
410ok ($class->bpow(2,16),65536);
411ok ($class->bpow(2,$class->new(16)),65536);
412
413ok ($class->new(2**15)->brsft(1),2**14);
414ok ($class->brsft(2**15,1),2**14);
415ok ($class->brsft(2**15,$class->new(1)),2**14);
416
417ok ($class->new(2**13)->blsft(1),2**14);
418ok ($class->blsft(2**13,1),2**14);
419ok ($class->blsft(2**13,$class->new(1)),2**14);
420
421###############################################################################
6854fd01 422# test for floating-point input (other tests in bnorm() below)
423
424$z = 1050000000000000; # may be int on systems with 64bit?
425$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
426$z = 1e+129; # definitely a float (may fail on UTS)
427# don't compare to $z, since some Perl versions stringify $z into something
428# like '1.e+129' or something equally ugly
429$x = $class->new($z); ok ($x->bsstr(),'1e+129');
430
431###############################################################################
56d9de68 432# test for whitespace inlcuding newlines to be handled correctly
433
434# ok ($Math::BigInt::strict,1); # the default
435
436foreach my $c (
437 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
438 {
439 my $m = $class->new($c);
440 ok ($class->new("$c"),$m);
441 ok ($class->new(" $c"),$m);
442 ok ($class->new("$c "),$m);
443 ok ($class->new(" $c "),$m);
444 ok ($class->new("\n$c"),$m);
445 ok ($class->new("$c\n"),$m);
446 ok ($class->new("\n$c\n"),$m);
447 ok ($class->new(" \n$c\n"),$m);
448 ok ($class->new(" \n$c \n"),$m);
449 ok ($class->new(" \n$c\n "),$m);
450 ok ($class->new(" \n$c\n1"),'NaN');
451 ok ($class->new("1 \n$c\n1"),'NaN');
452 }
453
454###############################################################################
6854fd01 455# prime number tests, also test for **= and length()
456# found on: http://www.utm.edu/research/primes/notes/by_year.html
457
458# ((2^148)-1)/17
459$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
460ok ($x,"20988936657440586486151264256610222593863921");
461ok ($x->length(),length "20988936657440586486151264256610222593863921");
462
463# MM7 = 2^127-1
464$x = $class->new(2); $x **= 127; $x--;
465ok ($x,"170141183460469231731687303715884105727");
466
467$x = $class->new('215960156869840440586892398248');
468($x,$y) = $x->length();
469ok ($x,30); ok ($y,0);
470
471$x = $class->new('1_000_000_000_000');
472($x,$y) = $x->length();
473ok ($x,13); ok ($y,0);
474
475# I am afraid the following is not yet possible due to slowness
476# Also, testing for 2 meg output is a bit hard ;)
477#$x = $class->new(2); $x **= 6972593; $x--;
478
479# 593573509*2^332162+1 has exactly 1,000,000 digits
480# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
481#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
482#ok ($x->length(),1_000_000);
483
484###############################################################################
485# inheritance and overriding of _swap
486
487$x = Math::Foo->new(5);
488$x = $x - 8; # 8 - 5 instead of 5-8
489ok ($x,3);
490ok (ref($x),'Math::Foo');
491
492$x = Math::Foo->new(5);
493$x = 8 - $x; # 5 - 8 instead of 8 - 5
494ok ($x,-3);
495ok (ref($x),'Math::Foo');
496
497###############################################################################
498# Test whether +inf eq inf
499# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
500# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
501# like 1e100000 crash on some platforms. So simple test for the string 'inf'
502$x = $class->new('+inf'); ok ($x,'inf');
503
504###############################################################################
505###############################################################################
56d9de68 506# the followin tests only make sense with Math::BigInt::Calc or BareCalc or
507# FastCalc
6854fd01 508
56d9de68 509exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01 510
511###############################################################################
512# check proper length of internal arrays
513
394e6ffb 514my $bl = $CL->_base_len();
6854fd01 515my $BASE = '9' x $bl;
516my $MAX = $BASE;
517$BASE++;
518
519$x = $class->new($MAX); is_valid($x); # f.i. 9999
520$x += 1; ok ($x,$BASE); is_valid($x); # 10000
521$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
522
523###############################################################################
524# check numify
525
526$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
527$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 528
529# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
530$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 531$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
532$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
533ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
534
535###############################################################################
536# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
537
394e6ffb 538$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
539if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
540
541$x = $class->new($BASE+3); $x++;
542if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 543
394e6ffb 544# test for +0 instead of int():
545$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 546
547###############################################################################
56b9c951 548# test bug that $class->digit($string) did not work
549
550ok ($class->digit(123,2),1);
551
552###############################################################################
6854fd01 553# bug in sub where number with at least 6 trailing zeros after any op failed
554
394e6ffb 555$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 556ok ($z, 100000);
557ok ($x, 23456);
558
559###############################################################################
560# bug in shortcut in mul()
561
61f5c3f5 562# construct a number with a zero-hole of BASE_LEN_SMALL
563{
564 my @bl = $CL->_base_len(); my $bl = $bl[4];
565
566 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
567 $y = '1' x (2*$bl);
568 $x = $class->new($x)->bmul($y);
569 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
570 $y = ''; my $d = '';
571 for (my $i = 1; $i <= $bl; $i++)
572 {
573 $y .= $i; $d = $i.$d;
574 }
575 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
576 ok ($x,$y);
577
6854fd01 578
f9a08e12 579 #############################################################################
580 # see if mul shortcut for small numbers works
394e6ffb 581
f9a08e12 582 $x = '9' x $bl;
583 $x = $class->new($x);
584 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
585 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
586}
61f5c3f5 587
394e6ffb 588###############################################################################
6854fd01 589# bug with rest "-0" in div, causing further div()s to fail
590
394e6ffb 591$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 592
61f5c3f5 593ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 594
79c55733 595###############################################################################
f9a08e12 596# bug in $x->bmod($y)
07d34614 597
f9a08e12 598# if $x < 0 and $y > 0
07d34614 599$x = $class->new('-629'); ok ($x->bmod(5033),4404);
600
601###############################################################################
56b9c951 602# bone/binf etc as plain calls (Lite failed them)
603
604ok ($class->bzero(),0);
605ok ($class->bone(),1);
606ok ($class->bone('+'),1);
607ok ($class->bone('-'),-1);
608ok ($class->bnan(),'NaN');
609ok ($class->binf(),'inf');
610ok ($class->binf('+'),'inf');
611ok ($class->binf('-'),'-inf');
612ok ($class->binf('-inf'),'-inf');
613
614###############################################################################
61f5c3f5 615# all tests done
6854fd01 616
6171;
618
619###############################################################################
61f5c3f5 620###############################################################################
6854fd01 621# Perl 5.005 does not like ok ($x,undef)
622
623sub ok_undef
624 {
625 my $x = shift;
626
627 ok (1,1) and return if !defined $x;
628 ok ($x,'undef');
629 }
630
631###############################################################################
632# sub to check validity of a BigInt internally, to ensure that no op leaves a
633# number object in an invalid state (f.i. "-0")
634
635sub is_valid
636 {
637 my ($x,$f) = @_;
638
639 my $e = 0; # error?
6854fd01 640
56b9c951 641 # allow the check to pass for all Lite, and all MBI and subclasses
642 # ok as reference?
643 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 644
56b9c951 645 if (ref($x) ne 'Math::BigInt::Lite')
646 {
647 # has ok sign?
648 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
649 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
650
651 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
652 $e = $CALC->_check($x->{value}) if $e eq '0';
653 }
6854fd01 654
655 # test done, see if error did crop up
656 ok (1,1), return if ($e eq '0');
657
027dc388 658 ok (1,$e." after op '$f'");
6854fd01 659 }
660
661__DATA__
027dc388 662&.=
6631234:-345:1234-345
664&+=
6651:2:3
666-1:-2:-3
667&-=
6681:2:-1
669-1:-2:1
670&*=
6712:3:6
672-1:5:-5
673&%=
674100:3:1
6758:9:8
07d34614 676-629:5033:4404
027dc388 677&/=
678100:3:33
679-8:2:-4
680&|=
6812:1:3
682&&=
6835:7:5
684&^=
6855:7:2
6854fd01 686&is_negative
6870:0
688-1:1
6891:0
690+inf:0
691-inf:1
692NaNneg:0
693&is_positive
6940:1
695-1:0
6961:1
697+inf:1
698-inf:0
699NaNneg:0
b3abae2a 700&is_int
701-inf:0
702+inf:0
703NaNis_int:0
7041:1
7050:1
706123e12:1
6854fd01 707&is_odd
708abc:0
7090:0
7101:1
7113:1
712-1:1
713-3:1
71410000001:1
71510000002:0
7162:0
b3abae2a 717120:0
718121:1
6854fd01 719&is_even
720abc:0
7210:1
7221:0
7233:0
724-1:0
725-3:0
72610000001:0
72710000002:1
7282:1
b3abae2a 729120:1
730121:0
6854fd01 731&bacmp
732+0:-0:0
733+0:+1:-1
734-1:+1:0
735+1:-1:0
736-1:+2:-1
737+2:-1:1
738-123456789:+987654321:-1
739+123456789:-987654321:-1
740+987654321:+123456789:1
741-987654321:+123456789:1
742-123:+4567889:-1
743# NaNs
744acmpNaN:123:
745123:acmpNaN:
746acmpNaN:acmpNaN:
747# infinity
748+inf:+inf:0
749-inf:-inf:0
750+inf:-inf:0
751-inf:+inf:0
752+inf:123:1
753-inf:123:1
754+inf:-123:1
755-inf:-123:1
756# return undef
757+inf:NaN:
758NaN:inf:
759-inf:NaN:
760NaN:-inf:
761&bnorm
762123:123
763# binary input
7640babc:NaN
7650b123:NaN
7660b0:0
767-0b0:0
768-0b1:-1
7690b0001:1
7700b001:1
7710b011:3
7720b101:5
61f5c3f5 7730b1001:9
7740b10001:17
7750b100001:33
7760b1000001:65
7770b10000001:129
7780b100000001:257
7790b1000000001:513
7800b10000000001:1025
7810b100000000001:2049
7820b1000000000001:4097
7830b10000000000001:8193
7840b100000000000001:16385
7850b1000000000000001:32769
7860b10000000000000001:65537
7870b100000000000000001:131073
7880b1000000000000000001:262145
7890b10000000000000000001:524289
7900b100000000000000000001:1048577
7910b1000000000000000000001:2097153
7920b10000000000000000000001:4194305
7930b100000000000000000000001:8388609
7940b1000000000000000000000001:16777217
7950b10000000000000000000000001:33554433
7960b100000000000000000000000001:67108865
7970b1000000000000000000000000001:134217729
7980b10000000000000000000000000001:268435457
7990b100000000000000000000000000001:536870913
8000b1000000000000000000000000000001:1073741825
8010b10000000000000000000000000000001:2147483649
8020b100000000000000000000000000000001:4294967297
8030b1000000000000000000000000000000001:8589934593
8040b10000000000000000000000000000000001:17179869185
6854fd01 8050b_101:NaN
8060b1_0_1:5
394e6ffb 8070b0_0_0_1:1
6854fd01 808# hex input
809-0x0:0
8100xabcdefgh:NaN
8110x1234:4660
8120xabcdef:11259375
813-0xABCDEF:-11259375
814-0x1234:-4660
8150x12345678:305419896
8160x1_2_3_4_56_78:305419896
394e6ffb 8170xa_b_c_d_e_f:11259375
6854fd01 8180x_123:NaN
61f5c3f5 8190x9:9
8200x11:17
8210x21:33
8220x41:65
8230x81:129
8240x101:257
8250x201:513
8260x401:1025
8270x801:2049
8280x1001:4097
8290x2001:8193
8300x4001:16385
8310x8001:32769
8320x10001:65537
8330x20001:131073
8340x40001:262145
8350x80001:524289
8360x100001:1048577
8370x200001:2097153
8380x400001:4194305
8390x800001:8388609
8400x1000001:16777217
8410x2000001:33554433
8420x4000001:67108865
8430x8000001:134217729
8440x10000001:268435457
8450x20000001:536870913
8460x40000001:1073741825
8470x80000001:2147483649
8480x100000001:4294967297
8490x200000001:8589934593
8500x400000001:17179869185
8510x800000001:34359738369
6854fd01 852# inf input
853inf:inf
854+inf:inf
855-inf:-inf
8560inf:NaN
027dc388 857# abnormal input
6854fd01 858:NaN
859abc:NaN
860 1 a:NaN
8611bcd2:NaN
86211111b:NaN
863+1z:NaN
864-1z:NaN
027dc388 865# only one underscore between two digits
866_123:NaN
867_123_:NaN
868123_:NaN
8691__23:NaN
8701E1__2:NaN
8711_E12:NaN
8721E_12:NaN
8731_E_12:NaN
874+_1E12:NaN
875+0_1E2:100
876+0_0_1E2:100
877-0_0_1E2:-100
878-0_0_1E+0_0_2:-100
879E1:NaN
880E23:NaN
8811.23E1:NaN
8821.23E-1:NaN
883# bug with two E's in number beeing valid
8841e2e3:NaN
8851e2r:NaN
8861e2.0:NaN
07d34614 887# bug with two '.' in number beeing valid
8881.2.2:NaN
8891.2.3e1:NaN
890-1.2.3:NaN
891-1.2.3e-4:NaN
8921.2e3.4:NaN
8931.2e-3.4:NaN
8941.2.3.4:NaN
8951.2.t:NaN
8961..2:NaN
8971..2e1:NaN
8981..2e1..1:NaN
89912e1..1:NaN
900..2:NaN
901.-2:NaN
61f5c3f5 902# leading zeros
903012:12
9040123:123
90501234:1234
906012345:12345
9070123456:123456
90801234567:1234567
909012345678:12345678
9100123456789:123456789
91101234567891:1234567891
912012345678912:12345678912
9130123456789123:123456789123
91401234567891234:1234567891234
027dc388 915# normal input
6854fd01 9160:0
917+0:0
918+00:0
919+000:0
920000000000000000000:0
921-0:0
922-0000:0
923+1:1
924+01:1
925+001:1
926+00000100000:100000
927123456789:123456789
928-1:-1
929-01:-1
930-001:-1
931-123456789:-123456789
932-00000100000:-100000
9331_2_3:123
6854fd01 93410000000000E-1_0:1
9351E2:100
9361E1:10
9371E0:1
6854fd01 9381.23E2:123
6854fd01 939100E-1:10
940# floating point input
027dc388 941# .2e2:20
9421.E3:1000
6854fd01 9431.01E2:101
9441010E-1:101
945-1010E0:-1010
946-1010E1:-10100
027dc388 9471234.00:1234
948# non-integer numbers
6854fd01 949-1010E-2:NaN
950-1.01E+1:NaN
951-1.01E-1:NaN
6854fd01 952&bnan
9531:NaN
9542:NaN
955abc:NaN
956&bone
61f5c3f5 9572:+:1
6854fd01 9582:-:-1
959boneNaN:-:-1
61f5c3f5 960boneNaN:+:1
9612:abc:1
9623::1
6854fd01 963&binf
9641:+:inf
9652:-:-inf
9663:abc:inf
027dc388 967&is_nan
968123:0
969abc:1
970NaN:1
971-123:0
6854fd01 972&is_inf
973+inf::1
974-inf::1
975abc::0
9761::0
977NaN::0
978-1::0
979+inf:-:0
980+inf:+:1
981-inf:-:1
982-inf:+:0
79c55733 983-inf:-inf:1
984-inf:+inf:0
985+inf:-inf:0
986+inf:+inf:1
6854fd01 987# it must be exactly /^[+-]inf$/
988+infinity::0
989-infinity::0
990&blsft
991abc:abc:NaN
61f5c3f5 992+2:+2:8
993+1:+32:4294967296
994+1:+48:281474976710656
6854fd01 995+8:-2:NaN
996# excercise base 10
997+12345:4:10:123450000
998-1234:0:10:-1234
61f5c3f5 999+1234:0:10:1234
6854fd01 1000+2:2:10:200
1001+12:2:10:1200
1002+1234:-3:10:NaN
10031234567890123:12:10:1234567890123000000000000
b3abae2a 1004-3:1:2:-6
1005-5:1:2:-10
1006-2:1:2:-4
1007-102533203:1:2:-205066406
6854fd01 1008&brsft
1009abc:abc:NaN
61f5c3f5 1010+8:+2:2
1011+4294967296:+32:1
1012+281474976710656:+48:1
6854fd01 1013+2:-2:NaN
1014# excercise base 10
1015-1234:0:10:-1234
61f5c3f5 1016+1234:0:10:1234
6854fd01 1017+200:2:10:2
1018+1234:3:10:1
1019+1234:2:10:12
1020+1234:-3:10:NaN
1021310000:4:10:31
102212300000:5:10:123
10231230000000000:10:10:123
102409876123456789067890:12:10:9876123
10251234561234567890123:13:10:123456
b3abae2a 1026820265627:1:2:410132813
1027# test shifting negative numbers in base 2
1028-15:1:2:-8
1029-14:1:2:-7
1030-13:1:2:-7
1031-12:1:2:-6
1032-11:1:2:-6
1033-10:1:2:-5
1034-9:1:2:-5
1035-8:1:2:-4
1036-7:1:2:-4
1037-6:1:2:-3
1038-5:1:2:-3
1039-4:1:2:-2
1040-3:1:2:-2
1041-2:1:2:-1
1042-1:1:2:-1
1043-1640531254:2:2:-410132814
1044-1640531254:1:2:-820265627
1045-820265627:1:2:-410132814
1046-205066405:1:2:-102533203
6854fd01 1047&bsstr
56d9de68 1048+inf:inf
1049-inf:-inf
6854fd01 10501e+34:1e+34
1051123.456E3:123456e+0
1052100:1e+2
56d9de68 1053bsstrabc:NaN
1054-5:-5e+0
1055-100:-1e+2
1056&numify
1057numifyabc:NaN
1058+inf:inf
1059-inf:-inf
10605:5
1061-5:-5
1062100:100
1063-100:-100
6854fd01 1064&bneg
1065bnegNaN:NaN
1066+inf:-inf
1067-inf:inf
1068abd:NaN
61f5c3f5 10690:0
10701:-1
1071-1:1
6854fd01 1072+123456789:-123456789
61f5c3f5 1073-123456789:123456789
6854fd01 1074&babs
1075babsNaN:NaN
1076+inf:inf
1077-inf:inf
61f5c3f5 10780:0
10791:1
1080-1:1
1081+123456789:123456789
1082-123456789:123456789
6854fd01 1083&bcmp
1084bcmpNaN:bcmpNaN:
61f5c3f5 1085bcmpNaN:0:
10860:bcmpNaN:
10870:0:0
1088-1:0:-1
10890:-1:1
10901:0:1
10910:1:-1
1092-1:1:-1
10931:-1:1
6854fd01 1094-1:-1:0
61f5c3f5 10951:1:0
1096123:123:0
1097123:12:1
109812:123:-1
6854fd01 1099-123:-123:0
1100-123:-12:-1
1101-12:-123:1
61f5c3f5 1102123:124:-1
1103124:123:1
6854fd01 1104-123:-124:1
1105-124:-123:-1
61f5c3f5 1106100:5:1
1107-123456789:987654321:-1
6854fd01 1108+123456789:-987654321:1
61f5c3f5 1109-987654321:123456789:-1
6854fd01 1110-inf:5432112345:-1
1111+inf:5432112345:1
1112-inf:-5432112345:-1
1113+inf:-5432112345:1
1114+inf:+inf:0
1115-inf:-inf:0
1116+inf:-inf:1
1117-inf:+inf:-1
11185:inf:-1
11195:inf:-1
1120-5:-inf:1
1121-5:-inf:1
1122# return undef
1123+inf:NaN:
1124NaN:inf:
1125-inf:NaN:
1126NaN:-inf:
1127&binc
1128abc:NaN
1129+inf:inf
1130-inf:-inf
61f5c3f5 1131+0:1
1132+1:2
1133-1:0
6854fd01 1134&bdec
1135abc:NaN
1136+inf:inf
1137-inf:-inf
1138+0:-1
61f5c3f5 1139+1:0
6854fd01 1140-1:-2
1141&badd
1142abc:abc:NaN
61f5c3f5 1143abc:0:NaN
6854fd01 1144+0:abc:NaN
b3abae2a 1145+inf:-inf:NaN
1146-inf:+inf:NaN
6854fd01 1147+inf:+inf:inf
1148-inf:-inf:-inf
1149baddNaN:+inf:NaN
1150baddNaN:+inf:NaN
1151+inf:baddNaN:NaN
1152-inf:baddNaN:NaN
61f5c3f5 11530:0:0
11541:0:1
11550:1:1
11561:1:2
1157-1:0:-1
11580:-1:-1
6854fd01 1159-1:-1:-2
61f5c3f5 1160-1:+1:0
1161+1:-1:0
1162+9:+1:10
1163+99:+1:100
1164+999:+1:1000
1165+9999:+1:10000
1166+99999:+1:100000
1167+999999:+1:1000000
1168+9999999:+1:10000000
1169+99999999:+1:100000000
1170+999999999:+1:1000000000
1171+9999999999:+1:10000000000
1172+99999999999:+1:100000000000
1173+10:-1:9
1174+100:-1:99
1175+1000:-1:999
1176+10000:-1:9999
1177+100000:-1:99999
1178+1000000:-1:999999
1179+10000000:-1:9999999
1180+100000000:-1:99999999
1181+1000000000:-1:999999999
1182+10000000000:-1:9999999999
1183+123456789:987654321:1111111110
1184-123456789:987654321:864197532
6854fd01 1185-123456789:-987654321:-1111111110
1186+123456789:-987654321:-864197532
56b9c951 1187-1:10001:10000
1188-1:100001:100000
1189-1:1000001:1000000
1190-1:10000001:10000000
1191-1:100000001:100000000
1192-1:1000000001:1000000000
1193-1:10000000001:10000000000
1194-1:100000000001:100000000000
1195-1:1000000000001:1000000000000
1196-1:10000000000001:10000000000000
1197-1:-10001:-10002
1198-1:-100001:-100002
1199-1:-1000001:-1000002
1200-1:-10000001:-10000002
1201-1:-100000001:-100000002
1202-1:-1000000001:-1000000002
1203-1:-10000000001:-10000000002
1204-1:-100000000001:-100000000002
1205-1:-1000000000001:-1000000000002
1206-1:-10000000000001:-10000000000002
6854fd01 1207&bsub
1208abc:abc:NaN
1209abc:+0:NaN
1210+0:abc:NaN
1211+inf:-inf:inf
1212-inf:+inf:-inf
b3abae2a 1213+inf:+inf:NaN
1214-inf:-inf:NaN
61f5c3f5 1215+0:+0:0
1216+1:+0:1
6854fd01 1217+0:+1:-1
61f5c3f5 1218+1:+1:0
6854fd01 1219-1:+0:-1
61f5c3f5 1220+0:-1:1
1221-1:-1:0
6854fd01 1222-1:+1:-2
61f5c3f5 1223+1:-1:2
1224+9:+1:8
1225+99:+1:98
1226+999:+1:998
1227+9999:+1:9998
1228+99999:+1:99998
1229+999999:+1:999998
1230+9999999:+1:9999998
1231+99999999:+1:99999998
1232+999999999:+1:999999998
1233+9999999999:+1:9999999998
1234+99999999999:+1:99999999998
1235+10:-1:11
1236+100:-1:101
1237+1000:-1:1001
1238+10000:-1:10001
1239+100000:-1:100001
1240+1000000:-1:1000001
1241+10000000:-1:10000001
1242+100000000:-1:100000001
1243+1000000000:-1:1000000001
1244+10000000000:-1:10000000001
6854fd01 1245+123456789:+987654321:-864197532
1246-123456789:+987654321:-1111111110
61f5c3f5 1247-123456789:-987654321:864197532
1248+123456789:-987654321:1111111110
56b9c951 124910001:1:10000
1250100001:1:100000
12511000001:1:1000000
125210000001:1:10000000
1253100000001:1:100000000
12541000000001:1:1000000000
125510000000001:1:10000000000
1256100000000001:1:100000000000
12571000000000001:1:1000000000000
125810000000000001:1:10000000000000
125910001:-1:10002
1260100001:-1:100002
12611000001:-1:1000002
126210000001:-1:10000002
1263100000001:-1:100000002
12641000000001:-1:1000000002
126510000000001:-1:10000000002
1266100000000001:-1:100000000002
12671000000000001:-1:1000000000002
126810000000000001:-1:10000000000002
6854fd01 1269&bmul
1270abc:abc:NaN
1271abc:+0:NaN
1272+0:abc:NaN
1273NaNmul:+inf:NaN
1274NaNmul:-inf:NaN
1275-inf:NaNmul:NaN
1276+inf:NaNmul:NaN
1277+inf:+inf:inf
1278+inf:-inf:-inf
1279-inf:+inf:-inf
1280-inf:-inf:inf
61f5c3f5 1281+0:+0:0
1282+0:+1:0
1283+1:+0:0
1284+0:-1:0
1285-1:+0:0
1286123456789123456789:0:0
12870:123456789123456789:0
1288-1:-1:1
6854fd01 1289-1:+1:-1
1290+1:-1:-1
61f5c3f5 1291+1:+1:1
1292+2:+3:6
6854fd01 1293-2:+3:-6
1294+2:-3:-6
61f5c3f5 1295-2:-3:6
1296111:111:12321
129710101:10101:102030201
12981001001:1001001:1002003002001
1299100010001:100010001:10002000300020001
130010000100001:10000100001:100002000030000200001
130111111111111:9:99999999999
130222222222222:9:199999999998
130333333333333:9:299999999997
130444444444444:9:399999999996
130555555555555:9:499999999995
130666666666666:9:599999999994
130777777777777:9:699999999993
130888888888888:9:799999999992
130999999999999:9:899999999991
1310+25:+25:625
1311+12345:+12345:152399025
1312+99999:+11111:1111088889
6854fd01 13139999:10000:99990000
131499999:100000:9999900000
1315999999:1000000:999999000000
13169999999:10000000:99999990000000
131799999999:100000000:9999999900000000
1318999999999:1000000000:999999999000000000
13199999999999:10000000000:99999999990000000000
132099999999999:100000000000:9999999999900000000000
1321999999999999:1000000000000:999999999999000000000000
13229999999999999:10000000000000:99999999999990000000000000
132399999999999999:100000000000000:9999999999999900000000000000
1324999999999999999:1000000000000000:999999999999999000000000000000
13259999999999999999:10000000000000000:99999999999999990000000000000000
132699999999999999999:100000000000000000:9999999999999999900000000000000000
1327999999999999999999:1000000000000000000:999999999999999999000000000000000000
13289999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1329&bdiv-list
1330100:20:5,0
13314095:4095:1,0
1332-4095:-4095:1,0
13334095:-4095:-1,0
1334-4095:4095:-1,0
1335123:2:61,1
b3abae2a 13369:5:1,4
13379:4:2,1
6854fd01 1338# inf handling and general remainder
13395:8:0,5
13400:8:0,0
134111:2:5,1
134211:-2:-5,-1
1343-11:2:-5,1
1344# see table in documentation in MBI
13450:inf:0,0
13460:-inf:0,0
13475:inf:0,5
13485:-inf:0,5
1349-5:inf:0,-5
1350-5:-inf:0,-5
1351inf:5:inf,0
1352-inf:5:-inf,0
1353inf:-5:-inf,0
1354-inf:-5:inf,0
13555:5:1,0
1356-5:-5:1,0
b3abae2a 1357inf:inf:NaN,NaN
1358-inf:-inf:NaN,NaN
1359-inf:inf:NaN,NaN
1360inf:-inf:NaN,NaN
6854fd01 13618:0:inf,8
1362inf:0:inf,inf
1363# exceptions to reminder rule
1364-8:0:-inf,-8
1365-inf:0:-inf,-inf
13660:0:NaN,NaN
1367&bdiv
1368abc:abc:NaN
61f5c3f5 1369abc:1:NaN
13701:abc:NaN
13710:0:NaN
6854fd01 1372# inf handling (see table in doc)
13730:inf:0
13740:-inf:0
13755:inf:0
13765:-inf:0
1377-5:inf:0
1378-5:-inf:0
1379inf:5:inf
1380-inf:5:-inf
1381inf:-5:-inf
1382-inf:-5:inf
13835:5:1
1384-5:-5:1
b3abae2a 1385inf:inf:NaN
1386-inf:-inf:NaN
1387-inf:inf:NaN
1388inf:-inf:NaN
6854fd01 13898:0:inf
1390inf:0:inf
1391-8:0:-inf
1392-inf:0:-inf
13930:0:NaN
139411:2:5
1395-11:-2:5
1396-11:2:-5
139711:-2:-5
61f5c3f5 13980:1:0
13990:-1:0
14001:1:1
1401-1:-1:1
14021:-1:-1
1403-1:1:-1
14041:2:0
14052:1:2
14061:26:0
14071000000000:9:111111111
14082000000000:9:222222222
14093000000000:9:333333333
14104000000000:9:444444444
14115000000000:9:555555555
14126000000000:9:666666666
14137000000000:9:777777777
14148000000000:9:888888888
14159000000000:9:1000000000
141635500000:113:314159
141771000000:226:314159
1418106500000:339:314159
14191000000000:3:333333333
1420+10:+5:2
1421+100:+4:25
1422+1000:+8:125
1423+10000:+16:625
1424999999999999:9:111111111111
1425999999999999:99:10101010101
1426999999999999:999:1001001001
1427999999999999:9999:100010001
1428999999999999999:99999:10000100001
1429+1111088889:99999:11111
6854fd01 1430-5:-3:1
1431-5:3:-1
14324:3:1
14334:-3:-1
14341:3:0
14351:-3:0
1436-2:-3:0
1437-2:3:0
14388:3:2
1439-8:3:-2
144014:-3:-4
1441-14:3:-4
1442-14:-3:4
144314:3:4
1444# bug in Calc with '99999' vs $BASE-1
144510000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
07d34614 1446&bmodinv
1447# format: number:modulus:result
1448# bmodinv Data errors
1449abc:abc:NaN
1450abc:5:NaN
14515:abc:NaN
1452# bmodinv Expected Results from normal use
14531:5:1
14543:5:2
1455-2:5:2
14568:5033:4404
56d9de68 14571234567891:13:6
1458-1234567891:13:7
07d34614 1459324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1460## bmodinv Error cases / useless use of function
07d34614 14613:-5:NaN
1462inf:5:NaN
1ddff52a 14635:inf:NaN
1464-inf:5:NaN
14655:-inf:NaN
07d34614 1466&bmodpow
1467# format: number:exponent:modulus:result
1468# bmodpow Data errors
1469abc:abc:abc:NaN
14705:abc:abc:NaN
1471abc:5:abc:NaN
1472abc:abc:5:NaN
14735:5:abc:NaN
14745:abc:5:NaN
1475abc:5:5:NaN
1476# bmodpow Expected results
14770:0:2:1
14781:0:2:1
14790:0:1:0
14808:7:5032:3840
14818:-1:5033:4404
148298436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1483# bmodpow Error cases
14848:8:-5:NaN
14858:-1:16:NaN
1486inf:5:13:NaN
14875:inf:13:NaN
6854fd01 1488&bmod
1489# inf handling, see table in doc
14900:inf:0
14910:-inf:0
14925:inf:5
14935:-inf:5
1494-5:inf:-5
1495-5:-inf:-5
1496inf:5:0
1497-inf:5:0
1498inf:-5:0
1499-inf:-5:0
15005:5:0
1501-5:-5:0
b3abae2a 1502inf:inf:NaN
1503-inf:-inf:NaN
1504-inf:inf:NaN
1505inf:-inf:NaN
6854fd01 15068:0:8
1507inf:0:inf
1508# exceptions to reminder rule
1509-inf:0:-inf
1510-8:0:-8
15110:0:NaN
1512abc:abc:NaN
61f5c3f5 1513abc:1:abc:NaN
15141:abc:NaN
15150:0:NaN
15160:1:0
15171:0:1
15180:-1:0
1519-1:0:-1
15201:1:0
1521-1:-1:0
15221:-1:0
1523-1:1:0
15241:2:1
15252:1:0
15261000000000:9:1
15272000000000:9:2
15283000000000:9:3
15294000000000:9:4
15305000000000:9:5
15316000000000:9:6
15327000000000:9:7
15338000000000:9:8
15349000000000:9:0
153535500000:113:33
153671000000:226:66
1537106500000:339:99
15381000000000:3:1
153910:5:0
1540100:4:0
15411000:8:0
154210000:16:0
1543999999999999:9:0
1544999999999999:99:0
1545999999999999:999:0
1546999999999999:9999:0
1547999999999999999:99999:0
1548-9:+5:1
6854fd01 1549+9:-5:-1
1550-9:-5:-4
1551-5:3:1
1552-2:3:1
15534:3:1
15541:3:1
1555-5:-3:-2
1556-2:-3:-2
15574:-3:-2
15581:-3:-2
15594095:4095:0
027dc388 1560100041000510123:3:0
1561152403346:12345:4321
b3abae2a 15629:5:4
28df3e88 1563# test shortcuts in Calc
1564# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
15651234:9:1
1566123456:9:3
156712345678:9:0
15681234567891:9:1
1569123456789123:9:6
157012345678912345:9:6
15711234567891234567:9:1
1572123456789123456789:9:0
15731234:10:4
1574123456:10:6
157512345678:10:8
15761234567891:10:1
1577123456789123:10:3
157812345678912345:10:5
15791234567891234567:10:7
1580123456789123456789:10:9
15811234:113:104
1582123456:113:60
158312345678:113:89
15841234567891:113:64
1585123456789123:113:95
158612345678912345:113:53
15871234567891234567:113:56
1588123456789123456789:113:39
07d34614 1589# bug in bmod() not modifying the variable in place
1590-629:5033:4404
6854fd01 1591&bgcd
1592abc:abc:NaN
1593abc:+0:NaN
1594+0:abc:NaN
61f5c3f5 1595+0:+0:0
1596+0:+1:1
1597+1:+0:1
1598+1:+1:1
1599+2:+3:1
1600+3:+2:1
1601-3:+2:1
1602100:625:25
16034096:81:1
16041034:804:2
160527:90:56:1
160627:90:54:9
6854fd01 1607&blcm
1608abc:abc:NaN
1609abc:+0:NaN
1610+0:abc:NaN
1611+0:+0:NaN
61f5c3f5 1612+1:+0:0
1613+0:+1:0
1614+27:+90:270
1615+1034:+804:415668
6854fd01 1616&band
1617abc:abc:NaN
1618abc:0:NaN
16190:abc:NaN
16201:2:0
16213:2:2
61f5c3f5 1622+8:+2:0
1623+281474976710656:0:0
1624+281474976710656:1:0
1625+281474976710656:+281474976710656:281474976710656
6854fd01 1626-2:-3:-4
1627-1:-1:-1
1628-6:-6:-6
1629-7:-4:-8
1630-7:4:0
1631-4:7:4
394e6ffb 1632# equal arguments are treated special, so also do some test with unequal ones
16330xFFFF:0xFFFF:0x0xFFFF
16340xFFFFFF:0xFFFFFF:0x0xFFFFFF
16350xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
16360xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
16370xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
16380xF0F0:0xF0F0:0x0xF0F0
16390x0F0F:0x0F0F:0x0x0F0F
16400xF0F0F0:0xF0F0F0:0x0xF0F0F0
16410x0F0F0F:0x0F0F0F:0x0x0F0F0F
16420xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
16430x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
16440xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
16450x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
16460xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
16470x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
16480x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1649&bior
1650abc:abc:NaN
1651abc:0:NaN
16520:abc:NaN
16531:2:3
61f5c3f5 1654+8:+2:10
1655+281474976710656:0:281474976710656
1656+281474976710656:1:281474976710657
1657+281474976710656:281474976710656:281474976710656
6854fd01 1658-2:-3:-1
1659-1:-1:-1
1660-6:-6:-6
1661-7:4:-3
1662-4:7:-1
394e6ffb 1663# equal arguments are treated special, so also do some test with unequal ones
16640xFFFF:0xFFFF:0x0xFFFF
16650xFFFFFF:0xFFFFFF:0x0xFFFFFF
16660xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
16670xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
16680xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
16690:0xFFFF:0x0xFFFF
16700:0xFFFFFF:0x0xFFFFFF
16710:0xFFFFFFFF:0x0xFFFFFFFF
16720:0xFFFFFFFFFF:0x0xFFFFFFFFFF
16730:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
16740xFFFF:0:0x0xFFFF
16750xFFFFFF:0:0x0xFFFFFF
16760xFFFFFFFF:0:0x0xFFFFFFFF
16770xFFFFFFFFFF:0:0x0xFFFFFFFFFF
16780xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
16790xF0F0:0xF0F0:0x0xF0F0
16800x0F0F:0x0F0F:0x0x0F0F
16810xF0F0:0x0F0F:0x0xFFFF
16820xF0F0F0:0xF0F0F0:0x0xF0F0F0
16830x0F0F0F:0x0F0F0F:0x0x0F0F0F
16840x0F0F0F:0xF0F0F0:0x0xFFFFFF
16850xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
16860x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
16870x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
16880xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
16890x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
16900x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
16910xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
16920x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
16930x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
16940x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1695&bxor
1696abc:abc:NaN
1697abc:0:NaN
16980:abc:NaN
16991:2:3
61f5c3f5 1700+8:+2:10
1701+281474976710656:0:281474976710656
1702+281474976710656:1:281474976710657
1703+281474976710656:281474976710656:0
6854fd01 1704-2:-3:3
1705-1:-1:0
1706-6:-6:0
1707-7:4:-3
1708-4:7:-5
17094:-7:-3
1710-4:-7:5
394e6ffb 1711# equal arguments are treated special, so also do some test with unequal ones
17120xFFFF:0xFFFF:0
17130xFFFFFF:0xFFFFFF:0
17140xFFFFFFFF:0xFFFFFFFF:0
17150xFFFFFFFFFF:0xFFFFFFFFFF:0
17160xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
17170:0xFFFF:0x0xFFFF
17180:0xFFFFFF:0x0xFFFFFF
17190:0xFFFFFFFF:0x0xFFFFFFFF
17200:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17210:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17220xFFFF:0:0x0xFFFF
17230xFFFFFF:0:0x0xFFFFFF
17240xFFFFFFFF:0:0x0xFFFFFFFF
17250xFFFFFFFFFF:0:0x0xFFFFFFFFFF
17260xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
17270xF0F0:0xF0F0:0
17280x0F0F:0x0F0F:0
17290xF0F0:0x0F0F:0x0xFFFF
17300xF0F0F0:0xF0F0F0:0
17310x0F0F0F:0x0F0F0F:0
17320x0F0F0F:0xF0F0F0:0x0xFFFFFF
17330xF0F0F0F0:0xF0F0F0F0:0
17340x0F0F0F0F:0x0F0F0F0F:0
17350x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
17360xF0F0F0F0F0:0xF0F0F0F0F0:0
17370x0F0F0F0F0F:0x0F0F0F0F0F:0
17380x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
17390xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
17400x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
17410x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1742&bnot
1743abc:NaN
1744+0:-1
1745+8:-9
1746+281474976710656:-281474976710657
1747-1:0
1748-2:1
1749-12:11
1750&digit
17510:0:0
175212:0:2
175312:1:1
1754123:0:3
1755123:1:2
1756123:2:1
1757123:-1:1
1758123:-2:2
1759123:-3:3
1760123456:0:6
1761123456:1:5
1762123456:2:4
1763123456:3:3
1764123456:4:2
1765123456:5:1
1766123456:-1:1
1767123456:-2:2
1768123456:-3:3
1769100000:-3:0
1770100000:0:0
1771100000:1:0
1772&mantissa
1773abc:NaN
17741e4:1
17752e0:2
1776123:123
1777-1:-1
1778-2:-2
1779+inf:inf
1780-inf:-inf
1781&exponent
1782abc:NaN
17831e4:4
17842e0:0
1785123:0
1786-1:0
1787-2:0
17880:1
1789+inf:inf
1790-inf:inf
1791&parts
1792abc:NaN,NaN
17931e4:1,4
17942e0:2,0
1795123:123,0
1796-1:-1,0
1797-2:-2,0
17980:0,1
1799+inf:inf,inf
1800-inf:-inf,inf
b3abae2a 1801&bfac
1802-1:NaN
1803NaNfac:NaN
1804+inf:NaN
1805-inf:NaN
18060:1
18071:1
18082:2
18093:6
18104:24
18115:120
18126:720
181310:3628800
181411:39916800
181512:479001600
6854fd01 1816&bpow
1817abc:12:NaN
181812:abc:NaN
18190:0:1
18200:1:0
18210:2:0
18220:-1:NaN
18230:-2:NaN
18241:0:1
18251:1:1
18261:2:1
18271:3:1
18281:-1:1
18291:-2:1
18301:-3:1
18312:0:1
18322:1:2
18332:2:4
18342:3:8
18353:3:27
18362:-1:NaN
1837-2:-1:NaN
18382:-2:NaN
1839-2:-2:NaN
1840+inf:1234500012:inf
1841-inf:1234500012:-inf
1842+inf:-12345000123:inf
1843-inf:-12345000123:-inf
1844# 1 ** -x => 1 / (1 ** x)
1845-1:0:1
1846-2:0:1
1847-1:1:-1
1848-1:2:1
1849-1:3:-1
1850-1:4:1
1851-1:5:-1
1852-1:-1:-1
1853-1:-2:1
1854-1:-3:-1
1855-1:-4:1
185610:2:100
185710:3:1000
185810:4:10000
185910:5:100000
186010:6:1000000
186110:7:10000000
186210:8:100000000
186310:9:1000000000
186410:20:100000000000000000000
1865123456:2:15241383936
1866&length
1867100:3
186810:2
18691:1
18700:1
187112345:5
187210000000000000000:17
1873-123:3
1874215960156869840440586892398248:30
1875&bsqrt
394e6ffb 1876145:12
6854fd01 1877144:12
394e6ffb 1878143:11
6854fd01 187916:4
394e6ffb 1880170:13
1881169:13
1882168:12
6854fd01 18834:2
394e6ffb 18843:1
6854fd01 18852:1
394e6ffb 18869:3
6854fd01 188712:3
1888256:16
1889100000000:10000
18904000000000000:2000000
394e6ffb 1891152399026:12345
1892152399025:12345
1893152399024:12344
6854fd01 18941:1
18950:0
1896-2:NaN
394e6ffb 1897-123:NaN
6854fd01 1898Nan:NaN
394e6ffb 1899+inf:NaN
6854fd01 1900&bround
1901$round_mode('trunc')
19020:12:0
1903NaNbround:12:NaN
1904+inf:12:inf
1905-inf:12:-inf
19061234:0:1234
19071234:2:1200
1908123456:4:123400
1909123456:5:123450
1910123456:6:123456
61f5c3f5 1911+10123456789:5:10123000000
6854fd01 1912-10123456789:5:-10123000000
61f5c3f5 1913+10123456789:9:10123456700
6854fd01 1914-10123456789:9:-10123456700
61f5c3f5 1915+101234500:6:101234000
6854fd01 1916-101234500:6:-101234000
61f5c3f5 1917#+101234500:-4:101234000
6854fd01 1918#-101234500:-4:-101234000
1919$round_mode('zero')
61f5c3f5 1920+20123456789:5:20123000000
6854fd01 1921-20123456789:5:-20123000000
61f5c3f5 1922+20123456789:9:20123456800
6854fd01 1923-20123456789:9:-20123456800
61f5c3f5 1924+201234500:6:201234000
6854fd01 1925-201234500:6:-201234000
61f5c3f5 1926#+201234500:-4:201234000
6854fd01 1927#-201234500:-4:-201234000
1928+12345000:4:12340000
1929-12345000:4:-12340000
1930$round_mode('+inf')
61f5c3f5 1931+30123456789:5:30123000000
6854fd01 1932-30123456789:5:-30123000000
61f5c3f5 1933+30123456789:9:30123456800
6854fd01 1934-30123456789:9:-30123456800
61f5c3f5 1935+301234500:6:301235000
6854fd01 1936-301234500:6:-301234000
61f5c3f5 1937#+301234500:-4:301235000
6854fd01 1938#-301234500:-4:-301234000
1939+12345000:4:12350000
1940-12345000:4:-12340000
1941$round_mode('-inf')
61f5c3f5 1942+40123456789:5:40123000000
6854fd01 1943-40123456789:5:-40123000000
61f5c3f5 1944+40123456789:9:40123456800
6854fd01 1945-40123456789:9:-40123456800
61f5c3f5 1946+401234500:6:401234000
1947+401234500:6:401234000
6854fd01 1948#-401234500:-4:-401235000
1949#-401234500:-4:-401235000
1950+12345000:4:12340000
1951-12345000:4:-12350000
1952$round_mode('odd')
61f5c3f5 1953+50123456789:5:50123000000
6854fd01 1954-50123456789:5:-50123000000
61f5c3f5 1955+50123456789:9:50123456800
6854fd01 1956-50123456789:9:-50123456800
61f5c3f5 1957+501234500:6:501235000
6854fd01 1958-501234500:6:-501235000
61f5c3f5 1959#+501234500:-4:501235000
6854fd01 1960#-501234500:-4:-501235000
1961+12345000:4:12350000
1962-12345000:4:-12350000
1963$round_mode('even')
61f5c3f5 1964+60123456789:5:60123000000
6854fd01 1965-60123456789:5:-60123000000
61f5c3f5 1966+60123456789:9:60123456800
6854fd01 1967-60123456789:9:-60123456800
61f5c3f5 1968+601234500:6:601234000
6854fd01 1969-601234500:6:-601234000
61f5c3f5 1970#+601234500:-4:601234000
6854fd01 1971#-601234500:-4:-601234000
1972#-601234500:-9:0
1973#-501234500:-9:0
1974#-601234500:-8:0
1975#-501234500:-8:0
1976+1234567:7:1234567
1977+1234567:6:1234570
1978+12345000:4:12340000
1979-12345000:4:-12340000
1980&is_zero
19810:1
1982NaNzero:0
1983+inf:0
1984-inf:0
1985123:0
1986-1:0
19871:0
1988&is_one
19890:0
1990NaNone:0
1991+inf:0
1992-inf:0
19931:1
19942:0
1995-1:0
1996-2:0
1997# floor and ceil tests are pretty pointless in integer space...but play safe
1998&bfloor
19990:0
2000NaNfloor:NaN
2001+inf:inf
2002-inf:-inf
2003-1:-1
2004-2:-2
20052:2
20063:3
2007abc:NaN
2008&bceil
2009NaNceil:NaN
2010+inf:inf
2011-inf:-inf
20120:0
2013-1:-1
2014-2:-2
20152:2
20163:3
2017abc:NaN
2018&as_hex
2019128:0x80
2020-128:-0x80
20210:0x0
2022-0:0x0
20231:0x1
20240x123456789123456789:0x123456789123456789
2025+inf:inf
2026-inf:-inf
2027NaNas_hex:NaN
2028&as_bin
2029128:0b10000000
2030-128:-0b10000000
20310:0b0
2032-0:0b0
20331:0b1
20340b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 20350x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2036+inf:inf
2037-inf:-inf
2038NaNas_bin:NaN