Rename exception() to apitest_exception() in XS/APItest, so that it
[p5sagit/p5-mst-13.2.git] / lib / Math / BigInt / t / bigintpm.inc
CommitLineData
6854fd01 1#include this file into another for subclass testing
2
3my $version = ${"$class\::VERSION"};
4
56d9de68 5use strict;
6
6854fd01 7##############################################################################
8# for testing inheritance of _swap
9
10package Math::Foo;
11
61f5c3f5 12use Math::BigInt lib => $main::CL;
6854fd01 13use vars qw/@ISA/;
14@ISA = (qw/Math::BigInt/);
15
16use overload
17# customized overload for sub, since original does not use swap there
18'-' => sub { my @a = ref($_[0])->_swap(@_);
19 $a[0]->bsub($a[1])};
20
21sub _swap
22 {
23 # a fake _swap, which reverses the params
24 my $self = shift; # for override in subclass
25 if ($_[2])
26 {
27 my $c = ref ($_[0] ) || 'Math::Foo';
28 return ( $_[0]->copy(), $_[1] );
29 }
30 else
31 {
32 return ( Math::Foo->new($_[1]), $_[0] );
33 }
34 }
35
36##############################################################################
37package main;
38
b3abae2a 39my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
6854fd01 40
b3abae2a 41my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
6854fd01 42
43while (<DATA>)
44 {
d614cd8b 45 chomp;
6854fd01 46 next if /^#/; # skip comments
47 if (s/^&//)
48 {
61f5c3f5 49 $f = $_; next;
6854fd01 50 }
51 elsif (/^\$/)
52 {
61f5c3f5 53 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
6854fd01 54 }
61f5c3f5 55
56 @args = split(/:/,$_,99); $ans = pop(@args);
b3abae2a 57 $expected_class = $class;
58 if ($ans =~ /(.*?)=(.*)/)
59 {
60 $expected_class = $2; $ans = $1;
61 }
61f5c3f5 62 $try = "\$x = $class->new(\"$args[0]\");";
63 if ($f eq "bnorm")
6854fd01 64 {
61f5c3f5 65 $try = "\$x = $class->bnorm(\"$args[0]\");";
66 # some is_xxx tests
b3abae2a 67 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
56d9de68 68 $try .= "\$x->$f() || 0;";
61f5c3f5 69 } elsif ($f eq "is_inf") {
70 $try .= "\$x->is_inf('$args[1]');";
71 } elsif ($f eq "binf") {
72 $try .= "\$x->binf('$args[1]');";
73 } elsif ($f eq "bone") {
74 $try .= "\$x->bone('$args[1]');";
56d9de68 75 # some unary ops
b3abae2a 76 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
61f5c3f5 77 $try .= "\$x->$f();";
56d9de68 78 } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
79 $try .= "\$x->$f();";
61f5c3f5 80 } elsif ($f eq "exponent"){
81 # ->bstr() to see if an object is returned
82 $try .= '$x = $x->exponent()->bstr();';
83 } elsif ($f eq "mantissa"){
84 # ->bstr() to see if an object is returned
85 $try .= '$x = $x->mantissa()->bstr();';
86 } elsif ($f eq "parts"){
87 $try .= '($m,$e) = $x->parts();';
88 # ->bstr() to see if an object is returned
89 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
90 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
91 $try .= '"$m,$e";';
92 } else {
56d9de68 93 # binary ops
61f5c3f5 94 $try .= "\$y = $class->new('$args[1]');";
95 if ($f eq "bcmp")
96 {
97 $try .= '$x <=> $y;';
98 } elsif ($f eq "bround") {
6854fd01 99 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5 100 } elsif ($f eq "bacmp"){
101 $try .= '$x->bacmp($y);';
102 } elsif ($f eq "badd"){
103 $try .= '$x + $y;';
104 } elsif ($f eq "bsub"){
105 $try .= '$x - $y;';
106 } elsif ($f eq "bmul"){
107 $try .= '$x * $y;';
108 } elsif ($f eq "bdiv"){
109 $try .= '$x / $y;';
110 } elsif ($f eq "bdiv-list"){
111 $try .= 'join (",",$x->bdiv($y));';
027dc388 112 # overload via x=
61f5c3f5 113 } elsif ($f =~ /^.=$/){
114 $try .= "\$x $f \$y;";
027dc388 115 # overload via x
61f5c3f5 116 } elsif ($f =~ /^.$/){
117 $try .= "\$x $f \$y;";
118 } elsif ($f eq "bmod"){
119 $try .= '$x % $y;';
120 } elsif ($f eq "bgcd")
6854fd01 121 {
122 if (defined $args[2])
123 {
61f5c3f5 124 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 125 }
126 $try .= "$class\::bgcd(\$x, \$y";
127 $try .= ", \$z" if (defined $args[2]);
128 $try .= " );";
129 }
130 elsif ($f eq "blcm")
131 {
132 if (defined $args[2])
133 {
61f5c3f5 134 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 135 }
136 $try .= "$class\::blcm(\$x, \$y";
137 $try .= ", \$z" if (defined $args[2]);
138 $try .= " );";
139 }elsif ($f eq "blsft"){
140 if (defined $args[2])
141 {
142 $try .= "\$x->blsft(\$y,$args[2]);";
143 }
144 else
145 {
146 $try .= "\$x << \$y;";
147 }
148 }elsif ($f eq "brsft"){
149 if (defined $args[2])
150 {
151 $try .= "\$x->brsft(\$y,$args[2]);";
152 }
153 else
154 {
155 $try .= "\$x >> \$y;";
156 }
990fb837 157 }elsif ($f eq "broot"){
158 $try .= "\$x->broot(\$y);";
091c87b1 159 }elsif ($f eq "blog"){
160 $try .= "\$x->blog(\$y);";
6854fd01 161 }elsif ($f eq "band"){
162 $try .= "\$x & \$y;";
163 }elsif ($f eq "bior"){
164 $try .= "\$x | \$y;";
165 }elsif ($f eq "bxor"){
166 $try .= "\$x ^ \$y;";
167 }elsif ($f eq "bpow"){
168 $try .= "\$x ** \$y;";
d614cd8b 169 } elsif( $f eq "bmodinv") {
170 $try .= "\$x->bmodinv(\$y);";
6854fd01 171 }elsif ($f eq "digit"){
56b9c951 172 $try .= "\$x->digit(\$y);";
d614cd8b 173 } else {
174 $try .= "\$z = $class->new(\"$args[2]\");";
175
176 # Functions with three arguments
177 if( $f eq "bmodpow") {
178 $try .= "\$x->bmodpow(\$y,\$z);";
179 } else { warn "Unknown op '$f'"; }
180 }
61f5c3f5 181 } # end else all other ops
182
183 $ans1 = eval $try;
184 # convert hex/binary targets to decimal
185 if ($ans =~ /^(0x0x|0b0b)/)
186 {
187 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 188 }
61f5c3f5 189 if ($ans eq "")
190 {
191 ok_undef ($ans1);
192 }
193 else
194 {
195 # print "try: $try ans: $ans1 $ans\n";
196 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 197 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 198 }
61f5c3f5 199 # check internal state of number objects
200 is_valid($ans1,$f) if ref $ans1;
6854fd01 201 } # endwhile data tests
202close DATA;
203
204# test some more
205@a = ();
206for (my $i = 1; $i < 10; $i++)
207 {
208 push @a, $i;
209 }
210ok "@a", "1 2 3 4 5 6 7 8 9";
211
212# test whether self-multiplication works correctly (result is 2**64)
213$try = "\$x = $class->new('4294967296');";
214$try .= '$a = $x->bmul($x);';
215$ans1 = eval $try;
216print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
217# test self-pow
218$try = "\$x = $class->new(10);";
219$try .= '$a = $x->bpow($x);';
220$ans1 = eval $try;
221print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
222
07d34614 223###############################################################################
6854fd01 224# test whether op destroys args or not (should better not)
225
226$x = $class->new(3);
227$y = $class->new(4);
228$z = $x & $y;
229ok ($x,3);
230ok ($y,4);
231ok ($z,0);
232$z = $x | $y;
233ok ($x,3);
234ok ($y,4);
235ok ($z,7);
236$x = $class->new(1);
237$y = $class->new(2);
238$z = $x | $y;
239ok ($x,1);
240ok ($y,2);
241ok ($z,3);
242
243$x = $class->new(5);
244$y = $class->new(4);
245$z = $x ^ $y;
246ok ($x,5);
247ok ($y,4);
248ok ($z,1);
249
250$x = $class->new(-5); $y = -$x;
251ok ($x, -5);
252
253$x = $class->new(-5); $y = abs($x);
254ok ($x, -5);
255
07d34614 256$x = $class->new(8);
257$y = $class->new(-1);
258$z = $class->new(5033);
259my $u = $x->copy()->bmodpow($y,$z);
260ok ($u,4404);
261ok ($y,-1);
262ok ($z,5033);
263
264$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
265$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
266
267$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
268$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
269$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
270$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
271$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
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,8); ok ($y,3);
275$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); 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,2); 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,2); ok($y,-3);
281$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); 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,-1); ok($y,-3);
284
285###############################################################################
6854fd01 286# check whether overloading cmp works
287$try = "\$x = $class->new(0);";
288$try .= "\$y = 10;";
289$try .= "'false' if \$x ne \$y;";
290$ans = eval $try;
291print "# For '$try'\n" if (!ok "$ans" , "false" );
292
293# we cant test for working cmpt with other objects here, we would need a dummy
294# object with stringify overload for this. see Math::String tests as example
295
296###############################################################################
6854fd01 297# check reversed order of arguments
027dc388 298
6854fd01 299$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
300$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
301print "# For '$try'\n" if (!ok "$ans" , "ok" );
302
303$try = "\$x = $class->new(10); \$x = 2 * \$x;";
304$try .= "'ok' if \$x == 20;"; $ans = eval $try;
305print "# For '$try'\n" if (!ok "$ans" , "ok" );
306
307$try = "\$x = $class->new(10); \$x = 2 + \$x;";
308$try .= "'ok' if \$x == 12;"; $ans = eval $try;
309print "# For '$try'\n" if (!ok "$ans" , "ok" );
310
311$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
312$try .= "'ok' if \$x == -8;"; $ans = eval $try;
313print "# For '$try'\n" if (!ok "$ans" , "ok" );
314
315$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
316$try .= "'ok' if \$x == 2;"; $ans = eval $try;
317print "# For '$try'\n" if (!ok "$ans" , "ok" );
318
027dc388 319$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
320$try .= "'ok' if \$x == 2;"; $ans = eval $try;
321print "# For '$try'\n" if (!ok "$ans" , "ok" );
322
323$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
324$try .= "'ok' if \$x == 4;"; $ans = eval $try;
325print "# For '$try'\n" if (!ok "$ans" , "ok" );
326
327$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
328$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
329print "# For '$try'\n" if (!ok "$ans" , "ok" );
330
331$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
332$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
333print "# For '$try'\n" if (!ok "$ans" , "ok" );
334
6854fd01 335###############################################################################
336# check badd(4,5) form
337
338$try = "\$x = $class\->badd(4,5);";
339$try .= "'ok' if \$x == 9;";
340$ans = eval $try;
341print "# For '$try'\n" if (!ok "$ans" , "ok" );
342
343###############################################################################
344# check undefs: NOT DONE YET
345
346###############################################################################
347# bool
348
f9a08e12 349$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
350$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 351
352###############################################################################
353# objectify()
354
355@args = Math::BigInt::objectify(2,4,5);
356ok (scalar @args,3); # $class, 4, 5
56b9c951 357ok ($args[0] =~ /^Math::BigInt/);
6854fd01 358ok ($args[1],4);
359ok ($args[2],5);
360
361@args = Math::BigInt::objectify(0,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(2,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,6,7);
374ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 375ok ($args[0] =~ /^Math::BigInt/);
6854fd01 376ok ($args[1],4); ok (ref($args[1]),$args[0]);
377ok ($args[2],5); ok (ref($args[2]),$args[0]);
378ok ($args[3],6); ok (ref($args[3]),'');
379ok ($args[4],7); ok (ref($args[4]),'');
380
381@args = Math::BigInt::objectify(2,$class,4,5,6,7);
382ok (scalar @args,5); # $class, 4, 5, 6, 7
383ok ($args[0],$class);
384ok ($args[1],4); ok (ref($args[1]),$args[0]);
385ok ($args[2],5); ok (ref($args[2]),$args[0]);
386ok ($args[3],6); ok (ref($args[3]),'');
387ok ($args[4],7); ok (ref($args[4]),'');
388
389###############################################################################
f9a08e12 390# test whether an opp calls objectify properly or not (or at least does what
391# it should do given non-objects, w/ or w/o objectify())
392
393ok ($class->new(123)->badd(123),246);
394ok ($class->badd(123,321),444);
395ok ($class->badd(123,$class->new(321)),444);
396
397ok ($class->new(123)->bsub(122),1);
398ok ($class->bsub(321,123),198);
399ok ($class->bsub(321,$class->new(123)),198);
400
401ok ($class->new(123)->bmul(123),15129);
402ok ($class->bmul(123,123),15129);
403ok ($class->bmul(123,$class->new(123)),15129);
404
405ok ($class->new(15129)->bdiv(123),123);
406ok ($class->bdiv(15129,123),123);
407ok ($class->bdiv(15129,$class->new(123)),123);
408
409ok ($class->new(15131)->bmod(123),2);
410ok ($class->bmod(15131,123),2);
411ok ($class->bmod(15131,$class->new(123)),2);
412
413ok ($class->new(2)->bpow(16),65536);
414ok ($class->bpow(2,16),65536);
415ok ($class->bpow(2,$class->new(16)),65536);
416
417ok ($class->new(2**15)->brsft(1),2**14);
418ok ($class->brsft(2**15,1),2**14);
419ok ($class->brsft(2**15,$class->new(1)),2**14);
420
421ok ($class->new(2**13)->blsft(1),2**14);
422ok ($class->blsft(2**13,1),2**14);
423ok ($class->blsft(2**13,$class->new(1)),2**14);
424
425###############################################################################
6854fd01 426# test for floating-point input (other tests in bnorm() below)
427
428$z = 1050000000000000; # may be int on systems with 64bit?
429$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
430$z = 1e+129; # definitely a float (may fail on UTS)
431# don't compare to $z, since some Perl versions stringify $z into something
432# like '1.e+129' or something equally ugly
433$x = $class->new($z); ok ($x->bsstr(),'1e+129');
434
435###############################################################################
56d9de68 436# test for whitespace inlcuding newlines to be handled correctly
437
438# ok ($Math::BigInt::strict,1); # the default
439
440foreach my $c (
441 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
442 {
443 my $m = $class->new($c);
444 ok ($class->new("$c"),$m);
445 ok ($class->new(" $c"),$m);
446 ok ($class->new("$c "),$m);
447 ok ($class->new(" $c "),$m);
448 ok ($class->new("\n$c"),$m);
449 ok ($class->new("$c\n"),$m);
450 ok ($class->new("\n$c\n"),$m);
451 ok ($class->new(" \n$c\n"),$m);
452 ok ($class->new(" \n$c \n"),$m);
453 ok ($class->new(" \n$c\n "),$m);
454 ok ($class->new(" \n$c\n1"),'NaN');
455 ok ($class->new("1 \n$c\n1"),'NaN');
456 }
457
458###############################################################################
6854fd01 459# prime number tests, also test for **= and length()
460# found on: http://www.utm.edu/research/primes/notes/by_year.html
461
462# ((2^148)-1)/17
463$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
464ok ($x,"20988936657440586486151264256610222593863921");
465ok ($x->length(),length "20988936657440586486151264256610222593863921");
466
467# MM7 = 2^127-1
468$x = $class->new(2); $x **= 127; $x--;
469ok ($x,"170141183460469231731687303715884105727");
470
471$x = $class->new('215960156869840440586892398248');
472($x,$y) = $x->length();
473ok ($x,30); ok ($y,0);
474
475$x = $class->new('1_000_000_000_000');
476($x,$y) = $x->length();
477ok ($x,13); ok ($y,0);
478
2d2b2744 479# test <<=, >>=
480$x = $class->new('2');
481my $y = $class->new('18');
482ok ($x <<= $y, 2 << 18);
483ok ($x, 2 << 18);
484ok ($x >>= $y, 2);
485ok ($x, 2);
486
6854fd01 487# I am afraid the following is not yet possible due to slowness
488# Also, testing for 2 meg output is a bit hard ;)
489#$x = $class->new(2); $x **= 6972593; $x--;
490
491# 593573509*2^332162+1 has exactly 1,000,000 digits
492# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
493#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
494#ok ($x->length(),1_000_000);
495
496###############################################################################
497# inheritance and overriding of _swap
498
499$x = Math::Foo->new(5);
500$x = $x - 8; # 8 - 5 instead of 5-8
501ok ($x,3);
502ok (ref($x),'Math::Foo');
503
504$x = Math::Foo->new(5);
505$x = 8 - $x; # 5 - 8 instead of 8 - 5
506ok ($x,-3);
507ok (ref($x),'Math::Foo');
508
509###############################################################################
510# Test whether +inf eq inf
511# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
512# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
513# like 1e100000 crash on some platforms. So simple test for the string 'inf'
514$x = $class->new('+inf'); ok ($x,'inf');
515
516###############################################################################
517###############################################################################
56d9de68 518# the followin tests only make sense with Math::BigInt::Calc or BareCalc or
519# FastCalc
6854fd01 520
56d9de68 521exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01 522
523###############################################################################
524# check proper length of internal arrays
525
394e6ffb 526my $bl = $CL->_base_len();
6854fd01 527my $BASE = '9' x $bl;
528my $MAX = $BASE;
529$BASE++;
530
531$x = $class->new($MAX); is_valid($x); # f.i. 9999
532$x += 1; ok ($x,$BASE); is_valid($x); # 10000
533$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
534
535###############################################################################
536# check numify
537
538$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
539$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 540
541# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
542$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 543$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
544$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
545ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
546
547###############################################################################
548# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
549
394e6ffb 550$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
551if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
552
553$x = $class->new($BASE+3); $x++;
554if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 555
394e6ffb 556# test for +0 instead of int():
557$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 558
559###############################################################################
56b9c951 560# test bug that $class->digit($string) did not work
561
562ok ($class->digit(123,2),1);
563
564###############################################################################
6854fd01 565# bug in sub where number with at least 6 trailing zeros after any op failed
566
394e6ffb 567$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 568ok ($z, 100000);
569ok ($x, 23456);
570
571###############################################################################
572# bug in shortcut in mul()
573
61f5c3f5 574# construct a number with a zero-hole of BASE_LEN_SMALL
575{
576 my @bl = $CL->_base_len(); my $bl = $bl[4];
577
578 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
579 $y = '1' x (2*$bl);
580 $x = $class->new($x)->bmul($y);
581 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
582 $y = ''; my $d = '';
583 for (my $i = 1; $i <= $bl; $i++)
584 {
585 $y .= $i; $d = $i.$d;
586 }
587 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
588 ok ($x,$y);
589
6854fd01 590
f9a08e12 591 #############################################################################
592 # see if mul shortcut for small numbers works
394e6ffb 593
f9a08e12 594 $x = '9' x $bl;
595 $x = $class->new($x);
596 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
597 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
598}
61f5c3f5 599
394e6ffb 600###############################################################################
6854fd01 601# bug with rest "-0" in div, causing further div()s to fail
602
394e6ffb 603$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 604
61f5c3f5 605ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 606
79c55733 607###############################################################################
f9a08e12 608# bug in $x->bmod($y)
07d34614 609
f9a08e12 610# if $x < 0 and $y > 0
07d34614 611$x = $class->new('-629'); ok ($x->bmod(5033),4404);
612
613###############################################################################
56b9c951 614# bone/binf etc as plain calls (Lite failed them)
615
616ok ($class->bzero(),0);
617ok ($class->bone(),1);
618ok ($class->bone('+'),1);
619ok ($class->bone('-'),-1);
620ok ($class->bnan(),'NaN');
621ok ($class->binf(),'inf');
622ok ($class->binf('+'),'inf');
623ok ($class->binf('-'),'-inf');
624ok ($class->binf('-inf'),'-inf');
625
626###############################################################################
990fb837 627# is_one('-')
628
629ok ($class->new(1)->is_one('-'),0);
630ok ($class->new(-1)->is_one('-'),1);
631ok ($class->new(1)->is_one(),1);
632ok ($class->new(-1)->is_one(),0);
633
634###############################################################################
03874afe 635# [perl #30609] bug with $x -= $x not beeing 0, but 2*$x
636
637$x = $class->new(3); $x -= $x; ok ($x, 0);
638$x = $class->new(-3); $x -= $x; ok ($x, 0);
639$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
640$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
641$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
642
643$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
644$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
645$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
646$x = $class->new(3); $x += $x; ok ($x, 6);
647$x = $class->new(-3); $x += $x; ok ($x, -6);
648
649$x = $class->new(3); $x *= $x; ok ($x, 9);
650$x = $class->new(-3); $x *= $x; ok ($x, 9);
651$x = $class->new(3); $x /= $x; ok ($x, 1);
652$x = $class->new(-3); $x /= $x; ok ($x, 1);
653$x = $class->new(3); $x %= $x; ok ($x, 0);
654$x = $class->new(-3); $x %= $x; ok ($x, 0);
655
656###############################################################################
61f5c3f5 657# all tests done
6854fd01 658
6591;
660
661###############################################################################
61f5c3f5 662###############################################################################
6854fd01 663# Perl 5.005 does not like ok ($x,undef)
664
665sub ok_undef
666 {
667 my $x = shift;
668
669 ok (1,1) and return if !defined $x;
670 ok ($x,'undef');
671 }
672
673###############################################################################
674# sub to check validity of a BigInt internally, to ensure that no op leaves a
675# number object in an invalid state (f.i. "-0")
676
677sub is_valid
678 {
679 my ($x,$f) = @_;
680
681 my $e = 0; # error?
6854fd01 682
56b9c951 683 # allow the check to pass for all Lite, and all MBI and subclasses
684 # ok as reference?
685 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 686
56b9c951 687 if (ref($x) ne 'Math::BigInt::Lite')
688 {
689 # has ok sign?
690 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
691 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
692
693 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
694 $e = $CALC->_check($x->{value}) if $e eq '0';
695 }
6854fd01 696
697 # test done, see if error did crop up
698 ok (1,1), return if ($e eq '0');
699
027dc388 700 ok (1,$e." after op '$f'");
6854fd01 701 }
702
703__DATA__
027dc388 704&.=
7051234:-345:1234-345
706&+=
7071:2:3
708-1:-2:-3
709&-=
7101:2:-1
711-1:-2:1
712&*=
7132:3:6
714-1:5:-5
715&%=
716100:3:1
7178:9:8
07d34614 718-629:5033:4404
027dc388 719&/=
720100:3:33
721-8:2:-4
722&|=
7232:1:3
724&&=
7255:7:5
726&^=
7275:7:2
091c87b1 728&blog
729NaNlog:2:NaN
730122:NaNlog:NaN
731NaNlog1:NaNlog:NaN
732122:inf:NaN
733inf:122:NaN
734122:-inf:NaN
735-inf:122:NaN
736-inf:-inf:NaN
737inf:inf:NaN
7380:4:NaN
739-21:4:NaN
74021:-21:NaN
741# normal results
7421024:2:10
74381:3:4
744# 3.01.. truncate
74582:3:4
746# 3.9... truncate
74780:3:3
74815625:5:6
74915626:5:6
75015624:5:5
8df1e0a2 7511000:10:3
75210000:10:4
753100000:10:5
7541000000:10:6
75510000000:10:7
756100000000:10:8
7578916100448256:12:12
7588916100448257:12:12
7598916100448255:12:11
7602251799813685248:8:17
76172057594037927936:2:56
762144115188075855872:2:57
763288230376151711744:2:58
764576460752303423488:2:59
7654096:2:12
7661329227995784915872903807060280344576:2:120
091c87b1 767# $x == $base => result 1
7683:3:1
769# $x < $base => result 0 ($base ** 0 <= $x)
7703:4:0
771# $x == 1 => result 0
7721:5:0
6854fd01 773&is_negative
7740:0
775-1:1
7761:0
777+inf:0
778-inf:1
779NaNneg:0
780&is_positive
b68b7ab1 7810:0
6854fd01 782-1:0
7831:1
784+inf:1
785-inf:0
786NaNneg:0
b3abae2a 787&is_int
788-inf:0
789+inf:0
790NaNis_int:0
7911:1
7920:1
793123e12:1
6854fd01 794&is_odd
795abc:0
7960:0
7971:1
7983:1
799-1:1
800-3:1
80110000001:1
80210000002:0
8032:0
b3abae2a 804120:0
805121:1
6854fd01 806&is_even
807abc:0
8080:1
8091:0
8103:0
811-1:0
812-3:0
81310000001:0
81410000002:1
8152:1
b3abae2a 816120:1
817121:0
6854fd01 818&bacmp
819+0:-0:0
820+0:+1:-1
821-1:+1:0
822+1:-1:0
823-1:+2:-1
824+2:-1:1
825-123456789:+987654321:-1
826+123456789:-987654321:-1
827+987654321:+123456789:1
828-987654321:+123456789:1
829-123:+4567889:-1
830# NaNs
831acmpNaN:123:
832123:acmpNaN:
833acmpNaN:acmpNaN:
834# infinity
835+inf:+inf:0
836-inf:-inf:0
837+inf:-inf:0
838-inf:+inf:0
839+inf:123:1
840-inf:123:1
841+inf:-123:1
842-inf:-123:1
ef9466ea 843123:-inf:-1
844-123:inf:-1
845-123:-inf:-1
846123:inf:-1
6854fd01 847# return undef
848+inf:NaN:
849NaN:inf:
850-inf:NaN:
851NaN:-inf:
852&bnorm
aef458a0 8530e999:0
8540e-999:0
855-0e999:0
856-0e-999:0
6854fd01 857123:123
858# binary input
8590babc:NaN
8600b123:NaN
8610b0:0
862-0b0:0
863-0b1:-1
8640b0001:1
8650b001:1
8660b011:3
8670b101:5
61f5c3f5 8680b1001:9
8690b10001:17
8700b100001:33
8710b1000001:65
8720b10000001:129
8730b100000001:257
8740b1000000001:513
8750b10000000001:1025
8760b100000000001:2049
8770b1000000000001:4097
8780b10000000000001:8193
8790b100000000000001:16385
8800b1000000000000001:32769
8810b10000000000000001:65537
8820b100000000000000001:131073
8830b1000000000000000001:262145
8840b10000000000000000001:524289
8850b100000000000000000001:1048577
8860b1000000000000000000001:2097153
8870b10000000000000000000001:4194305
8880b100000000000000000000001:8388609
8890b1000000000000000000000001:16777217
8900b10000000000000000000000001:33554433
8910b100000000000000000000000001:67108865
8920b1000000000000000000000000001:134217729
8930b10000000000000000000000000001:268435457
8940b100000000000000000000000000001:536870913
8950b1000000000000000000000000000001:1073741825
8960b10000000000000000000000000000001:2147483649
8970b100000000000000000000000000000001:4294967297
8980b1000000000000000000000000000000001:8589934593
8990b10000000000000000000000000000000001:17179869185
6854fd01 9000b_101:NaN
9010b1_0_1:5
394e6ffb 9020b0_0_0_1:1
6854fd01 903# hex input
904-0x0:0
9050xabcdefgh:NaN
9060x1234:4660
9070xabcdef:11259375
908-0xABCDEF:-11259375
909-0x1234:-4660
9100x12345678:305419896
9110x1_2_3_4_56_78:305419896
394e6ffb 9120xa_b_c_d_e_f:11259375
6854fd01 9130x_123:NaN
61f5c3f5 9140x9:9
9150x11:17
9160x21:33
9170x41:65
9180x81:129
9190x101:257
9200x201:513
9210x401:1025
9220x801:2049
9230x1001:4097
9240x2001:8193
9250x4001:16385
9260x8001:32769
9270x10001:65537
9280x20001:131073
9290x40001:262145
9300x80001:524289
9310x100001:1048577
9320x200001:2097153
9330x400001:4194305
9340x800001:8388609
9350x1000001:16777217
9360x2000001:33554433
9370x4000001:67108865
9380x8000001:134217729
9390x10000001:268435457
9400x20000001:536870913
9410x40000001:1073741825
9420x80000001:2147483649
9430x100000001:4294967297
9440x200000001:8589934593
9450x400000001:17179869185
9460x800000001:34359738369
2d2b2744 947# bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex()
9480x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
6854fd01 949# inf input
950inf:inf
951+inf:inf
952-inf:-inf
9530inf:NaN
027dc388 954# abnormal input
6854fd01 955:NaN
956abc:NaN
957 1 a:NaN
9581bcd2:NaN
95911111b:NaN
960+1z:NaN
961-1z:NaN
027dc388 962# only one underscore between two digits
963_123:NaN
964_123_:NaN
965123_:NaN
9661__23:NaN
9671E1__2:NaN
9681_E12:NaN
9691E_12:NaN
9701_E_12:NaN
971+_1E12:NaN
972+0_1E2:100
973+0_0_1E2:100
974-0_0_1E2:-100
975-0_0_1E+0_0_2:-100
976E1:NaN
977E23:NaN
9781.23E1:NaN
9791.23E-1:NaN
980# bug with two E's in number beeing valid
9811e2e3:NaN
9821e2r:NaN
9831e2.0:NaN
07d34614 984# bug with two '.' in number beeing valid
9851.2.2:NaN
9861.2.3e1:NaN
987-1.2.3:NaN
988-1.2.3e-4:NaN
9891.2e3.4:NaN
9901.2e-3.4:NaN
9911.2.3.4:NaN
9921.2.t:NaN
9931..2:NaN
9941..2e1:NaN
9951..2e1..1:NaN
99612e1..1:NaN
997..2:NaN
998.-2:NaN
61f5c3f5 999# leading zeros
1000012:12
10010123:123
100201234:1234
1003012345:12345
10040123456:123456
100501234567:1234567
1006012345678:12345678
10070123456789:123456789
100801234567891:1234567891
1009012345678912:12345678912
10100123456789123:123456789123
101101234567891234:1234567891234
2d2b2744 1012# some inputs that result in zero
10130e0:0
1014+0e0:0
1015+0e+0:0
1016-0e+0:0
10170e-0:0
1018-0e-0:0
1019+0e-0:0
1020000:0
102100e2:0
102200e02:0
1023000e002:0
1024000e1230:0
102500e-3:0
102600e+3:0
102700e-03:0
102800e+03:0
1029-000:0
1030-00e2:0
1031-00e02:0
1032-000e002:0
1033-000e1230:0
1034-00e-3:0
1035-00e+3:0
1036-00e-03:0
1037-00e+03:0
027dc388 1038# normal input
6854fd01 10390:0
1040+0:0
1041+00:0
1042+000:0
1043000000000000000000:0
1044-0:0
1045-0000:0
1046+1:1
1047+01:1
1048+001:1
1049+00000100000:100000
1050123456789:123456789
1051-1:-1
1052-01:-1
1053-001:-1
1054-123456789:-123456789
1055-00000100000:-100000
10561_2_3:123
6854fd01 105710000000000E-1_0:1
10581E2:100
10591E1:10
10601E0:1
6854fd01 10611.23E2:123
6854fd01 1062100E-1:10
1063# floating point input
027dc388 1064# .2e2:20
10651.E3:1000
6854fd01 10661.01E2:101
10671010E-1:101
1068-1010E0:-1010
1069-1010E1:-10100
027dc388 10701234.00:1234
1071# non-integer numbers
6854fd01 1072-1010E-2:NaN
1073-1.01E+1:NaN
1074-1.01E-1:NaN
6854fd01 1075&bnan
10761:NaN
10772:NaN
1078abc:NaN
1079&bone
61f5c3f5 10802:+:1
6854fd01 10812:-:-1
1082boneNaN:-:-1
61f5c3f5 1083boneNaN:+:1
10842:abc:1
10853::1
6854fd01 1086&binf
10871:+:inf
10882:-:-inf
10893:abc:inf
027dc388 1090&is_nan
1091123:0
1092abc:1
1093NaN:1
1094-123:0
6854fd01 1095&is_inf
1096+inf::1
1097-inf::1
1098abc::0
10991::0
1100NaN::0
1101-1::0
1102+inf:-:0
1103+inf:+:1
1104-inf:-:1
1105-inf:+:0
79c55733 1106-inf:-inf:1
1107-inf:+inf:0
1108+inf:-inf:0
1109+inf:+inf:1
6854fd01 1110# it must be exactly /^[+-]inf$/
1111+infinity::0
1112-infinity::0
1113&blsft
1114abc:abc:NaN
61f5c3f5 1115+2:+2:8
1116+1:+32:4294967296
1117+1:+48:281474976710656
6854fd01 1118+8:-2:NaN
1119# excercise base 10
1120+12345:4:10:123450000
1121-1234:0:10:-1234
61f5c3f5 1122+1234:0:10:1234
6854fd01 1123+2:2:10:200
1124+12:2:10:1200
1125+1234:-3:10:NaN
11261234567890123:12:10:1234567890123000000000000
b3abae2a 1127-3:1:2:-6
1128-5:1:2:-10
1129-2:1:2:-4
1130-102533203:1:2:-205066406
6854fd01 1131&brsft
1132abc:abc:NaN
61f5c3f5 1133+8:+2:2
1134+4294967296:+32:1
1135+281474976710656:+48:1
6854fd01 1136+2:-2:NaN
1137# excercise base 10
1138-1234:0:10:-1234
61f5c3f5 1139+1234:0:10:1234
6854fd01 1140+200:2:10:2
1141+1234:3:10:1
1142+1234:2:10:12
1143+1234:-3:10:NaN
1144310000:4:10:31
114512300000:5:10:123
11461230000000000:10:10:123
114709876123456789067890:12:10:9876123
11481234561234567890123:13:10:123456
b3abae2a 1149820265627:1:2:410132813
1150# test shifting negative numbers in base 2
1151-15:1:2:-8
1152-14:1:2:-7
1153-13:1:2:-7
1154-12:1:2:-6
1155-11:1:2:-6
1156-10:1:2:-5
1157-9:1:2:-5
1158-8:1:2:-4
1159-7:1:2:-4
1160-6:1:2:-3
1161-5:1:2:-3
1162-4:1:2:-2
1163-3:1:2:-2
1164-2:1:2:-1
1165-1:1:2:-1
1166-1640531254:2:2:-410132814
1167-1640531254:1:2:-820265627
1168-820265627:1:2:-410132814
1169-205066405:1:2:-102533203
6854fd01 1170&bsstr
56d9de68 1171+inf:inf
1172-inf:-inf
6854fd01 11731e+34:1e+34
1174123.456E3:123456e+0
1175100:1e+2
56d9de68 1176bsstrabc:NaN
1177-5:-5e+0
1178-100:-1e+2
1179&numify
1180numifyabc:NaN
1181+inf:inf
1182-inf:-inf
11835:5
1184-5:-5
1185100:100
1186-100:-100
6854fd01 1187&bneg
1188bnegNaN:NaN
1189+inf:-inf
1190-inf:inf
1191abd:NaN
61f5c3f5 11920:0
11931:-1
1194-1:1
6854fd01 1195+123456789:-123456789
61f5c3f5 1196-123456789:123456789
6854fd01 1197&babs
1198babsNaN:NaN
1199+inf:inf
1200-inf:inf
61f5c3f5 12010:0
12021:1
1203-1:1
1204+123456789:123456789
1205-123456789:123456789
6854fd01 1206&bcmp
1207bcmpNaN:bcmpNaN:
61f5c3f5 1208bcmpNaN:0:
12090:bcmpNaN:
12100:0:0
1211-1:0:-1
12120:-1:1
12131:0:1
12140:1:-1
1215-1:1:-1
12161:-1:1
6854fd01 1217-1:-1:0
61f5c3f5 12181:1:0
1219123:123:0
1220123:12:1
122112:123:-1
6854fd01 1222-123:-123:0
1223-123:-12:-1
1224-12:-123:1
61f5c3f5 1225123:124:-1
1226124:123:1
6854fd01 1227-123:-124:1
1228-124:-123:-1
61f5c3f5 1229100:5:1
1230-123456789:987654321:-1
6854fd01 1231+123456789:-987654321:1
61f5c3f5 1232-987654321:123456789:-1
6854fd01 1233-inf:5432112345:-1
1234+inf:5432112345:1
1235-inf:-5432112345:-1
1236+inf:-5432112345:1
1237+inf:+inf:0
1238-inf:-inf:0
1239+inf:-inf:1
1240-inf:+inf:-1
12415:inf:-1
12425:inf:-1
1243-5:-inf:1
1244-5:-inf:1
1245# return undef
1246+inf:NaN:
1247NaN:inf:
1248-inf:NaN:
1249NaN:-inf:
1250&binc
1251abc:NaN
1252+inf:inf
1253-inf:-inf
61f5c3f5 1254+0:1
1255+1:2
1256-1:0
6854fd01 1257&bdec
1258abc:NaN
1259+inf:inf
1260-inf:-inf
1261+0:-1
61f5c3f5 1262+1:0
6854fd01 1263-1:-2
1264&badd
1265abc:abc:NaN
61f5c3f5 1266abc:0:NaN
6854fd01 1267+0:abc:NaN
b3abae2a 1268+inf:-inf:NaN
1269-inf:+inf:NaN
6854fd01 1270+inf:+inf:inf
1271-inf:-inf:-inf
1272baddNaN:+inf:NaN
1273baddNaN:+inf:NaN
1274+inf:baddNaN:NaN
1275-inf:baddNaN:NaN
61f5c3f5 12760:0:0
12771:0:1
12780:1:1
12791:1:2
1280-1:0:-1
12810:-1:-1
6854fd01 1282-1:-1:-2
61f5c3f5 1283-1:+1:0
1284+1:-1:0
1285+9:+1:10
1286+99:+1:100
1287+999:+1:1000
1288+9999:+1:10000
1289+99999:+1:100000
1290+999999:+1:1000000
1291+9999999:+1:10000000
1292+99999999:+1:100000000
1293+999999999:+1:1000000000
1294+9999999999:+1:10000000000
1295+99999999999:+1:100000000000
1296+10:-1:9
1297+100:-1:99
1298+1000:-1:999
1299+10000:-1:9999
1300+100000:-1:99999
1301+1000000:-1:999999
1302+10000000:-1:9999999
1303+100000000:-1:99999999
1304+1000000000:-1:999999999
1305+10000000000:-1:9999999999
1306+123456789:987654321:1111111110
1307-123456789:987654321:864197532
6854fd01 1308-123456789:-987654321:-1111111110
1309+123456789:-987654321:-864197532
56b9c951 1310-1:10001:10000
1311-1:100001:100000
1312-1:1000001:1000000
1313-1:10000001:10000000
1314-1:100000001:100000000
1315-1:1000000001:1000000000
1316-1:10000000001:10000000000
1317-1:100000000001:100000000000
1318-1:1000000000001:1000000000000
1319-1:10000000000001:10000000000000
1320-1:-10001:-10002
1321-1:-100001:-100002
1322-1:-1000001:-1000002
1323-1:-10000001:-10000002
1324-1:-100000001:-100000002
1325-1:-1000000001:-1000000002
1326-1:-10000000001:-10000000002
1327-1:-100000000001:-100000000002
1328-1:-1000000000001:-1000000000002
1329-1:-10000000000001:-10000000000002
6854fd01 1330&bsub
1331abc:abc:NaN
1332abc:+0:NaN
1333+0:abc:NaN
1334+inf:-inf:inf
1335-inf:+inf:-inf
b3abae2a 1336+inf:+inf:NaN
1337-inf:-inf:NaN
61f5c3f5 1338+0:+0:0
1339+1:+0:1
6854fd01 1340+0:+1:-1
61f5c3f5 1341+1:+1:0
6854fd01 1342-1:+0:-1
61f5c3f5 1343+0:-1:1
1344-1:-1:0
6854fd01 1345-1:+1:-2
61f5c3f5 1346+1:-1:2
1347+9:+1:8
1348+99:+1:98
1349+999:+1:998
1350+9999:+1:9998
1351+99999:+1:99998
1352+999999:+1:999998
1353+9999999:+1:9999998
1354+99999999:+1:99999998
1355+999999999:+1:999999998
1356+9999999999:+1:9999999998
1357+99999999999:+1:99999999998
1358+10:-1:11
1359+100:-1:101
1360+1000:-1:1001
1361+10000:-1:10001
1362+100000:-1:100001
1363+1000000:-1:1000001
1364+10000000:-1:10000001
1365+100000000:-1:100000001
1366+1000000000:-1:1000000001
1367+10000000000:-1:10000000001
6854fd01 1368+123456789:+987654321:-864197532
1369-123456789:+987654321:-1111111110
61f5c3f5 1370-123456789:-987654321:864197532
1371+123456789:-987654321:1111111110
56b9c951 137210001:1:10000
1373100001:1:100000
13741000001:1:1000000
137510000001:1:10000000
1376100000001:1:100000000
13771000000001:1:1000000000
137810000000001:1:10000000000
1379100000000001:1:100000000000
13801000000000001:1:1000000000000
138110000000000001:1:10000000000000
138210001:-1:10002
1383100001:-1:100002
13841000001:-1:1000002
138510000001:-1:10000002
1386100000001:-1:100000002
13871000000001:-1:1000000002
138810000000001:-1:10000000002
1389100000000001:-1:100000000002
13901000000000001:-1:1000000000002
139110000000000001:-1:10000000000002
6854fd01 1392&bmul
1393abc:abc:NaN
1394abc:+0:NaN
1395+0:abc:NaN
1396NaNmul:+inf:NaN
1397NaNmul:-inf:NaN
1398-inf:NaNmul:NaN
1399+inf:NaNmul:NaN
1400+inf:+inf:inf
1401+inf:-inf:-inf
1402-inf:+inf:-inf
1403-inf:-inf:inf
61f5c3f5 1404+0:+0:0
1405+0:+1:0
1406+1:+0:0
1407+0:-1:0
1408-1:+0:0
1409123456789123456789:0:0
14100:123456789123456789:0
1411-1:-1:1
6854fd01 1412-1:+1:-1
1413+1:-1:-1
61f5c3f5 1414+1:+1:1
1415+2:+3:6
6854fd01 1416-2:+3:-6
1417+2:-3:-6
61f5c3f5 1418-2:-3:6
1419111:111:12321
142010101:10101:102030201
14211001001:1001001:1002003002001
1422100010001:100010001:10002000300020001
142310000100001:10000100001:100002000030000200001
142411111111111:9:99999999999
142522222222222:9:199999999998
142633333333333:9:299999999997
142744444444444:9:399999999996
142855555555555:9:499999999995
142966666666666:9:599999999994
143077777777777:9:699999999993
143188888888888:9:799999999992
143299999999999:9:899999999991
1433+25:+25:625
1434+12345:+12345:152399025
1435+99999:+11111:1111088889
6854fd01 14369999:10000:99990000
143799999:100000:9999900000
1438999999:1000000:999999000000
14399999999:10000000:99999990000000
144099999999:100000000:9999999900000000
1441999999999:1000000000:999999999000000000
14429999999999:10000000000:99999999990000000000
144399999999999:100000000000:9999999999900000000000
1444999999999999:1000000000000:999999999999000000000000
14459999999999999:10000000000000:99999999999990000000000000
144699999999999999:100000000000000:9999999999999900000000000000
1447999999999999999:1000000000000000:999999999999999000000000000000
14489999999999999999:10000000000000000:99999999999999990000000000000000
144999999999999999999:100000000000000000:9999999999999999900000000000000000
1450999999999999999999:1000000000000000000:999999999999999999000000000000000000
14519999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1452&bdiv-list
1453100:20:5,0
14544095:4095:1,0
1455-4095:-4095:1,0
14564095:-4095:-1,0
1457-4095:4095:-1,0
1458123:2:61,1
b3abae2a 14599:5:1,4
14609:4:2,1
6854fd01 1461# inf handling and general remainder
14625:8:0,5
14630:8:0,0
146411:2:5,1
146511:-2:-5,-1
1466-11:2:-5,1
1467# see table in documentation in MBI
14680:inf:0,0
14690:-inf:0,0
14705:inf:0,5
14715:-inf:0,5
1472-5:inf:0,-5
1473-5:-inf:0,-5
1474inf:5:inf,0
1475-inf:5:-inf,0
1476inf:-5:-inf,0
1477-inf:-5:inf,0
14785:5:1,0
1479-5:-5:1,0
b3abae2a 1480inf:inf:NaN,NaN
1481-inf:-inf:NaN,NaN
1482-inf:inf:NaN,NaN
1483inf:-inf:NaN,NaN
6854fd01 14848:0:inf,8
1485inf:0:inf,inf
1486# exceptions to reminder rule
1487-8:0:-inf,-8
1488-inf:0:-inf,-inf
14890:0:NaN,NaN
990fb837 1490# test the shortcut in Calc if @$x == @$yorg
14911234567812345678:123456712345678:10,688888898
149212345671234567:1234561234567:10,58888897
1493123456123456:12345123456:10,4888896
14941234512345:123412345:10,388895
14951234567890999999999:1234567890:1000000000,999999999
14961234567890000000000:1234567890:1000000000,0
14971234567890999999999:9876543210:124999998,9503086419
14981234567890000000000:9876543210:124999998,8503086420
149996969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
7596a890 1500# bug in v1.76
15011267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
b68b7ab1 1502# excercise shortcut for numbers of the same length in div
1503999999999999999999999999999999999:999999999999999999999999999999999:1,0
1504999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1505999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1506999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1507999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1508999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1509999999999999999999999999999999999:333333333333333333333333333333333:3,0
1510999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1511999999999999999999999999999999999:111111111111111111111111111111111:9,0
15129999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
15139999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
15149999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
15159999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
15169999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
15179999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
15189999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
15199999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
15209999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
15219999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
15229999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
6854fd01 1523&bdiv
1524abc:abc:NaN
61f5c3f5 1525abc:1:NaN
15261:abc:NaN
15270:0:NaN
6854fd01 1528# inf handling (see table in doc)
15290:inf:0
15300:-inf:0
15315:inf:0
15325:-inf:0
1533-5:inf:0
1534-5:-inf:0
1535inf:5:inf
1536-inf:5:-inf
1537inf:-5:-inf
1538-inf:-5:inf
15395:5:1
1540-5:-5:1
b3abae2a 1541inf:inf:NaN
1542-inf:-inf:NaN
1543-inf:inf:NaN
1544inf:-inf:NaN
6854fd01 15458:0:inf
1546inf:0:inf
1547-8:0:-inf
1548-inf:0:-inf
15490:0:NaN
155011:2:5
1551-11:-2:5
1552-11:2:-5
155311:-2:-5
61f5c3f5 15540:1:0
15550:-1:0
15561:1:1
1557-1:-1:1
15581:-1:-1
1559-1:1:-1
15601:2:0
15612:1:2
15621:26:0
15631000000000:9:111111111
15642000000000:9:222222222
15653000000000:9:333333333
15664000000000:9:444444444
15675000000000:9:555555555
15686000000000:9:666666666
15697000000000:9:777777777
15708000000000:9:888888888
15719000000000:9:1000000000
157235500000:113:314159
157371000000:226:314159
1574106500000:339:314159
15751000000000:3:333333333
1576+10:+5:2
1577+100:+4:25
1578+1000:+8:125
1579+10000:+16:625
1580999999999999:9:111111111111
1581999999999999:99:10101010101
1582999999999999:999:1001001001
1583999999999999:9999:100010001
1584999999999999999:99999:10000100001
1585+1111088889:99999:11111
6854fd01 1586-5:-3:1
1587-5:3:-1
15884:3:1
15894:-3:-1
15901:3:0
15911:-3:0
1592-2:-3:0
1593-2:3:0
15948:3:2
1595-8:3:-2
159614:-3:-4
1597-14:3:-4
1598-14:-3:4
159914:3:4
1600# bug in Calc with '99999' vs $BASE-1
160110000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1602# test the shortcut in Calc if @$x == @$yorg
16031234567812345678:123456712345678:10
160412345671234567:1234561234567:10
1605123456123456:12345123456:10
16061234512345:123412345:10
16071234567890999999999:1234567890:1000000000
16081234567890000000000:1234567890:1000000000
16091234567890999999999:9876543210:124999998
16101234567890000000000:9876543210:124999998
161196969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1612# bug up to v0.35 in Calc (--$q one too many)
161384696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
161484696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
161584696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
161684696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
b68b7ab1 1617# excercise shortcut for numbers of the same length in div
1618999999999999999999999999999999999:999999999999999999999999999999999:1
1619999999999999999999999999999999999:888888888888888888888888888888888:1
1620999999999999999999999999999999999:777777777777777777777777777777777:1
1621999999999999999999999999999999999:666666666666666666666666666666666:1
1622999999999999999999999999999999999:555555555555555555555555555555555:1
1623999999999999999999999999999999999:444444444444444444444444444444444:2
1624999999999999999999999999999999999:333333333333333333333333333333333:3
1625999999999999999999999999999999999:222222222222222222222222222222222:4
1626999999999999999999999999999999999:111111111111111111111111111111111:9
16279999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
16289999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
16299999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
16309999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
16319999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
16329999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
16339999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
16349999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
16359999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
16369999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
16379999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
a87115f0 1638# bug with shortcut in Calc 0.44
1639949418181818187070707070707070707070:181818181853535353535353535353535353:5
07d34614 1640&bmodinv
1641# format: number:modulus:result
1642# bmodinv Data errors
1643abc:abc:NaN
1644abc:5:NaN
16455:abc:NaN
1646# bmodinv Expected Results from normal use
16471:5:1
16483:5:2
1649-2:5:2
16508:5033:4404
56d9de68 16511234567891:13:6
1652-1234567891:13:7
07d34614 1653324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1654## bmodinv Error cases / useless use of function
07d34614 16553:-5:NaN
1656inf:5:NaN
1ddff52a 16575:inf:NaN
1658-inf:5:NaN
16595:-inf:NaN
07d34614 1660&bmodpow
1661# format: number:exponent:modulus:result
1662# bmodpow Data errors
1663abc:abc:abc:NaN
16645:abc:abc:NaN
1665abc:5:abc:NaN
1666abc:abc:5:NaN
16675:5:abc:NaN
16685:abc:5:NaN
1669abc:5:5:NaN
1670# bmodpow Expected results
16710:0:2:1
16721:0:2:1
16730:0:1:0
16748:7:5032:3840
16758:-1:5033:4404
167698436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1677# bmodpow Error cases
16788:8:-5:NaN
16798:-1:16:NaN
1680inf:5:13:NaN
16815:inf:13:NaN
6854fd01 1682&bmod
1683# inf handling, see table in doc
16840:inf:0
16850:-inf:0
16865:inf:5
16875:-inf:5
1688-5:inf:-5
1689-5:-inf:-5
1690inf:5:0
1691-inf:5:0
1692inf:-5:0
1693-inf:-5:0
16945:5:0
1695-5:-5:0
b3abae2a 1696inf:inf:NaN
1697-inf:-inf:NaN
1698-inf:inf:NaN
1699inf:-inf:NaN
6854fd01 17008:0:8
1701inf:0:inf
1702# exceptions to reminder rule
1703-inf:0:-inf
1704-8:0:-8
17050:0:NaN
1706abc:abc:NaN
61f5c3f5 1707abc:1:abc:NaN
17081:abc:NaN
17090:0:NaN
17100:1:0
17111:0:1
17120:-1:0
1713-1:0:-1
17141:1:0
1715-1:-1:0
17161:-1:0
1717-1:1:0
17181:2:1
17192:1:0
17201000000000:9:1
17212000000000:9:2
17223000000000:9:3
17234000000000:9:4
17245000000000:9:5
17256000000000:9:6
17267000000000:9:7
17278000000000:9:8
17289000000000:9:0
172935500000:113:33
173071000000:226:66
1731106500000:339:99
17321000000000:3:1
173310:5:0
1734100:4:0
17351000:8:0
173610000:16:0
1737999999999999:9:0
1738999999999999:99:0
1739999999999999:999:0
1740999999999999:9999:0
1741999999999999999:99999:0
1742-9:+5:1
6854fd01 1743+9:-5:-1
1744-9:-5:-4
1745-5:3:1
1746-2:3:1
17474:3:1
17481:3:1
1749-5:-3:-2
1750-2:-3:-2
17514:-3:-2
17521:-3:-2
17534095:4095:0
027dc388 1754100041000510123:3:0
1755152403346:12345:4321
b3abae2a 17569:5:4
28df3e88 1757# test shortcuts in Calc
1758# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
17591234:9:1
1760123456:9:3
176112345678:9:0
17621234567891:9:1
1763123456789123:9:6
176412345678912345:9:6
17651234567891234567:9:1
1766123456789123456789:9:0
17671234:10:4
1768123456:10:6
176912345678:10:8
17701234567891:10:1
1771123456789123:10:3
177212345678912345:10:5
17731234567891234567:10:7
1774123456789123456789:10:9
17751234:113:104
1776123456:113:60
177712345678:113:89
17781234567891:113:64
1779123456789123:113:95
178012345678912345:113:53
17811234567891234567:113:56
1782123456789123456789:113:39
07d34614 1783# bug in bmod() not modifying the variable in place
1784-629:5033:4404
aef458a0 1785# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1786# when X == X and X was big
1787111111111111111111111111111111:111111111111111111111111111111:0
178812345678901234567890:12345678901234567890:0
6854fd01 1789&bgcd
9b924220 1790inf:12:NaN
1791-inf:12:NaN
179212:inf:NaN
179312:-inf:NaN
1794inf:inf:NaN
1795inf:-inf:NaN
1796-inf:-inf:NaN
6854fd01 1797abc:abc:NaN
1798abc:+0:NaN
1799+0:abc:NaN
61f5c3f5 1800+0:+0:0
1801+0:+1:1
1802+1:+0:1
1803+1:+1:1
1804+2:+3:1
1805+3:+2:1
1806-3:+2:1
9b924220 1807-3:-2:1
1808-144:-60:12
1809144:-60:12
1810144:60:12
61f5c3f5 1811100:625:25
18124096:81:1
18131034:804:2
181427:90:56:1
181527:90:54:9
6854fd01 1816&blcm
1817abc:abc:NaN
1818abc:+0:NaN
1819+0:abc:NaN
1820+0:+0:NaN
61f5c3f5 1821+1:+0:0
1822+0:+1:0
1823+27:+90:270
1824+1034:+804:415668
6854fd01 1825&band
1826abc:abc:NaN
1827abc:0:NaN
18280:abc:NaN
18291:2:0
18303:2:2
61f5c3f5 1831+8:+2:0
1832+281474976710656:0:0
1833+281474976710656:1:0
1834+281474976710656:+281474976710656:281474976710656
9b924220 1835281474976710656:-1:281474976710656
6854fd01 1836-2:-3:-4
1837-1:-1:-1
1838-6:-6:-6
1839-7:-4:-8
1840-7:4:0
1841-4:7:4
9b924220 1842# negative argument is bitwise shorter than positive [perl #26559]
184330:-3:28
1844123:-1:123
394e6ffb 1845# equal arguments are treated special, so also do some test with unequal ones
18460xFFFF:0xFFFF:0x0xFFFF
18470xFFFFFF:0xFFFFFF:0x0xFFFFFF
18480xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18490xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18500xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18510xF0F0:0xF0F0:0x0xF0F0
18520x0F0F:0x0F0F:0x0x0F0F
18530xF0F0F0:0xF0F0F0:0x0xF0F0F0
18540x0F0F0F:0x0F0F0F:0x0x0F0F0F
18550xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18560x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18570xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18580x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18590xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18600x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18610x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1862&bior
1863abc:abc:NaN
1864abc:0:NaN
18650:abc:NaN
18661:2:3
61f5c3f5 1867+8:+2:10
1868+281474976710656:0:281474976710656
1869+281474976710656:1:281474976710657
1870+281474976710656:281474976710656:281474976710656
6854fd01 1871-2:-3:-1
1872-1:-1:-1
1873-6:-6:-6
1874-7:4:-3
1875-4:7:-1
9b924220 1876+281474976710656:-1:-1
187730:-3:-1
187830:-4:-2
1879300:-76:-68
1880-76:300:-68
394e6ffb 1881# equal arguments are treated special, so also do some test with unequal ones
18820xFFFF:0xFFFF:0x0xFFFF
18830xFFFFFF:0xFFFFFF:0x0xFFFFFF
18840xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18850xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18860xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18870:0xFFFF:0x0xFFFF
18880:0xFFFFFF:0x0xFFFFFF
18890:0xFFFFFFFF:0x0xFFFFFFFF
18900:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18910:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18920xFFFF:0:0x0xFFFF
18930xFFFFFF:0:0x0xFFFFFF
18940xFFFFFFFF:0:0x0xFFFFFFFF
18950xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18960xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18970xF0F0:0xF0F0:0x0xF0F0
18980x0F0F:0x0F0F:0x0x0F0F
18990xF0F0:0x0F0F:0x0xFFFF
19000xF0F0F0:0xF0F0F0:0x0xF0F0F0
19010x0F0F0F:0x0F0F0F:0x0x0F0F0F
19020x0F0F0F:0xF0F0F0:0x0xFFFFFF
19030xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19040x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19050x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19060xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19070x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19080x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19090xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19100x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19110x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
19120x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1913&bxor
1914abc:abc:NaN
1915abc:0:NaN
19160:abc:NaN
19171:2:3
61f5c3f5 1918+8:+2:10
1919+281474976710656:0:281474976710656
1920+281474976710656:1:281474976710657
1921+281474976710656:281474976710656:0
6854fd01 1922-2:-3:3
1923-1:-1:0
1924-6:-6:0
1925-7:4:-3
1926-4:7:-5
19274:-7:-3
1928-4:-7:5
9b924220 192930:-3:-29
193030:-4:-30
1931300:-76:-360
1932-76:300:-360
394e6ffb 1933# equal arguments are treated special, so also do some test with unequal ones
19340xFFFF:0xFFFF:0
19350xFFFFFF:0xFFFFFF:0
19360xFFFFFFFF:0xFFFFFFFF:0
19370xFFFFFFFFFF:0xFFFFFFFFFF:0
19380xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
19390:0xFFFF:0x0xFFFF
19400:0xFFFFFF:0x0xFFFFFF
19410:0xFFFFFFFF:0x0xFFFFFFFF
19420:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19430:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19440xFFFF:0:0x0xFFFF
19450xFFFFFF:0:0x0xFFFFFF
19460xFFFFFFFF:0:0x0xFFFFFFFF
19470xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19480xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19490xF0F0:0xF0F0:0
19500x0F0F:0x0F0F:0
19510xF0F0:0x0F0F:0x0xFFFF
19520xF0F0F0:0xF0F0F0:0
19530x0F0F0F:0x0F0F0F:0
19540x0F0F0F:0xF0F0F0:0x0xFFFFFF
19550xF0F0F0F0:0xF0F0F0F0:0
19560x0F0F0F0F:0x0F0F0F0F:0
19570x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19580xF0F0F0F0F0:0xF0F0F0F0F0:0
19590x0F0F0F0F0F:0x0F0F0F0F0F:0
19600x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19610xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
19620x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
19630x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1964&bnot
1965abc:NaN
1966+0:-1
1967+8:-9
1968+281474976710656:-281474976710657
1969-1:0
1970-2:1
1971-12:11
1972&digit
19730:0:0
197412:0:2
197512:1:1
1976123:0:3
1977123:1:2
1978123:2:1
1979123:-1:1
1980123:-2:2
1981123:-3:3
1982123456:0:6
1983123456:1:5
1984123456:2:4
1985123456:3:3
1986123456:4:2
1987123456:5:1
1988123456:-1:1
1989123456:-2:2
1990123456:-3:3
1991100000:-3:0
1992100000:0:0
1993100000:1:0
1994&mantissa
1995abc:NaN
19961e4:1
19972e0:2
1998123:123
1999-1:-1
2000-2:-2
2001+inf:inf
2002-inf:-inf
2003&exponent
2004abc:NaN
20051e4:4
20062e0:0
2007123:0
2008-1:0
2009-2:0
20100:1
2011+inf:inf
2012-inf:inf
2013&parts
2014abc:NaN,NaN
20151e4:1,4
20162e0:2,0
2017123:123,0
2018-1:-1,0
2019-2:-2,0
20200:0,1
2021+inf:inf,inf
2022-inf:-inf,inf
b3abae2a 2023&bfac
2024-1:NaN
2025NaNfac:NaN
b282a552 2026+inf:inf
b3abae2a 2027-inf:NaN
20280:1
20291:1
20302:2
20313:6
20324:24
20335:120
20346:720
990fb837 20357:5040
20368:40320
20379:362880
b3abae2a 203810:3628800
203911:39916800
204012:479001600
6854fd01 2041&bpow
2042abc:12:NaN
204312:abc:NaN
20440:0:1
20450:1:0
20460:2:0
9b924220 20470:-1:inf
20480:-2:inf
6854fd01 20491:0:1
20501:1:1
20511:2:1
20521:3:1
20531:-1:1
20541:-2:1
20551:-3:1
20562:0:1
20572:1:2
20582:2:4
20592:3:8
20603:3:27
2d2b2744 2061-2:2:4
2062-2:3:-8
2063-2:4:16
2064-2:5:-32
6854fd01 20652:-1:NaN
2066-2:-1:NaN
20672:-2:NaN
2068-2:-2:NaN
2d2b2744 2069# inf tests
6854fd01 2070+inf:1234500012:inf
2d2b2744 2071-inf:1234500012:inf
2072-inf:1234500013:-inf
6854fd01 2073+inf:-12345000123:inf
2074-inf:-12345000123:-inf
2d2b2744 2075# -inf * -inf = inf
2076-inf:2:inf
2077-inf:0:NaN
2078-inf:-1:0
2079-inf:inf:NaN
20802:inf:inf
20812:-inf:0
20820:inf:0
20830:-inf:inf
2084-1:-inf:NaN
2085-1:inf:NaN
2086-2:inf:NaN
2087-2:-inf:0
2088NaN:inf:NaN
2089NaN:-inf:NaN
2090-inf:NaN:NaN
2091inf:NaN:NaN
2092inf:-inf:NaN
20931:inf:1
20941:-inf:1
6854fd01 2095# 1 ** -x => 1 / (1 ** x)
2096-1:0:1
2097-2:0:1
2098-1:1:-1
2099-1:2:1
2100-1:3:-1
2101-1:4:1
2102-1:5:-1
2103-1:-1:-1
2104-1:-2:1
2105-1:-3:-1
2106-1:-4:1
210710:2:100
210810:3:1000
210910:4:10000
211010:5:100000
211110:6:1000000
211210:7:10000000
211310:8:100000000
211410:9:1000000000
211510:20:100000000000000000000
2116123456:2:15241383936
9b924220 2117-2:2:4
2118-2:3:-8
2119-2:4:16
2120-2:5:-32
2121-3:2:9
2122-3:3:-27
2123-3:4:81
2124-3:5:-243
6854fd01 2125&length
2126100:3
212710:2
21281:1
21290:1
213012345:5
213110000000000000000:17
2132-123:3
2133215960156869840440586892398248:30
990fb837 2134&broot
2135# sqrt()
2136+0:2:0
2137+1:2:1
2138-1:2:NaN
2139# -$x ** (1/2) => -$y, but not in froot()
2140-123:2:NaN
2141+inf:2:inf
2142-inf:2:NaN
21432:2:1
2144-2:2:NaN
21454:2:2
21469:2:3
214716:2:4
2148100:2:10
2149123:2:11
215015241:2:123
2151144:2:12
215212:2:3
21530.49:2:0
21540.0049:2:0
2155# invalid ones
21561:NaN:NaN
2157-1:NaN:NaN
21580:NaN:NaN
2159-inf:NaN:NaN
2160+inf:NaN:NaN
2161NaN:0:NaN
2162NaN:2:NaN
2163NaN:inf:NaN
2164NaN:inf:NaN
216512:-inf:NaN
216612:inf:NaN
2167+0:0:NaN
2168+1:0:NaN
2169-1:0:NaN
2170-2:0:NaN
2171-123.45:0:NaN
2172+inf:0:NaN
217312:1:12
2174-12:1:NaN
21758:-1:NaN
2176-8:-1:NaN
2177# cubic root
21788:3:2
2179-8:3:NaN
2180# fourths root
c38b2de2 218116:4:2
218281:4:3
3a427a11 2183# 2 ** 64
c38b2de2 218418446744073709551616:4:65536
218518446744073709551616:8:256
218618446744073709551616:16:16
218718446744073709551616:32:4
218818446744073709551616:64:2
218918446744073709551616:128:1
3a427a11 2190# 213 ** 15
219184274086103068221283760416414557757:15:213
2192# see t/bigroot for more tests
6854fd01 2193&bsqrt
394e6ffb 2194145:12
6854fd01 2195144:12
394e6ffb 2196143:11
6854fd01 219716:4
394e6ffb 2198170:13
2199169:13
2200168:12
6854fd01 22014:2
394e6ffb 22023:1
6854fd01 22032:1
394e6ffb 22049:3
6854fd01 220512:3
2206256:16
2207100000000:10000
22084000000000000:2000000
394e6ffb 2209152399026:12345
2210152399025:12345
2211152399024:12344
3a427a11 2212# 2 ** 64 => 2 ** 32
221318446744073709551616:4294967296
221484274086103068221283760416414557757:290299993288095377
6854fd01 22151:1
22160:0
2217-2:NaN
394e6ffb 2218-123:NaN
6854fd01 2219Nan:NaN
990fb837 2220+inf:inf
2221-inf:NaN
6854fd01 2222&bround
2223$round_mode('trunc')
22240:12:0
2225NaNbround:12:NaN
2226+inf:12:inf
2227-inf:12:-inf
22281234:0:1234
22291234:2:1200
2230123456:4:123400
2231123456:5:123450
2232123456:6:123456
61f5c3f5 2233+10123456789:5:10123000000
6854fd01 2234-10123456789:5:-10123000000
61f5c3f5 2235+10123456789:9:10123456700
6854fd01 2236-10123456789:9:-10123456700
61f5c3f5 2237+101234500:6:101234000
6854fd01 2238-101234500:6:-101234000
61f5c3f5 2239#+101234500:-4:101234000
6854fd01 2240#-101234500:-4:-101234000
2241$round_mode('zero')
61f5c3f5 2242+20123456789:5:20123000000
6854fd01 2243-20123456789:5:-20123000000
61f5c3f5 2244+20123456789:9:20123456800
6854fd01 2245-20123456789:9:-20123456800
61f5c3f5 2246+201234500:6:201234000
6854fd01 2247-201234500:6:-201234000
61f5c3f5 2248#+201234500:-4:201234000
6854fd01 2249#-201234500:-4:-201234000
2250+12345000:4:12340000
2251-12345000:4:-12340000
2252$round_mode('+inf')
61f5c3f5 2253+30123456789:5:30123000000
6854fd01 2254-30123456789:5:-30123000000
61f5c3f5 2255+30123456789:9:30123456800
6854fd01 2256-30123456789:9:-30123456800
61f5c3f5 2257+301234500:6:301235000
6854fd01 2258-301234500:6:-301234000
61f5c3f5 2259#+301234500:-4:301235000
6854fd01 2260#-301234500:-4:-301234000
2261+12345000:4:12350000
2262-12345000:4:-12340000
2263$round_mode('-inf')
61f5c3f5 2264+40123456789:5:40123000000
6854fd01 2265-40123456789:5:-40123000000
61f5c3f5 2266+40123456789:9:40123456800
6854fd01 2267-40123456789:9:-40123456800
61f5c3f5 2268+401234500:6:401234000
2269+401234500:6:401234000
6854fd01 2270#-401234500:-4:-401235000
2271#-401234500:-4:-401235000
2272+12345000:4:12340000
2273-12345000:4:-12350000
2274$round_mode('odd')
61f5c3f5 2275+50123456789:5:50123000000
6854fd01 2276-50123456789:5:-50123000000
61f5c3f5 2277+50123456789:9:50123456800
6854fd01 2278-50123456789:9:-50123456800
61f5c3f5 2279+501234500:6:501235000
6854fd01 2280-501234500:6:-501235000
61f5c3f5 2281#+501234500:-4:501235000
6854fd01 2282#-501234500:-4:-501235000
2283+12345000:4:12350000
2284-12345000:4:-12350000
2285$round_mode('even')
61f5c3f5 2286+60123456789:5:60123000000
6854fd01 2287-60123456789:5:-60123000000
61f5c3f5 2288+60123456789:9:60123456800
6854fd01 2289-60123456789:9:-60123456800
61f5c3f5 2290+601234500:6:601234000
6854fd01 2291-601234500:6:-601234000
61f5c3f5 2292#+601234500:-4:601234000
6854fd01 2293#-601234500:-4:-601234000
2294#-601234500:-9:0
2295#-501234500:-9:0
2296#-601234500:-8:0
2297#-501234500:-8:0
2298+1234567:7:1234567
2299+1234567:6:1234570
2300+12345000:4:12340000
2301-12345000:4:-12340000
7b29e1e6 2302$round_mode('common')
2303+60123456789:5:60123000000
2304+60123199999:5:60123000000
2305+60123299999:5:60123000000
2306+60123399999:5:60123000000
2307+60123499999:5:60123000000
2308+60123500000:5:60124000000
2309+60123600000:5:60124000000
2310+60123700000:5:60124000000
2311+60123800000:5:60124000000
2312+60123900000:5:60124000000
2313-60123456789:5:-60123000000
2314-60123199999:5:-60123000000
2315-60123299999:5:-60123000000
2316-60123399999:5:-60123000000
2317-60123499999:5:-60123000000
2318-60123500000:5:-60124000000
2319-60123600000:5:-60124000000
2320-60123700000:5:-60124000000
2321-60123800000:5:-60124000000
2322-60123900000:5:-60124000000
6854fd01 2323&is_zero
23240:1
2325NaNzero:0
2326+inf:0
2327-inf:0
2328123:0
2329-1:0
23301:0
2331&is_one
23320:0
2333NaNone:0
2334+inf:0
2335-inf:0
23361:1
23372:0
2338-1:0
2339-2:0
2340# floor and ceil tests are pretty pointless in integer space...but play safe
2341&bfloor
23420:0
2343NaNfloor:NaN
2344+inf:inf
2345-inf:-inf
2346-1:-1
2347-2:-2
23482:2
23493:3
2350abc:NaN
2351&bceil
2352NaNceil:NaN
2353+inf:inf
2354-inf:-inf
23550:0
2356-1:-1
2357-2:-2
23582:2
23593:3
2360abc:NaN
2361&as_hex
2362128:0x80
2363-128:-0x80
23640:0x0
2365-0:0x0
23661:0x1
23670x123456789123456789:0x123456789123456789
2368+inf:inf
2369-inf:-inf
2370NaNas_hex:NaN
2371&as_bin
2372128:0b10000000
2373-128:-0b10000000
23740:0b0
2375-0:0b0
23761:0b1
23770b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 23780x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2379+inf:inf
2380-inf:-inf
2381NaNas_bin:NaN