pidigits benchmark and bpi() method in Math::BigFloat/Math::BigInt, take 7 [PATCH]
[p5sagit/p5-mst-13.2.git] / lib / Math / BigInt / t / bigintpm.inc
CommitLineData
6854fd01 1#include this file into another for subclass testing
2
3my $version = ${"$class\::VERSION"};
4
56d9de68 5use strict;
6
6854fd01 7##############################################################################
8# for testing inheritance of _swap
9
10package Math::Foo;
11
61f5c3f5 12use Math::BigInt lib => $main::CL;
6854fd01 13use vars qw/@ISA/;
14@ISA = (qw/Math::BigInt/);
15
16use overload
17# customized overload for sub, since original does not use swap there
18'-' => sub { my @a = ref($_[0])->_swap(@_);
19 $a[0]->bsub($a[1])};
20
21sub _swap
22 {
23 # a fake _swap, which reverses the params
24 my $self = shift; # for override in subclass
25 if ($_[2])
26 {
27 my $c = ref ($_[0] ) || 'Math::Foo';
28 return ( $_[0]->copy(), $_[1] );
29 }
30 else
31 {
32 return ( Math::Foo->new($_[1]), $_[0] );
33 }
34 }
35
36##############################################################################
37package main;
38
b3abae2a 39my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
6854fd01 40
b3abae2a 41my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
6854fd01 42
43while (<DATA>)
44 {
d614cd8b 45 chomp;
6854fd01 46 next if /^#/; # skip comments
47 if (s/^&//)
48 {
61f5c3f5 49 $f = $_; next;
6854fd01 50 }
51 elsif (/^\$/)
52 {
61f5c3f5 53 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
6854fd01 54 }
61f5c3f5 55
56 @args = split(/:/,$_,99); $ans = pop(@args);
b3abae2a 57 $expected_class = $class;
58 if ($ans =~ /(.*?)=(.*)/)
59 {
60 $expected_class = $2; $ans = $1;
61 }
61f5c3f5 62 $try = "\$x = $class->new(\"$args[0]\");";
63 if ($f eq "bnorm")
6854fd01 64 {
61f5c3f5 65 $try = "\$x = $class->bnorm(\"$args[0]\");";
66 # some is_xxx tests
b3abae2a 67 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
56d9de68 68 $try .= "\$x->$f() || 0;";
61f5c3f5 69 } elsif ($f eq "is_inf") {
70 $try .= "\$x->is_inf('$args[1]');";
71 } elsif ($f eq "binf") {
72 $try .= "\$x->binf('$args[1]');";
73 } elsif ($f eq "bone") {
74 $try .= "\$x->bone('$args[1]');";
56d9de68 75 # some unary ops
b3abae2a 76 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
61f5c3f5 77 $try .= "\$x->$f();";
56d9de68 78 } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
79 $try .= "\$x->$f();";
61f5c3f5 80 } elsif ($f eq "exponent"){
81 # ->bstr() to see if an object is returned
82 $try .= '$x = $x->exponent()->bstr();';
83 } elsif ($f eq "mantissa"){
84 # ->bstr() to see if an object is returned
85 $try .= '$x = $x->mantissa()->bstr();';
86 } elsif ($f eq "parts"){
87 $try .= '($m,$e) = $x->parts();';
88 # ->bstr() to see if an object is returned
89 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
90 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
91 $try .= '"$m,$e";';
50109ad0 92 }elsif ($f eq "bexp"){
93 $try .= "\$x->bexp();";
fdb4b05f 94 } elsif ($f eq "bpi"){
95 $try .= "$class\->bpi(\$x);";
61f5c3f5 96 } else {
56d9de68 97 # binary ops
61f5c3f5 98 $try .= "\$y = $class->new('$args[1]');";
99 if ($f eq "bcmp")
100 {
a0ac753d 101 $try .= '$x->bcmp($y);';
61f5c3f5 102 } elsif ($f eq "bround") {
6854fd01 103 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5 104 } elsif ($f eq "bacmp"){
105 $try .= '$x->bacmp($y);';
106 } elsif ($f eq "badd"){
107 $try .= '$x + $y;';
108 } elsif ($f eq "bsub"){
109 $try .= '$x - $y;';
110 } elsif ($f eq "bmul"){
111 $try .= '$x * $y;';
112 } elsif ($f eq "bdiv"){
113 $try .= '$x / $y;';
114 } elsif ($f eq "bdiv-list"){
115 $try .= 'join (",",$x->bdiv($y));';
027dc388 116 # overload via x=
61f5c3f5 117 } elsif ($f =~ /^.=$/){
118 $try .= "\$x $f \$y;";
027dc388 119 # overload via x
61f5c3f5 120 } elsif ($f =~ /^.$/){
121 $try .= "\$x $f \$y;";
122 } elsif ($f eq "bmod"){
123 $try .= '$x % $y;';
124 } elsif ($f eq "bgcd")
6854fd01 125 {
126 if (defined $args[2])
127 {
61f5c3f5 128 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 129 }
130 $try .= "$class\::bgcd(\$x, \$y";
131 $try .= ", \$z" if (defined $args[2]);
132 $try .= " );";
133 }
134 elsif ($f eq "blcm")
135 {
136 if (defined $args[2])
137 {
61f5c3f5 138 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 139 }
140 $try .= "$class\::blcm(\$x, \$y";
141 $try .= ", \$z" if (defined $args[2]);
142 $try .= " );";
143 }elsif ($f eq "blsft"){
144 if (defined $args[2])
145 {
146 $try .= "\$x->blsft(\$y,$args[2]);";
147 }
148 else
149 {
150 $try .= "\$x << \$y;";
151 }
152 }elsif ($f eq "brsft"){
153 if (defined $args[2])
154 {
155 $try .= "\$x->brsft(\$y,$args[2]);";
156 }
157 else
158 {
159 $try .= "\$x >> \$y;";
160 }
50109ad0 161 }elsif ($f eq "bnok"){
162 $try .= "\$x->bnok(\$y);";
990fb837 163 }elsif ($f eq "broot"){
164 $try .= "\$x->broot(\$y);";
091c87b1 165 }elsif ($f eq "blog"){
166 $try .= "\$x->blog(\$y);";
6854fd01 167 }elsif ($f eq "band"){
168 $try .= "\$x & \$y;";
169 }elsif ($f eq "bior"){
170 $try .= "\$x | \$y;";
171 }elsif ($f eq "bxor"){
172 $try .= "\$x ^ \$y;";
173 }elsif ($f eq "bpow"){
174 $try .= "\$x ** \$y;";
d614cd8b 175 } elsif( $f eq "bmodinv") {
176 $try .= "\$x->bmodinv(\$y);";
6854fd01 177 }elsif ($f eq "digit"){
56b9c951 178 $try .= "\$x->digit(\$y);";
d614cd8b 179 } else {
180 $try .= "\$z = $class->new(\"$args[2]\");";
181
182 # Functions with three arguments
183 if( $f eq "bmodpow") {
184 $try .= "\$x->bmodpow(\$y,\$z);";
185 } else { warn "Unknown op '$f'"; }
186 }
61f5c3f5 187 } # end else all other ops
188
189 $ans1 = eval $try;
190 # convert hex/binary targets to decimal
191 if ($ans =~ /^(0x0x|0b0b)/)
192 {
193 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 194 }
61f5c3f5 195 if ($ans eq "")
196 {
197 ok_undef ($ans1);
198 }
199 else
200 {
201 # print "try: $try ans: $ans1 $ans\n";
202 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 203 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 204 }
61f5c3f5 205 # check internal state of number objects
206 is_valid($ans1,$f) if ref $ans1;
6854fd01 207 } # endwhile data tests
208close DATA;
209
210# test some more
211@a = ();
212for (my $i = 1; $i < 10; $i++)
213 {
214 push @a, $i;
215 }
216ok "@a", "1 2 3 4 5 6 7 8 9";
217
218# test whether self-multiplication works correctly (result is 2**64)
219$try = "\$x = $class->new('4294967296');";
220$try .= '$a = $x->bmul($x);';
221$ans1 = eval $try;
222print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
223# test self-pow
224$try = "\$x = $class->new(10);";
225$try .= '$a = $x->bpow($x);';
226$ans1 = eval $try;
227print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
228
07d34614 229###############################################################################
6854fd01 230# test whether op destroys args or not (should better not)
231
232$x = $class->new(3);
233$y = $class->new(4);
234$z = $x & $y;
235ok ($x,3);
236ok ($y,4);
237ok ($z,0);
238$z = $x | $y;
239ok ($x,3);
240ok ($y,4);
241ok ($z,7);
242$x = $class->new(1);
243$y = $class->new(2);
244$z = $x | $y;
245ok ($x,1);
246ok ($y,2);
247ok ($z,3);
248
249$x = $class->new(5);
250$y = $class->new(4);
251$z = $x ^ $y;
252ok ($x,5);
253ok ($y,4);
254ok ($z,1);
255
256$x = $class->new(-5); $y = -$x;
257ok ($x, -5);
258
259$x = $class->new(-5); $y = abs($x);
260ok ($x, -5);
261
07d34614 262$x = $class->new(8);
263$y = $class->new(-1);
264$z = $class->new(5033);
265my $u = $x->copy()->bmodpow($y,$z);
266ok ($u,4404);
267ok ($y,-1);
268ok ($z,5033);
269
270$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
271$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
272
273$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
274$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
275$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
276$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
277$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
278
279$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
280$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
281$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
282$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
283$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
284
285$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
286$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
287$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
288$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
289$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
290
291###############################################################################
6854fd01 292# check whether overloading cmp works
293$try = "\$x = $class->new(0);";
294$try .= "\$y = 10;";
295$try .= "'false' if \$x ne \$y;";
296$ans = eval $try;
297print "# For '$try'\n" if (!ok "$ans" , "false" );
298
299# we cant test for working cmpt with other objects here, we would need a dummy
300# object with stringify overload for this. see Math::String tests as example
301
302###############################################################################
6854fd01 303# check reversed order of arguments
027dc388 304
6854fd01 305$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
306$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
307print "# For '$try'\n" if (!ok "$ans" , "ok" );
308
309$try = "\$x = $class->new(10); \$x = 2 * \$x;";
310$try .= "'ok' if \$x == 20;"; $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 == 12;"; $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 == -8;"; $ans = eval $try;
319print "# For '$try'\n" if (!ok "$ans" , "ok" );
320
321$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
322$try .= "'ok' if \$x == 2;"; $ans = eval $try;
323print "# For '$try'\n" if (!ok "$ans" , "ok" );
324
027dc388 325$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
326$try .= "'ok' if \$x == 2;"; $ans = eval $try;
327print "# For '$try'\n" if (!ok "$ans" , "ok" );
328
329$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
330$try .= "'ok' if \$x == 4;"; $ans = eval $try;
331print "# For '$try'\n" if (!ok "$ans" , "ok" );
332
333$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
334$try .= "'ok' if \$x == 0x27;"; $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
6854fd01 341###############################################################################
342# check badd(4,5) form
343
344$try = "\$x = $class\->badd(4,5);";
345$try .= "'ok' if \$x == 9;";
346$ans = eval $try;
347print "# For '$try'\n" if (!ok "$ans" , "ok" );
348
349###############################################################################
350# check undefs: NOT DONE YET
351
352###############################################################################
353# bool
354
f9a08e12 355$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
356$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 357
358###############################################################################
359# objectify()
360
361@args = Math::BigInt::objectify(2,4,5);
362ok (scalar @args,3); # $class, 4, 5
56b9c951 363ok ($args[0] =~ /^Math::BigInt/);
6854fd01 364ok ($args[1],4);
365ok ($args[2],5);
366
367@args = Math::BigInt::objectify(0,4,5);
368ok (scalar @args,3); # $class, 4, 5
56b9c951 369ok ($args[0] =~ /^Math::BigInt/);
6854fd01 370ok ($args[1],4);
371ok ($args[2],5);
372
373@args = Math::BigInt::objectify(2,4,5);
374ok (scalar @args,3); # $class, 4, 5
56b9c951 375ok ($args[0] =~ /^Math::BigInt/);
6854fd01 376ok ($args[1],4);
377ok ($args[2],5);
378
379@args = Math::BigInt::objectify(2,4,5,6,7);
380ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 381ok ($args[0] =~ /^Math::BigInt/);
6854fd01 382ok ($args[1],4); ok (ref($args[1]),$args[0]);
383ok ($args[2],5); ok (ref($args[2]),$args[0]);
384ok ($args[3],6); ok (ref($args[3]),'');
385ok ($args[4],7); ok (ref($args[4]),'');
386
387@args = Math::BigInt::objectify(2,$class,4,5,6,7);
388ok (scalar @args,5); # $class, 4, 5, 6, 7
389ok ($args[0],$class);
390ok ($args[1],4); ok (ref($args[1]),$args[0]);
391ok ($args[2],5); ok (ref($args[2]),$args[0]);
392ok ($args[3],6); ok (ref($args[3]),'');
393ok ($args[4],7); ok (ref($args[4]),'');
394
395###############################################################################
f9a08e12 396# test whether an opp calls objectify properly or not (or at least does what
397# it should do given non-objects, w/ or w/o objectify())
398
399ok ($class->new(123)->badd(123),246);
400ok ($class->badd(123,321),444);
401ok ($class->badd(123,$class->new(321)),444);
402
403ok ($class->new(123)->bsub(122),1);
404ok ($class->bsub(321,123),198);
405ok ($class->bsub(321,$class->new(123)),198);
406
407ok ($class->new(123)->bmul(123),15129);
408ok ($class->bmul(123,123),15129);
409ok ($class->bmul(123,$class->new(123)),15129);
410
411ok ($class->new(15129)->bdiv(123),123);
412ok ($class->bdiv(15129,123),123);
413ok ($class->bdiv(15129,$class->new(123)),123);
414
415ok ($class->new(15131)->bmod(123),2);
416ok ($class->bmod(15131,123),2);
417ok ($class->bmod(15131,$class->new(123)),2);
418
419ok ($class->new(2)->bpow(16),65536);
420ok ($class->bpow(2,16),65536);
421ok ($class->bpow(2,$class->new(16)),65536);
422
423ok ($class->new(2**15)->brsft(1),2**14);
424ok ($class->brsft(2**15,1),2**14);
425ok ($class->brsft(2**15,$class->new(1)),2**14);
426
427ok ($class->new(2**13)->blsft(1),2**14);
428ok ($class->blsft(2**13,1),2**14);
429ok ($class->blsft(2**13,$class->new(1)),2**14);
430
431###############################################################################
6854fd01 432# test for floating-point input (other tests in bnorm() below)
433
434$z = 1050000000000000; # may be int on systems with 64bit?
435$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
436$z = 1e+129; # definitely a float (may fail on UTS)
437# don't compare to $z, since some Perl versions stringify $z into something
438# like '1.e+129' or something equally ugly
439$x = $class->new($z); ok ($x->bsstr(),'1e+129');
440
441###############################################################################
56d9de68 442# test for whitespace inlcuding newlines to be handled correctly
443
444# ok ($Math::BigInt::strict,1); # the default
445
446foreach my $c (
447 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
448 {
449 my $m = $class->new($c);
450 ok ($class->new("$c"),$m);
451 ok ($class->new(" $c"),$m);
452 ok ($class->new("$c "),$m);
453 ok ($class->new(" $c "),$m);
454 ok ($class->new("\n$c"),$m);
455 ok ($class->new("$c\n"),$m);
456 ok ($class->new("\n$c\n"),$m);
457 ok ($class->new(" \n$c\n"),$m);
458 ok ($class->new(" \n$c \n"),$m);
459 ok ($class->new(" \n$c\n "),$m);
460 ok ($class->new(" \n$c\n1"),'NaN');
461 ok ($class->new("1 \n$c\n1"),'NaN');
462 }
463
464###############################################################################
6854fd01 465# prime number tests, also test for **= and length()
466# found on: http://www.utm.edu/research/primes/notes/by_year.html
467
468# ((2^148)-1)/17
469$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
470ok ($x,"20988936657440586486151264256610222593863921");
471ok ($x->length(),length "20988936657440586486151264256610222593863921");
472
473# MM7 = 2^127-1
474$x = $class->new(2); $x **= 127; $x--;
475ok ($x,"170141183460469231731687303715884105727");
476
477$x = $class->new('215960156869840440586892398248');
478($x,$y) = $x->length();
479ok ($x,30); ok ($y,0);
480
481$x = $class->new('1_000_000_000_000');
482($x,$y) = $x->length();
483ok ($x,13); ok ($y,0);
484
2d2b2744 485# test <<=, >>=
486$x = $class->new('2');
487my $y = $class->new('18');
488ok ($x <<= $y, 2 << 18);
489ok ($x, 2 << 18);
490ok ($x >>= $y, 2);
491ok ($x, 2);
492
6854fd01 493# I am afraid the following is not yet possible due to slowness
494# Also, testing for 2 meg output is a bit hard ;)
495#$x = $class->new(2); $x **= 6972593; $x--;
496
497# 593573509*2^332162+1 has exactly 1,000,000 digits
498# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
499#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
500#ok ($x->length(),1_000_000);
501
502###############################################################################
503# inheritance and overriding of _swap
504
505$x = Math::Foo->new(5);
506$x = $x - 8; # 8 - 5 instead of 5-8
507ok ($x,3);
508ok (ref($x),'Math::Foo');
509
510$x = Math::Foo->new(5);
511$x = 8 - $x; # 5 - 8 instead of 8 - 5
512ok ($x,-3);
513ok (ref($x),'Math::Foo');
514
515###############################################################################
516# Test whether +inf eq inf
517# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
518# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
519# like 1e100000 crash on some platforms. So simple test for the string 'inf'
520$x = $class->new('+inf'); ok ($x,'inf');
521
522###############################################################################
523###############################################################################
56d9de68 524# the followin tests only make sense with Math::BigInt::Calc or BareCalc or
525# FastCalc
6854fd01 526
56d9de68 527exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01 528
529###############################################################################
530# check proper length of internal arrays
531
394e6ffb 532my $bl = $CL->_base_len();
6854fd01 533my $BASE = '9' x $bl;
534my $MAX = $BASE;
535$BASE++;
536
537$x = $class->new($MAX); is_valid($x); # f.i. 9999
538$x += 1; ok ($x,$BASE); is_valid($x); # 10000
539$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
540
541###############################################################################
542# check numify
543
544$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
545$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 546
547# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
548$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 549$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
550$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
551ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
552
553###############################################################################
554# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
555
394e6ffb 556$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
557if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
558
559$x = $class->new($BASE+3); $x++;
560if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 561
394e6ffb 562# test for +0 instead of int():
563$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 564
565###############################################################################
56b9c951 566# test bug that $class->digit($string) did not work
567
568ok ($class->digit(123,2),1);
569
570###############################################################################
6854fd01 571# bug in sub where number with at least 6 trailing zeros after any op failed
572
394e6ffb 573$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 574ok ($z, 100000);
575ok ($x, 23456);
576
577###############################################################################
578# bug in shortcut in mul()
579
61f5c3f5 580# construct a number with a zero-hole of BASE_LEN_SMALL
581{
582 my @bl = $CL->_base_len(); my $bl = $bl[4];
583
584 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
585 $y = '1' x (2*$bl);
586 $x = $class->new($x)->bmul($y);
587 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
588 $y = ''; my $d = '';
589 for (my $i = 1; $i <= $bl; $i++)
590 {
591 $y .= $i; $d = $i.$d;
592 }
593 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
594 ok ($x,$y);
595
6854fd01 596
f9a08e12 597 #############################################################################
598 # see if mul shortcut for small numbers works
394e6ffb 599
f9a08e12 600 $x = '9' x $bl;
601 $x = $class->new($x);
602 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
603 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
604}
61f5c3f5 605
394e6ffb 606###############################################################################
6854fd01 607# bug with rest "-0" in div, causing further div()s to fail
608
394e6ffb 609$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 610
61f5c3f5 611ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 612
79c55733 613###############################################################################
f9a08e12 614# bug in $x->bmod($y)
07d34614 615
f9a08e12 616# if $x < 0 and $y > 0
07d34614 617$x = $class->new('-629'); ok ($x->bmod(5033),4404);
618
619###############################################################################
56b9c951 620# bone/binf etc as plain calls (Lite failed them)
621
622ok ($class->bzero(),0);
623ok ($class->bone(),1);
624ok ($class->bone('+'),1);
625ok ($class->bone('-'),-1);
626ok ($class->bnan(),'NaN');
627ok ($class->binf(),'inf');
628ok ($class->binf('+'),'inf');
629ok ($class->binf('-'),'-inf');
630ok ($class->binf('-inf'),'-inf');
631
632###############################################################################
990fb837 633# is_one('-')
634
635ok ($class->new(1)->is_one('-'),0);
636ok ($class->new(-1)->is_one('-'),1);
637ok ($class->new(1)->is_one(),1);
638ok ($class->new(-1)->is_one(),0);
639
640###############################################################################
03874afe 641# [perl #30609] bug with $x -= $x not beeing 0, but 2*$x
642
643$x = $class->new(3); $x -= $x; ok ($x, 0);
644$x = $class->new(-3); $x -= $x; ok ($x, 0);
645$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
646$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
647$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
648
649$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
650$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
651$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
652$x = $class->new(3); $x += $x; ok ($x, 6);
653$x = $class->new(-3); $x += $x; ok ($x, -6);
654
655$x = $class->new(3); $x *= $x; ok ($x, 9);
656$x = $class->new(-3); $x *= $x; ok ($x, 9);
657$x = $class->new(3); $x /= $x; ok ($x, 1);
658$x = $class->new(-3); $x /= $x; ok ($x, 1);
659$x = $class->new(3); $x %= $x; ok ($x, 0);
660$x = $class->new(-3); $x %= $x; ok ($x, 0);
661
662###############################################################################
61f5c3f5 663# all tests done
6854fd01 664
6651;
666
667###############################################################################
61f5c3f5 668###############################################################################
6854fd01 669# Perl 5.005 does not like ok ($x,undef)
670
671sub ok_undef
672 {
673 my $x = shift;
674
675 ok (1,1) and return if !defined $x;
676 ok ($x,'undef');
677 }
678
679###############################################################################
680# sub to check validity of a BigInt internally, to ensure that no op leaves a
681# number object in an invalid state (f.i. "-0")
682
683sub is_valid
684 {
685 my ($x,$f) = @_;
686
687 my $e = 0; # error?
6854fd01 688
56b9c951 689 # allow the check to pass for all Lite, and all MBI and subclasses
690 # ok as reference?
691 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 692
56b9c951 693 if (ref($x) ne 'Math::BigInt::Lite')
694 {
695 # has ok sign?
696 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
697 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
698
699 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
700 $e = $CALC->_check($x->{value}) if $e eq '0';
701 }
6854fd01 702
703 # test done, see if error did crop up
704 ok (1,1), return if ($e eq '0');
705
027dc388 706 ok (1,$e." after op '$f'");
6854fd01 707 }
708
709__DATA__
027dc388 710&.=
7111234:-345:1234-345
712&+=
7131:2:3
714-1:-2:-3
715&-=
7161:2:-1
717-1:-2:1
718&*=
7192:3:6
720-1:5:-5
721&%=
722100:3:1
7238:9:8
07d34614 724-629:5033:4404
027dc388 725&/=
726100:3:33
727-8:2:-4
728&|=
7292:1:3
730&&=
7315:7:5
732&^=
7335:7:2
091c87b1 734&blog
735NaNlog:2:NaN
736122:NaNlog:NaN
737NaNlog1:NaNlog:NaN
738122:inf:NaN
739inf:122:NaN
740122:-inf:NaN
741-inf:122:NaN
742-inf:-inf:NaN
743inf:inf:NaN
7440:4:NaN
745-21:4:NaN
74621:-21:NaN
747# normal results
7481024:2:10
74981:3:4
750# 3.01.. truncate
75182:3:4
752# 3.9... truncate
75380:3:3
75415625:5:6
75515626:5:6
75615624:5:5
8df1e0a2 7571000:10:3
75810000:10:4
759100000:10:5
7601000000:10:6
76110000000:10:7
762100000000:10:8
7638916100448256:12:12
7648916100448257:12:12
7658916100448255:12:11
7662251799813685248:8:17
76772057594037927936:2:56
768144115188075855872:2:57
769288230376151711744:2:58
770576460752303423488:2:59
7714096:2:12
7721329227995784915872903807060280344576:2:120
091c87b1 773# $x == $base => result 1
7743:3:1
775# $x < $base => result 0 ($base ** 0 <= $x)
7763:4:0
777# $x == 1 => result 0
7781:5:0
6854fd01 779&is_negative
7800:0
781-1:1
7821:0
783+inf:0
784-inf:1
785NaNneg:0
786&is_positive
b68b7ab1 7870:0
6854fd01 788-1:0
7891:1
790+inf:1
791-inf:0
792NaNneg:0
b3abae2a 793&is_int
794-inf:0
795+inf:0
796NaNis_int:0
7971:1
7980:1
799123e12:1
6854fd01 800&is_odd
801abc:0
8020:0
8031:1
8043:1
805-1:1
806-3:1
80710000001:1
80810000002:0
8092:0
b3abae2a 810120:0
811121:1
6854fd01 812&is_even
813abc:0
8140:1
8151:0
8163:0
817-1:0
818-3:0
81910000001:0
82010000002:1
8212:1
b3abae2a 822120:1
823121:0
6854fd01 824&bacmp
825+0:-0:0
826+0:+1:-1
827-1:+1:0
828+1:-1:0
829-1:+2:-1
830+2:-1:1
831-123456789:+987654321:-1
832+123456789:-987654321:-1
833+987654321:+123456789:1
834-987654321:+123456789:1
835-123:+4567889:-1
836# NaNs
837acmpNaN:123:
838123:acmpNaN:
839acmpNaN:acmpNaN:
840# infinity
841+inf:+inf:0
842-inf:-inf:0
843+inf:-inf:0
844-inf:+inf:0
845+inf:123:1
846-inf:123:1
847+inf:-123:1
848-inf:-123:1
ef9466ea 849123:-inf:-1
850-123:inf:-1
851-123:-inf:-1
852123:inf:-1
6854fd01 853# return undef
854+inf:NaN:
855NaN:inf:
856-inf:NaN:
857NaN:-inf:
858&bnorm
aef458a0 8590e999:0
8600e-999:0
861-0e999:0
862-0e-999:0
6854fd01 863123:123
864# binary input
8650babc:NaN
8660b123:NaN
8670b0:0
868-0b0:0
869-0b1:-1
8700b0001:1
8710b001:1
8720b011:3
8730b101:5
61f5c3f5 8740b1001:9
8750b10001:17
8760b100001:33
8770b1000001:65
8780b10000001:129
8790b100000001:257
8800b1000000001:513
8810b10000000001:1025
8820b100000000001:2049
8830b1000000000001:4097
8840b10000000000001:8193
8850b100000000000001:16385
8860b1000000000000001:32769
8870b10000000000000001:65537
8880b100000000000000001:131073
8890b1000000000000000001:262145
8900b10000000000000000001:524289
8910b100000000000000000001:1048577
8920b1000000000000000000001:2097153
8930b10000000000000000000001:4194305
8940b100000000000000000000001:8388609
8950b1000000000000000000000001:16777217
8960b10000000000000000000000001:33554433
8970b100000000000000000000000001:67108865
8980b1000000000000000000000000001:134217729
8990b10000000000000000000000000001:268435457
9000b100000000000000000000000000001:536870913
9010b1000000000000000000000000000001:1073741825
9020b10000000000000000000000000000001:2147483649
9030b100000000000000000000000000000001:4294967297
9040b1000000000000000000000000000000001:8589934593
9050b10000000000000000000000000000000001:17179869185
6854fd01 9060b_101:NaN
9070b1_0_1:5
394e6ffb 9080b0_0_0_1:1
6854fd01 909# hex input
910-0x0:0
9110xabcdefgh:NaN
9120x1234:4660
9130xabcdef:11259375
914-0xABCDEF:-11259375
915-0x1234:-4660
9160x12345678:305419896
9170x1_2_3_4_56_78:305419896
394e6ffb 9180xa_b_c_d_e_f:11259375
6854fd01 9190x_123:NaN
61f5c3f5 9200x9:9
9210x11:17
9220x21:33
9230x41:65
9240x81:129
9250x101:257
9260x201:513
9270x401:1025
9280x801:2049
9290x1001:4097
9300x2001:8193
9310x4001:16385
9320x8001:32769
9330x10001:65537
9340x20001:131073
9350x40001:262145
9360x80001:524289
9370x100001:1048577
9380x200001:2097153
9390x400001:4194305
9400x800001:8388609
9410x1000001:16777217
9420x2000001:33554433
9430x4000001:67108865
9440x8000001:134217729
9450x10000001:268435457
9460x20000001:536870913
9470x40000001:1073741825
9480x80000001:2147483649
9490x100000001:4294967297
9500x200000001:8589934593
9510x400000001:17179869185
9520x800000001:34359738369
2d2b2744 953# bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex()
9540x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
6854fd01 955# inf input
956inf:inf
957+inf:inf
958-inf:-inf
9590inf:NaN
027dc388 960# abnormal input
6854fd01 961:NaN
962abc:NaN
963 1 a:NaN
9641bcd2:NaN
96511111b:NaN
966+1z:NaN
967-1z:NaN
027dc388 968# only one underscore between two digits
969_123:NaN
970_123_:NaN
971123_:NaN
9721__23:NaN
9731E1__2:NaN
9741_E12:NaN
9751E_12:NaN
9761_E_12:NaN
977+_1E12:NaN
978+0_1E2:100
979+0_0_1E2:100
980-0_0_1E2:-100
981-0_0_1E+0_0_2:-100
982E1:NaN
983E23:NaN
9841.23E1:NaN
9851.23E-1:NaN
986# bug with two E's in number beeing valid
9871e2e3:NaN
9881e2r:NaN
9891e2.0:NaN
07d34614 990# bug with two '.' in number beeing valid
9911.2.2:NaN
9921.2.3e1:NaN
993-1.2.3:NaN
994-1.2.3e-4:NaN
9951.2e3.4:NaN
9961.2e-3.4:NaN
9971.2.3.4:NaN
9981.2.t:NaN
9991..2:NaN
10001..2e1:NaN
10011..2e1..1:NaN
100212e1..1:NaN
1003..2:NaN
1004.-2:NaN
61f5c3f5 1005# leading zeros
1006012:12
10070123:123
100801234:1234
1009012345:12345
10100123456:123456
101101234567:1234567
1012012345678:12345678
10130123456789:123456789
101401234567891:1234567891
1015012345678912:12345678912
10160123456789123:123456789123
101701234567891234:1234567891234
2d2b2744 1018# some inputs that result in zero
10190e0:0
1020+0e0:0
1021+0e+0:0
1022-0e+0:0
10230e-0:0
1024-0e-0:0
1025+0e-0:0
1026000:0
102700e2:0
102800e02:0
1029000e002:0
1030000e1230:0
103100e-3:0
103200e+3:0
103300e-03:0
103400e+03:0
1035-000:0
1036-00e2:0
1037-00e02:0
1038-000e002:0
1039-000e1230:0
1040-00e-3:0
1041-00e+3:0
1042-00e-03:0
1043-00e+03:0
027dc388 1044# normal input
6854fd01 10450:0
1046+0:0
1047+00:0
1048+000:0
1049000000000000000000:0
1050-0:0
1051-0000:0
1052+1:1
1053+01:1
1054+001:1
1055+00000100000:100000
1056123456789:123456789
1057-1:-1
1058-01:-1
1059-001:-1
1060-123456789:-123456789
1061-00000100000:-100000
10621_2_3:123
6854fd01 106310000000000E-1_0:1
10641E2:100
10651E1:10
10661E0:1
6854fd01 10671.23E2:123
6854fd01 1068100E-1:10
1069# floating point input
027dc388 1070# .2e2:20
10711.E3:1000
6854fd01 10721.01E2:101
10731010E-1:101
1074-1010E0:-1010
1075-1010E1:-10100
027dc388 10761234.00:1234
1077# non-integer numbers
6854fd01 1078-1010E-2:NaN
1079-1.01E+1:NaN
1080-1.01E-1:NaN
6854fd01 1081&bnan
10821:NaN
10832:NaN
1084abc:NaN
1085&bone
61f5c3f5 10862:+:1
6854fd01 10872:-:-1
1088boneNaN:-:-1
61f5c3f5 1089boneNaN:+:1
10902:abc:1
10913::1
6854fd01 1092&binf
10931:+:inf
10942:-:-inf
10953:abc:inf
027dc388 1096&is_nan
1097123:0
1098abc:1
1099NaN:1
1100-123:0
6854fd01 1101&is_inf
1102+inf::1
1103-inf::1
1104abc::0
11051::0
1106NaN::0
1107-1::0
1108+inf:-:0
1109+inf:+:1
1110-inf:-:1
1111-inf:+:0
79c55733 1112-inf:-inf:1
1113-inf:+inf:0
1114+inf:-inf:0
1115+inf:+inf:1
6854fd01 1116# it must be exactly /^[+-]inf$/
1117+infinity::0
1118-infinity::0
1119&blsft
1120abc:abc:NaN
61f5c3f5 1121+2:+2:8
1122+1:+32:4294967296
1123+1:+48:281474976710656
6854fd01 1124+8:-2:NaN
1125# excercise base 10
1126+12345:4:10:123450000
1127-1234:0:10:-1234
61f5c3f5 1128+1234:0:10:1234
6854fd01 1129+2:2:10:200
1130+12:2:10:1200
1131+1234:-3:10:NaN
11321234567890123:12:10:1234567890123000000000000
b3abae2a 1133-3:1:2:-6
1134-5:1:2:-10
1135-2:1:2:-4
1136-102533203:1:2:-205066406
6854fd01 1137&brsft
1138abc:abc:NaN
61f5c3f5 1139+8:+2:2
1140+4294967296:+32:1
1141+281474976710656:+48:1
6854fd01 1142+2:-2:NaN
1143# excercise base 10
1144-1234:0:10:-1234
61f5c3f5 1145+1234:0:10:1234
6854fd01 1146+200:2:10:2
1147+1234:3:10:1
1148+1234:2:10:12
1149+1234:-3:10:NaN
1150310000:4:10:31
115112300000:5:10:123
11521230000000000:10:10:123
115309876123456789067890:12:10:9876123
11541234561234567890123:13:10:123456
b3abae2a 1155820265627:1:2:410132813
1156# test shifting negative numbers in base 2
1157-15:1:2:-8
1158-14:1:2:-7
1159-13:1:2:-7
1160-12:1:2:-6
1161-11:1:2:-6
1162-10:1:2:-5
1163-9:1:2:-5
1164-8:1:2:-4
1165-7:1:2:-4
1166-6:1:2:-3
1167-5:1:2:-3
1168-4:1:2:-2
1169-3:1:2:-2
1170-2:1:2:-1
1171-1:1:2:-1
1172-1640531254:2:2:-410132814
1173-1640531254:1:2:-820265627
1174-820265627:1:2:-410132814
1175-205066405:1:2:-102533203
6854fd01 1176&bsstr
56d9de68 1177+inf:inf
1178-inf:-inf
6854fd01 11791e+34:1e+34
1180123.456E3:123456e+0
1181100:1e+2
56d9de68 1182bsstrabc:NaN
1183-5:-5e+0
1184-100:-1e+2
1185&numify
1186numifyabc:NaN
1187+inf:inf
1188-inf:-inf
11895:5
1190-5:-5
1191100:100
1192-100:-100
6854fd01 1193&bneg
1194bnegNaN:NaN
1195+inf:-inf
1196-inf:inf
1197abd:NaN
61f5c3f5 11980:0
11991:-1
1200-1:1
6854fd01 1201+123456789:-123456789
61f5c3f5 1202-123456789:123456789
6854fd01 1203&babs
1204babsNaN:NaN
1205+inf:inf
1206-inf:inf
61f5c3f5 12070:0
12081:1
1209-1:1
1210+123456789:123456789
1211-123456789:123456789
6854fd01 1212&bcmp
1213bcmpNaN:bcmpNaN:
61f5c3f5 1214bcmpNaN:0:
12150:bcmpNaN:
12160:0:0
1217-1:0:-1
12180:-1:1
12191:0:1
12200:1:-1
1221-1:1:-1
12221:-1:1
6854fd01 1223-1:-1:0
61f5c3f5 12241:1:0
1225123:123:0
1226123:12:1
122712:123:-1
6854fd01 1228-123:-123:0
1229-123:-12:-1
1230-12:-123:1
61f5c3f5 1231123:124:-1
1232124:123:1
6854fd01 1233-123:-124:1
1234-124:-123:-1
61f5c3f5 1235100:5:1
1236-123456789:987654321:-1
6854fd01 1237+123456789:-987654321:1
61f5c3f5 1238-987654321:123456789:-1
6854fd01 1239-inf:5432112345:-1
1240+inf:5432112345:1
1241-inf:-5432112345:-1
1242+inf:-5432112345:1
1243+inf:+inf:0
1244-inf:-inf:0
1245+inf:-inf:1
1246-inf:+inf:-1
12475:inf:-1
12485:inf:-1
1249-5:-inf:1
1250-5:-inf:1
1251# return undef
1252+inf:NaN:
1253NaN:inf:
1254-inf:NaN:
1255NaN:-inf:
1256&binc
1257abc:NaN
1258+inf:inf
1259-inf:-inf
61f5c3f5 1260+0:1
1261+1:2
1262-1:0
6854fd01 1263&bdec
1264abc:NaN
1265+inf:inf
1266-inf:-inf
1267+0:-1
61f5c3f5 1268+1:0
6854fd01 1269-1:-2
1270&badd
1271abc:abc:NaN
61f5c3f5 1272abc:0:NaN
6854fd01 1273+0:abc:NaN
b3abae2a 1274+inf:-inf:NaN
1275-inf:+inf:NaN
6854fd01 1276+inf:+inf:inf
1277-inf:-inf:-inf
1278baddNaN:+inf:NaN
1279baddNaN:+inf:NaN
1280+inf:baddNaN:NaN
1281-inf:baddNaN:NaN
61f5c3f5 12820:0:0
12831:0:1
12840:1:1
12851:1:2
1286-1:0:-1
12870:-1:-1
6854fd01 1288-1:-1:-2
61f5c3f5 1289-1:+1:0
1290+1:-1:0
1291+9:+1:10
1292+99:+1:100
1293+999:+1:1000
1294+9999:+1:10000
1295+99999:+1:100000
1296+999999:+1:1000000
1297+9999999:+1:10000000
1298+99999999:+1:100000000
1299+999999999:+1:1000000000
1300+9999999999:+1:10000000000
1301+99999999999:+1:100000000000
1302+10:-1:9
1303+100:-1:99
1304+1000:-1:999
1305+10000:-1:9999
1306+100000:-1:99999
1307+1000000:-1:999999
1308+10000000:-1:9999999
1309+100000000:-1:99999999
1310+1000000000:-1:999999999
1311+10000000000:-1:9999999999
1312+123456789:987654321:1111111110
1313-123456789:987654321:864197532
6854fd01 1314-123456789:-987654321:-1111111110
1315+123456789:-987654321:-864197532
56b9c951 1316-1:10001:10000
1317-1:100001:100000
1318-1:1000001:1000000
1319-1:10000001:10000000
1320-1:100000001:100000000
1321-1:1000000001:1000000000
1322-1:10000000001:10000000000
1323-1:100000000001:100000000000
1324-1:1000000000001:1000000000000
1325-1:10000000000001:10000000000000
1326-1:-10001:-10002
1327-1:-100001:-100002
1328-1:-1000001:-1000002
1329-1:-10000001:-10000002
1330-1:-100000001:-100000002
1331-1:-1000000001:-1000000002
1332-1:-10000000001:-10000000002
1333-1:-100000000001:-100000000002
1334-1:-1000000000001:-1000000000002
1335-1:-10000000000001:-10000000000002
6854fd01 1336&bsub
1337abc:abc:NaN
1338abc:+0:NaN
1339+0:abc:NaN
1340+inf:-inf:inf
1341-inf:+inf:-inf
b3abae2a 1342+inf:+inf:NaN
1343-inf:-inf:NaN
61f5c3f5 1344+0:+0:0
1345+1:+0:1
6854fd01 1346+0:+1:-1
61f5c3f5 1347+1:+1:0
6854fd01 1348-1:+0:-1
61f5c3f5 1349+0:-1:1
1350-1:-1:0
6854fd01 1351-1:+1:-2
61f5c3f5 1352+1:-1:2
1353+9:+1:8
1354+99:+1:98
1355+999:+1:998
1356+9999:+1:9998
1357+99999:+1:99998
1358+999999:+1:999998
1359+9999999:+1:9999998
1360+99999999:+1:99999998
1361+999999999:+1:999999998
1362+9999999999:+1:9999999998
1363+99999999999:+1:99999999998
1364+10:-1:11
1365+100:-1:101
1366+1000:-1:1001
1367+10000:-1:10001
1368+100000:-1:100001
1369+1000000:-1:1000001
1370+10000000:-1:10000001
1371+100000000:-1:100000001
1372+1000000000:-1:1000000001
1373+10000000000:-1:10000000001
6854fd01 1374+123456789:+987654321:-864197532
1375-123456789:+987654321:-1111111110
61f5c3f5 1376-123456789:-987654321:864197532
1377+123456789:-987654321:1111111110
56b9c951 137810001:1:10000
1379100001:1:100000
13801000001:1:1000000
138110000001:1:10000000
1382100000001:1:100000000
13831000000001:1:1000000000
138410000000001:1:10000000000
1385100000000001:1:100000000000
13861000000000001:1:1000000000000
138710000000000001:1:10000000000000
138810001:-1:10002
1389100001:-1:100002
13901000001:-1:1000002
139110000001:-1:10000002
1392100000001:-1:100000002
13931000000001:-1:1000000002
139410000000001:-1:10000000002
1395100000000001:-1:100000000002
13961000000000001:-1:1000000000002
139710000000000001:-1:10000000000002
6854fd01 1398&bmul
1399abc:abc:NaN
1400abc:+0:NaN
1401+0:abc:NaN
1402NaNmul:+inf:NaN
1403NaNmul:-inf:NaN
1404-inf:NaNmul:NaN
1405+inf:NaNmul:NaN
1406+inf:+inf:inf
1407+inf:-inf:-inf
1408-inf:+inf:-inf
1409-inf:-inf:inf
61f5c3f5 1410+0:+0:0
1411+0:+1:0
1412+1:+0:0
1413+0:-1:0
1414-1:+0:0
1415123456789123456789:0:0
14160:123456789123456789:0
1417-1:-1:1
6854fd01 1418-1:+1:-1
1419+1:-1:-1
61f5c3f5 1420+1:+1:1
1421+2:+3:6
6854fd01 1422-2:+3:-6
1423+2:-3:-6
61f5c3f5 1424-2:-3:6
1425111:111:12321
142610101:10101:102030201
14271001001:1001001:1002003002001
1428100010001:100010001:10002000300020001
142910000100001:10000100001:100002000030000200001
143011111111111:9:99999999999
143122222222222:9:199999999998
143233333333333:9:299999999997
143344444444444:9:399999999996
143455555555555:9:499999999995
143566666666666:9:599999999994
143677777777777:9:699999999993
143788888888888:9:799999999992
143899999999999:9:899999999991
1439+25:+25:625
1440+12345:+12345:152399025
1441+99999:+11111:1111088889
6854fd01 14429999:10000:99990000
144399999:100000:9999900000
1444999999:1000000:999999000000
14459999999:10000000:99999990000000
144699999999:100000000:9999999900000000
1447999999999:1000000000:999999999000000000
14489999999999:10000000000:99999999990000000000
144999999999999:100000000000:9999999999900000000000
1450999999999999:1000000000000:999999999999000000000000
14519999999999999:10000000000000:99999999999990000000000000
145299999999999999:100000000000000:9999999999999900000000000000
1453999999999999999:1000000000000000:999999999999999000000000000000
14549999999999999999:10000000000000000:99999999999999990000000000000000
145599999999999999999:100000000000000000:9999999999999999900000000000000000
1456999999999999999999:1000000000000000000:999999999999999999000000000000000000
14579999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1458&bdiv-list
1459100:20:5,0
14604095:4095:1,0
1461-4095:-4095:1,0
14624095:-4095:-1,0
1463-4095:4095:-1,0
1464123:2:61,1
b3abae2a 14659:5:1,4
14669:4:2,1
6854fd01 1467# inf handling and general remainder
14685:8:0,5
14690:8:0,0
147011:2:5,1
147111:-2:-5,-1
1472-11:2:-5,1
1473# see table in documentation in MBI
14740:inf:0,0
14750:-inf:0,0
14765:inf:0,5
14775:-inf:0,5
1478-5:inf:0,-5
1479-5:-inf:0,-5
1480inf:5:inf,0
1481-inf:5:-inf,0
1482inf:-5:-inf,0
1483-inf:-5:inf,0
14845:5:1,0
1485-5:-5:1,0
b3abae2a 1486inf:inf:NaN,NaN
1487-inf:-inf:NaN,NaN
1488-inf:inf:NaN,NaN
1489inf:-inf:NaN,NaN
6854fd01 14908:0:inf,8
1491inf:0:inf,inf
1492# exceptions to reminder rule
1493-8:0:-inf,-8
1494-inf:0:-inf,-inf
14950:0:NaN,NaN
990fb837 1496# test the shortcut in Calc if @$x == @$yorg
14971234567812345678:123456712345678:10,688888898
149812345671234567:1234561234567:10,58888897
1499123456123456:12345123456:10,4888896
15001234512345:123412345:10,388895
15011234567890999999999:1234567890:1000000000,999999999
15021234567890000000000:1234567890:1000000000,0
15031234567890999999999:9876543210:124999998,9503086419
15041234567890000000000:9876543210:124999998,8503086420
150596969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
7596a890 1506# bug in v1.76
15071267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
b68b7ab1 1508# excercise shortcut for numbers of the same length in div
1509999999999999999999999999999999999:999999999999999999999999999999999:1,0
1510999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1511999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1512999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1513999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1514999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1515999999999999999999999999999999999:333333333333333333333333333333333:3,0
1516999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1517999999999999999999999999999999999:111111111111111111111111111111111:9,0
15189999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
15199999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
15209999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
15219999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
15229999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
15239999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
15249999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
15259999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
15269999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
15279999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
15289999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
6854fd01 1529&bdiv
1530abc:abc:NaN
61f5c3f5 1531abc:1:NaN
15321:abc:NaN
15330:0:NaN
6854fd01 1534# inf handling (see table in doc)
15350:inf:0
15360:-inf:0
15375:inf:0
15385:-inf:0
1539-5:inf:0
1540-5:-inf:0
1541inf:5:inf
1542-inf:5:-inf
1543inf:-5:-inf
1544-inf:-5:inf
15455:5:1
1546-5:-5:1
b3abae2a 1547inf:inf:NaN
1548-inf:-inf:NaN
1549-inf:inf:NaN
1550inf:-inf:NaN
6854fd01 15518:0:inf
1552inf:0:inf
1553-8:0:-inf
1554-inf:0:-inf
15550:0:NaN
155611:2:5
1557-11:-2:5
1558-11:2:-5
155911:-2:-5
61f5c3f5 15600:1:0
15610:-1:0
15621:1:1
1563-1:-1:1
15641:-1:-1
1565-1:1:-1
15661:2:0
15672:1:2
15681:26:0
15691000000000:9:111111111
15702000000000:9:222222222
15713000000000:9:333333333
15724000000000:9:444444444
15735000000000:9:555555555
15746000000000:9:666666666
15757000000000:9:777777777
15768000000000:9:888888888
15779000000000:9:1000000000
157835500000:113:314159
157971000000:226:314159
1580106500000:339:314159
15811000000000:3:333333333
1582+10:+5:2
1583+100:+4:25
1584+1000:+8:125
1585+10000:+16:625
1586999999999999:9:111111111111
1587999999999999:99:10101010101
1588999999999999:999:1001001001
1589999999999999:9999:100010001
1590999999999999999:99999:10000100001
1591+1111088889:99999:11111
6854fd01 1592-5:-3:1
1593-5:3:-1
15944:3:1
15954:-3:-1
15961:3:0
15971:-3:0
1598-2:-3:0
1599-2:3:0
16008:3:2
1601-8:3:-2
160214:-3:-4
1603-14:3:-4
1604-14:-3:4
160514:3:4
1606# bug in Calc with '99999' vs $BASE-1
160710000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1608# test the shortcut in Calc if @$x == @$yorg
16091234567812345678:123456712345678:10
161012345671234567:1234561234567:10
1611123456123456:12345123456:10
16121234512345:123412345:10
16131234567890999999999:1234567890:1000000000
16141234567890000000000:1234567890:1000000000
16151234567890999999999:9876543210:124999998
16161234567890000000000:9876543210:124999998
161796969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1618# bug up to v0.35 in Calc (--$q one too many)
161984696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
162084696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
162184696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
162284696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
b68b7ab1 1623# excercise shortcut for numbers of the same length in div
1624999999999999999999999999999999999:999999999999999999999999999999999:1
1625999999999999999999999999999999999:888888888888888888888888888888888:1
1626999999999999999999999999999999999:777777777777777777777777777777777:1
1627999999999999999999999999999999999:666666666666666666666666666666666:1
1628999999999999999999999999999999999:555555555555555555555555555555555:1
1629999999999999999999999999999999999:444444444444444444444444444444444:2
1630999999999999999999999999999999999:333333333333333333333333333333333:3
1631999999999999999999999999999999999:222222222222222222222222222222222:4
1632999999999999999999999999999999999:111111111111111111111111111111111:9
16339999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
16349999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
16359999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
16369999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
16379999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
16389999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
16399999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
16409999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
16419999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
16429999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
16439999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
a87115f0 1644# bug with shortcut in Calc 0.44
1645949418181818187070707070707070707070:181818181853535353535353535353535353:5
07d34614 1646&bmodinv
1647# format: number:modulus:result
1648# bmodinv Data errors
1649abc:abc:NaN
1650abc:5:NaN
16515:abc:NaN
1652# bmodinv Expected Results from normal use
16531:5:1
16543:5:2
1655-2:5:2
16568:5033:4404
56d9de68 16571234567891:13:6
1658-1234567891:13:7
07d34614 1659324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1660## bmodinv Error cases / useless use of function
07d34614 16613:-5:NaN
1662inf:5:NaN
1ddff52a 16635:inf:NaN
1664-inf:5:NaN
16655:-inf:NaN
07d34614 1666&bmodpow
1667# format: number:exponent:modulus:result
1668# bmodpow Data errors
1669abc:abc:abc:NaN
16705:abc:abc:NaN
1671abc:5:abc:NaN
1672abc:abc:5:NaN
16735:5:abc:NaN
16745:abc:5:NaN
1675abc:5:5:NaN
1676# bmodpow Expected results
16770:0:2:1
16781:0:2:1
16790:0:1:0
16808:7:5032:3840
16818:-1:5033:4404
168298436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1683# bmodpow Error cases
16848:8:-5:NaN
16858:-1:16:NaN
1686inf:5:13:NaN
16875:inf:13:NaN
6854fd01 1688&bmod
1689# inf handling, see table in doc
16900:inf:0
16910:-inf:0
16925:inf:5
16935:-inf:5
1694-5:inf:-5
1695-5:-inf:-5
1696inf:5:0
1697-inf:5:0
1698inf:-5:0
1699-inf:-5:0
17005:5:0
1701-5:-5:0
b3abae2a 1702inf:inf:NaN
1703-inf:-inf:NaN
1704-inf:inf:NaN
1705inf:-inf:NaN
6854fd01 17068:0:8
1707inf:0:inf
1708# exceptions to reminder rule
1709-inf:0:-inf
1710-8:0:-8
17110:0:NaN
1712abc:abc:NaN
61f5c3f5 1713abc:1:abc:NaN
17141:abc:NaN
17150:0:NaN
17160:1:0
17171:0:1
17180:-1:0
1719-1:0:-1
17201:1:0
1721-1:-1:0
17221:-1:0
1723-1:1:0
17241:2:1
17252:1:0
17261000000000:9:1
17272000000000:9:2
17283000000000:9:3
17294000000000:9:4
17305000000000:9:5
17316000000000:9:6
17327000000000:9:7
17338000000000:9:8
17349000000000:9:0
173535500000:113:33
173671000000:226:66
1737106500000:339:99
17381000000000:3:1
173910:5:0
1740100:4:0
17411000:8:0
174210000:16:0
1743999999999999:9:0
1744999999999999:99:0
1745999999999999:999:0
1746999999999999:9999:0
1747999999999999999:99999:0
1748-9:+5:1
6854fd01 1749+9:-5:-1
1750-9:-5:-4
1751-5:3:1
1752-2:3:1
17534:3:1
17541:3:1
1755-5:-3:-2
1756-2:-3:-2
17574:-3:-2
17581:-3:-2
17594095:4095:0
027dc388 1760100041000510123:3:0
1761152403346:12345:4321
b3abae2a 17629:5:4
28df3e88 1763# test shortcuts in Calc
1764# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
17651234:9:1
1766123456:9:3
176712345678:9:0
17681234567891:9:1
1769123456789123:9:6
177012345678912345:9:6
17711234567891234567:9:1
1772123456789123456789:9:0
17731234:10:4
1774123456:10:6
177512345678:10:8
17761234567891:10:1
1777123456789123:10:3
177812345678912345:10:5
17791234567891234567:10:7
1780123456789123456789:10:9
17811234:113:104
1782123456:113:60
178312345678:113:89
17841234567891:113:64
1785123456789123:113:95
178612345678912345:113:53
17871234567891234567:113:56
1788123456789123456789:113:39
07d34614 1789# bug in bmod() not modifying the variable in place
1790-629:5033:4404
aef458a0 1791# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1792# when X == X and X was big
1793111111111111111111111111111111:111111111111111111111111111111:0
179412345678901234567890:12345678901234567890:0
6854fd01 1795&bgcd
9b924220 1796inf:12:NaN
1797-inf:12:NaN
179812:inf:NaN
179912:-inf:NaN
1800inf:inf:NaN
1801inf:-inf:NaN
1802-inf:-inf:NaN
6854fd01 1803abc:abc:NaN
1804abc:+0:NaN
1805+0:abc:NaN
61f5c3f5 1806+0:+0:0
1807+0:+1:1
1808+1:+0:1
1809+1:+1:1
1810+2:+3:1
1811+3:+2:1
1812-3:+2:1
9b924220 1813-3:-2:1
1814-144:-60:12
1815144:-60:12
1816144:60:12
61f5c3f5 1817100:625:25
18184096:81:1
18191034:804:2
182027:90:56:1
182127:90:54:9
6854fd01 1822&blcm
1823abc:abc:NaN
1824abc:+0:NaN
1825+0:abc:NaN
1826+0:+0:NaN
61f5c3f5 1827+1:+0:0
1828+0:+1:0
1829+27:+90:270
1830+1034:+804:415668
6854fd01 1831&band
1832abc:abc:NaN
1833abc:0:NaN
18340:abc:NaN
18351:2:0
18363:2:2
61f5c3f5 1837+8:+2:0
1838+281474976710656:0:0
1839+281474976710656:1:0
1840+281474976710656:+281474976710656:281474976710656
9b924220 1841281474976710656:-1:281474976710656
6854fd01 1842-2:-3:-4
1843-1:-1:-1
1844-6:-6:-6
1845-7:-4:-8
1846-7:4:0
1847-4:7:4
9b924220 1848# negative argument is bitwise shorter than positive [perl #26559]
184930:-3:28
1850123:-1:123
394e6ffb 1851# equal arguments are treated special, so also do some test with unequal ones
18520xFFFF:0xFFFF:0x0xFFFF
18530xFFFFFF:0xFFFFFF:0x0xFFFFFF
18540xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18550xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18560xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18570xF0F0:0xF0F0:0x0xF0F0
18580x0F0F:0x0F0F:0x0x0F0F
18590xF0F0F0:0xF0F0F0:0x0xF0F0F0
18600x0F0F0F:0x0F0F0F:0x0x0F0F0F
18610xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18620x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18630xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18640x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18650xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18660x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18670x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1868&bior
1869abc:abc:NaN
1870abc:0:NaN
18710:abc:NaN
18721:2:3
61f5c3f5 1873+8:+2:10
1874+281474976710656:0:281474976710656
1875+281474976710656:1:281474976710657
1876+281474976710656:281474976710656:281474976710656
6854fd01 1877-2:-3:-1
1878-1:-1:-1
1879-6:-6:-6
1880-7:4:-3
1881-4:7:-1
9b924220 1882+281474976710656:-1:-1
188330:-3:-1
188430:-4:-2
1885300:-76:-68
1886-76:300:-68
394e6ffb 1887# equal arguments are treated special, so also do some test with unequal ones
18880xFFFF:0xFFFF:0x0xFFFF
18890xFFFFFF:0xFFFFFF:0x0xFFFFFF
18900xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18910xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18920xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18930:0xFFFF:0x0xFFFF
18940:0xFFFFFF:0x0xFFFFFF
18950:0xFFFFFFFF:0x0xFFFFFFFF
18960:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18970:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18980xFFFF:0:0x0xFFFF
18990xFFFFFF:0:0x0xFFFFFF
19000xFFFFFFFF:0:0x0xFFFFFFFF
19010xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19020xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19030xF0F0:0xF0F0:0x0xF0F0
19040x0F0F:0x0F0F:0x0x0F0F
19050xF0F0:0x0F0F:0x0xFFFF
19060xF0F0F0:0xF0F0F0:0x0xF0F0F0
19070x0F0F0F:0x0F0F0F:0x0x0F0F0F
19080x0F0F0F:0xF0F0F0:0x0xFFFFFF
19090xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19100x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19110x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19120xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19130x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19140x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19150xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19160x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19170x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
19180x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1919&bxor
1920abc:abc:NaN
1921abc:0:NaN
19220:abc:NaN
19231:2:3
61f5c3f5 1924+8:+2:10
1925+281474976710656:0:281474976710656
1926+281474976710656:1:281474976710657
1927+281474976710656:281474976710656:0
6854fd01 1928-2:-3:3
1929-1:-1:0
1930-6:-6:0
1931-7:4:-3
1932-4:7:-5
19334:-7:-3
1934-4:-7:5
9b924220 193530:-3:-29
193630:-4:-30
1937300:-76:-360
1938-76:300:-360
394e6ffb 1939# equal arguments are treated special, so also do some test with unequal ones
19400xFFFF:0xFFFF:0
19410xFFFFFF:0xFFFFFF:0
19420xFFFFFFFF:0xFFFFFFFF:0
19430xFFFFFFFFFF:0xFFFFFFFFFF:0
19440xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
19450:0xFFFF:0x0xFFFF
19460:0xFFFFFF:0x0xFFFFFF
19470:0xFFFFFFFF:0x0xFFFFFFFF
19480:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19490:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19500xFFFF:0:0x0xFFFF
19510xFFFFFF:0:0x0xFFFFFF
19520xFFFFFFFF:0:0x0xFFFFFFFF
19530xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19540xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19550xF0F0:0xF0F0:0
19560x0F0F:0x0F0F:0
19570xF0F0:0x0F0F:0x0xFFFF
19580xF0F0F0:0xF0F0F0:0
19590x0F0F0F:0x0F0F0F:0
19600x0F0F0F:0xF0F0F0:0x0xFFFFFF
19610xF0F0F0F0:0xF0F0F0F0:0
19620x0F0F0F0F:0x0F0F0F0F:0
19630x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19640xF0F0F0F0F0:0xF0F0F0F0F0:0
19650x0F0F0F0F0F:0x0F0F0F0F0F:0
19660x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19670xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
19680x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
19690x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1970&bnot
1971abc:NaN
1972+0:-1
1973+8:-9
1974+281474976710656:-281474976710657
1975-1:0
1976-2:1
1977-12:11
1978&digit
19790:0:0
198012:0:2
198112:1:1
1982123:0:3
1983123:1:2
1984123:2:1
1985123:-1:1
1986123:-2:2
1987123:-3:3
1988123456:0:6
1989123456:1:5
1990123456:2:4
1991123456:3:3
1992123456:4:2
1993123456:5:1
1994123456:-1:1
1995123456:-2:2
1996123456:-3:3
1997100000:-3:0
1998100000:0:0
1999100000:1:0
2000&mantissa
2001abc:NaN
20021e4:1
20032e0:2
2004123:123
2005-1:-1
2006-2:-2
2007+inf:inf
2008-inf:-inf
2009&exponent
2010abc:NaN
20111e4:4
20122e0:0
2013123:0
2014-1:0
2015-2:0
20160:1
2017+inf:inf
2018-inf:inf
2019&parts
2020abc:NaN,NaN
20211e4:1,4
20222e0:2,0
2023123:123,0
2024-1:-1,0
2025-2:-2,0
20260:0,1
2027+inf:inf,inf
2028-inf:-inf,inf
b3abae2a 2029&bfac
2030-1:NaN
2031NaNfac:NaN
b282a552 2032+inf:inf
b3abae2a 2033-inf:NaN
20340:1
20351:1
20362:2
20373:6
20384:24
20395:120
20406:720
990fb837 20417:5040
20428:40320
20439:362880
b3abae2a 204410:3628800
204511:39916800
204612:479001600
50109ad0 204720:2432902008176640000
204822:1124000727777607680000
204969:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
6854fd01 2050&bpow
2051abc:12:NaN
205212:abc:NaN
20530:0:1
20540:1:0
20550:2:0
9b924220 20560:-1:inf
20570:-2:inf
6854fd01 20581:0:1
20591:1:1
20601:2:1
20611:3:1
20621:-1:1
20631:-2:1
20641:-3:1
20652:0:1
20662:1:2
20672:2:4
20682:3:8
20693:3:27
2d2b2744 2070-2:2:4
2071-2:3:-8
2072-2:4:16
2073-2:5:-32
6854fd01 20742:-1:NaN
2075-2:-1:NaN
20762:-2:NaN
2077-2:-2:NaN
2d2b2744 2078# inf tests
6854fd01 2079+inf:1234500012:inf
2d2b2744 2080-inf:1234500012:inf
2081-inf:1234500013:-inf
6854fd01 2082+inf:-12345000123:inf
2083-inf:-12345000123:-inf
2d2b2744 2084# -inf * -inf = inf
2085-inf:2:inf
2086-inf:0:NaN
2087-inf:-1:0
2088-inf:inf:NaN
20892:inf:inf
20902:-inf:0
20910:inf:0
20920:-inf:inf
2093-1:-inf:NaN
2094-1:inf:NaN
2095-2:inf:NaN
2096-2:-inf:0
2097NaN:inf:NaN
2098NaN:-inf:NaN
2099-inf:NaN:NaN
2100inf:NaN:NaN
2101inf:-inf:NaN
21021:inf:1
21031:-inf:1
6854fd01 2104# 1 ** -x => 1 / (1 ** x)
2105-1:0:1
2106-2:0:1
2107-1:1:-1
2108-1:2:1
2109-1:3:-1
2110-1:4:1
2111-1:5:-1
2112-1:-1:-1
2113-1:-2:1
2114-1:-3:-1
2115-1:-4:1
211610:2:100
211710:3:1000
211810:4:10000
211910:5:100000
212010:6:1000000
212110:7:10000000
212210:8:100000000
212310:9:1000000000
212410:20:100000000000000000000
2125123456:2:15241383936
9b924220 2126-2:2:4
2127-2:3:-8
2128-2:4:16
2129-2:5:-32
2130-3:2:9
2131-3:3:-27
2132-3:4:81
2133-3:5:-243
6854fd01 2134&length
2135100:3
213610:2
21371:1
21380:1
213912345:5
214010000000000000000:17
2141-123:3
2142215960156869840440586892398248:30
990fb837 2143&broot
2144# sqrt()
2145+0:2:0
2146+1:2:1
2147-1:2:NaN
2148# -$x ** (1/2) => -$y, but not in froot()
2149-123:2:NaN
2150+inf:2:inf
2151-inf:2:NaN
21522:2:1
2153-2:2:NaN
21544:2:2
21559:2:3
215616:2:4
2157100:2:10
2158123:2:11
215915241:2:123
2160144:2:12
216112:2:3
21620.49:2:0
21630.0049:2:0
2164# invalid ones
21651:NaN:NaN
2166-1:NaN:NaN
21670:NaN:NaN
2168-inf:NaN:NaN
2169+inf:NaN:NaN
2170NaN:0:NaN
2171NaN:2:NaN
2172NaN:inf:NaN
2173NaN:inf:NaN
217412:-inf:NaN
217512:inf:NaN
2176+0:0:NaN
2177+1:0:NaN
2178-1:0:NaN
2179-2:0:NaN
2180-123.45:0:NaN
2181+inf:0:NaN
218212:1:12
2183-12:1:NaN
21848:-1:NaN
2185-8:-1:NaN
2186# cubic root
21878:3:2
2188-8:3:NaN
2189# fourths root
c38b2de2 219016:4:2
219181:4:3
3a427a11 2192# 2 ** 64
c38b2de2 219318446744073709551616:4:65536
219418446744073709551616:8:256
219518446744073709551616:16:16
219618446744073709551616:32:4
219718446744073709551616:64:2
219818446744073709551616:128:1
3a427a11 2199# 213 ** 15
220084274086103068221283760416414557757:15:213
50109ad0 2201# see t/bigroot.t for more tests
6854fd01 2202&bsqrt
394e6ffb 2203145:12
6854fd01 2204144:12
394e6ffb 2205143:11
6854fd01 220616:4
394e6ffb 2207170:13
2208169:13
2209168:12
6854fd01 22104:2
394e6ffb 22113:1
6854fd01 22122:1
394e6ffb 22139:3
6854fd01 221412:3
2215256:16
2216100000000:10000
22174000000000000:2000000
394e6ffb 2218152399026:12345
2219152399025:12345
2220152399024:12344
3a427a11 2221# 2 ** 64 => 2 ** 32
222218446744073709551616:4294967296
222384274086103068221283760416414557757:290299993288095377
6854fd01 22241:1
22250:0
2226-2:NaN
394e6ffb 2227-123:NaN
6854fd01 2228Nan:NaN
990fb837 2229+inf:inf
2230-inf:NaN
50109ad0 2231# see t/biglog.t for more tests
2232&bexp
2233NaN:NaN
2234inf:inf
22351:2
22362:7
fdb4b05f 2237&bpi
223877:3
2239+0:3
224011:3
50109ad0 2241# see t/bignok.t for more tests
2242&bnok
2243+inf:10:inf
2244NaN:NaN:NaN
2245NaN:1:NaN
22461:NaN:NaN
22471:1:1
2248# k > n
22491:2:0
22502:3:0
2251# k < 0
22521:-2:0
2253# 7 over 3 = 35
22547:3:35
22557:6:1
2256100:90:17310309456440
2257100:95:75287520
6854fd01 2258&bround
2259$round_mode('trunc')
22600:12:0
2261NaNbround:12:NaN
2262+inf:12:inf
2263-inf:12:-inf
22641234:0:1234
22651234:2:1200
2266123456:4:123400
2267123456:5:123450
2268123456:6:123456
61f5c3f5 2269+10123456789:5:10123000000
6854fd01 2270-10123456789:5:-10123000000
61f5c3f5 2271+10123456789:9:10123456700
6854fd01 2272-10123456789:9:-10123456700
61f5c3f5 2273+101234500:6:101234000
6854fd01 2274-101234500:6:-101234000
61f5c3f5 2275#+101234500:-4:101234000
6854fd01 2276#-101234500:-4:-101234000
2277$round_mode('zero')
61f5c3f5 2278+20123456789:5:20123000000
6854fd01 2279-20123456789:5:-20123000000
61f5c3f5 2280+20123456789:9:20123456800
6854fd01 2281-20123456789:9:-20123456800
61f5c3f5 2282+201234500:6:201234000
6854fd01 2283-201234500:6:-201234000
61f5c3f5 2284#+201234500:-4:201234000
6854fd01 2285#-201234500:-4:-201234000
2286+12345000:4:12340000
2287-12345000:4:-12340000
2288$round_mode('+inf')
61f5c3f5 2289+30123456789:5:30123000000
6854fd01 2290-30123456789:5:-30123000000
61f5c3f5 2291+30123456789:9:30123456800
6854fd01 2292-30123456789:9:-30123456800
61f5c3f5 2293+301234500:6:301235000
6854fd01 2294-301234500:6:-301234000
61f5c3f5 2295#+301234500:-4:301235000
6854fd01 2296#-301234500:-4:-301234000
2297+12345000:4:12350000
2298-12345000:4:-12340000
2299$round_mode('-inf')
61f5c3f5 2300+40123456789:5:40123000000
6854fd01 2301-40123456789:5:-40123000000
61f5c3f5 2302+40123456789:9:40123456800
6854fd01 2303-40123456789:9:-40123456800
61f5c3f5 2304+401234500:6:401234000
2305+401234500:6:401234000
6854fd01 2306#-401234500:-4:-401235000
2307#-401234500:-4:-401235000
2308+12345000:4:12340000
2309-12345000:4:-12350000
2310$round_mode('odd')
61f5c3f5 2311+50123456789:5:50123000000
6854fd01 2312-50123456789:5:-50123000000
61f5c3f5 2313+50123456789:9:50123456800
6854fd01 2314-50123456789:9:-50123456800
61f5c3f5 2315+501234500:6:501235000
6854fd01 2316-501234500:6:-501235000
61f5c3f5 2317#+501234500:-4:501235000
6854fd01 2318#-501234500:-4:-501235000
2319+12345000:4:12350000
2320-12345000:4:-12350000
2321$round_mode('even')
61f5c3f5 2322+60123456789:5:60123000000
6854fd01 2323-60123456789:5:-60123000000
61f5c3f5 2324+60123456789:9:60123456800
6854fd01 2325-60123456789:9:-60123456800
61f5c3f5 2326+601234500:6:601234000
6854fd01 2327-601234500:6:-601234000
61f5c3f5 2328#+601234500:-4:601234000
6854fd01 2329#-601234500:-4:-601234000
2330#-601234500:-9:0
2331#-501234500:-9:0
2332#-601234500:-8:0
2333#-501234500:-8:0
2334+1234567:7:1234567
2335+1234567:6:1234570
2336+12345000:4:12340000
2337-12345000:4:-12340000
7b29e1e6 2338$round_mode('common')
2339+60123456789:5:60123000000
2340+60123199999:5:60123000000
2341+60123299999:5:60123000000
2342+60123399999:5:60123000000
2343+60123499999:5:60123000000
2344+60123500000:5:60124000000
2345+60123600000:5:60124000000
2346+60123700000:5:60124000000
2347+60123800000:5:60124000000
2348+60123900000:5:60124000000
2349-60123456789:5:-60123000000
2350-60123199999:5:-60123000000
2351-60123299999:5:-60123000000
2352-60123399999:5:-60123000000
2353-60123499999:5:-60123000000
2354-60123500000:5:-60124000000
2355-60123600000:5:-60124000000
2356-60123700000:5:-60124000000
2357-60123800000:5:-60124000000
2358-60123900000:5:-60124000000
6854fd01 2359&is_zero
23600:1
2361NaNzero:0
2362+inf:0
2363-inf:0
2364123:0
2365-1:0
23661:0
2367&is_one
23680:0
2369NaNone:0
2370+inf:0
2371-inf:0
23721:1
23732:0
2374-1:0
2375-2:0
2376# floor and ceil tests are pretty pointless in integer space...but play safe
2377&bfloor
23780:0
2379NaNfloor:NaN
2380+inf:inf
2381-inf:-inf
2382-1:-1
2383-2:-2
23842:2
23853:3
2386abc:NaN
2387&bceil
2388NaNceil:NaN
2389+inf:inf
2390-inf:-inf
23910:0
2392-1:-1
2393-2:-2
23942:2
23953:3
2396abc:NaN
2397&as_hex
2398128:0x80
2399-128:-0x80
24000:0x0
2401-0:0x0
24021:0x1
24030x123456789123456789:0x123456789123456789
2404+inf:inf
2405-inf:-inf
2406NaNas_hex:NaN
2407&as_bin
2408128:0b10000000
2409-128:-0b10000000
24100:0b0
2411-0:0b0
24121:0b1
24130b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 24140x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2415+inf:inf
2416-inf:-inf
2417NaNas_bin:NaN