This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #85334] Document actual behaviour of from_xxx() methods.
[perl5.git] / dist / Math-BigInt / t / bigintpm.inc
CommitLineData
6854fd01
JH
1#include this file into another for subclass testing
2
3my $version = ${"$class\::VERSION"};
4
56d9de68
T
5use strict;
6
6854fd01
JH
7##############################################################################
8# for testing inheritance of _swap
9
10package Math::Foo;
11
61f5c3f5 12use Math::BigInt lib => $main::CL;
6854fd01
JH
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
3167abe5 39my $CALC = $class->config()->{lib}; is ($CALC,$CL);
6854fd01 40
b3abae2a 41my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
6854fd01
JH
42
43while (<DATA>)
44 {
f7f86b73 45 $_ =~ s/[\n\r]//g; # remove newlines
6854fd01
JH
46 next if /^#/; # skip comments
47 if (s/^&//)
48 {
61f5c3f5 49 $f = $_; next;
6854fd01
JH
50 }
51 elsif (/^\$/)
52 {
61f5c3f5 53 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
6854fd01 54 }
61f5c3f5
T
55
56 @args = split(/:/,$_,99); $ans = pop(@args);
b3abae2a
JH
57 $expected_class = $class;
58 if ($ans =~ /(.*?)=(.*)/)
59 {
60 $expected_class = $2; $ans = $1;
61 }
61f5c3f5
T
62 $try = "\$x = $class->new(\"$args[0]\");";
63 if ($f eq "bnorm")
6854fd01 64 {
61f5c3f5
T
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
T
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
T
78 } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
79 $try .= "\$x->$f();";
61f5c3f5
T
80 } elsif ($f eq "exponent"){
81 # ->bstr() to see if an object is returned
82 $try .= '$x = $x->exponent()->bstr();';
83 } elsif ($f eq "mantissa"){
84 # ->bstr() to see if an object is returned
85 $try .= '$x = $x->mantissa()->bstr();';
86 } elsif ($f eq "parts"){
87 $try .= '($m,$e) = $x->parts();';
88 # ->bstr() to see if an object is returned
89 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
90 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
91 $try .= '"$m,$e";';
50109ad0
RGS
92 }elsif ($f eq "bexp"){
93 $try .= "\$x->bexp();";
fdb4b05f
T
94 } elsif ($f eq "bpi"){
95 $try .= "$class\->bpi(\$x);";
61f5c3f5 96 } else {
56d9de68 97 # binary ops
61f5c3f5
T
98 $try .= "\$y = $class->new('$args[1]');";
99 if ($f eq "bcmp")
100 {
a0ac753d 101 $try .= '$x->bcmp($y);';
61f5c3f5 102 } elsif ($f eq "bround") {
6854fd01 103 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5
T
104 } elsif ($f eq "bacmp"){
105 $try .= '$x->bacmp($y);';
106 } elsif ($f eq "badd"){
107 $try .= '$x + $y;';
108 } elsif ($f eq "bsub"){
109 $try .= '$x - $y;';
110 } elsif ($f eq "bmul"){
111 $try .= '$x * $y;';
112 } elsif ($f eq "bdiv"){
113 $try .= '$x / $y;';
114 } elsif ($f eq "bdiv-list"){
115 $try .= 'join (",",$x->bdiv($y));';
027dc388 116 # overload via x=
61f5c3f5
T
117 } elsif ($f =~ /^.=$/){
118 $try .= "\$x $f \$y;";
027dc388 119 # overload via x
61f5c3f5
T
120 } elsif ($f =~ /^.$/){
121 $try .= "\$x $f \$y;";
122 } elsif ($f eq "bmod"){
123 $try .= '$x % $y;';
124 } elsif ($f eq "bgcd")
6854fd01
JH
125 {
126 if (defined $args[2])
127 {
61f5c3f5 128 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01
JH
129 }
130 $try .= "$class\::bgcd(\$x, \$y";
131 $try .= ", \$z" if (defined $args[2]);
132 $try .= " );";
133 }
134 elsif ($f eq "blcm")
135 {
136 if (defined $args[2])
137 {
61f5c3f5 138 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01
JH
139 }
140 $try .= "$class\::blcm(\$x, \$y";
141 $try .= ", \$z" if (defined $args[2]);
142 $try .= " );";
143 }elsif ($f eq "blsft"){
144 if (defined $args[2])
145 {
146 $try .= "\$x->blsft(\$y,$args[2]);";
147 }
148 else
149 {
150 $try .= "\$x << \$y;";
151 }
152 }elsif ($f eq "brsft"){
153 if (defined $args[2])
154 {
155 $try .= "\$x->brsft(\$y,$args[2]);";
156 }
157 else
158 {
159 $try .= "\$x >> \$y;";
160 }
50109ad0
RGS
161 }elsif ($f eq "bnok"){
162 $try .= "\$x->bnok(\$y);";
990fb837
RGS
163 }elsif ($f eq "broot"){
164 $try .= "\$x->broot(\$y);";
091c87b1
T
165 }elsif ($f eq "blog"){
166 $try .= "\$x->blog(\$y);";
6854fd01
JH
167 }elsif ($f eq "band"){
168 $try .= "\$x & \$y;";
169 }elsif ($f eq "bior"){
170 $try .= "\$x | \$y;";
171 }elsif ($f eq "bxor"){
172 $try .= "\$x ^ \$y;";
173 }elsif ($f eq "bpow"){
174 $try .= "\$x ** \$y;";
d614cd8b
JH
175 } elsif( $f eq "bmodinv") {
176 $try .= "\$x->bmodinv(\$y);";
6854fd01 177 }elsif ($f eq "digit"){
56b9c951 178 $try .= "\$x->digit(\$y);";
30afc38d
T
179 }elsif ($f eq "batan2"){
180 $try .= "\$x->batan2(\$y);";
d614cd8b 181 } else {
80365507 182 # Functions with three arguments
d614cd8b
JH
183 $try .= "\$z = $class->new(\"$args[2]\");";
184
d614cd8b
JH
185 if( $f eq "bmodpow") {
186 $try .= "\$x->bmodpow(\$y,\$z);";
80365507
T
187 } elsif ($f eq "bmuladd"){
188 $try .= "\$x->bmuladd(\$y,\$z);";
d614cd8b
JH
189 } else { warn "Unknown op '$f'"; }
190 }
61f5c3f5
T
191 } # end else all other ops
192
193 $ans1 = eval $try;
194 # convert hex/binary targets to decimal
195 if ($ans =~ /^(0x0x|0b0b)/)
196 {
197 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 198 }
61f5c3f5
T
199 if ($ans eq "")
200 {
3167abe5 201 is ($ans1, undef);
61f5c3f5
T
202 }
203 else
204 {
205 # print "try: $try ans: $ans1 $ans\n";
3167abe5
NC
206 print "# Tried: '$try'\n" if !is ($ans1, $ans);
207 is (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 208 }
61f5c3f5
T
209 # check internal state of number objects
210 is_valid($ans1,$f) if ref $ans1;
6854fd01
JH
211 } # endwhile data tests
212close DATA;
213
214# test some more
215@a = ();
216for (my $i = 1; $i < 10; $i++)
217 {
218 push @a, $i;
219 }
3167abe5 220is("@a", "1 2 3 4 5 6 7 8 9");
6854fd01
JH
221
222# test whether self-multiplication works correctly (result is 2**64)
223$try = "\$x = $class->new('4294967296');";
224$try .= '$a = $x->bmul($x);';
225$ans1 = eval $try;
3167abe5 226print "# Tried: '$try'\n" if !is ($ans1, $class->new(2) ** 64);
6854fd01
JH
227# test self-pow
228$try = "\$x = $class->new(10);";
229$try .= '$a = $x->bpow($x);';
230$ans1 = eval $try;
3167abe5 231print "# Tried: '$try'\n" if !is ($ans1, $class->new(10) ** 10);
6854fd01 232
07d34614 233###############################################################################
6854fd01
JH
234# test whether op destroys args or not (should better not)
235
236$x = $class->new(3);
237$y = $class->new(4);
238$z = $x & $y;
3167abe5
NC
239is ($x,3);
240is ($y,4);
241is ($z,0);
6854fd01 242$z = $x | $y;
3167abe5
NC
243is ($x,3);
244is ($y,4);
245is ($z,7);
6854fd01
JH
246$x = $class->new(1);
247$y = $class->new(2);
248$z = $x | $y;
3167abe5
NC
249is ($x,1);
250is ($y,2);
251is ($z,3);
6854fd01
JH
252
253$x = $class->new(5);
254$y = $class->new(4);
255$z = $x ^ $y;
3167abe5
NC
256is ($x,5);
257is ($y,4);
258is ($z,1);
6854fd01
JH
259
260$x = $class->new(-5); $y = -$x;
3167abe5 261is ($x, -5);
6854fd01
JH
262
263$x = $class->new(-5); $y = abs($x);
3167abe5 264is ($x, -5);
6854fd01 265
07d34614
T
266$x = $class->new(8);
267$y = $class->new(-1);
268$z = $class->new(5033);
269my $u = $x->copy()->bmodpow($y,$z);
3167abe5
NC
270is ($u,4404);
271is ($y,-1);
272is ($z,5033);
273
274$x = $class->new(-5); $y = -$x; is ($x,-5); is ($y,5);
275$x = $class->new(-5); $y = $x->copy()->bneg(); is ($x,-5); is ($y,5);
276
277$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); is ($x,-15); is ($y,3);
278$x = $class->new(-5); $y = $class->new(3); $x->badd($y); is ($x,-2); is ($y,3);
279$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); is ($x,-8); is ($y,3);
280$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); is ($x,-5); is ($y,3);
281$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); is ($x,1); is ($y,3);
282
283$x = $class->new(5); $y = $class->new(3); $x->bmul($y); is ($x,15); is ($y,3);
284$x = $class->new(5); $y = $class->new(3); $x->badd($y); is ($x,8); is ($y,3);
285$x = $class->new(5); $y = $class->new(3); $x->bsub($y); is ($x,2); is ($y,3);
286$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); is ($x,5); is ($y,3);
287$x = $class->new(5); $y = $class->new(3); $x->bmod($y); is ($x,2); is ($y,3);
288
289$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); is ($x,-15); is ($y,-3);
290$x = $class->new(5); $y = $class->new(-3); $x->badd($y); is ($x,2); is ($y,-3);
291$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); is ($x,8); is ($y,-3);
292$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); is ($x,-5); is ($y,-3);
293$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); is ($x,-1); is ($y,-3);
07d34614
T
294
295###############################################################################
6854fd01
JH
296# check whether overloading cmp works
297$try = "\$x = $class->new(0);";
298$try .= "\$y = 10;";
299$try .= "'false' if \$x ne \$y;";
300$ans = eval $try;
3167abe5 301print "# For '$try'\n" if (!is ("$ans" , "false") );
6854fd01
JH
302
303# we cant test for working cmpt with other objects here, we would need a dummy
304# object with stringify overload for this. see Math::String tests as example
305
306###############################################################################
6854fd01 307# check reversed order of arguments
027dc388 308
6854fd01
JH
309$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
310$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
311print "# For '$try'\n" if (!ok "$ans" , "ok" );
312
313$try = "\$x = $class->new(10); \$x = 2 * \$x;";
314$try .= "'ok' if \$x == 20;"; $ans = eval $try;
315print "# For '$try'\n" if (!ok "$ans" , "ok" );
316
317$try = "\$x = $class->new(10); \$x = 2 + \$x;";
318$try .= "'ok' if \$x == 12;"; $ans = eval $try;
319print "# For '$try'\n" if (!ok "$ans" , "ok" );
320
321$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
322$try .= "'ok' if \$x == -8;"; $ans = eval $try;
323print "# For '$try'\n" if (!ok "$ans" , "ok" );
324
325$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
326$try .= "'ok' if \$x == 2;"; $ans = eval $try;
327print "# For '$try'\n" if (!ok "$ans" , "ok" );
328
027dc388
JH
329$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
330$try .= "'ok' if \$x == 2;"; $ans = eval $try;
331print "# For '$try'\n" if (!ok "$ans" , "ok" );
332
333$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
334$try .= "'ok' if \$x == 4;"; $ans = eval $try;
335print "# For '$try'\n" if (!ok "$ans" , "ok" );
336
337$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
338$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
339print "# For '$try'\n" if (!ok "$ans" , "ok" );
340
341$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
342$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
343print "# For '$try'\n" if (!ok "$ans" , "ok" );
344
6854fd01
JH
345###############################################################################
346# check badd(4,5) form
347
348$try = "\$x = $class\->badd(4,5);";
349$try .= "'ok' if \$x == 9;";
350$ans = eval $try;
351print "# For '$try'\n" if (!ok "$ans" , "ok" );
352
353###############################################################################
354# check undefs: NOT DONE YET
355
356###############################################################################
357# bool
358
3167abe5
NC
359$x = $class->new(1); if ($x) { is (1,1); } else { is ($x,'to be true') }
360$x = $class->new(0); if (!$x) { is (1,1); } else { is ($x,'to be false') }
6854fd01
JH
361
362###############################################################################
363# objectify()
364
365@args = Math::BigInt::objectify(2,4,5);
3167abe5
NC
366is (scalar @args,3); # $class, 4, 5
367like ($args[0], qr/^Math::BigInt/);
368is ($args[1],4);
369is ($args[2],5);
6854fd01
JH
370
371@args = Math::BigInt::objectify(0,4,5);
3167abe5
NC
372is (scalar @args,3); # $class, 4, 5
373like ($args[0], qr/^Math::BigInt/);
374is ($args[1],4);
375is ($args[2],5);
6854fd01
JH
376
377@args = Math::BigInt::objectify(2,4,5);
3167abe5
NC
378is (scalar @args,3); # $class, 4, 5
379like ($args[0], qr/^Math::BigInt/);
380is ($args[1],4);
381is ($args[2],5);
6854fd01
JH
382
383@args = Math::BigInt::objectify(2,4,5,6,7);
3167abe5
NC
384is (scalar @args,5); # $class, 4, 5, 6, 7
385like ($args[0], qr/^Math::BigInt/);
386is ($args[1],4); is (ref($args[1]),$args[0]);
387is ($args[2],5); is (ref($args[2]),$args[0]);
388is ($args[3],6); is (ref($args[3]),'');
389is ($args[4],7); is (ref($args[4]),'');
6854fd01
JH
390
391@args = Math::BigInt::objectify(2,$class,4,5,6,7);
3167abe5
NC
392is (scalar @args,5); # $class, 4, 5, 6, 7
393is ($args[0],$class);
394is ($args[1],4); is (ref($args[1]),$args[0]);
395is ($args[2],5); is (ref($args[2]),$args[0]);
396is ($args[3],6); is (ref($args[3]),'');
397is ($args[4],7); is (ref($args[4]),'');
6854fd01
JH
398
399###############################################################################
f9a08e12
JH
400# test whether an opp calls objectify properly or not (or at least does what
401# it should do given non-objects, w/ or w/o objectify())
402
3167abe5
NC
403is ($class->new(123)->badd(123),246);
404is ($class->badd(123,321),444);
405is ($class->badd(123,$class->new(321)),444);
f9a08e12 406
3167abe5
NC
407is ($class->new(123)->bsub(122),1);
408is ($class->bsub(321,123),198);
409is ($class->bsub(321,$class->new(123)),198);
f9a08e12 410
3167abe5
NC
411is ($class->new(123)->bmul(123),15129);
412is ($class->bmul(123,123),15129);
413is ($class->bmul(123,$class->new(123)),15129);
f9a08e12 414
3167abe5
NC
415is ($class->new(15129)->bdiv(123),123);
416is ($class->bdiv(15129,123),123);
417is ($class->bdiv(15129,$class->new(123)),123);
f9a08e12 418
3167abe5
NC
419is ($class->new(15131)->bmod(123),2);
420is ($class->bmod(15131,123),2);
421is ($class->bmod(15131,$class->new(123)),2);
f9a08e12 422
3167abe5
NC
423is ($class->new(2)->bpow(16),65536);
424is ($class->bpow(2,16),65536);
425is ($class->bpow(2,$class->new(16)),65536);
f9a08e12 426
3167abe5
NC
427is ($class->new(2**15)->brsft(1),2**14);
428is ($class->brsft(2**15,1),2**14);
429is ($class->brsft(2**15,$class->new(1)),2**14);
f9a08e12 430
3167abe5
NC
431is ($class->new(2**13)->blsft(1),2**14);
432is ($class->blsft(2**13,1),2**14);
433is ($class->blsft(2**13,$class->new(1)),2**14);
f9a08e12
JH
434
435###############################################################################
6854fd01
JH
436# test for floating-point input (other tests in bnorm() below)
437
438$z = 1050000000000000; # may be int on systems with 64bit?
3167abe5 439$x = $class->new($z); is ($x->bsstr(),'105e+13'); # not 1.05e+15
6854fd01
JH
440$z = 1e+129; # definitely a float (may fail on UTS)
441# don't compare to $z, since some Perl versions stringify $z into something
442# like '1.e+129' or something equally ugly
3167abe5 443$x = $class->new($z); is ($x->bsstr(),'1e+129');
6854fd01
JH
444
445###############################################################################
9681bfa6 446# test for whitespace including newlines to be handled correctly
56d9de68 447
3167abe5 448# is ($Math::BigInt::strict,1); # the default
56d9de68
T
449
450foreach my $c (
451 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
452 {
453 my $m = $class->new($c);
3167abe5
NC
454 is ($class->new("$c"),$m);
455 is ($class->new(" $c"),$m);
456 is ($class->new("$c "),$m);
457 is ($class->new(" $c "),$m);
458 is ($class->new("\n$c"),$m);
459 is ($class->new("$c\n"),$m);
460 is ($class->new("\n$c\n"),$m);
461 is ($class->new(" \n$c\n"),$m);
462 is ($class->new(" \n$c \n"),$m);
463 is ($class->new(" \n$c\n "),$m);
464 is ($class->new(" \n$c\n1"),'NaN');
465 is ($class->new("1 \n$c\n1"),'NaN');
56d9de68
T
466 }
467
468###############################################################################
6854fd01
JH
469# prime number tests, also test for **= and length()
470# found on: http://www.utm.edu/research/primes/notes/by_year.html
471
472# ((2^148)-1)/17
473$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
3167abe5
NC
474is ($x,"20988936657440586486151264256610222593863921");
475is ($x->length(),length "20988936657440586486151264256610222593863921");
6854fd01
JH
476
477# MM7 = 2^127-1
478$x = $class->new(2); $x **= 127; $x--;
3167abe5 479is ($x,"170141183460469231731687303715884105727");
6854fd01
JH
480
481$x = $class->new('215960156869840440586892398248');
482($x,$y) = $x->length();
3167abe5 483is ($x,30); is ($y,0);
6854fd01
JH
484
485$x = $class->new('1_000_000_000_000');
486($x,$y) = $x->length();
3167abe5 487is ($x,13); is ($y,0);
6854fd01 488
2d2b2744
T
489# test <<=, >>=
490$x = $class->new('2');
491my $y = $class->new('18');
3167abe5
NC
492is ($x <<= $y, 2 << 18);
493is ($x, 2 << 18);
494is ($x >>= $y, 2);
495is ($x, 2);
2d2b2744 496
6854fd01
JH
497# I am afraid the following is not yet possible due to slowness
498# Also, testing for 2 meg output is a bit hard ;)
499#$x = $class->new(2); $x **= 6972593; $x--;
500
501# 593573509*2^332162+1 has exactly 1,000,000 digits
502# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
503#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
3167abe5 504#is ($x->length(),1_000_000);
6854fd01
JH
505
506###############################################################################
507# inheritance and overriding of _swap
508
509$x = Math::Foo->new(5);
510$x = $x - 8; # 8 - 5 instead of 5-8
3167abe5
NC
511is ($x,3);
512is (ref($x),'Math::Foo');
6854fd01
JH
513
514$x = Math::Foo->new(5);
515$x = 8 - $x; # 5 - 8 instead of 8 - 5
3167abe5
NC
516is ($x,-3);
517is (ref($x),'Math::Foo');
6854fd01
JH
518
519###############################################################################
520# Test whether +inf eq inf
521# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
522# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
523# like 1e100000 crash on some platforms. So simple test for the string 'inf'
3167abe5 524$x = $class->new('+inf'); is ($x,'inf');
6854fd01
JH
525
526###############################################################################
527###############################################################################
9681bfa6 528# the following tests only make sense with Math::BigInt::Calc or BareCalc or
56d9de68 529# FastCalc
6854fd01 530
56d9de68 531exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01
JH
532
533###############################################################################
534# check proper length of internal arrays
535
394e6ffb 536my $bl = $CL->_base_len();
6854fd01
JH
537my $BASE = '9' x $bl;
538my $MAX = $BASE;
539$BASE++;
540
541$x = $class->new($MAX); is_valid($x); # f.i. 9999
3167abe5
NC
542$x += 1; is ($x,$BASE); is_valid($x); # 10000
543$x -= 1; is ($x,$MAX); is_valid($x); # 9999 again
6854fd01
JH
544
545###############################################################################
546# check numify
547
3167abe5
NC
548$x = $class->new($BASE-1); is ($x->numify(),$BASE-1);
549$x = $class->new(-($BASE-1)); is ($x->numify(),-($BASE-1));
61f5c3f5
T
550
551# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
3167abe5
NC
552$x = $class->new($BASE); is ($x->numify()+0,$BASE+0);
553$x = $class->new(-$BASE); is ($x->numify(),-$BASE);
6854fd01 554$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
3167abe5 555is ($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
6854fd01
JH
556
557###############################################################################
558# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
559
394e6ffb 560$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
3167abe5 561if ($x > $BASE) { is (1,1) } else { is ("$x < $BASE","$x > $BASE"); }
394e6ffb
JH
562
563$x = $class->new($BASE+3); $x++;
3167abe5 564if ($x > $BASE) { is (1,1) } else { is ("$x > $BASE","$x < $BASE"); }
6854fd01 565
394e6ffb 566# test for +0 instead of int():
3167abe5 567$x = $class->new($MAX); is ($x->length(), length($MAX));
6854fd01
JH
568
569###############################################################################
56b9c951
JH
570# test bug that $class->digit($string) did not work
571
3167abe5 572is ($class->digit(123,2),1);
56b9c951
JH
573
574###############################################################################
6854fd01
JH
575# bug in sub where number with at least 6 trailing zeros after any op failed
576
394e6ffb 577$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
3167abe5
NC
578is ($z, 100000);
579is ($x, 23456);
6854fd01
JH
580
581###############################################################################
582# bug in shortcut in mul()
583
61f5c3f5
T
584# construct a number with a zero-hole of BASE_LEN_SMALL
585{
f800d0e1 586 my @bl = $CL->_base_len(); my $bl = $bl[5];
61f5c3f5
T
587
588 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
589 $y = '1' x (2*$bl);
590 $x = $class->new($x)->bmul($y);
591 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
592 $y = ''; my $d = '';
593 for (my $i = 1; $i <= $bl; $i++)
594 {
595 $y .= $i; $d = $i.$d;
596 }
597 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
3167abe5 598 is ($x,$y);
61f5c3f5 599
6854fd01 600
f9a08e12
JH
601 #############################################################################
602 # see if mul shortcut for small numbers works
394e6ffb 603
f9a08e12
JH
604 $x = '9' x $bl;
605 $x = $class->new($x);
606 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
3167abe5 607 is ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
f9a08e12 608}
61f5c3f5 609
394e6ffb 610###############################################################################
6854fd01
JH
611# bug with rest "-0" in div, causing further div()s to fail
612
394e6ffb 613$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 614
3167abe5 615is ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 616
79c55733 617###############################################################################
f9a08e12 618# bug in $x->bmod($y)
07d34614 619
f9a08e12 620# if $x < 0 and $y > 0
3167abe5 621$x = $class->new('-629'); is ($x->bmod(5033),4404);
07d34614
T
622
623###############################################################################
56b9c951
JH
624# bone/binf etc as plain calls (Lite failed them)
625
3167abe5
NC
626is ($class->bzero(),0);
627is ($class->bone(),1);
628is ($class->bone('+'),1);
629is ($class->bone('-'),-1);
630is ($class->bnan(),'NaN');
631is ($class->binf(),'inf');
632is ($class->binf('+'),'inf');
633is ($class->binf('-'),'-inf');
634is ($class->binf('-inf'),'-inf');
56b9c951
JH
635
636###############################################################################
990fb837
RGS
637# is_one('-')
638
3167abe5
NC
639is ($class->new(1)->is_one('-'),0);
640is ($class->new(-1)->is_one('-'),1);
641is ($class->new(1)->is_one(),1);
642is ($class->new(-1)->is_one(),0);
990fb837
RGS
643
644###############################################################################
0ac635f7 645# [perl #30609] bug with $x -= $x not being 0, but 2*$x
03874afe 646
3167abe5
NC
647$x = $class->new(3); $x -= $x; is ($x, 0);
648$x = $class->new(-3); $x -= $x; is ($x, 0);
649$x = $class->new('NaN'); $x -= $x; is ($x->is_nan(), 1);
650$x = $class->new('inf'); $x -= $x; is ($x->is_nan(), 1);
651$x = $class->new('-inf'); $x -= $x; is ($x->is_nan(), 1);
652
653$x = $class->new('NaN'); $x += $x; is ($x->is_nan(), 1);
654$x = $class->new('inf'); $x += $x; is ($x->is_inf(), 1);
655$x = $class->new('-inf'); $x += $x; is ($x->is_inf('-'), 1);
656$x = $class->new(3); $x += $x; is ($x, 6);
657$x = $class->new(-3); $x += $x; is ($x, -6);
658
659$x = $class->new(3); $x *= $x; is ($x, 9);
660$x = $class->new(-3); $x *= $x; is ($x, 9);
661$x = $class->new(3); $x /= $x; is ($x, 1);
662$x = $class->new(-3); $x /= $x; is ($x, 1);
663$x = $class->new(3); $x %= $x; is ($x, 0);
664$x = $class->new(-3); $x %= $x; is ($x, 0);
03874afe
T
665
666###############################################################################
61f5c3f5 667# all tests done
6854fd01
JH
668
6691;
670
671###############################################################################
6854fd01
JH
672# sub to check validity of a BigInt internally, to ensure that no op leaves a
673# number object in an invalid state (f.i. "-0")
674
675sub is_valid
676 {
677 my ($x,$f) = @_;
678
679 my $e = 0; # error?
6854fd01 680
56b9c951
JH
681 # allow the check to pass for all Lite, and all MBI and subclasses
682 # ok as reference?
683 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 684
56b9c951
JH
685 if (ref($x) ne 'Math::BigInt::Lite')
686 {
687 # has ok sign?
688 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
689 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
690
691 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
692 $e = $CALC->_check($x->{value}) if $e eq '0';
693 }
6854fd01
JH
694
695 # test done, see if error did crop up
3167abe5 696 is (1,1), return if ($e eq '0');
6854fd01 697
3167abe5 698 is (1,$e." after op '$f'");
6854fd01
JH
699 }
700
701__DATA__
027dc388
JH
702&.=
7031234:-345:1234-345
704&+=
7051:2:3
706-1:-2:-3
707&-=
7081:2:-1
709-1:-2:1
710&*=
7112:3:6
712-1:5:-5
713&%=
714100:3:1
7158:9:8
07d34614 716-629:5033:4404
027dc388
JH
717&/=
718100:3:33
719-8:2:-4
720&|=
7212:1:3
722&&=
7235:7:5
724&^=
7255:7:2
091c87b1
T
726&blog
727NaNlog:2:NaN
728122:NaNlog:NaN
729NaNlog1:NaNlog:NaN
730122:inf:NaN
731inf:122:NaN
732122:-inf:NaN
733-inf:122:NaN
734-inf:-inf:NaN
735inf:inf:NaN
7360:4:NaN
737-21:4:NaN
73821:-21:NaN
739# normal results
7401024:2:10
74181:3:4
742# 3.01.. truncate
74382:3:4
744# 3.9... truncate
74580:3:3
74615625:5:6
74715626:5:6
74815624:5:5
8df1e0a2
T
7491000:10:3
75010000:10:4
751100000:10:5
7521000000:10:6
75310000000:10:7
754100000000:10:8
7558916100448256:12:12
7568916100448257:12:12
7578916100448255:12:11
7582251799813685248:8:17
75972057594037927936:2:56
760144115188075855872:2:57
761288230376151711744:2:58
762576460752303423488:2:59
7634096:2:12
7641329227995784915872903807060280344576:2:120
091c87b1
T
765# $x == $base => result 1
7663:3:1
767# $x < $base => result 0 ($base ** 0 <= $x)
7683:4:0
769# $x == 1 => result 0
7701:5:0
6854fd01
JH
771&is_negative
7720:0
773-1:1
7741:0
775+inf:0
776-inf:1
777NaNneg:0
778&is_positive
b68b7ab1 7790:0
6854fd01
JH
780-1:0
7811:1
782+inf:1
783-inf:0
784NaNneg:0
b3abae2a
JH
785&is_int
786-inf:0
787+inf:0
788NaNis_int:0
7891:1
7900:1
791123e12:1
6854fd01
JH
792&is_odd
793abc:0
7940:0
7951:1
7963:1
797-1:1
798-3:1
79910000001:1
80010000002:0
8012:0
b3abae2a
JH
802120:0
803121:1
6854fd01
JH
804&is_even
805abc:0
8060:1
8071:0
8083:0
809-1:0
810-3:0
81110000001:0
81210000002:1
8132:1
b3abae2a
JH
814120:1
815121:0
6854fd01
JH
816&bacmp
817+0:-0:0
818+0:+1:-1
819-1:+1:0
820+1:-1:0
821-1:+2:-1
822+2:-1:1
823-123456789:+987654321:-1
824+123456789:-987654321:-1
825+987654321:+123456789:1
826-987654321:+123456789:1
827-123:+4567889:-1
828# NaNs
829acmpNaN:123:
830123:acmpNaN:
831acmpNaN:acmpNaN:
832# infinity
833+inf:+inf:0
834-inf:-inf:0
835+inf:-inf:0
836-inf:+inf:0
837+inf:123:1
838-inf:123:1
839+inf:-123:1
840-inf:-123:1
ef9466ea
T
841123:-inf:-1
842-123:inf:-1
843-123:-inf:-1
844123:inf:-1
6854fd01
JH
845# return undef
846+inf:NaN:
847NaN:inf:
848-inf:NaN:
849NaN:-inf:
850&bnorm
aef458a0
JH
8510e999:0
8520e-999:0
853-0e999:0
854-0e-999:0
6854fd01
JH
855123:123
856# binary input
8570babc:NaN
8580b123:NaN
8590b0:0
860-0b0:0
861-0b1:-1
8620b0001:1
8630b001:1
8640b011:3
8650b101:5
61f5c3f5
T
8660b1001:9
8670b10001:17
8680b100001:33
8690b1000001:65
8700b10000001:129
8710b100000001:257
8720b1000000001:513
8730b10000000001:1025
8740b100000000001:2049
8750b1000000000001:4097
8760b10000000000001:8193
8770b100000000000001:16385
8780b1000000000000001:32769
8790b10000000000000001:65537
8800b100000000000000001:131073
8810b1000000000000000001:262145
8820b10000000000000000001:524289
8830b100000000000000000001:1048577
8840b1000000000000000000001:2097153
8850b10000000000000000000001:4194305
8860b100000000000000000000001:8388609
8870b1000000000000000000000001:16777217
8880b10000000000000000000000001:33554433
8890b100000000000000000000000001:67108865
8900b1000000000000000000000000001:134217729
8910b10000000000000000000000000001:268435457
8920b100000000000000000000000000001:536870913
8930b1000000000000000000000000000001:1073741825
8940b10000000000000000000000000000001:2147483649
8950b100000000000000000000000000000001:4294967297
8960b1000000000000000000000000000000001:8589934593
8970b10000000000000000000000000000000001:17179869185
de1ac46b 8980b__101:NaN
6854fd01 8990b1_0_1:5
394e6ffb 9000b0_0_0_1:1
6854fd01
JH
901# hex input
902-0x0:0
9030xabcdefgh:NaN
9040x1234:4660
9050xabcdef:11259375
906-0xABCDEF:-11259375
907-0x1234:-4660
9080x12345678:305419896
9090x1_2_3_4_56_78:305419896
394e6ffb 9100xa_b_c_d_e_f:11259375
de1ac46b 9110x__123:NaN
61f5c3f5
T
9120x9:9
9130x11:17
9140x21:33
9150x41:65
9160x81:129
9170x101:257
9180x201:513
9190x401:1025
9200x801:2049
9210x1001:4097
9220x2001:8193
9230x4001:16385
9240x8001:32769
9250x10001:65537
9260x20001:131073
9270x40001:262145
9280x80001:524289
9290x100001:1048577
9300x200001:2097153
9310x400001:4194305
9320x800001:8388609
9330x1000001:16777217
9340x2000001:33554433
9350x4000001:67108865
9360x8000001:134217729
9370x10000001:268435457
9380x20000001:536870913
9390x40000001:1073741825
9400x80000001:2147483649
9410x100000001:4294967297
9420x200000001:8589934593
9430x400000001:17179869185
9440x800000001:34359738369
2d2b2744
T
945# bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex()
9460x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
6854fd01
JH
947# inf input
948inf:inf
949+inf:inf
950-inf:-inf
9510inf:NaN
027dc388 952# abnormal input
6854fd01
JH
953:NaN
954abc:NaN
955 1 a:NaN
9561bcd2:NaN
95711111b:NaN
958+1z:NaN
959-1z:NaN
027dc388
JH
960# only one underscore between two digits
961_123:NaN
962_123_:NaN
963123_:NaN
9641__23:NaN
9651E1__2:NaN
9661_E12:NaN
9671E_12:NaN
9681_E_12:NaN
969+_1E12:NaN
970+0_1E2:100
971+0_0_1E2:100
972-0_0_1E2:-100
973-0_0_1E+0_0_2:-100
974E1:NaN
975E23:NaN
9761.23E1:NaN
9771.23E-1:NaN
0ac635f7 978# bug with two E's in number being valid
027dc388
JH
9791e2e3:NaN
9801e2r:NaN
9811e2.0:NaN
0ac635f7 982# bug with two '.' in number being valid
07d34614
T
9831.2.2:NaN
9841.2.3e1:NaN
985-1.2.3:NaN
986-1.2.3e-4:NaN
9871.2e3.4:NaN
9881.2e-3.4:NaN
9891.2.3.4:NaN
9901.2.t:NaN
9911..2:NaN
9921..2e1:NaN
9931..2e1..1:NaN
99412e1..1:NaN
995..2:NaN
996.-2:NaN
61f5c3f5
T
997# leading zeros
998012:12
9990123:123
100001234:1234
1001012345:12345
10020123456:123456
100301234567:1234567
1004012345678:12345678
10050123456789:123456789
100601234567891:1234567891
1007012345678912:12345678912
10080123456789123:123456789123
100901234567891234:1234567891234
2d2b2744
T
1010# some inputs that result in zero
10110e0:0
1012+0e0:0
1013+0e+0:0
1014-0e+0:0
10150e-0:0
1016-0e-0:0
1017+0e-0:0
1018000:0
101900e2:0
102000e02:0
1021000e002:0
1022000e1230:0
102300e-3:0
102400e+3:0
102500e-03:0
102600e+03:0
1027-000:0
1028-00e2:0
1029-00e02:0
1030-000e002:0
1031-000e1230:0
1032-00e-3:0
1033-00e+3:0
1034-00e-03:0
1035-00e+03:0
027dc388 1036# normal input
6854fd01
JH
10370:0
1038+0:0
1039+00:0
1040+000:0
1041000000000000000000:0
1042-0:0
1043-0000:0
1044+1:1
1045+01:1
1046+001:1
1047+00000100000:100000
1048123456789:123456789
1049-1:-1
1050-01:-1
1051-001:-1
1052-123456789:-123456789
1053-00000100000:-100000
10541_2_3:123
6854fd01
JH
105510000000000E-1_0:1
10561E2:100
10571E1:10
10581E0:1
6854fd01 10591.23E2:123
6854fd01
JH
1060100E-1:10
1061# floating point input
027dc388
JH
1062# .2e2:20
10631.E3:1000
6854fd01
JH
10641.01E2:101
10651010E-1:101
1066-1010E0:-1010
1067-1010E1:-10100
027dc388
JH
10681234.00:1234
1069# non-integer numbers
6854fd01
JH
1070-1010E-2:NaN
1071-1.01E+1:NaN
1072-1.01E-1:NaN
6854fd01
JH
1073&bnan
10741:NaN
10752:NaN
1076abc:NaN
1077&bone
61f5c3f5 10782:+:1
6854fd01
JH
10792:-:-1
1080boneNaN:-:-1
61f5c3f5
T
1081boneNaN:+:1
10822:abc:1
10833::1
6854fd01
JH
1084&binf
10851:+:inf
10862:-:-inf
10873:abc:inf
027dc388
JH
1088&is_nan
1089123:0
1090abc:1
1091NaN:1
1092-123:0
6854fd01
JH
1093&is_inf
1094+inf::1
1095-inf::1
1096abc::0
10971::0
1098NaN::0
1099-1::0
1100+inf:-:0
1101+inf:+:1
1102-inf:-:1
1103-inf:+:0
79c55733
JH
1104-inf:-inf:1
1105-inf:+inf:0
1106+inf:-inf:0
1107+inf:+inf:1
6854fd01
JH
1108# it must be exactly /^[+-]inf$/
1109+infinity::0
1110-infinity::0
1111&blsft
1112abc:abc:NaN
61f5c3f5
T
1113+2:+2:8
1114+1:+32:4294967296
1115+1:+48:281474976710656
6854fd01
JH
1116+8:-2:NaN
1117# excercise base 10
1118+12345:4:10:123450000
1119-1234:0:10:-1234
61f5c3f5 1120+1234:0:10:1234
6854fd01
JH
1121+2:2:10:200
1122+12:2:10:1200
1123+1234:-3:10:NaN
11241234567890123:12:10:1234567890123000000000000
b3abae2a
JH
1125-3:1:2:-6
1126-5:1:2:-10
1127-2:1:2:-4
1128-102533203:1:2:-205066406
6854fd01
JH
1129&brsft
1130abc:abc:NaN
61f5c3f5
T
1131+8:+2:2
1132+4294967296:+32:1
1133+281474976710656:+48:1
6854fd01
JH
1134+2:-2:NaN
1135# excercise base 10
1136-1234:0:10:-1234
61f5c3f5 1137+1234:0:10:1234
6854fd01
JH
1138+200:2:10:2
1139+1234:3:10:1
1140+1234:2:10:12
1141+1234:-3:10:NaN
1142310000:4:10:31
114312300000:5:10:123
11441230000000000:10:10:123
114509876123456789067890:12:10:9876123
11461234561234567890123:13:10:123456
b3abae2a
JH
1147820265627:1:2:410132813
1148# test shifting negative numbers in base 2
1149-15:1:2:-8
1150-14:1:2:-7
1151-13:1:2:-7
1152-12:1:2:-6
1153-11:1:2:-6
1154-10:1:2:-5
1155-9:1:2:-5
1156-8:1:2:-4
1157-7:1:2:-4
1158-6:1:2:-3
1159-5:1:2:-3
1160-4:1:2:-2
1161-3:1:2:-2
1162-2:1:2:-1
1163-1:1:2:-1
1164-1640531254:2:2:-410132814
1165-1640531254:1:2:-820265627
1166-820265627:1:2:-410132814
1167-205066405:1:2:-102533203
6854fd01 1168&bsstr
56d9de68
T
1169+inf:inf
1170-inf:-inf
6854fd01
JH
11711e+34:1e+34
1172123.456E3:123456e+0
1173100:1e+2
56d9de68
T
1174bsstrabc:NaN
1175-5:-5e+0
1176-100:-1e+2
1177&numify
1178numifyabc:NaN
1179+inf:inf
1180-inf:-inf
11815:5
1182-5:-5
1183100:100
1184-100:-100
6854fd01
JH
1185&bneg
1186bnegNaN:NaN
1187+inf:-inf
1188-inf:inf
1189abd:NaN
61f5c3f5
T
11900:0
11911:-1
1192-1:1
6854fd01 1193+123456789:-123456789
61f5c3f5 1194-123456789:123456789
6854fd01
JH
1195&babs
1196babsNaN:NaN
1197+inf:inf
1198-inf:inf
61f5c3f5
T
11990:0
12001:1
1201-1:1
1202+123456789:123456789
1203-123456789:123456789
6854fd01
JH
1204&bcmp
1205bcmpNaN:bcmpNaN:
61f5c3f5
T
1206bcmpNaN:0:
12070:bcmpNaN:
12080:0:0
1209-1:0:-1
12100:-1:1
12111:0:1
12120:1:-1
1213-1:1:-1
12141:-1:1
6854fd01 1215-1:-1:0
61f5c3f5
T
12161:1:0
1217123:123:0
1218123:12:1
121912:123:-1
6854fd01
JH
1220-123:-123:0
1221-123:-12:-1
1222-12:-123:1
61f5c3f5
T
1223123:124:-1
1224124:123:1
6854fd01
JH
1225-123:-124:1
1226-124:-123:-1
61f5c3f5
T
1227100:5:1
1228-123456789:987654321:-1
6854fd01 1229+123456789:-987654321:1
61f5c3f5 1230-987654321:123456789:-1
6854fd01
JH
1231-inf:5432112345:-1
1232+inf:5432112345:1
1233-inf:-5432112345:-1
1234+inf:-5432112345:1
1235+inf:+inf:0
1236-inf:-inf:0
1237+inf:-inf:1
1238-inf:+inf:-1
12395:inf:-1
12405:inf:-1
1241-5:-inf:1
1242-5:-inf:1
1243# return undef
1244+inf:NaN:
1245NaN:inf:
1246-inf:NaN:
1247NaN:-inf:
1248&binc
1249abc:NaN
1250+inf:inf
1251-inf:-inf
61f5c3f5
T
1252+0:1
1253+1:2
1254-1:0
6854fd01
JH
1255&bdec
1256abc:NaN
1257+inf:inf
1258-inf:-inf
1259+0:-1
61f5c3f5 1260+1:0
6854fd01
JH
1261-1:-2
1262&badd
1263abc:abc:NaN
61f5c3f5 1264abc:0:NaN
6854fd01 1265+0:abc:NaN
b3abae2a
JH
1266+inf:-inf:NaN
1267-inf:+inf:NaN
6854fd01
JH
1268+inf:+inf:inf
1269-inf:-inf:-inf
1270baddNaN:+inf:NaN
1271baddNaN:+inf:NaN
1272+inf:baddNaN:NaN
1273-inf:baddNaN:NaN
61f5c3f5
T
12740:0:0
12751:0:1
12760:1:1
12771:1:2
1278-1:0:-1
12790:-1:-1
6854fd01 1280-1:-1:-2
61f5c3f5
T
1281-1:+1:0
1282+1:-1:0
1283+9:+1:10
1284+99:+1:100
1285+999:+1:1000
1286+9999:+1:10000
1287+99999:+1:100000
1288+999999:+1:1000000
1289+9999999:+1:10000000
1290+99999999:+1:100000000
1291+999999999:+1:1000000000
1292+9999999999:+1:10000000000
1293+99999999999:+1:100000000000
1294+10:-1:9
1295+100:-1:99
1296+1000:-1:999
1297+10000:-1:9999
1298+100000:-1:99999
1299+1000000:-1:999999
1300+10000000:-1:9999999
1301+100000000:-1:99999999
1302+1000000000:-1:999999999
1303+10000000000:-1:9999999999
1304+123456789:987654321:1111111110
1305-123456789:987654321:864197532
6854fd01
JH
1306-123456789:-987654321:-1111111110
1307+123456789:-987654321:-864197532
56b9c951
JH
1308-1:10001:10000
1309-1:100001:100000
1310-1:1000001:1000000
1311-1:10000001:10000000
1312-1:100000001:100000000
1313-1:1000000001:1000000000
1314-1:10000000001:10000000000
1315-1:100000000001:100000000000
1316-1:1000000000001:1000000000000
1317-1:10000000000001:10000000000000
1318-1:-10001:-10002
1319-1:-100001:-100002
1320-1:-1000001:-1000002
1321-1:-10000001:-10000002
1322-1:-100000001:-100000002
1323-1:-1000000001:-1000000002
1324-1:-10000000001:-10000000002
1325-1:-100000000001:-100000000002
1326-1:-1000000000001:-1000000000002
1327-1:-10000000000001:-10000000000002
6854fd01
JH
1328&bsub
1329abc:abc:NaN
1330abc:+0:NaN
1331+0:abc:NaN
1332+inf:-inf:inf
1333-inf:+inf:-inf
b3abae2a
JH
1334+inf:+inf:NaN
1335-inf:-inf:NaN
61f5c3f5
T
1336+0:+0:0
1337+1:+0:1
6854fd01 1338+0:+1:-1
61f5c3f5 1339+1:+1:0
6854fd01 1340-1:+0:-1
61f5c3f5
T
1341+0:-1:1
1342-1:-1:0
6854fd01 1343-1:+1:-2
61f5c3f5
T
1344+1:-1:2
1345+9:+1:8
1346+99:+1:98
1347+999:+1:998
1348+9999:+1:9998
1349+99999:+1:99998
1350+999999:+1:999998
1351+9999999:+1:9999998
1352+99999999:+1:99999998
1353+999999999:+1:999999998
1354+9999999999:+1:9999999998
1355+99999999999:+1:99999999998
1356+10:-1:11
1357+100:-1:101
1358+1000:-1:1001
1359+10000:-1:10001
1360+100000:-1:100001
1361+1000000:-1:1000001
1362+10000000:-1:10000001
1363+100000000:-1:100000001
1364+1000000000:-1:1000000001
1365+10000000000:-1:10000000001
6854fd01
JH
1366+123456789:+987654321:-864197532
1367-123456789:+987654321:-1111111110
61f5c3f5
T
1368-123456789:-987654321:864197532
1369+123456789:-987654321:1111111110
56b9c951
JH
137010001:1:10000
1371100001:1:100000
13721000001:1:1000000
137310000001:1:10000000
1374100000001:1:100000000
13751000000001:1:1000000000
137610000000001:1:10000000000
1377100000000001:1:100000000000
13781000000000001:1:1000000000000
137910000000000001:1:10000000000000
138010001:-1:10002
1381100001:-1:100002
13821000001:-1:1000002
138310000001:-1:10000002
1384100000001:-1:100000002
13851000000001:-1:1000000002
138610000000001:-1:10000000002
1387100000000001:-1:100000000002
13881000000000001:-1:1000000000002
138910000000000001:-1:10000000000002
80365507
T
1390&bmuladd
1391abc:abc:0:NaN
1392abc:+0:0:NaN
1393+0:abc:0:NaN
1394+0:0:abc:NaN
1395NaNmul:+inf:0:NaN
1396NaNmul:-inf:0:NaN
1397-inf:NaNmul:0:NaN
1398+inf:NaNmul:0:NaN
1399+inf:+inf:0:inf
1400+inf:-inf:0:-inf
1401-inf:+inf:0:-inf
1402-inf:-inf:0:inf
1403+0:+0:0:0
1404+0:+1:0:0
1405+1:+0:0:0
1406+0:-1:0:0
1407-1:+0:0:0
1408123456789123456789:0:0:0
14090:123456789123456789:0:0
1410-1:-1:0:1
1411-1:-1:0:1
1412-1:+1:0:-1
1413+1:-1:0:-1
1414+1:+1:0:1
1415+2:+3:0:6
1416-2:+3:0:-6
1417+2:-3:0:-6
1418-2:-3:0:6
1419111:111:0:12321
142010101:10101:0:102030201
14211001001:1001001:0:1002003002001
1422100010001:100010001:0:10002000300020001
142310000100001:10000100001:0:100002000030000200001
142411111111111:9:0:99999999999
142522222222222:9:0:199999999998
142633333333333:9:0:299999999997
142744444444444:9:0:399999999996
142855555555555:9:0:499999999995
142966666666666:9:0:599999999994
143077777777777:9:0:699999999993
143188888888888:9:0:799999999992
143299999999999:9:0:899999999991
143311111111111:9:1:100000000000
143422222222222:9:1:199999999999
143533333333333:9:1:299999999998
143644444444444:9:1:399999999997
143755555555555:9:1:499999999996
143866666666666:9:1:599999999995
143977777777777:9:1:699999999994
144088888888888:9:1:799999999993
144199999999999:9:1:899999999992
1442-3:-4:-5:7
14433:-4:-5:-17
1444-3:4:-5:-17
14453:4:-5:7
1446-3:4:5:-7
14473:-4:5:-7
14489999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890
14492:3:12345678901234567890:12345678901234567896
6854fd01
JH
1450&bmul
1451abc:abc:NaN
1452abc:+0:NaN
1453+0:abc:NaN
1454NaNmul:+inf:NaN
1455NaNmul:-inf:NaN
1456-inf:NaNmul:NaN
1457+inf:NaNmul:NaN
1458+inf:+inf:inf
1459+inf:-inf:-inf
1460-inf:+inf:-inf
1461-inf:-inf:inf
61f5c3f5
T
1462+0:+0:0
1463+0:+1:0
1464+1:+0:0
1465+0:-1:0
1466-1:+0:0
1467123456789123456789:0:0
14680:123456789123456789:0
1469-1:-1:1
6854fd01
JH
1470-1:+1:-1
1471+1:-1:-1
61f5c3f5
T
1472+1:+1:1
1473+2:+3:6
6854fd01
JH
1474-2:+3:-6
1475+2:-3:-6
61f5c3f5
T
1476-2:-3:6
1477111:111:12321
147810101:10101:102030201
14791001001:1001001:1002003002001
1480100010001:100010001:10002000300020001
148110000100001:10000100001:100002000030000200001
148211111111111:9:99999999999
148322222222222:9:199999999998
148433333333333:9:299999999997
148544444444444:9:399999999996
148655555555555:9:499999999995
148766666666666:9:599999999994
148877777777777:9:699999999993
148988888888888:9:799999999992
149099999999999:9:899999999991
1491+25:+25:625
1492+12345:+12345:152399025
1493+99999:+11111:1111088889
6854fd01
JH
14949999:10000:99990000
149599999:100000:9999900000
1496999999:1000000:999999000000
14979999999:10000000:99999990000000
149899999999:100000000:9999999900000000
1499999999999:1000000000:999999999000000000
15009999999999:10000000000:99999999990000000000
150199999999999:100000000000:9999999999900000000000
1502999999999999:1000000000000:999999999999000000000000
15039999999999999:10000000000000:99999999999990000000000000
150499999999999999:100000000000000:9999999999999900000000000000
1505999999999999999:1000000000000000:999999999999999000000000000000
15069999999999999999:10000000000000000:99999999999999990000000000000000
150799999999999999999:100000000000000000:9999999999999999900000000000000000
1508999999999999999999:1000000000000000000:999999999999999999000000000000000000
15099999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1510&bdiv-list
1511100:20:5,0
15124095:4095:1,0
1513-4095:-4095:1,0
15144095:-4095:-1,0
1515-4095:4095:-1,0
1516123:2:61,1
b3abae2a
JH
15179:5:1,4
15189:4:2,1
6854fd01
JH
1519# inf handling and general remainder
15205:8:0,5
15210:8:0,0
152211:2:5,1
152311:-2:-5,-1
1524-11:2:-5,1
1525# see table in documentation in MBI
15260:inf:0,0
15270:-inf:0,0
15285:inf:0,5
15295:-inf:0,5
1530-5:inf:0,-5
1531-5:-inf:0,-5
1532inf:5:inf,0
1533-inf:5:-inf,0
1534inf:-5:-inf,0
1535-inf:-5:inf,0
15365:5:1,0
1537-5:-5:1,0
b3abae2a
JH
1538inf:inf:NaN,NaN
1539-inf:-inf:NaN,NaN
1540-inf:inf:NaN,NaN
1541inf:-inf:NaN,NaN
6854fd01
JH
15428:0:inf,8
1543inf:0:inf,inf
f603091d 1544# exceptions to remainder rule
6854fd01
JH
1545-8:0:-inf,-8
1546-inf:0:-inf,-inf
15470:0:NaN,NaN
990fb837
RGS
1548# test the shortcut in Calc if @$x == @$yorg
15491234567812345678:123456712345678:10,688888898
155012345671234567:1234561234567:10,58888897
1551123456123456:12345123456:10,4888896
15521234512345:123412345:10,388895
15531234567890999999999:1234567890:1000000000,999999999
15541234567890000000000:1234567890:1000000000,0
15551234567890999999999:9876543210:124999998,9503086419
15561234567890000000000:9876543210:124999998,8503086420
155796969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
7596a890
RGS
1558# bug in v1.76
15591267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
b68b7ab1
T
1560# excercise shortcut for numbers of the same length in div
1561999999999999999999999999999999999:999999999999999999999999999999999:1,0
1562999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1563999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1564999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1565999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1566999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1567999999999999999999999999999999999:333333333333333333333333333333333:3,0
1568999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1569999999999999999999999999999999999:111111111111111111111111111111111:9,0
15709999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
15719999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
15729999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
15739999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
15749999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
15759999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
15769999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
15779999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
15789999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
15799999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
15809999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
6854fd01
JH
1581&bdiv
1582abc:abc:NaN
61f5c3f5
T
1583abc:1:NaN
15841:abc:NaN
15850:0:NaN
6854fd01
JH
1586# inf handling (see table in doc)
15870:inf:0
15880:-inf:0
15895:inf:0
15905:-inf:0
1591-5:inf:0
1592-5:-inf:0
1593inf:5:inf
1594-inf:5:-inf
1595inf:-5:-inf
1596-inf:-5:inf
15975:5:1
1598-5:-5:1
b3abae2a
JH
1599inf:inf:NaN
1600-inf:-inf:NaN
1601-inf:inf:NaN
1602inf:-inf:NaN
6854fd01
JH
16038:0:inf
1604inf:0:inf
1605-8:0:-inf
1606-inf:0:-inf
16070:0:NaN
160811:2:5
1609-11:-2:5
1610-11:2:-5
161111:-2:-5
61f5c3f5
T
16120:1:0
16130:-1:0
16141:1:1
1615-1:-1:1
16161:-1:-1
1617-1:1:-1
16181:2:0
16192:1:2
16201:26:0
16211000000000:9:111111111
16222000000000:9:222222222
16233000000000:9:333333333
16244000000000:9:444444444
16255000000000:9:555555555
16266000000000:9:666666666
16277000000000:9:777777777
16288000000000:9:888888888
16299000000000:9:1000000000
163035500000:113:314159
163171000000:226:314159
1632106500000:339:314159
16331000000000:3:333333333
1634+10:+5:2
1635+100:+4:25
1636+1000:+8:125
1637+10000:+16:625
1638999999999999:9:111111111111
1639999999999999:99:10101010101
1640999999999999:999:1001001001
1641999999999999:9999:100010001
1642999999999999999:99999:10000100001
1643+1111088889:99999:11111
6854fd01
JH
1644-5:-3:1
1645-5:3:-1
16464:3:1
16474:-3:-1
16481:3:0
16491:-3:0
1650-2:-3:0
1651-2:3:0
16528:3:2
1653-8:3:-2
165414:-3:-4
1655-14:3:-4
1656-14:-3:4
165714:3:4
1658# bug in Calc with '99999' vs $BASE-1
165910000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837
RGS
1660# test the shortcut in Calc if @$x == @$yorg
16611234567812345678:123456712345678:10
166212345671234567:1234561234567:10
1663123456123456:12345123456:10
16641234512345:123412345:10
16651234567890999999999:1234567890:1000000000
16661234567890000000000:1234567890:1000000000
16671234567890999999999:9876543210:124999998
16681234567890000000000:9876543210:124999998
166996969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0
JH
1670# bug up to v0.35 in Calc (--$q one too many)
167184696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
167284696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
167384696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
167484696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
c4a6f826 1675# exercise shortcut for numbers of the same length in div
b68b7ab1
T
1676999999999999999999999999999999999:999999999999999999999999999999999:1
1677999999999999999999999999999999999:888888888888888888888888888888888:1
1678999999999999999999999999999999999:777777777777777777777777777777777:1
1679999999999999999999999999999999999:666666666666666666666666666666666:1
1680999999999999999999999999999999999:555555555555555555555555555555555:1
1681999999999999999999999999999999999:444444444444444444444444444444444:2
1682999999999999999999999999999999999:333333333333333333333333333333333:3
1683999999999999999999999999999999999:222222222222222222222222222222222:4
1684999999999999999999999999999999999:111111111111111111111111111111111:9
16859999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
16869999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
16879999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
16889999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
16899999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
16909999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
16919999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
16929999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
16939999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
16949999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
16959999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
a87115f0
RGS
1696# bug with shortcut in Calc 0.44
1697949418181818187070707070707070707070:181818181853535353535353535353535353:5
07d34614
T
1698&bmodinv
1699# format: number:modulus:result
1700# bmodinv Data errors
1701abc:abc:NaN
1702abc:5:NaN
17035:abc:NaN
1704# bmodinv Expected Results from normal use
17051:5:1
17063:5:2
487de07a 17073:-5:-3
07d34614
T
1708-2:5:2
17098:5033:4404
56d9de68
T
17101234567891:13:6
1711-1234567891:13:7
07d34614 1712324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
116f6d6b
PJA
1713-2:1:0
1714-1:1:0
17150:1:0
17161:1:0
17172:1:0
17183:1:0
17194:1:0
1720-2:3:1
1721-1:3:2
17220:3:NaN
17231:3:1
17242:3:2
17253:3:NaN
17264:3:1
1727-2:4:NaN
1728-1:4:3
17290:4:NaN
17301:4:1
17312:4:NaN
17323:4:3
17334:4:NaN
d614cd8b 1734## bmodinv Error cases / useless use of function
07d34614 1735inf:5:NaN
1ddff52a
JH
17365:inf:NaN
1737-inf:5:NaN
17385:-inf:NaN
07d34614
T
1739&bmodpow
1740# format: number:exponent:modulus:result
1741# bmodpow Data errors
1742abc:abc:abc:NaN
17435:abc:abc:NaN
1744abc:5:abc:NaN
1745abc:abc:5:NaN
17465:5:abc:NaN
17475:abc:5:NaN
1748abc:5:5:NaN
3a7a056a 17493:5:0:NaN
07d34614
T
1750# bmodpow Expected results
17510:0:2:1
17521:0:2:1
3a7a056a 17530:3:5:0
116f6d6b
PJA
1754-2:-2:1:0
1755-1:-2:1:0
17560:-2:1:0
17571:-2:1:0
17582:-2:1:0
17593:-2:1:0
17604:-2:1:0
1761-2:-1:1:0
1762-1:-1:1:0
17630:-1:1:0
17641:-1:1:0
17652:-1:1:0
17663:-1:1:0
17674:-1:1:0
1768-2:0:1:0
1769-1:0:1:0
17700:0:1:0
17711:0:1:0
17722:0:1:0
17733:0:1:0
17744:0:1:0
1775-2:1:1:0
1776-1:1:1:0
17770:1:1:0
17781:1:1:0
17792:1:1:0
17803:1:1:0
17814:1:1:0
1782-2:2:1:0
1783-1:2:1:0
17840:2:1:0
17851:2:1:0
17862:2:1:0
17873:2:1:0
17884:2:1:0
1789-2:3:1:0
1790-1:3:1:0
17910:3:1:0
17921:3:1:0
17932:3:1:0
17943:3:1:0
17954:3:1:0
1796-2:4:1:0
1797-1:4:1:0
17980:4:1:0
17991:4:1:0
18002:4:1:0
18013:4:1:0
18024:4:1:0
1803-2:-2:3:1
1804-1:-2:3:1
18050:-2:3:NaN
18061:-2:3:1
18072:-2:3:1
18083:-2:3:NaN
18094:-2:3:1
1810-2:-1:3:1
1811-1:-1:3:2
18120:-1:3:NaN
18131:-1:3:1
18142:-1:3:2
18153:-1:3:NaN
18164:-1:3:1
1817-2:0:3:1
1818-1:0:3:1
18190:0:3:1
18201:0:3:1
18212:0:3:1
18223:0:3:1
18234:0:3:1
1824-2:1:3:1
1825-1:1:3:2
18260:1:3:0
18271:1:3:1
18282:1:3:2
18293:1:3:0
18304:1:3:1
1831-2:2:3:1
1832-1:2:3:1
18330:2:3:0
18341:2:3:1
18352:2:3:1
18363:2:3:0
18374:2:3:1
1838-2:3:3:1
1839-1:3:3:2
18400:3:3:0
18411:3:3:1
18422:3:3:2
18433:3:3:0
18444:3:3:1
1845-2:4:3:1
1846-1:4:3:1
18470:4:3:0
18481:4:3:1
18492:4:3:1
18503:4:3:0
18514:4:3:1
1852-2:-2:4:NaN
1853-1:-2:4:1
18540:-2:4:NaN
18551:-2:4:1
18562:-2:4:NaN
18573:-2:4:1
18584:-2:4:NaN
1859-2:-1:4:NaN
1860-1:-1:4:3
18610:-1:4:NaN
18621:-1:4:1
18632:-1:4:NaN
18643:-1:4:3
18654:-1:4:NaN
1866-2:0:4:1
1867-1:0:4:1
18680:0:4:1
18691:0:4:1
18702:0:4:1
18713:0:4:1
18724:0:4:1
1873-2:1:4:2
1874-1:1:4:3
18750:1:4:0
18761:1:4:1
18772:1:4:2
18783:1:4:3
18794:1:4:0
1880-2:2:4:0
1881-1:2:4:1
18820:2:4:0
18831:2:4:1
18842:2:4:0
18853:2:4:1
18864:2:4:0
1887-2:3:4:0
1888-1:3:4:3
18890:3:4:0
18901:3:4:1
18912:3:4:0
18923:3:4:3
18934:3:4:0
1894-2:4:4:0
1895-1:4:4:1
18960:4:4:0
18971:4:4:1
18982:4:4:0
18993:4:4:1
19004:4:4:0
19018:-1:16:NaN
07d34614 19028:-1:5033:4404
116f6d6b
PJA
19038:7:5032:3840
19048:8:-5:-4
ddb27680 19051e50:1:1:0
07d34614
T
190698436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1907# bmodpow Error cases
07d34614
T
1908inf:5:13:NaN
19095:inf:13:NaN
6854fd01
JH
1910&bmod
1911# inf handling, see table in doc
19120:inf:0
19130:-inf:0
19145:inf:5
19155:-inf:5
1916-5:inf:-5
1917-5:-inf:-5
1918inf:5:0
1919-inf:5:0
1920inf:-5:0
1921-inf:-5:0
19225:5:0
1923-5:-5:0
b3abae2a
JH
1924inf:inf:NaN
1925-inf:-inf:NaN
1926-inf:inf:NaN
1927inf:-inf:NaN
6854fd01
JH
19288:0:8
1929inf:0:inf
f603091d 1930# exceptions to remainder rule
6854fd01
JH
1931-inf:0:-inf
1932-8:0:-8
19330:0:NaN
1934abc:abc:NaN
61f5c3f5
T
1935abc:1:abc:NaN
19361:abc:NaN
19370:0:NaN
19380:1:0
19391:0:1
19400:-1:0
1941-1:0:-1
19421:1:0
1943-1:-1:0
19441:-1:0
1945-1:1:0
19461:2:1
19472:1:0
19481000000000:9:1
19492000000000:9:2
19503000000000:9:3
19514000000000:9:4
19525000000000:9:5
19536000000000:9:6
19547000000000:9:7
19558000000000:9:8
19569000000000:9:0
195735500000:113:33
195871000000:226:66
1959106500000:339:99
19601000000000:3:1
196110:5:0
1962100:4:0
19631000:8:0
196410000:16:0
1965999999999999:9:0
1966999999999999:99:0
1967999999999999:999:0
1968999999999999:9999:0
1969999999999999999:99999:0
1970-9:+5:1
6854fd01
JH
1971+9:-5:-1
1972-9:-5:-4
1973-5:3:1
1974-2:3:1
19754:3:1
19761:3:1
1977-5:-3:-2
1978-2:-3:-2
19794:-3:-2
19801:-3:-2
19814095:4095:0
027dc388
JH
1982100041000510123:3:0
1983152403346:12345:4321
b3abae2a 19849:5:4
28df3e88
JH
1985# test shortcuts in Calc
1986# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
19871234:9:1
1988123456:9:3
198912345678:9:0
19901234567891:9:1
1991123456789123:9:6
199212345678912345:9:6
19931234567891234567:9:1
1994123456789123456789:9:0
19951234:10:4
1996123456:10:6
199712345678:10:8
19981234567891:10:1
1999123456789123:10:3
200012345678912345:10:5
20011234567891234567:10:7
2002123456789123456789:10:9
20031234:113:104
2004123456:113:60
200512345678:113:89
20061234567891:113:64
2007123456789123:113:95
200812345678912345:113:53
20091234567891234567:113:56
2010123456789123456789:113:39
07d34614
T
2011# bug in bmod() not modifying the variable in place
2012-629:5033:4404
aef458a0
JH
2013# bug in bmod() in Calc in the _div_use_div() shortcut code path,
2014# when X == X and X was big
2015111111111111111111111111111111:111111111111111111111111111111:0
201612345678901234567890:12345678901234567890:0
6854fd01 2017&bgcd
9b924220
RGS
2018inf:12:NaN
2019-inf:12:NaN
202012:inf:NaN
202112:-inf:NaN
2022inf:inf:NaN
2023inf:-inf:NaN
2024-inf:-inf:NaN
6854fd01
JH
2025abc:abc:NaN
2026abc:+0:NaN
2027+0:abc:NaN
61f5c3f5
T
2028+0:+0:0
2029+0:+1:1
2030+1:+0:1
2031+1:+1:1
2032+2:+3:1
2033+3:+2:1
2034-3:+2:1
9b924220
RGS
2035-3:-2:1
2036-144:-60:12
2037144:-60:12
2038144:60:12
61f5c3f5
T
2039100:625:25
20404096:81:1
20411034:804:2
204227:90:56:1
204327:90:54:9
6854fd01
JH
2044&blcm
2045abc:abc:NaN
2046abc:+0:NaN
2047+0:abc:NaN
2048+0:+0:NaN
61f5c3f5
T
2049+1:+0:0
2050+0:+1:0
2051+27:+90:270
2052+1034:+804:415668
6854fd01
JH
2053&band
2054abc:abc:NaN
2055abc:0:NaN
20560:abc:NaN
20571:2:0
20583:2:2
61f5c3f5
T
2059+8:+2:0
2060+281474976710656:0:0
2061+281474976710656:1:0
2062+281474976710656:+281474976710656:281474976710656
9b924220 2063281474976710656:-1:281474976710656
6854fd01
JH
2064-2:-3:-4
2065-1:-1:-1
2066-6:-6:-6
2067-7:-4:-8
2068-7:4:0
2069-4:7:4
9b924220
RGS
2070# negative argument is bitwise shorter than positive [perl #26559]
207130:-3:28
2072123:-1:123
394e6ffb
JH
2073# equal arguments are treated special, so also do some test with unequal ones
20740xFFFF:0xFFFF:0x0xFFFF
20750xFFFFFF:0xFFFFFF:0x0xFFFFFF
20760xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
20770xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
20780xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
20790xF0F0:0xF0F0:0x0xF0F0
20800x0F0F:0x0F0F:0x0x0F0F
20810xF0F0F0:0xF0F0F0:0x0xF0F0F0
20820x0F0F0F:0x0F0F0F:0x0x0F0F0F
20830xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
20840x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
20850xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
20860x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
20870xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
20880x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
20890x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01
JH
2090&bior
2091abc:abc:NaN
2092abc:0:NaN
20930:abc:NaN
20941:2:3
61f5c3f5
T
2095+8:+2:10
2096+281474976710656:0:281474976710656
2097+281474976710656:1:281474976710657
2098+281474976710656:281474976710656:281474976710656
6854fd01
JH
2099-2:-3:-1
2100-1:-1:-1
2101-6:-6:-6
2102-7:4:-3
2103-4:7:-1
9b924220
RGS
2104+281474976710656:-1:-1
210530:-3:-1
210630:-4:-2
2107300:-76:-68
2108-76:300:-68
394e6ffb
JH
2109# equal arguments are treated special, so also do some test with unequal ones
21100xFFFF:0xFFFF:0x0xFFFF
21110xFFFFFF:0xFFFFFF:0x0xFFFFFF
21120xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
21130xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
21140xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
21150:0xFFFF:0x0xFFFF
21160:0xFFFFFF:0x0xFFFFFF
21170:0xFFFFFFFF:0x0xFFFFFFFF
21180:0xFFFFFFFFFF:0x0xFFFFFFFFFF
21190:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
21200xFFFF:0:0x0xFFFF
21210xFFFFFF:0:0x0xFFFFFF
21220xFFFFFFFF:0:0x0xFFFFFFFF
21230xFFFFFFFFFF:0:0x0xFFFFFFFFFF
21240xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
21250xF0F0:0xF0F0:0x0xF0F0
21260x0F0F:0x0F0F:0x0x0F0F
21270xF0F0:0x0F0F:0x0xFFFF
21280xF0F0F0:0xF0F0F0:0x0xF0F0F0
21290x0F0F0F:0x0F0F0F:0x0x0F0F0F
21300x0F0F0F:0xF0F0F0:0x0xFFFFFF
21310xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
21320x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
21330x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
21340xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
21350x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
21360x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
21370xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
21380x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
21390x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
21400x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01
JH
2141&bxor
2142abc:abc:NaN
2143abc:0:NaN
21440:abc:NaN
21451:2:3
61f5c3f5
T
2146+8:+2:10
2147+281474976710656:0:281474976710656
2148+281474976710656:1:281474976710657
2149+281474976710656:281474976710656:0
6854fd01
JH
2150-2:-3:3
2151-1:-1:0
2152-6:-6:0
2153-7:4:-3
2154-4:7:-5
21554:-7:-3
2156-4:-7:5
9b924220
RGS
215730:-3:-29
215830:-4:-30
2159300:-76:-360
2160-76:300:-360
394e6ffb
JH
2161# equal arguments are treated special, so also do some test with unequal ones
21620xFFFF:0xFFFF:0
21630xFFFFFF:0xFFFFFF:0
21640xFFFFFFFF:0xFFFFFFFF:0
21650xFFFFFFFFFF:0xFFFFFFFFFF:0
21660xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
21670:0xFFFF:0x0xFFFF
21680:0xFFFFFF:0x0xFFFFFF
21690:0xFFFFFFFF:0x0xFFFFFFFF
21700:0xFFFFFFFFFF:0x0xFFFFFFFFFF
21710:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
21720xFFFF:0:0x0xFFFF
21730xFFFFFF:0:0x0xFFFFFF
21740xFFFFFFFF:0:0x0xFFFFFFFF
21750xFFFFFFFFFF:0:0x0xFFFFFFFFFF
21760xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
21770xF0F0:0xF0F0:0
21780x0F0F:0x0F0F:0
21790xF0F0:0x0F0F:0x0xFFFF
21800xF0F0F0:0xF0F0F0:0
21810x0F0F0F:0x0F0F0F:0
21820x0F0F0F:0xF0F0F0:0x0xFFFFFF
21830xF0F0F0F0:0xF0F0F0F0:0
21840x0F0F0F0F:0x0F0F0F0F:0
21850x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
21860xF0F0F0F0F0:0xF0F0F0F0F0:0
21870x0F0F0F0F0F:0x0F0F0F0F0F:0
21880x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
21890xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
21900x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
21910x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01
JH
2192&bnot
2193abc:NaN
2194+0:-1
2195+8:-9
2196+281474976710656:-281474976710657
2197-1:0
2198-2:1
2199-12:11
2200&digit
22010:0:0
220212:0:2
220312:1:1
2204123:0:3
2205123:1:2
2206123:2:1
2207123:-1:1
2208123:-2:2
2209123:-3:3
2210123456:0:6
2211123456:1:5
2212123456:2:4
2213123456:3:3
2214123456:4:2
2215123456:5:1
2216123456:-1:1
2217123456:-2:2
2218123456:-3:3
2219100000:-3:0
2220100000:0:0
2221100000:1:0
2222&mantissa
2223abc:NaN
22241e4:1
22252e0:2
2226123:123
2227-1:-1
2228-2:-2
2229+inf:inf
2230-inf:-inf
2231&exponent
2232abc:NaN
22331e4:4
22342e0:0
2235123:0
2236-1:0
2237-2:0
22380:1
2239+inf:inf
2240-inf:inf
2241&parts
2242abc:NaN,NaN
22431e4:1,4
22442e0:2,0
2245123:123,0
2246-1:-1,0
2247-2:-2,0
22480:0,1
2249+inf:inf,inf
2250-inf:-inf,inf
b3abae2a
JH
2251&bfac
2252-1:NaN
2253NaNfac:NaN
b282a552 2254+inf:inf
b3abae2a
JH
2255-inf:NaN
22560:1
22571:1
22582:2
22593:6
22604:24
22615:120
22626:720
990fb837
RGS
22637:5040
22648:40320
22659:362880
b3abae2a
JH
226610:3628800
226711:39916800
226812:479001600
50109ad0
RGS
226920:2432902008176640000
227022:1124000727777607680000
227169:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
6854fd01
JH
2272&bpow
2273abc:12:NaN
227412:abc:NaN
22750:0:1
22760:1:0
22770:2:0
9b924220
RGS
22780:-1:inf
22790:-2:inf
6854fd01
JH
22801:0:1
22811:1:1
22821:2:1
22831:3:1
22841:-1:1
22851:-2:1
22861:-3:1
22872:0:1
22882:1:2
22892:2:4
22902:3:8
22913:3:27
2d2b2744
T
2292-2:2:4
2293-2:3:-8
2294-2:4:16
2295-2:5:-32
6854fd01
JH
22962:-1:NaN
2297-2:-1:NaN
22982:-2:NaN
2299-2:-2:NaN
2d2b2744 2300# inf tests
6854fd01 2301+inf:1234500012:inf
2d2b2744
T
2302-inf:1234500012:inf
2303-inf:1234500013:-inf
6854fd01
JH
2304+inf:-12345000123:inf
2305-inf:-12345000123:-inf
2d2b2744
T
2306# -inf * -inf = inf
2307-inf:2:inf
2308-inf:0:NaN
2309-inf:-1:0
2310-inf:inf:NaN
23112:inf:inf
23122:-inf:0
23130:inf:0
23140:-inf:inf
2315-1:-inf:NaN
2316-1:inf:NaN
2317-2:inf:NaN
2318-2:-inf:0
2319NaN:inf:NaN
2320NaN:-inf:NaN
2321-inf:NaN:NaN
2322inf:NaN:NaN
2323inf:-inf:NaN
23241:inf:1
23251:-inf:1
6854fd01
JH
2326# 1 ** -x => 1 / (1 ** x)
2327-1:0:1
2328-2:0:1
2329-1:1:-1
2330-1:2:1
2331-1:3:-1
2332-1:4:1
2333-1:5:-1
2334-1:-1:-1
2335-1:-2:1
2336-1:-3:-1
2337-1:-4:1
233810:2:100
233910:3:1000
234010:4:10000
234110:5:100000
234210:6:1000000
234310:7:10000000
234410:8:100000000
234510:9:1000000000
234610:20:100000000000000000000
2347123456:2:15241383936
9b924220
RGS
2348-2:2:4
2349-2:3:-8
2350-2:4:16
2351-2:5:-32
2352-3:2:9
2353-3:3:-27
2354-3:4:81
2355-3:5:-243
6854fd01
JH
2356&length
2357100:3
235810:2
23591:1
23600:1
236112345:5
236210000000000000000:17
2363-123:3
2364215960156869840440586892398248:30
990fb837
RGS
2365&broot
2366# sqrt()
2367+0:2:0
2368+1:2:1
2369-1:2:NaN
2370# -$x ** (1/2) => -$y, but not in froot()
2371-123:2:NaN
2372+inf:2:inf
2373-inf:2:NaN
23742:2:1
2375-2:2:NaN
23764:2:2
23779:2:3
237816:2:4
2379100:2:10
2380123:2:11
238115241:2:123
2382144:2:12
238312:2:3
23840.49:2:0
23850.0049:2:0
2386# invalid ones
23871:NaN:NaN
2388-1:NaN:NaN
23890:NaN:NaN
2390-inf:NaN:NaN
2391+inf:NaN:NaN
2392NaN:0:NaN
2393NaN:2:NaN
2394NaN:inf:NaN
2395NaN:inf:NaN
239612:-inf:NaN
239712:inf:NaN
2398+0:0:NaN
2399+1:0:NaN
2400-1:0:NaN
2401-2:0:NaN
2402-123.45:0:NaN
2403+inf:0:NaN
240412:1:12
2405-12:1:NaN
24068:-1:NaN
2407-8:-1:NaN
2408# cubic root
24098:3:2
2410-8:3:NaN
2411# fourths root
c38b2de2
JH
241216:4:2
241381:4:3
3a427a11 2414# 2 ** 64
c38b2de2
JH
241518446744073709551616:4:65536
241618446744073709551616:8:256
241718446744073709551616:16:16
241818446744073709551616:32:4
241918446744073709551616:64:2
242018446744073709551616:128:1
3a427a11
RGS
2421# 213 ** 15
242284274086103068221283760416414557757:15:213
50109ad0 2423# see t/bigroot.t for more tests
6854fd01 2424&bsqrt
394e6ffb 2425145:12
6854fd01 2426144:12
394e6ffb 2427143:11
6854fd01 242816:4
394e6ffb
JH
2429170:13
2430169:13
2431168:12
6854fd01 24324:2
394e6ffb 24333:1
6854fd01 24342:1
394e6ffb 24359:3
6854fd01
JH
243612:3
2437256:16
2438100000000:10000
24394000000000000:2000000
394e6ffb
JH
2440152399026:12345
2441152399025:12345
2442152399024:12344
3a427a11
RGS
2443# 2 ** 64 => 2 ** 32
244418446744073709551616:4294967296
244584274086103068221283760416414557757:290299993288095377
6854fd01
JH
24461:1
24470:0
2448-2:NaN
394e6ffb 2449-123:NaN
6854fd01 2450Nan:NaN
990fb837
RGS
2451+inf:inf
2452-inf:NaN
50109ad0
RGS
2453# see t/biglog.t for more tests
2454&bexp
2455NaN:NaN
2456inf:inf
24571:2
24582:7
30afc38d
T
2459&batan2
2460NaN:1:10:NaN
2461NaN:NaN:10:NaN
24621:NaN:10:NaN
2463inf:1:14:1
2464-inf:1:14:-1
0dceeee6
RGS
24650:-inf:14:3
2466-1:-inf:14:-3
24671:-inf:14:3
24680:inf:14:0
2469inf:-inf:14:2
2470-inf:-inf:14:-2
2471# +- 0.78....
2472inf:+inf:14:0
2473-inf:+inf:14:0
30afc38d
T
24741:5:13:0
24751:5:14:0
24760:0:10:0
24770:1:14:0
24780:2:14:0
24791:0:14:1
24805:0:14:1
2481-1:0:11:-1
2482-2:0:77:-1
24832:0:77:1
2484-1:5:14:0
24851:5:14:0
2486-1:8:14:0
24871:8:14:0
2488-1:1:14:0
fdb4b05f
T
2489&bpi
249077:3
2491+0:3
249211:3
50109ad0
RGS
2493# see t/bignok.t for more tests
2494&bnok
2495+inf:10:inf
2496NaN:NaN:NaN
2497NaN:1:NaN
24981:NaN:NaN
24991:1:1
2500# k > n
25011:2:0
25022:3:0
2503# k < 0
25041:-2:0
2505# 7 over 3 = 35
25067:3:35
d5735945 25077:6:7
50109ad0
RGS
2508100:90:17310309456440
2509100:95:75287520
d5735945
PF
25102:0:1
25117:0:1
25122:1:2
6854fd01
JH
2513&bround
2514$round_mode('trunc')
25150:12:0
2516NaNbround:12:NaN
2517+inf:12:inf
2518-inf:12:-inf
25191234:0:1234
25201234:2:1200
2521123456:4:123400
2522123456:5:123450
2523123456:6:123456
61f5c3f5 2524+10123456789:5:10123000000
6854fd01 2525-10123456789:5:-10123000000
61f5c3f5 2526+10123456789:9:10123456700
6854fd01 2527-10123456789:9:-10123456700
61f5c3f5 2528+101234500:6:101234000
6854fd01 2529-101234500:6:-101234000
61f5c3f5 2530#+101234500:-4:101234000
6854fd01
JH
2531#-101234500:-4:-101234000
2532$round_mode('zero')
61f5c3f5 2533+20123456789:5:20123000000
6854fd01 2534-20123456789:5:-20123000000
61f5c3f5 2535+20123456789:9:20123456800
6854fd01 2536-20123456789:9:-20123456800
61f5c3f5 2537+201234500:6:201234000
6854fd01 2538-201234500:6:-201234000
61f5c3f5 2539#+201234500:-4:201234000
6854fd01
JH
2540#-201234500:-4:-201234000
2541+12345000:4:12340000
2542-12345000:4:-12340000
2543$round_mode('+inf')
61f5c3f5 2544+30123456789:5:30123000000
6854fd01 2545-30123456789:5:-30123000000
61f5c3f5 2546+30123456789:9:30123456800
6854fd01 2547-30123456789:9:-30123456800
61f5c3f5 2548+301234500:6:301235000
6854fd01 2549-301234500:6:-301234000
61f5c3f5 2550#+301234500:-4:301235000
6854fd01
JH
2551#-301234500:-4:-301234000
2552+12345000:4:12350000
2553-12345000:4:-12340000
2554$round_mode('-inf')
61f5c3f5 2555+40123456789:5:40123000000
6854fd01 2556-40123456789:5:-40123000000
61f5c3f5 2557+40123456789:9:40123456800
6854fd01 2558-40123456789:9:-40123456800
61f5c3f5
T
2559+401234500:6:401234000
2560+401234500:6:401234000
6854fd01
JH
2561#-401234500:-4:-401235000
2562#-401234500:-4:-401235000
2563+12345000:4:12340000
2564-12345000:4:-12350000
2565$round_mode('odd')
61f5c3f5 2566+50123456789:5:50123000000
6854fd01 2567-50123456789:5:-50123000000
61f5c3f5 2568+50123456789:9:50123456800
6854fd01 2569-50123456789:9:-50123456800
61f5c3f5 2570+501234500:6:501235000
6854fd01 2571-501234500:6:-501235000
61f5c3f5 2572#+501234500:-4:501235000
6854fd01
JH
2573#-501234500:-4:-501235000
2574+12345000:4:12350000
2575-12345000:4:-12350000
2576$round_mode('even')
61f5c3f5 2577+60123456789:5:60123000000
6854fd01 2578-60123456789:5:-60123000000
61f5c3f5 2579+60123456789:9:60123456800
6854fd01 2580-60123456789:9:-60123456800
61f5c3f5 2581+601234500:6:601234000
6854fd01 2582-601234500:6:-601234000
61f5c3f5 2583#+601234500:-4:601234000
6854fd01
JH
2584#-601234500:-4:-601234000
2585#-601234500:-9:0
2586#-501234500:-9:0
2587#-601234500:-8:0
2588#-501234500:-8:0
2589+1234567:7:1234567
2590+1234567:6:1234570
2591+12345000:4:12340000
2592-12345000:4:-12340000
7b29e1e6
T
2593$round_mode('common')
2594+60123456789:5:60123000000
2595+60123199999:5:60123000000
2596+60123299999:5:60123000000
2597+60123399999:5:60123000000
2598+60123499999:5:60123000000
2599+60123500000:5:60124000000
2600+60123600000:5:60124000000
2601+60123700000:5:60124000000
2602+60123800000:5:60124000000
2603+60123900000:5:60124000000
2604-60123456789:5:-60123000000
2605-60123199999:5:-60123000000
2606-60123299999:5:-60123000000
2607-60123399999:5:-60123000000
2608-60123499999:5:-60123000000
2609-60123500000:5:-60124000000
2610-60123600000:5:-60124000000
2611-60123700000:5:-60124000000
2612-60123800000:5:-60124000000
2613-60123900000:5:-60124000000
6854fd01
JH
2614&is_zero
26150:1
2616NaNzero:0
2617+inf:0
2618-inf:0
2619123:0
2620-1:0
26211:0
2622&is_one
26230:0
2624NaNone:0
2625+inf:0
2626-inf:0
26271:1
26282:0
2629-1:0
2630-2:0
2631# floor and ceil tests are pretty pointless in integer space...but play safe
2632&bfloor
26330:0
2634NaNfloor:NaN
2635+inf:inf
2636-inf:-inf
2637-1:-1
2638-2:-2
26392:2
26403:3
2641abc:NaN
2642&bceil
2643NaNceil:NaN
2644+inf:inf
2645-inf:-inf
26460:0
2647-1:-1
2648-2:-2
26492:2
26503:3
2651abc:NaN
2652&as_hex
2653128:0x80
2654-128:-0x80
26550:0x0
2656-0:0x0
26571:0x1
26580x123456789123456789:0x123456789123456789
2659+inf:inf
2660-inf:-inf
2661NaNas_hex:NaN
2662&as_bin
2663128:0b10000000
2664-128:-0b10000000
26650:0b0
2666-0:0b0
26671:0b1
26680b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 26690x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01
JH
2670+inf:inf
2671-inf:-inf
2672NaNas_bin:NaN