AUTHORS updates.
[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
5##############################################################################
6# for testing inheritance of _swap
7
8package Math::Foo;
9
61f5c3f5 10use Math::BigInt lib => $main::CL;
6854fd01 11use vars qw/@ISA/;
12@ISA = (qw/Math::BigInt/);
13
14use overload
15# customized overload for sub, since original does not use swap there
16'-' => sub { my @a = ref($_[0])->_swap(@_);
17 $a[0]->bsub($a[1])};
18
19sub _swap
20 {
21 # a fake _swap, which reverses the params
22 my $self = shift; # for override in subclass
23 if ($_[2])
24 {
25 my $c = ref ($_[0] ) || 'Math::Foo';
26 return ( $_[0]->copy(), $_[1] );
27 }
28 else
29 {
30 return ( Math::Foo->new($_[1]), $_[0] );
31 }
32 }
33
34##############################################################################
35package main;
36
b3abae2a 37my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
6854fd01 38
b3abae2a 39my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
6854fd01 40
41while (<DATA>)
42 {
d614cd8b 43 chomp;
6854fd01 44 next if /^#/; # skip comments
45 if (s/^&//)
46 {
61f5c3f5 47 $f = $_; next;
6854fd01 48 }
49 elsif (/^\$/)
50 {
61f5c3f5 51 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
6854fd01 52 }
61f5c3f5 53
54 @args = split(/:/,$_,99); $ans = pop(@args);
b3abae2a 55 $expected_class = $class;
56 if ($ans =~ /(.*?)=(.*)/)
57 {
58 $expected_class = $2; $ans = $1;
59 }
61f5c3f5 60 $try = "\$x = $class->new(\"$args[0]\");";
61 if ($f eq "bnorm")
6854fd01 62 {
61f5c3f5 63 $try = "\$x = $class->bnorm(\"$args[0]\");";
64 # some is_xxx tests
b3abae2a 65 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
61f5c3f5 66 $try .= "\$x->$f();";
67 } elsif ($f eq "as_hex") {
68 $try .= '$x->as_hex();';
69 } elsif ($f eq "as_bin") {
70 $try .= '$x->as_bin();';
71 } elsif ($f eq "is_inf") {
72 $try .= "\$x->is_inf('$args[1]');";
73 } elsif ($f eq "binf") {
74 $try .= "\$x->binf('$args[1]');";
75 } elsif ($f eq "bone") {
76 $try .= "\$x->bone('$args[1]');";
77 # some unary ops
b3abae2a 78 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
61f5c3f5 79 $try .= "\$x->$f();";
80 } elsif ($f eq "length") {
81 $try .= '$x->length();';
82 } elsif ($f eq "exponent"){
83 # ->bstr() to see if an object is returned
84 $try .= '$x = $x->exponent()->bstr();';
85 } elsif ($f eq "mantissa"){
86 # ->bstr() to see if an object is returned
87 $try .= '$x = $x->mantissa()->bstr();';
88 } elsif ($f eq "parts"){
89 $try .= '($m,$e) = $x->parts();';
90 # ->bstr() to see if an object is returned
91 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
92 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
93 $try .= '"$m,$e";';
94 } else {
95 $try .= "\$y = $class->new('$args[1]');";
96 if ($f eq "bcmp")
97 {
98 $try .= '$x <=> $y;';
99 } elsif ($f eq "bround") {
6854fd01 100 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5 101 } elsif ($f eq "bacmp"){
102 $try .= '$x->bacmp($y);';
103 } elsif ($f eq "badd"){
104 $try .= '$x + $y;';
105 } elsif ($f eq "bsub"){
106 $try .= '$x - $y;';
107 } elsif ($f eq "bmul"){
108 $try .= '$x * $y;';
109 } elsif ($f eq "bdiv"){
110 $try .= '$x / $y;';
111 } elsif ($f eq "bdiv-list"){
112 $try .= 'join (",",$x->bdiv($y));';
027dc388 113 # overload via x=
61f5c3f5 114 } elsif ($f =~ /^.=$/){
115 $try .= "\$x $f \$y;";
027dc388 116 # overload via x
61f5c3f5 117 } elsif ($f =~ /^.$/){
118 $try .= "\$x $f \$y;";
119 } elsif ($f eq "bmod"){
120 $try .= '$x % $y;';
121 } elsif ($f eq "bgcd")
6854fd01 122 {
123 if (defined $args[2])
124 {
61f5c3f5 125 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 126 }
127 $try .= "$class\::bgcd(\$x, \$y";
128 $try .= ", \$z" if (defined $args[2]);
129 $try .= " );";
130 }
131 elsif ($f eq "blcm")
132 {
133 if (defined $args[2])
134 {
61f5c3f5 135 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 136 }
137 $try .= "$class\::blcm(\$x, \$y";
138 $try .= ", \$z" if (defined $args[2]);
139 $try .= " );";
140 }elsif ($f eq "blsft"){
141 if (defined $args[2])
142 {
143 $try .= "\$x->blsft(\$y,$args[2]);";
144 }
145 else
146 {
147 $try .= "\$x << \$y;";
148 }
149 }elsif ($f eq "brsft"){
150 if (defined $args[2])
151 {
152 $try .= "\$x->brsft(\$y,$args[2]);";
153 }
154 else
155 {
156 $try .= "\$x >> \$y;";
157 }
158 }elsif ($f eq "band"){
159 $try .= "\$x & \$y;";
160 }elsif ($f eq "bior"){
161 $try .= "\$x | \$y;";
162 }elsif ($f eq "bxor"){
163 $try .= "\$x ^ \$y;";
164 }elsif ($f eq "bpow"){
165 $try .= "\$x ** \$y;";
d614cd8b 166 } elsif( $f eq "bmodinv") {
167 $try .= "\$x->bmodinv(\$y);";
6854fd01 168 }elsif ($f eq "digit"){
56b9c951 169 $try .= "\$x->digit(\$y);";
d614cd8b 170 } else {
171 $try .= "\$z = $class->new(\"$args[2]\");";
172
173 # Functions with three arguments
174 if( $f eq "bmodpow") {
175 $try .= "\$x->bmodpow(\$y,\$z);";
176 } else { warn "Unknown op '$f'"; }
177 }
61f5c3f5 178 } # end else all other ops
179
180 $ans1 = eval $try;
181 # convert hex/binary targets to decimal
182 if ($ans =~ /^(0x0x|0b0b)/)
183 {
184 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 185 }
61f5c3f5 186 if ($ans eq "")
187 {
188 ok_undef ($ans1);
189 }
190 else
191 {
192 # print "try: $try ans: $ans1 $ans\n";
193 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 194 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 195 }
61f5c3f5 196 # check internal state of number objects
197 is_valid($ans1,$f) if ref $ans1;
6854fd01 198 } # endwhile data tests
199close DATA;
200
201# test some more
202@a = ();
203for (my $i = 1; $i < 10; $i++)
204 {
205 push @a, $i;
206 }
207ok "@a", "1 2 3 4 5 6 7 8 9";
208
209# test whether self-multiplication works correctly (result is 2**64)
210$try = "\$x = $class->new('4294967296');";
211$try .= '$a = $x->bmul($x);';
212$ans1 = eval $try;
213print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
214# test self-pow
215$try = "\$x = $class->new(10);";
216$try .= '$a = $x->bpow($x);';
217$ans1 = eval $try;
218print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
219
07d34614 220###############################################################################
6854fd01 221# test whether op destroys args or not (should better not)
222
223$x = $class->new(3);
224$y = $class->new(4);
225$z = $x & $y;
226ok ($x,3);
227ok ($y,4);
228ok ($z,0);
229$z = $x | $y;
230ok ($x,3);
231ok ($y,4);
232ok ($z,7);
233$x = $class->new(1);
234$y = $class->new(2);
235$z = $x | $y;
236ok ($x,1);
237ok ($y,2);
238ok ($z,3);
239
240$x = $class->new(5);
241$y = $class->new(4);
242$z = $x ^ $y;
243ok ($x,5);
244ok ($y,4);
245ok ($z,1);
246
247$x = $class->new(-5); $y = -$x;
248ok ($x, -5);
249
250$x = $class->new(-5); $y = abs($x);
251ok ($x, -5);
252
07d34614 253$x = $class->new(8);
254$y = $class->new(-1);
255$z = $class->new(5033);
256my $u = $x->copy()->bmodpow($y,$z);
257ok ($u,4404);
258ok ($y,-1);
259ok ($z,5033);
260
261$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
262$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
263
264$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
265$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
266$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
267$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
268$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
269
270$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
271$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
272$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
273$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
274$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
275
276$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
277$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
278$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
279$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
280$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
281
282###############################################################################
6854fd01 283# check whether overloading cmp works
284$try = "\$x = $class->new(0);";
285$try .= "\$y = 10;";
286$try .= "'false' if \$x ne \$y;";
287$ans = eval $try;
288print "# For '$try'\n" if (!ok "$ans" , "false" );
289
290# we cant test for working cmpt with other objects here, we would need a dummy
291# object with stringify overload for this. see Math::String tests as example
292
293###############################################################################
6854fd01 294# check reversed order of arguments
027dc388 295
6854fd01 296$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
297$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
298print "# For '$try'\n" if (!ok "$ans" , "ok" );
299
300$try = "\$x = $class->new(10); \$x = 2 * \$x;";
301$try .= "'ok' if \$x == 20;"; $ans = eval $try;
302print "# For '$try'\n" if (!ok "$ans" , "ok" );
303
304$try = "\$x = $class->new(10); \$x = 2 + \$x;";
305$try .= "'ok' if \$x == 12;"; $ans = eval $try;
306print "# For '$try'\n" if (!ok "$ans" , "ok" );
307
308$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
309$try .= "'ok' if \$x == -8;"; $ans = eval $try;
310print "# For '$try'\n" if (!ok "$ans" , "ok" );
311
312$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
313$try .= "'ok' if \$x == 2;"; $ans = eval $try;
314print "# For '$try'\n" if (!ok "$ans" , "ok" );
315
027dc388 316$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
317$try .= "'ok' if \$x == 2;"; $ans = eval $try;
318print "# For '$try'\n" if (!ok "$ans" , "ok" );
319
320$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
321$try .= "'ok' if \$x == 4;"; $ans = eval $try;
322print "# For '$try'\n" if (!ok "$ans" , "ok" );
323
324$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
325$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
326print "# For '$try'\n" if (!ok "$ans" , "ok" );
327
328$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
329$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
330print "# For '$try'\n" if (!ok "$ans" , "ok" );
331
6854fd01 332###############################################################################
333# check badd(4,5) form
334
335$try = "\$x = $class\->badd(4,5);";
336$try .= "'ok' if \$x == 9;";
337$ans = eval $try;
338print "# For '$try'\n" if (!ok "$ans" , "ok" );
339
340###############################################################################
341# check undefs: NOT DONE YET
342
343###############################################################################
344# bool
345
f9a08e12 346$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
347$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 348
349###############################################################################
350# objectify()
351
352@args = Math::BigInt::objectify(2,4,5);
353ok (scalar @args,3); # $class, 4, 5
56b9c951 354ok ($args[0] =~ /^Math::BigInt/);
6854fd01 355ok ($args[1],4);
356ok ($args[2],5);
357
358@args = Math::BigInt::objectify(0,4,5);
359ok (scalar @args,3); # $class, 4, 5
56b9c951 360ok ($args[0] =~ /^Math::BigInt/);
6854fd01 361ok ($args[1],4);
362ok ($args[2],5);
363
364@args = Math::BigInt::objectify(2,4,5);
365ok (scalar @args,3); # $class, 4, 5
56b9c951 366ok ($args[0] =~ /^Math::BigInt/);
6854fd01 367ok ($args[1],4);
368ok ($args[2],5);
369
370@args = Math::BigInt::objectify(2,4,5,6,7);
371ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 372ok ($args[0] =~ /^Math::BigInt/);
6854fd01 373ok ($args[1],4); ok (ref($args[1]),$args[0]);
374ok ($args[2],5); ok (ref($args[2]),$args[0]);
375ok ($args[3],6); ok (ref($args[3]),'');
376ok ($args[4],7); ok (ref($args[4]),'');
377
378@args = Math::BigInt::objectify(2,$class,4,5,6,7);
379ok (scalar @args,5); # $class, 4, 5, 6, 7
380ok ($args[0],$class);
381ok ($args[1],4); ok (ref($args[1]),$args[0]);
382ok ($args[2],5); ok (ref($args[2]),$args[0]);
383ok ($args[3],6); ok (ref($args[3]),'');
384ok ($args[4],7); ok (ref($args[4]),'');
385
386###############################################################################
f9a08e12 387# test whether an opp calls objectify properly or not (or at least does what
388# it should do given non-objects, w/ or w/o objectify())
389
390ok ($class->new(123)->badd(123),246);
391ok ($class->badd(123,321),444);
392ok ($class->badd(123,$class->new(321)),444);
393
394ok ($class->new(123)->bsub(122),1);
395ok ($class->bsub(321,123),198);
396ok ($class->bsub(321,$class->new(123)),198);
397
398ok ($class->new(123)->bmul(123),15129);
399ok ($class->bmul(123,123),15129);
400ok ($class->bmul(123,$class->new(123)),15129);
401
402ok ($class->new(15129)->bdiv(123),123);
403ok ($class->bdiv(15129,123),123);
404ok ($class->bdiv(15129,$class->new(123)),123);
405
406ok ($class->new(15131)->bmod(123),2);
407ok ($class->bmod(15131,123),2);
408ok ($class->bmod(15131,$class->new(123)),2);
409
410ok ($class->new(2)->bpow(16),65536);
411ok ($class->bpow(2,16),65536);
412ok ($class->bpow(2,$class->new(16)),65536);
413
414ok ($class->new(2**15)->brsft(1),2**14);
415ok ($class->brsft(2**15,1),2**14);
416ok ($class->brsft(2**15,$class->new(1)),2**14);
417
418ok ($class->new(2**13)->blsft(1),2**14);
419ok ($class->blsft(2**13,1),2**14);
420ok ($class->blsft(2**13,$class->new(1)),2**14);
421
422###############################################################################
6854fd01 423# test for floating-point input (other tests in bnorm() below)
424
425$z = 1050000000000000; # may be int on systems with 64bit?
426$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
427$z = 1e+129; # definitely a float (may fail on UTS)
428# don't compare to $z, since some Perl versions stringify $z into something
429# like '1.e+129' or something equally ugly
430$x = $class->new($z); ok ($x->bsstr(),'1e+129');
431
432###############################################################################
433# prime number tests, also test for **= and length()
434# found on: http://www.utm.edu/research/primes/notes/by_year.html
435
436# ((2^148)-1)/17
437$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
438ok ($x,"20988936657440586486151264256610222593863921");
439ok ($x->length(),length "20988936657440586486151264256610222593863921");
440
441# MM7 = 2^127-1
442$x = $class->new(2); $x **= 127; $x--;
443ok ($x,"170141183460469231731687303715884105727");
444
445$x = $class->new('215960156869840440586892398248');
446($x,$y) = $x->length();
447ok ($x,30); ok ($y,0);
448
449$x = $class->new('1_000_000_000_000');
450($x,$y) = $x->length();
451ok ($x,13); ok ($y,0);
452
453# I am afraid the following is not yet possible due to slowness
454# Also, testing for 2 meg output is a bit hard ;)
455#$x = $class->new(2); $x **= 6972593; $x--;
456
457# 593573509*2^332162+1 has exactly 1,000,000 digits
458# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
459#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
460#ok ($x->length(),1_000_000);
461
462###############################################################################
463# inheritance and overriding of _swap
464
465$x = Math::Foo->new(5);
466$x = $x - 8; # 8 - 5 instead of 5-8
467ok ($x,3);
468ok (ref($x),'Math::Foo');
469
470$x = Math::Foo->new(5);
471$x = 8 - $x; # 5 - 8 instead of 8 - 5
472ok ($x,-3);
473ok (ref($x),'Math::Foo');
474
475###############################################################################
476# Test whether +inf eq inf
477# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
478# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
479# like 1e100000 crash on some platforms. So simple test for the string 'inf'
480$x = $class->new('+inf'); ok ($x,'inf');
481
482###############################################################################
483###############################################################################
394e6ffb 484# the followin tests only make sense with Math::BigInt::Calc or BareCalc
6854fd01 485
394e6ffb 486exit if $CALC !~ /^Math::BigInt::(Calc|BareCalc)$/; # for Pari et al.
6854fd01 487
488###############################################################################
489# check proper length of internal arrays
490
394e6ffb 491my $bl = $CL->_base_len();
6854fd01 492my $BASE = '9' x $bl;
493my $MAX = $BASE;
494$BASE++;
495
496$x = $class->new($MAX); is_valid($x); # f.i. 9999
497$x += 1; ok ($x,$BASE); is_valid($x); # 10000
498$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
499
500###############################################################################
501# check numify
502
503$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
504$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 505
506# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
507$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 508$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
509$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
510ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
511
512###############################################################################
513# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
514
394e6ffb 515$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
516if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
517
518$x = $class->new($BASE+3); $x++;
519if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 520
394e6ffb 521# test for +0 instead of int():
522$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 523
524###############################################################################
56b9c951 525# test bug that $class->digit($string) did not work
526
527ok ($class->digit(123,2),1);
528
529###############################################################################
6854fd01 530# bug in sub where number with at least 6 trailing zeros after any op failed
531
394e6ffb 532$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 533ok ($z, 100000);
534ok ($x, 23456);
535
536###############################################################################
537# bug in shortcut in mul()
538
61f5c3f5 539# construct a number with a zero-hole of BASE_LEN_SMALL
540{
541 my @bl = $CL->_base_len(); my $bl = $bl[4];
542
543 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
544 $y = '1' x (2*$bl);
545 $x = $class->new($x)->bmul($y);
546 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
547 $y = ''; my $d = '';
548 for (my $i = 1; $i <= $bl; $i++)
549 {
550 $y .= $i; $d = $i.$d;
551 }
552 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
553 ok ($x,$y);
554
6854fd01 555
f9a08e12 556 #############################################################################
557 # see if mul shortcut for small numbers works
394e6ffb 558
f9a08e12 559 $x = '9' x $bl;
560 $x = $class->new($x);
561 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
562 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
563}
61f5c3f5 564
394e6ffb 565###############################################################################
6854fd01 566# bug with rest "-0" in div, causing further div()s to fail
567
394e6ffb 568$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 569
61f5c3f5 570ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 571
79c55733 572###############################################################################
f9a08e12 573# bug in $x->bmod($y)
07d34614 574
f9a08e12 575# if $x < 0 and $y > 0
07d34614 576$x = $class->new('-629'); ok ($x->bmod(5033),4404);
577
578###############################################################################
56b9c951 579# bone/binf etc as plain calls (Lite failed them)
580
581ok ($class->bzero(),0);
582ok ($class->bone(),1);
583ok ($class->bone('+'),1);
584ok ($class->bone('-'),-1);
585ok ($class->bnan(),'NaN');
586ok ($class->binf(),'inf');
587ok ($class->binf('+'),'inf');
588ok ($class->binf('-'),'-inf');
589ok ($class->binf('-inf'),'-inf');
590
591###############################################################################
61f5c3f5 592# all tests done
6854fd01 593
5941;
595
596###############################################################################
61f5c3f5 597###############################################################################
6854fd01 598# Perl 5.005 does not like ok ($x,undef)
599
600sub ok_undef
601 {
602 my $x = shift;
603
604 ok (1,1) and return if !defined $x;
605 ok ($x,'undef');
606 }
607
608###############################################################################
609# sub to check validity of a BigInt internally, to ensure that no op leaves a
610# number object in an invalid state (f.i. "-0")
611
612sub is_valid
613 {
614 my ($x,$f) = @_;
615
616 my $e = 0; # error?
6854fd01 617
56b9c951 618 # allow the check to pass for all Lite, and all MBI and subclasses
619 # ok as reference?
620 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 621
56b9c951 622 if (ref($x) ne 'Math::BigInt::Lite')
623 {
624 # has ok sign?
625 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
626 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
627
628 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
629 $e = $CALC->_check($x->{value}) if $e eq '0';
630 }
6854fd01 631
632 # test done, see if error did crop up
633 ok (1,1), return if ($e eq '0');
634
027dc388 635 ok (1,$e." after op '$f'");
6854fd01 636 }
637
638__DATA__
027dc388 639&.=
6401234:-345:1234-345
641&+=
6421:2:3
643-1:-2:-3
644&-=
6451:2:-1
646-1:-2:1
647&*=
6482:3:6
649-1:5:-5
650&%=
651100:3:1
6528:9:8
07d34614 653-629:5033:4404
027dc388 654&/=
655100:3:33
656-8:2:-4
657&|=
6582:1:3
659&&=
6605:7:5
661&^=
6625:7:2
6854fd01 663&is_negative
6640:0
665-1:1
6661:0
667+inf:0
668-inf:1
669NaNneg:0
670&is_positive
6710:1
672-1:0
6731:1
674+inf:1
675-inf:0
676NaNneg:0
b3abae2a 677&is_int
678-inf:0
679+inf:0
680NaNis_int:0
6811:1
6820:1
683123e12:1
6854fd01 684&is_odd
685abc:0
6860:0
6871:1
6883:1
689-1:1
690-3:1
69110000001:1
69210000002:0
6932:0
b3abae2a 694120:0
695121:1
6854fd01 696&is_even
697abc:0
6980:1
6991:0
7003:0
701-1:0
702-3:0
70310000001:0
70410000002:1
7052:1
b3abae2a 706120:1
707121:0
6854fd01 708&bacmp
709+0:-0:0
710+0:+1:-1
711-1:+1:0
712+1:-1:0
713-1:+2:-1
714+2:-1:1
715-123456789:+987654321:-1
716+123456789:-987654321:-1
717+987654321:+123456789:1
718-987654321:+123456789:1
719-123:+4567889:-1
720# NaNs
721acmpNaN:123:
722123:acmpNaN:
723acmpNaN:acmpNaN:
724# infinity
725+inf:+inf:0
726-inf:-inf:0
727+inf:-inf:0
728-inf:+inf:0
729+inf:123:1
730-inf:123:1
731+inf:-123:1
732-inf:-123:1
733# return undef
734+inf:NaN:
735NaN:inf:
736-inf:NaN:
737NaN:-inf:
738&bnorm
739123:123
740# binary input
7410babc:NaN
7420b123:NaN
7430b0:0
744-0b0:0
745-0b1:-1
7460b0001:1
7470b001:1
7480b011:3
7490b101:5
61f5c3f5 7500b1001:9
7510b10001:17
7520b100001:33
7530b1000001:65
7540b10000001:129
7550b100000001:257
7560b1000000001:513
7570b10000000001:1025
7580b100000000001:2049
7590b1000000000001:4097
7600b10000000000001:8193
7610b100000000000001:16385
7620b1000000000000001:32769
7630b10000000000000001:65537
7640b100000000000000001:131073
7650b1000000000000000001:262145
7660b10000000000000000001:524289
7670b100000000000000000001:1048577
7680b1000000000000000000001:2097153
7690b10000000000000000000001:4194305
7700b100000000000000000000001:8388609
7710b1000000000000000000000001:16777217
7720b10000000000000000000000001:33554433
7730b100000000000000000000000001:67108865
7740b1000000000000000000000000001:134217729
7750b10000000000000000000000000001:268435457
7760b100000000000000000000000000001:536870913
7770b1000000000000000000000000000001:1073741825
7780b10000000000000000000000000000001:2147483649
7790b100000000000000000000000000000001:4294967297
7800b1000000000000000000000000000000001:8589934593
7810b10000000000000000000000000000000001:17179869185
6854fd01 7820b_101:NaN
7830b1_0_1:5
394e6ffb 7840b0_0_0_1:1
6854fd01 785# hex input
786-0x0:0
7870xabcdefgh:NaN
7880x1234:4660
7890xabcdef:11259375
790-0xABCDEF:-11259375
791-0x1234:-4660
7920x12345678:305419896
7930x1_2_3_4_56_78:305419896
394e6ffb 7940xa_b_c_d_e_f:11259375
6854fd01 7950x_123:NaN
61f5c3f5 7960x9:9
7970x11:17
7980x21:33
7990x41:65
8000x81:129
8010x101:257
8020x201:513
8030x401:1025
8040x801:2049
8050x1001:4097
8060x2001:8193
8070x4001:16385
8080x8001:32769
8090x10001:65537
8100x20001:131073
8110x40001:262145
8120x80001:524289
8130x100001:1048577
8140x200001:2097153
8150x400001:4194305
8160x800001:8388609
8170x1000001:16777217
8180x2000001:33554433
8190x4000001:67108865
8200x8000001:134217729
8210x10000001:268435457
8220x20000001:536870913
8230x40000001:1073741825
8240x80000001:2147483649
8250x100000001:4294967297
8260x200000001:8589934593
8270x400000001:17179869185
8280x800000001:34359738369
6854fd01 829# inf input
830inf:inf
831+inf:inf
832-inf:-inf
8330inf:NaN
027dc388 834# abnormal input
6854fd01 835:NaN
836abc:NaN
837 1 a:NaN
8381bcd2:NaN
83911111b:NaN
840+1z:NaN
841-1z:NaN
027dc388 842# only one underscore between two digits
843_123:NaN
844_123_:NaN
845123_:NaN
8461__23:NaN
8471E1__2:NaN
8481_E12:NaN
8491E_12:NaN
8501_E_12:NaN
851+_1E12:NaN
852+0_1E2:100
853+0_0_1E2:100
854-0_0_1E2:-100
855-0_0_1E+0_0_2:-100
856E1:NaN
857E23:NaN
8581.23E1:NaN
8591.23E-1:NaN
860# bug with two E's in number beeing valid
8611e2e3:NaN
8621e2r:NaN
8631e2.0:NaN
07d34614 864# bug with two '.' in number beeing valid
8651.2.2:NaN
8661.2.3e1:NaN
867-1.2.3:NaN
868-1.2.3e-4:NaN
8691.2e3.4:NaN
8701.2e-3.4:NaN
8711.2.3.4:NaN
8721.2.t:NaN
8731..2:NaN
8741..2e1:NaN
8751..2e1..1:NaN
87612e1..1:NaN
877..2:NaN
878.-2:NaN
61f5c3f5 879# leading zeros
880012:12
8810123:123
88201234:1234
883012345:12345
8840123456:123456
88501234567:1234567
886012345678:12345678
8870123456789:123456789
88801234567891:1234567891
889012345678912:12345678912
8900123456789123:123456789123
89101234567891234:1234567891234
027dc388 892# normal input
6854fd01 8930:0
894+0:0
895+00:0
896+000:0
897000000000000000000:0
898-0:0
899-0000:0
900+1:1
901+01:1
902+001:1
903+00000100000:100000
904123456789:123456789
905-1:-1
906-01:-1
907-001:-1
908-123456789:-123456789
909-00000100000:-100000
9101_2_3:123
6854fd01 91110000000000E-1_0:1
9121E2:100
9131E1:10
9141E0:1
6854fd01 9151.23E2:123
6854fd01 916100E-1:10
917# floating point input
027dc388 918# .2e2:20
9191.E3:1000
6854fd01 9201.01E2:101
9211010E-1:101
922-1010E0:-1010
923-1010E1:-10100
027dc388 9241234.00:1234
925# non-integer numbers
6854fd01 926-1010E-2:NaN
927-1.01E+1:NaN
928-1.01E-1:NaN
6854fd01 929&bnan
9301:NaN
9312:NaN
932abc:NaN
933&bone
61f5c3f5 9342:+:1
6854fd01 9352:-:-1
936boneNaN:-:-1
61f5c3f5 937boneNaN:+:1
9382:abc:1
9393::1
6854fd01 940&binf
9411:+:inf
9422:-:-inf
9433:abc:inf
027dc388 944&is_nan
945123:0
946abc:1
947NaN:1
948-123:0
6854fd01 949&is_inf
950+inf::1
951-inf::1
952abc::0
9531::0
954NaN::0
955-1::0
956+inf:-:0
957+inf:+:1
958-inf:-:1
959-inf:+:0
79c55733 960-inf:-inf:1
961-inf:+inf:0
962+inf:-inf:0
963+inf:+inf:1
6854fd01 964# it must be exactly /^[+-]inf$/
965+infinity::0
966-infinity::0
967&blsft
968abc:abc:NaN
61f5c3f5 969+2:+2:8
970+1:+32:4294967296
971+1:+48:281474976710656
6854fd01 972+8:-2:NaN
973# excercise base 10
974+12345:4:10:123450000
975-1234:0:10:-1234
61f5c3f5 976+1234:0:10:1234
6854fd01 977+2:2:10:200
978+12:2:10:1200
979+1234:-3:10:NaN
9801234567890123:12:10:1234567890123000000000000
b3abae2a 981-3:1:2:-6
982-5:1:2:-10
983-2:1:2:-4
984-102533203:1:2:-205066406
6854fd01 985&brsft
986abc:abc:NaN
61f5c3f5 987+8:+2:2
988+4294967296:+32:1
989+281474976710656:+48:1
6854fd01 990+2:-2:NaN
991# excercise base 10
992-1234:0:10:-1234
61f5c3f5 993+1234:0:10:1234
6854fd01 994+200:2:10:2
995+1234:3:10:1
996+1234:2:10:12
997+1234:-3:10:NaN
998310000:4:10:31
99912300000:5:10:123
10001230000000000:10:10:123
100109876123456789067890:12:10:9876123
10021234561234567890123:13:10:123456
b3abae2a 1003820265627:1:2:410132813
1004# test shifting negative numbers in base 2
1005-15:1:2:-8
1006-14:1:2:-7
1007-13:1:2:-7
1008-12:1:2:-6
1009-11:1:2:-6
1010-10:1:2:-5
1011-9:1:2:-5
1012-8:1:2:-4
1013-7:1:2:-4
1014-6:1:2:-3
1015-5:1:2:-3
1016-4:1:2:-2
1017-3:1:2:-2
1018-2:1:2:-1
1019-1:1:2:-1
1020-1640531254:2:2:-410132814
1021-1640531254:1:2:-820265627
1022-820265627:1:2:-410132814
1023-205066405:1:2:-102533203
6854fd01 1024&bsstr
10251e+34:1e+34
1026123.456E3:123456e+0
1027100:1e+2
1028abc:NaN
1029&bneg
1030bnegNaN:NaN
1031+inf:-inf
1032-inf:inf
1033abd:NaN
61f5c3f5 10340:0
10351:-1
1036-1:1
6854fd01 1037+123456789:-123456789
61f5c3f5 1038-123456789:123456789
6854fd01 1039&babs
1040babsNaN:NaN
1041+inf:inf
1042-inf:inf
61f5c3f5 10430:0
10441:1
1045-1:1
1046+123456789:123456789
1047-123456789:123456789
6854fd01 1048&bcmp
1049bcmpNaN:bcmpNaN:
61f5c3f5 1050bcmpNaN:0:
10510:bcmpNaN:
10520:0:0
1053-1:0:-1
10540:-1:1
10551:0:1
10560:1:-1
1057-1:1:-1
10581:-1:1
6854fd01 1059-1:-1:0
61f5c3f5 10601:1:0
1061123:123:0
1062123:12:1
106312:123:-1
6854fd01 1064-123:-123:0
1065-123:-12:-1
1066-12:-123:1
61f5c3f5 1067123:124:-1
1068124:123:1
6854fd01 1069-123:-124:1
1070-124:-123:-1
61f5c3f5 1071100:5:1
1072-123456789:987654321:-1
6854fd01 1073+123456789:-987654321:1
61f5c3f5 1074-987654321:123456789:-1
6854fd01 1075-inf:5432112345:-1
1076+inf:5432112345:1
1077-inf:-5432112345:-1
1078+inf:-5432112345:1
1079+inf:+inf:0
1080-inf:-inf:0
1081+inf:-inf:1
1082-inf:+inf:-1
10835:inf:-1
10845:inf:-1
1085-5:-inf:1
1086-5:-inf:1
1087# return undef
1088+inf:NaN:
1089NaN:inf:
1090-inf:NaN:
1091NaN:-inf:
1092&binc
1093abc:NaN
1094+inf:inf
1095-inf:-inf
61f5c3f5 1096+0:1
1097+1:2
1098-1:0
6854fd01 1099&bdec
1100abc:NaN
1101+inf:inf
1102-inf:-inf
1103+0:-1
61f5c3f5 1104+1:0
6854fd01 1105-1:-2
1106&badd
1107abc:abc:NaN
61f5c3f5 1108abc:0:NaN
6854fd01 1109+0:abc:NaN
b3abae2a 1110+inf:-inf:NaN
1111-inf:+inf:NaN
6854fd01 1112+inf:+inf:inf
1113-inf:-inf:-inf
1114baddNaN:+inf:NaN
1115baddNaN:+inf:NaN
1116+inf:baddNaN:NaN
1117-inf:baddNaN:NaN
61f5c3f5 11180:0:0
11191:0:1
11200:1:1
11211:1:2
1122-1:0:-1
11230:-1:-1
6854fd01 1124-1:-1:-2
61f5c3f5 1125-1:+1:0
1126+1:-1:0
1127+9:+1:10
1128+99:+1:100
1129+999:+1:1000
1130+9999:+1:10000
1131+99999:+1:100000
1132+999999:+1:1000000
1133+9999999:+1:10000000
1134+99999999:+1:100000000
1135+999999999:+1:1000000000
1136+9999999999:+1:10000000000
1137+99999999999:+1:100000000000
1138+10:-1:9
1139+100:-1:99
1140+1000:-1:999
1141+10000:-1:9999
1142+100000:-1:99999
1143+1000000:-1:999999
1144+10000000:-1:9999999
1145+100000000:-1:99999999
1146+1000000000:-1:999999999
1147+10000000000:-1:9999999999
1148+123456789:987654321:1111111110
1149-123456789:987654321:864197532
6854fd01 1150-123456789:-987654321:-1111111110
1151+123456789:-987654321:-864197532
56b9c951 1152-1:10001:10000
1153-1:100001:100000
1154-1:1000001:1000000
1155-1:10000001:10000000
1156-1:100000001:100000000
1157-1:1000000001:1000000000
1158-1:10000000001:10000000000
1159-1:100000000001:100000000000
1160-1:1000000000001:1000000000000
1161-1:10000000000001:10000000000000
1162-1:-10001:-10002
1163-1:-100001:-100002
1164-1:-1000001:-1000002
1165-1:-10000001:-10000002
1166-1:-100000001:-100000002
1167-1:-1000000001:-1000000002
1168-1:-10000000001:-10000000002
1169-1:-100000000001:-100000000002
1170-1:-1000000000001:-1000000000002
1171-1:-10000000000001:-10000000000002
6854fd01 1172&bsub
1173abc:abc:NaN
1174abc:+0:NaN
1175+0:abc:NaN
1176+inf:-inf:inf
1177-inf:+inf:-inf
b3abae2a 1178+inf:+inf:NaN
1179-inf:-inf:NaN
61f5c3f5 1180+0:+0:0
1181+1:+0:1
6854fd01 1182+0:+1:-1
61f5c3f5 1183+1:+1:0
6854fd01 1184-1:+0:-1
61f5c3f5 1185+0:-1:1
1186-1:-1:0
6854fd01 1187-1:+1:-2
61f5c3f5 1188+1:-1:2
1189+9:+1:8
1190+99:+1:98
1191+999:+1:998
1192+9999:+1:9998
1193+99999:+1:99998
1194+999999:+1:999998
1195+9999999:+1:9999998
1196+99999999:+1:99999998
1197+999999999:+1:999999998
1198+9999999999:+1:9999999998
1199+99999999999:+1:99999999998
1200+10:-1:11
1201+100:-1:101
1202+1000:-1:1001
1203+10000:-1:10001
1204+100000:-1:100001
1205+1000000:-1:1000001
1206+10000000:-1:10000001
1207+100000000:-1:100000001
1208+1000000000:-1:1000000001
1209+10000000000:-1:10000000001
6854fd01 1210+123456789:+987654321:-864197532
1211-123456789:+987654321:-1111111110
61f5c3f5 1212-123456789:-987654321:864197532
1213+123456789:-987654321:1111111110
56b9c951 121410001:1:10000
1215100001:1:100000
12161000001:1:1000000
121710000001:1:10000000
1218100000001:1:100000000
12191000000001:1:1000000000
122010000000001:1:10000000000
1221100000000001:1:100000000000
12221000000000001:1:1000000000000
122310000000000001:1:10000000000000
122410001:-1:10002
1225100001:-1:100002
12261000001:-1:1000002
122710000001:-1:10000002
1228100000001:-1:100000002
12291000000001:-1:1000000002
123010000000001:-1:10000000002
1231100000000001:-1:100000000002
12321000000000001:-1:1000000000002
123310000000000001:-1:10000000000002
6854fd01 1234&bmul
1235abc:abc:NaN
1236abc:+0:NaN
1237+0:abc:NaN
1238NaNmul:+inf:NaN
1239NaNmul:-inf:NaN
1240-inf:NaNmul:NaN
1241+inf:NaNmul:NaN
1242+inf:+inf:inf
1243+inf:-inf:-inf
1244-inf:+inf:-inf
1245-inf:-inf:inf
61f5c3f5 1246+0:+0:0
1247+0:+1:0
1248+1:+0:0
1249+0:-1:0
1250-1:+0:0
1251123456789123456789:0:0
12520:123456789123456789:0
1253-1:-1:1
6854fd01 1254-1:+1:-1
1255+1:-1:-1
61f5c3f5 1256+1:+1:1
1257+2:+3:6
6854fd01 1258-2:+3:-6
1259+2:-3:-6
61f5c3f5 1260-2:-3:6
1261111:111:12321
126210101:10101:102030201
12631001001:1001001:1002003002001
1264100010001:100010001:10002000300020001
126510000100001:10000100001:100002000030000200001
126611111111111:9:99999999999
126722222222222:9:199999999998
126833333333333:9:299999999997
126944444444444:9:399999999996
127055555555555:9:499999999995
127166666666666:9:599999999994
127277777777777:9:699999999993
127388888888888:9:799999999992
127499999999999:9:899999999991
1275+25:+25:625
1276+12345:+12345:152399025
1277+99999:+11111:1111088889
6854fd01 12789999:10000:99990000
127999999:100000:9999900000
1280999999:1000000:999999000000
12819999999:10000000:99999990000000
128299999999:100000000:9999999900000000
1283999999999:1000000000:999999999000000000
12849999999999:10000000000:99999999990000000000
128599999999999:100000000000:9999999999900000000000
1286999999999999:1000000000000:999999999999000000000000
12879999999999999:10000000000000:99999999999990000000000000
128899999999999999:100000000000000:9999999999999900000000000000
1289999999999999999:1000000000000000:999999999999999000000000000000
12909999999999999999:10000000000000000:99999999999999990000000000000000
129199999999999999999:100000000000000000:9999999999999999900000000000000000
1292999999999999999999:1000000000000000000:999999999999999999000000000000000000
12939999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1294&bdiv-list
1295100:20:5,0
12964095:4095:1,0
1297-4095:-4095:1,0
12984095:-4095:-1,0
1299-4095:4095:-1,0
1300123:2:61,1
b3abae2a 13019:5:1,4
13029:4:2,1
6854fd01 1303# inf handling and general remainder
13045:8:0,5
13050:8:0,0
130611:2:5,1
130711:-2:-5,-1
1308-11:2:-5,1
1309# see table in documentation in MBI
13100:inf:0,0
13110:-inf:0,0
13125:inf:0,5
13135:-inf:0,5
1314-5:inf:0,-5
1315-5:-inf:0,-5
1316inf:5:inf,0
1317-inf:5:-inf,0
1318inf:-5:-inf,0
1319-inf:-5:inf,0
13205:5:1,0
1321-5:-5:1,0
b3abae2a 1322inf:inf:NaN,NaN
1323-inf:-inf:NaN,NaN
1324-inf:inf:NaN,NaN
1325inf:-inf:NaN,NaN
6854fd01 13268:0:inf,8
1327inf:0:inf,inf
1328# exceptions to reminder rule
1329-8:0:-inf,-8
1330-inf:0:-inf,-inf
13310:0:NaN,NaN
1332&bdiv
1333abc:abc:NaN
61f5c3f5 1334abc:1:NaN
13351:abc:NaN
13360:0:NaN
6854fd01 1337# inf handling (see table in doc)
13380:inf:0
13390:-inf:0
13405:inf:0
13415:-inf:0
1342-5:inf:0
1343-5:-inf:0
1344inf:5:inf
1345-inf:5:-inf
1346inf:-5:-inf
1347-inf:-5:inf
13485:5:1
1349-5:-5:1
b3abae2a 1350inf:inf:NaN
1351-inf:-inf:NaN
1352-inf:inf:NaN
1353inf:-inf:NaN
6854fd01 13548:0:inf
1355inf:0:inf
1356-8:0:-inf
1357-inf:0:-inf
13580:0:NaN
135911:2:5
1360-11:-2:5
1361-11:2:-5
136211:-2:-5
61f5c3f5 13630:1:0
13640:-1:0
13651:1:1
1366-1:-1:1
13671:-1:-1
1368-1:1:-1
13691:2:0
13702:1:2
13711:26:0
13721000000000:9:111111111
13732000000000:9:222222222
13743000000000:9:333333333
13754000000000:9:444444444
13765000000000:9:555555555
13776000000000:9:666666666
13787000000000:9:777777777
13798000000000:9:888888888
13809000000000:9:1000000000
138135500000:113:314159
138271000000:226:314159
1383106500000:339:314159
13841000000000:3:333333333
1385+10:+5:2
1386+100:+4:25
1387+1000:+8:125
1388+10000:+16:625
1389999999999999:9:111111111111
1390999999999999:99:10101010101
1391999999999999:999:1001001001
1392999999999999:9999:100010001
1393999999999999999:99999:10000100001
1394+1111088889:99999:11111
6854fd01 1395-5:-3:1
1396-5:3:-1
13974:3:1
13984:-3:-1
13991:3:0
14001:-3:0
1401-2:-3:0
1402-2:3:0
14038:3:2
1404-8:3:-2
140514:-3:-4
1406-14:3:-4
1407-14:-3:4
140814:3:4
1409# bug in Calc with '99999' vs $BASE-1
141010000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
07d34614 1411&bmodinv
1412# format: number:modulus:result
1413# bmodinv Data errors
1414abc:abc:NaN
1415abc:5:NaN
14165:abc:NaN
1417# bmodinv Expected Results from normal use
14181:5:1
14193:5:2
1420-2:5:2
14218:5033:4404
1422324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1423## bmodinv Error cases / useless use of function
07d34614 14243:-5:NaN
1425inf:5:NaN
1ddff52a 14265:inf:NaN
1427-inf:5:NaN
14285:-inf:NaN
07d34614 1429&bmodpow
1430# format: number:exponent:modulus:result
1431# bmodpow Data errors
1432abc:abc:abc:NaN
14335:abc:abc:NaN
1434abc:5:abc:NaN
1435abc:abc:5:NaN
14365:5:abc:NaN
14375:abc:5:NaN
1438abc:5:5:NaN
1439# bmodpow Expected results
14400:0:2:1
14411:0:2:1
14420:0:1:0
14438:7:5032:3840
14448:-1:5033:4404
144598436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1446# bmodpow Error cases
14478:8:-5:NaN
14488:-1:16:NaN
1449inf:5:13:NaN
14505:inf:13:NaN
6854fd01 1451&bmod
1452# inf handling, see table in doc
14530:inf:0
14540:-inf:0
14555:inf:5
14565:-inf:5
1457-5:inf:-5
1458-5:-inf:-5
1459inf:5:0
1460-inf:5:0
1461inf:-5:0
1462-inf:-5:0
14635:5:0
1464-5:-5:0
b3abae2a 1465inf:inf:NaN
1466-inf:-inf:NaN
1467-inf:inf:NaN
1468inf:-inf:NaN
6854fd01 14698:0:8
1470inf:0:inf
1471# exceptions to reminder rule
1472-inf:0:-inf
1473-8:0:-8
14740:0:NaN
1475abc:abc:NaN
61f5c3f5 1476abc:1:abc:NaN
14771:abc:NaN
14780:0:NaN
14790:1:0
14801:0:1
14810:-1:0
1482-1:0:-1
14831:1:0
1484-1:-1:0
14851:-1:0
1486-1:1:0
14871:2:1
14882:1:0
14891000000000:9:1
14902000000000:9:2
14913000000000:9:3
14924000000000:9:4
14935000000000:9:5
14946000000000:9:6
14957000000000:9:7
14968000000000:9:8
14979000000000:9:0
149835500000:113:33
149971000000:226:66
1500106500000:339:99
15011000000000:3:1
150210:5:0
1503100:4:0
15041000:8:0
150510000:16:0
1506999999999999:9:0
1507999999999999:99:0
1508999999999999:999:0
1509999999999999:9999:0
1510999999999999999:99999:0
1511-9:+5:1
6854fd01 1512+9:-5:-1
1513-9:-5:-4
1514-5:3:1
1515-2:3:1
15164:3:1
15171:3:1
1518-5:-3:-2
1519-2:-3:-2
15204:-3:-2
15211:-3:-2
15224095:4095:0
027dc388 1523100041000510123:3:0
1524152403346:12345:4321
b3abae2a 15259:5:4
28df3e88 1526# test shortcuts in Calc
1527# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
15281234:9:1
1529123456:9:3
153012345678:9:0
15311234567891:9:1
1532123456789123:9:6
153312345678912345:9:6
15341234567891234567:9:1
1535123456789123456789:9:0
15361234:10:4
1537123456:10:6
153812345678:10:8
15391234567891:10:1
1540123456789123:10:3
154112345678912345:10:5
15421234567891234567:10:7
1543123456789123456789:10:9
15441234:113:104
1545123456:113:60
154612345678:113:89
15471234567891:113:64
1548123456789123:113:95
154912345678912345:113:53
15501234567891234567:113:56
1551123456789123456789:113:39
07d34614 1552# bug in bmod() not modifying the variable in place
1553-629:5033:4404
6854fd01 1554&bgcd
1555abc:abc:NaN
1556abc:+0:NaN
1557+0:abc:NaN
61f5c3f5 1558+0:+0:0
1559+0:+1:1
1560+1:+0:1
1561+1:+1:1
1562+2:+3:1
1563+3:+2:1
1564-3:+2:1
1565100:625:25
15664096:81:1
15671034:804:2
156827:90:56:1
156927:90:54:9
6854fd01 1570&blcm
1571abc:abc:NaN
1572abc:+0:NaN
1573+0:abc:NaN
1574+0:+0:NaN
61f5c3f5 1575+1:+0:0
1576+0:+1:0
1577+27:+90:270
1578+1034:+804:415668
6854fd01 1579&band
1580abc:abc:NaN
1581abc:0:NaN
15820:abc:NaN
15831:2:0
15843:2:2
61f5c3f5 1585+8:+2:0
1586+281474976710656:0:0
1587+281474976710656:1:0
1588+281474976710656:+281474976710656:281474976710656
6854fd01 1589-2:-3:-4
1590-1:-1:-1
1591-6:-6:-6
1592-7:-4:-8
1593-7:4:0
1594-4:7:4
394e6ffb 1595# equal arguments are treated special, so also do some test with unequal ones
15960xFFFF:0xFFFF:0x0xFFFF
15970xFFFFFF:0xFFFFFF:0x0xFFFFFF
15980xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
15990xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
16000xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
16010xF0F0:0xF0F0:0x0xF0F0
16020x0F0F:0x0F0F:0x0x0F0F
16030xF0F0F0:0xF0F0F0:0x0xF0F0F0
16040x0F0F0F:0x0F0F0F:0x0x0F0F0F
16050xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
16060x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
16070xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
16080x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
16090xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
16100x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
16110x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1612&bior
1613abc:abc:NaN
1614abc:0:NaN
16150:abc:NaN
16161:2:3
61f5c3f5 1617+8:+2:10
1618+281474976710656:0:281474976710656
1619+281474976710656:1:281474976710657
1620+281474976710656:281474976710656:281474976710656
6854fd01 1621-2:-3:-1
1622-1:-1:-1
1623-6:-6:-6
1624-7:4:-3
1625-4:7:-1
394e6ffb 1626# equal arguments are treated special, so also do some test with unequal ones
16270xFFFF:0xFFFF:0x0xFFFF
16280xFFFFFF:0xFFFFFF:0x0xFFFFFF
16290xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
16300xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
16310xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
16320:0xFFFF:0x0xFFFF
16330:0xFFFFFF:0x0xFFFFFF
16340:0xFFFFFFFF:0x0xFFFFFFFF
16350:0xFFFFFFFFFF:0x0xFFFFFFFFFF
16360:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
16370xFFFF:0:0x0xFFFF
16380xFFFFFF:0:0x0xFFFFFF
16390xFFFFFFFF:0:0x0xFFFFFFFF
16400xFFFFFFFFFF:0:0x0xFFFFFFFFFF
16410xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
16420xF0F0:0xF0F0:0x0xF0F0
16430x0F0F:0x0F0F:0x0x0F0F
16440xF0F0:0x0F0F:0x0xFFFF
16450xF0F0F0:0xF0F0F0:0x0xF0F0F0
16460x0F0F0F:0x0F0F0F:0x0x0F0F0F
16470x0F0F0F:0xF0F0F0:0x0xFFFFFF
16480xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
16490x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
16500x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
16510xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
16520x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
16530x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
16540xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
16550x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
16560x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
16570x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1658&bxor
1659abc:abc:NaN
1660abc:0:NaN
16610:abc:NaN
16621:2:3
61f5c3f5 1663+8:+2:10
1664+281474976710656:0:281474976710656
1665+281474976710656:1:281474976710657
1666+281474976710656:281474976710656:0
6854fd01 1667-2:-3:3
1668-1:-1:0
1669-6:-6:0
1670-7:4:-3
1671-4:7:-5
16724:-7:-3
1673-4:-7:5
394e6ffb 1674# equal arguments are treated special, so also do some test with unequal ones
16750xFFFF:0xFFFF:0
16760xFFFFFF:0xFFFFFF:0
16770xFFFFFFFF:0xFFFFFFFF:0
16780xFFFFFFFFFF:0xFFFFFFFFFF:0
16790xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
16800:0xFFFF:0x0xFFFF
16810:0xFFFFFF:0x0xFFFFFF
16820:0xFFFFFFFF:0x0xFFFFFFFF
16830:0xFFFFFFFFFF:0x0xFFFFFFFFFF
16840:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
16850xFFFF:0:0x0xFFFF
16860xFFFFFF:0:0x0xFFFFFF
16870xFFFFFFFF:0:0x0xFFFFFFFF
16880xFFFFFFFFFF:0:0x0xFFFFFFFFFF
16890xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
16900xF0F0:0xF0F0:0
16910x0F0F:0x0F0F:0
16920xF0F0:0x0F0F:0x0xFFFF
16930xF0F0F0:0xF0F0F0:0
16940x0F0F0F:0x0F0F0F:0
16950x0F0F0F:0xF0F0F0:0x0xFFFFFF
16960xF0F0F0F0:0xF0F0F0F0:0
16970x0F0F0F0F:0x0F0F0F0F:0
16980x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
16990xF0F0F0F0F0:0xF0F0F0F0F0:0
17000x0F0F0F0F0F:0x0F0F0F0F0F:0
17010x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
17020xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
17030x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
17040x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1705&bnot
1706abc:NaN
1707+0:-1
1708+8:-9
1709+281474976710656:-281474976710657
1710-1:0
1711-2:1
1712-12:11
1713&digit
17140:0:0
171512:0:2
171612:1:1
1717123:0:3
1718123:1:2
1719123:2:1
1720123:-1:1
1721123:-2:2
1722123:-3:3
1723123456:0:6
1724123456:1:5
1725123456:2:4
1726123456:3:3
1727123456:4:2
1728123456:5:1
1729123456:-1:1
1730123456:-2:2
1731123456:-3:3
1732100000:-3:0
1733100000:0:0
1734100000:1:0
1735&mantissa
1736abc:NaN
17371e4:1
17382e0:2
1739123:123
1740-1:-1
1741-2:-2
1742+inf:inf
1743-inf:-inf
1744&exponent
1745abc:NaN
17461e4:4
17472e0:0
1748123:0
1749-1:0
1750-2:0
17510:1
1752+inf:inf
1753-inf:inf
1754&parts
1755abc:NaN,NaN
17561e4:1,4
17572e0:2,0
1758123:123,0
1759-1:-1,0
1760-2:-2,0
17610:0,1
1762+inf:inf,inf
1763-inf:-inf,inf
b3abae2a 1764&bfac
1765-1:NaN
1766NaNfac:NaN
1767+inf:NaN
1768-inf:NaN
17690:1
17701:1
17712:2
17723:6
17734:24
17745:120
17756:720
177610:3628800
177711:39916800
177812:479001600
6854fd01 1779&bpow
1780abc:12:NaN
178112:abc:NaN
17820:0:1
17830:1:0
17840:2:0
17850:-1:NaN
17860:-2:NaN
17871:0:1
17881:1:1
17891:2:1
17901:3:1
17911:-1:1
17921:-2:1
17931:-3:1
17942:0:1
17952:1:2
17962:2:4
17972:3:8
17983:3:27
17992:-1:NaN
1800-2:-1:NaN
18012:-2:NaN
1802-2:-2:NaN
1803+inf:1234500012:inf
1804-inf:1234500012:-inf
1805+inf:-12345000123:inf
1806-inf:-12345000123:-inf
1807# 1 ** -x => 1 / (1 ** x)
1808-1:0:1
1809-2:0:1
1810-1:1:-1
1811-1:2:1
1812-1:3:-1
1813-1:4:1
1814-1:5:-1
1815-1:-1:-1
1816-1:-2:1
1817-1:-3:-1
1818-1:-4:1
181910:2:100
182010:3:1000
182110:4:10000
182210:5:100000
182310:6:1000000
182410:7:10000000
182510:8:100000000
182610:9:1000000000
182710:20:100000000000000000000
1828123456:2:15241383936
1829&length
1830100:3
183110:2
18321:1
18330:1
183412345:5
183510000000000000000:17
1836-123:3
1837215960156869840440586892398248:30
1838&bsqrt
394e6ffb 1839145:12
6854fd01 1840144:12
394e6ffb 1841143:11
6854fd01 184216:4
394e6ffb 1843170:13
1844169:13
1845168:12
6854fd01 18464:2
394e6ffb 18473:1
6854fd01 18482:1
394e6ffb 18499:3
6854fd01 185012:3
1851256:16
1852100000000:10000
18534000000000000:2000000
394e6ffb 1854152399026:12345
1855152399025:12345
1856152399024:12344
6854fd01 18571:1
18580:0
1859-2:NaN
394e6ffb 1860-123:NaN
6854fd01 1861Nan:NaN
394e6ffb 1862+inf:NaN
6854fd01 1863&bround
1864$round_mode('trunc')
18650:12:0
1866NaNbround:12:NaN
1867+inf:12:inf
1868-inf:12:-inf
18691234:0:1234
18701234:2:1200
1871123456:4:123400
1872123456:5:123450
1873123456:6:123456
61f5c3f5 1874+10123456789:5:10123000000
6854fd01 1875-10123456789:5:-10123000000
61f5c3f5 1876+10123456789:9:10123456700
6854fd01 1877-10123456789:9:-10123456700
61f5c3f5 1878+101234500:6:101234000
6854fd01 1879-101234500:6:-101234000
61f5c3f5 1880#+101234500:-4:101234000
6854fd01 1881#-101234500:-4:-101234000
1882$round_mode('zero')
61f5c3f5 1883+20123456789:5:20123000000
6854fd01 1884-20123456789:5:-20123000000
61f5c3f5 1885+20123456789:9:20123456800
6854fd01 1886-20123456789:9:-20123456800
61f5c3f5 1887+201234500:6:201234000
6854fd01 1888-201234500:6:-201234000
61f5c3f5 1889#+201234500:-4:201234000
6854fd01 1890#-201234500:-4:-201234000
1891+12345000:4:12340000
1892-12345000:4:-12340000
1893$round_mode('+inf')
61f5c3f5 1894+30123456789:5:30123000000
6854fd01 1895-30123456789:5:-30123000000
61f5c3f5 1896+30123456789:9:30123456800
6854fd01 1897-30123456789:9:-30123456800
61f5c3f5 1898+301234500:6:301235000
6854fd01 1899-301234500:6:-301234000
61f5c3f5 1900#+301234500:-4:301235000
6854fd01 1901#-301234500:-4:-301234000
1902+12345000:4:12350000
1903-12345000:4:-12340000
1904$round_mode('-inf')
61f5c3f5 1905+40123456789:5:40123000000
6854fd01 1906-40123456789:5:-40123000000
61f5c3f5 1907+40123456789:9:40123456800
6854fd01 1908-40123456789:9:-40123456800
61f5c3f5 1909+401234500:6:401234000
1910+401234500:6:401234000
6854fd01 1911#-401234500:-4:-401235000
1912#-401234500:-4:-401235000
1913+12345000:4:12340000
1914-12345000:4:-12350000
1915$round_mode('odd')
61f5c3f5 1916+50123456789:5:50123000000
6854fd01 1917-50123456789:5:-50123000000
61f5c3f5 1918+50123456789:9:50123456800
6854fd01 1919-50123456789:9:-50123456800
61f5c3f5 1920+501234500:6:501235000
6854fd01 1921-501234500:6:-501235000
61f5c3f5 1922#+501234500:-4:501235000
6854fd01 1923#-501234500:-4:-501235000
1924+12345000:4:12350000
1925-12345000:4:-12350000
1926$round_mode('even')
61f5c3f5 1927+60123456789:5:60123000000
6854fd01 1928-60123456789:5:-60123000000
61f5c3f5 1929+60123456789:9:60123456800
6854fd01 1930-60123456789:9:-60123456800
61f5c3f5 1931+601234500:6:601234000
6854fd01 1932-601234500:6:-601234000
61f5c3f5 1933#+601234500:-4:601234000
6854fd01 1934#-601234500:-4:-601234000
1935#-601234500:-9:0
1936#-501234500:-9:0
1937#-601234500:-8:0
1938#-501234500:-8:0
1939+1234567:7:1234567
1940+1234567:6:1234570
1941+12345000:4:12340000
1942-12345000:4:-12340000
1943&is_zero
19440:1
1945NaNzero:0
1946+inf:0
1947-inf:0
1948123:0
1949-1:0
19501:0
1951&is_one
19520:0
1953NaNone:0
1954+inf:0
1955-inf:0
19561:1
19572:0
1958-1:0
1959-2:0
1960# floor and ceil tests are pretty pointless in integer space...but play safe
1961&bfloor
19620:0
1963NaNfloor:NaN
1964+inf:inf
1965-inf:-inf
1966-1:-1
1967-2:-2
19682:2
19693:3
1970abc:NaN
1971&bceil
1972NaNceil:NaN
1973+inf:inf
1974-inf:-inf
19750:0
1976-1:-1
1977-2:-2
19782:2
19793:3
1980abc:NaN
1981&as_hex
1982128:0x80
1983-128:-0x80
19840:0x0
1985-0:0x0
19861:0x1
19870x123456789123456789:0x123456789123456789
1988+inf:inf
1989-inf:-inf
1990NaNas_hex:NaN
1991&as_bin
1992128:0b10000000
1993-128:-0b10000000
19940:0b0
1995-0:0b0
19961:0b1
19970b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 19980x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 1999+inf:inf
2000-inf:-inf
2001NaNas_bin:NaN