Fix a typo
[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
b68b7ab1 1500# excercise shortcut for numbers of the same length in div
1501999999999999999999999999999999999:999999999999999999999999999999999:1,0
1502999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1503999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1504999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1505999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1506999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1507999999999999999999999999999999999:333333333333333333333333333333333:3,0
1508999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1509999999999999999999999999999999999:111111111111111111111111111111111:9,0
15109999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
15119999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
15129999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
15139999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
15149999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
15159999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
15169999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
15179999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
15189999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
15199999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
15209999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
6854fd01 1521&bdiv
1522abc:abc:NaN
61f5c3f5 1523abc:1:NaN
15241:abc:NaN
15250:0:NaN
6854fd01 1526# inf handling (see table in doc)
15270:inf:0
15280:-inf:0
15295:inf:0
15305:-inf:0
1531-5:inf:0
1532-5:-inf:0
1533inf:5:inf
1534-inf:5:-inf
1535inf:-5:-inf
1536-inf:-5:inf
15375:5:1
1538-5:-5:1
b3abae2a 1539inf:inf:NaN
1540-inf:-inf:NaN
1541-inf:inf:NaN
1542inf:-inf:NaN
6854fd01 15438:0:inf
1544inf:0:inf
1545-8:0:-inf
1546-inf:0:-inf
15470:0:NaN
154811:2:5
1549-11:-2:5
1550-11:2:-5
155111:-2:-5
61f5c3f5 15520:1:0
15530:-1:0
15541:1:1
1555-1:-1:1
15561:-1:-1
1557-1:1:-1
15581:2:0
15592:1:2
15601:26:0
15611000000000:9:111111111
15622000000000:9:222222222
15633000000000:9:333333333
15644000000000:9:444444444
15655000000000:9:555555555
15666000000000:9:666666666
15677000000000:9:777777777
15688000000000:9:888888888
15699000000000:9:1000000000
157035500000:113:314159
157171000000:226:314159
1572106500000:339:314159
15731000000000:3:333333333
1574+10:+5:2
1575+100:+4:25
1576+1000:+8:125
1577+10000:+16:625
1578999999999999:9:111111111111
1579999999999999:99:10101010101
1580999999999999:999:1001001001
1581999999999999:9999:100010001
1582999999999999999:99999:10000100001
1583+1111088889:99999:11111
6854fd01 1584-5:-3:1
1585-5:3:-1
15864:3:1
15874:-3:-1
15881:3:0
15891:-3:0
1590-2:-3:0
1591-2:3:0
15928:3:2
1593-8:3:-2
159414:-3:-4
1595-14:3:-4
1596-14:-3:4
159714:3:4
1598# bug in Calc with '99999' vs $BASE-1
159910000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1600# test the shortcut in Calc if @$x == @$yorg
16011234567812345678:123456712345678:10
160212345671234567:1234561234567:10
1603123456123456:12345123456:10
16041234512345:123412345:10
16051234567890999999999:1234567890:1000000000
16061234567890000000000:1234567890:1000000000
16071234567890999999999:9876543210:124999998
16081234567890000000000:9876543210:124999998
160996969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1610# bug up to v0.35 in Calc (--$q one too many)
161184696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
161284696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
161384696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
161484696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
b68b7ab1 1615# excercise shortcut for numbers of the same length in div
1616999999999999999999999999999999999:999999999999999999999999999999999:1
1617999999999999999999999999999999999:888888888888888888888888888888888:1
1618999999999999999999999999999999999:777777777777777777777777777777777:1
1619999999999999999999999999999999999:666666666666666666666666666666666:1
1620999999999999999999999999999999999:555555555555555555555555555555555:1
1621999999999999999999999999999999999:444444444444444444444444444444444:2
1622999999999999999999999999999999999:333333333333333333333333333333333:3
1623999999999999999999999999999999999:222222222222222222222222222222222:4
1624999999999999999999999999999999999:111111111111111111111111111111111:9
16259999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
16269999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
16279999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
16289999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
16299999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
16309999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
16319999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
16329999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
16339999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
16349999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
16359999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
a87115f0 1636# bug with shortcut in Calc 0.44
1637949418181818187070707070707070707070:181818181853535353535353535353535353:5
07d34614 1638&bmodinv
1639# format: number:modulus:result
1640# bmodinv Data errors
1641abc:abc:NaN
1642abc:5:NaN
16435:abc:NaN
1644# bmodinv Expected Results from normal use
16451:5:1
16463:5:2
1647-2:5:2
16488:5033:4404
56d9de68 16491234567891:13:6
1650-1234567891:13:7
07d34614 1651324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1652## bmodinv Error cases / useless use of function
07d34614 16533:-5:NaN
1654inf:5:NaN
1ddff52a 16555:inf:NaN
1656-inf:5:NaN
16575:-inf:NaN
07d34614 1658&bmodpow
1659# format: number:exponent:modulus:result
1660# bmodpow Data errors
1661abc:abc:abc:NaN
16625:abc:abc:NaN
1663abc:5:abc:NaN
1664abc:abc:5:NaN
16655:5:abc:NaN
16665:abc:5:NaN
1667abc:5:5:NaN
1668# bmodpow Expected results
16690:0:2:1
16701:0:2:1
16710:0:1:0
16728:7:5032:3840
16738:-1:5033:4404
167498436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1675# bmodpow Error cases
16768:8:-5:NaN
16778:-1:16:NaN
1678inf:5:13:NaN
16795:inf:13:NaN
6854fd01 1680&bmod
1681# inf handling, see table in doc
16820:inf:0
16830:-inf:0
16845:inf:5
16855:-inf:5
1686-5:inf:-5
1687-5:-inf:-5
1688inf:5:0
1689-inf:5:0
1690inf:-5:0
1691-inf:-5:0
16925:5:0
1693-5:-5:0
b3abae2a 1694inf:inf:NaN
1695-inf:-inf:NaN
1696-inf:inf:NaN
1697inf:-inf:NaN
6854fd01 16988:0:8
1699inf:0:inf
1700# exceptions to reminder rule
1701-inf:0:-inf
1702-8:0:-8
17030:0:NaN
1704abc:abc:NaN
61f5c3f5 1705abc:1:abc:NaN
17061:abc:NaN
17070:0:NaN
17080:1:0
17091:0:1
17100:-1:0
1711-1:0:-1
17121:1:0
1713-1:-1:0
17141:-1:0
1715-1:1:0
17161:2:1
17172:1:0
17181000000000:9:1
17192000000000:9:2
17203000000000:9:3
17214000000000:9:4
17225000000000:9:5
17236000000000:9:6
17247000000000:9:7
17258000000000:9:8
17269000000000:9:0
172735500000:113:33
172871000000:226:66
1729106500000:339:99
17301000000000:3:1
173110:5:0
1732100:4:0
17331000:8:0
173410000:16:0
1735999999999999:9:0
1736999999999999:99:0
1737999999999999:999:0
1738999999999999:9999:0
1739999999999999999:99999:0
1740-9:+5:1
6854fd01 1741+9:-5:-1
1742-9:-5:-4
1743-5:3:1
1744-2:3:1
17454:3:1
17461:3:1
1747-5:-3:-2
1748-2:-3:-2
17494:-3:-2
17501:-3:-2
17514095:4095:0
027dc388 1752100041000510123:3:0
1753152403346:12345:4321
b3abae2a 17549:5:4
28df3e88 1755# test shortcuts in Calc
1756# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
17571234:9:1
1758123456:9:3
175912345678:9:0
17601234567891:9:1
1761123456789123:9:6
176212345678912345:9:6
17631234567891234567:9:1
1764123456789123456789:9:0
17651234:10:4
1766123456:10:6
176712345678:10:8
17681234567891:10:1
1769123456789123:10:3
177012345678912345:10:5
17711234567891234567:10:7
1772123456789123456789:10:9
17731234:113:104
1774123456:113:60
177512345678:113:89
17761234567891:113:64
1777123456789123:113:95
177812345678912345:113:53
17791234567891234567:113:56
1780123456789123456789:113:39
07d34614 1781# bug in bmod() not modifying the variable in place
1782-629:5033:4404
aef458a0 1783# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1784# when X == X and X was big
1785111111111111111111111111111111:111111111111111111111111111111:0
178612345678901234567890:12345678901234567890:0
6854fd01 1787&bgcd
9b924220 1788inf:12:NaN
1789-inf:12:NaN
179012:inf:NaN
179112:-inf:NaN
1792inf:inf:NaN
1793inf:-inf:NaN
1794-inf:-inf:NaN
6854fd01 1795abc:abc:NaN
1796abc:+0:NaN
1797+0:abc:NaN
61f5c3f5 1798+0:+0:0
1799+0:+1:1
1800+1:+0:1
1801+1:+1:1
1802+2:+3:1
1803+3:+2:1
1804-3:+2:1
9b924220 1805-3:-2:1
1806-144:-60:12
1807144:-60:12
1808144:60:12
61f5c3f5 1809100:625:25
18104096:81:1
18111034:804:2
181227:90:56:1
181327:90:54:9
6854fd01 1814&blcm
1815abc:abc:NaN
1816abc:+0:NaN
1817+0:abc:NaN
1818+0:+0:NaN
61f5c3f5 1819+1:+0:0
1820+0:+1:0
1821+27:+90:270
1822+1034:+804:415668
6854fd01 1823&band
1824abc:abc:NaN
1825abc:0:NaN
18260:abc:NaN
18271:2:0
18283:2:2
61f5c3f5 1829+8:+2:0
1830+281474976710656:0:0
1831+281474976710656:1:0
1832+281474976710656:+281474976710656:281474976710656
9b924220 1833281474976710656:-1:281474976710656
6854fd01 1834-2:-3:-4
1835-1:-1:-1
1836-6:-6:-6
1837-7:-4:-8
1838-7:4:0
1839-4:7:4
9b924220 1840# negative argument is bitwise shorter than positive [perl #26559]
184130:-3:28
1842123:-1:123
394e6ffb 1843# equal arguments are treated special, so also do some test with unequal ones
18440xFFFF:0xFFFF:0x0xFFFF
18450xFFFFFF:0xFFFFFF:0x0xFFFFFF
18460xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18470xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18480xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18490xF0F0:0xF0F0:0x0xF0F0
18500x0F0F:0x0F0F:0x0x0F0F
18510xF0F0F0:0xF0F0F0:0x0xF0F0F0
18520x0F0F0F:0x0F0F0F:0x0x0F0F0F
18530xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18540x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18550xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18560x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18570xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18580x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18590x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1860&bior
1861abc:abc:NaN
1862abc:0:NaN
18630:abc:NaN
18641:2:3
61f5c3f5 1865+8:+2:10
1866+281474976710656:0:281474976710656
1867+281474976710656:1:281474976710657
1868+281474976710656:281474976710656:281474976710656
6854fd01 1869-2:-3:-1
1870-1:-1:-1
1871-6:-6:-6
1872-7:4:-3
1873-4:7:-1
9b924220 1874+281474976710656:-1:-1
187530:-3:-1
187630:-4:-2
1877300:-76:-68
1878-76:300:-68
394e6ffb 1879# equal arguments are treated special, so also do some test with unequal ones
18800xFFFF:0xFFFF:0x0xFFFF
18810xFFFFFF:0xFFFFFF:0x0xFFFFFF
18820xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18830xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18840xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18850:0xFFFF:0x0xFFFF
18860:0xFFFFFF:0x0xFFFFFF
18870:0xFFFFFFFF:0x0xFFFFFFFF
18880:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18890:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18900xFFFF:0:0x0xFFFF
18910xFFFFFF:0:0x0xFFFFFF
18920xFFFFFFFF:0:0x0xFFFFFFFF
18930xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18940xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18950xF0F0:0xF0F0:0x0xF0F0
18960x0F0F:0x0F0F:0x0x0F0F
18970xF0F0:0x0F0F:0x0xFFFF
18980xF0F0F0:0xF0F0F0:0x0xF0F0F0
18990x0F0F0F:0x0F0F0F:0x0x0F0F0F
19000x0F0F0F:0xF0F0F0:0x0xFFFFFF
19010xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19020x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19030x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19040xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19050x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19060x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19070xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19080x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19090x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
19100x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1911&bxor
1912abc:abc:NaN
1913abc:0:NaN
19140:abc:NaN
19151:2:3
61f5c3f5 1916+8:+2:10
1917+281474976710656:0:281474976710656
1918+281474976710656:1:281474976710657
1919+281474976710656:281474976710656:0
6854fd01 1920-2:-3:3
1921-1:-1:0
1922-6:-6:0
1923-7:4:-3
1924-4:7:-5
19254:-7:-3
1926-4:-7:5
9b924220 192730:-3:-29
192830:-4:-30
1929300:-76:-360
1930-76:300:-360
394e6ffb 1931# equal arguments are treated special, so also do some test with unequal ones
19320xFFFF:0xFFFF:0
19330xFFFFFF:0xFFFFFF:0
19340xFFFFFFFF:0xFFFFFFFF:0
19350xFFFFFFFFFF:0xFFFFFFFFFF:0
19360xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
19370:0xFFFF:0x0xFFFF
19380:0xFFFFFF:0x0xFFFFFF
19390:0xFFFFFFFF:0x0xFFFFFFFF
19400:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19410:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19420xFFFF:0:0x0xFFFF
19430xFFFFFF:0:0x0xFFFFFF
19440xFFFFFFFF:0:0x0xFFFFFFFF
19450xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19460xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19470xF0F0:0xF0F0:0
19480x0F0F:0x0F0F:0
19490xF0F0:0x0F0F:0x0xFFFF
19500xF0F0F0:0xF0F0F0:0
19510x0F0F0F:0x0F0F0F:0
19520x0F0F0F:0xF0F0F0:0x0xFFFFFF
19530xF0F0F0F0:0xF0F0F0F0:0
19540x0F0F0F0F:0x0F0F0F0F:0
19550x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19560xF0F0F0F0F0:0xF0F0F0F0F0:0
19570x0F0F0F0F0F:0x0F0F0F0F0F:0
19580x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19590xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
19600x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
19610x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1962&bnot
1963abc:NaN
1964+0:-1
1965+8:-9
1966+281474976710656:-281474976710657
1967-1:0
1968-2:1
1969-12:11
1970&digit
19710:0:0
197212:0:2
197312:1:1
1974123:0:3
1975123:1:2
1976123:2:1
1977123:-1:1
1978123:-2:2
1979123:-3:3
1980123456:0:6
1981123456:1:5
1982123456:2:4
1983123456:3:3
1984123456:4:2
1985123456:5:1
1986123456:-1:1
1987123456:-2:2
1988123456:-3:3
1989100000:-3:0
1990100000:0:0
1991100000:1:0
1992&mantissa
1993abc:NaN
19941e4:1
19952e0:2
1996123:123
1997-1:-1
1998-2:-2
1999+inf:inf
2000-inf:-inf
2001&exponent
2002abc:NaN
20031e4:4
20042e0:0
2005123:0
2006-1:0
2007-2:0
20080:1
2009+inf:inf
2010-inf:inf
2011&parts
2012abc:NaN,NaN
20131e4:1,4
20142e0:2,0
2015123:123,0
2016-1:-1,0
2017-2:-2,0
20180:0,1
2019+inf:inf,inf
2020-inf:-inf,inf
b3abae2a 2021&bfac
2022-1:NaN
2023NaNfac:NaN
b282a552 2024+inf:inf
b3abae2a 2025-inf:NaN
20260:1
20271:1
20282:2
20293:6
20304:24
20315:120
20326:720
990fb837 20337:5040
20348:40320
20359:362880
b3abae2a 203610:3628800
203711:39916800
203812:479001600
6854fd01 2039&bpow
2040abc:12:NaN
204112:abc:NaN
20420:0:1
20430:1:0
20440:2:0
9b924220 20450:-1:inf
20460:-2:inf
6854fd01 20471:0:1
20481:1:1
20491:2:1
20501:3:1
20511:-1:1
20521:-2:1
20531:-3:1
20542:0:1
20552:1:2
20562:2:4
20572:3:8
20583:3:27
2d2b2744 2059-2:2:4
2060-2:3:-8
2061-2:4:16
2062-2:5:-32
6854fd01 20632:-1:NaN
2064-2:-1:NaN
20652:-2:NaN
2066-2:-2:NaN
2d2b2744 2067# inf tests
6854fd01 2068+inf:1234500012:inf
2d2b2744 2069-inf:1234500012:inf
2070-inf:1234500013:-inf
6854fd01 2071+inf:-12345000123:inf
2072-inf:-12345000123:-inf
2d2b2744 2073# -inf * -inf = inf
2074-inf:2:inf
2075-inf:0:NaN
2076-inf:-1:0
2077-inf:inf:NaN
20782:inf:inf
20792:-inf:0
20800:inf:0
20810:-inf:inf
2082-1:-inf:NaN
2083-1:inf:NaN
2084-2:inf:NaN
2085-2:-inf:0
2086NaN:inf:NaN
2087NaN:-inf:NaN
2088-inf:NaN:NaN
2089inf:NaN:NaN
2090inf:-inf:NaN
20911:inf:1
20921:-inf:1
6854fd01 2093# 1 ** -x => 1 / (1 ** x)
2094-1:0:1
2095-2:0:1
2096-1:1:-1
2097-1:2:1
2098-1:3:-1
2099-1:4:1
2100-1:5:-1
2101-1:-1:-1
2102-1:-2:1
2103-1:-3:-1
2104-1:-4:1
210510:2:100
210610:3:1000
210710:4:10000
210810:5:100000
210910:6:1000000
211010:7:10000000
211110:8:100000000
211210:9:1000000000
211310:20:100000000000000000000
2114123456:2:15241383936
9b924220 2115-2:2:4
2116-2:3:-8
2117-2:4:16
2118-2:5:-32
2119-3:2:9
2120-3:3:-27
2121-3:4:81
2122-3:5:-243
6854fd01 2123&length
2124100:3
212510:2
21261:1
21270:1
212812345:5
212910000000000000000:17
2130-123:3
2131215960156869840440586892398248:30
990fb837 2132&broot
2133# sqrt()
2134+0:2:0
2135+1:2:1
2136-1:2:NaN
2137# -$x ** (1/2) => -$y, but not in froot()
2138-123:2:NaN
2139+inf:2:inf
2140-inf:2:NaN
21412:2:1
2142-2:2:NaN
21434:2:2
21449:2:3
214516:2:4
2146100:2:10
2147123:2:11
214815241:2:123
2149144:2:12
215012:2:3
21510.49:2:0
21520.0049:2:0
2153# invalid ones
21541:NaN:NaN
2155-1:NaN:NaN
21560:NaN:NaN
2157-inf:NaN:NaN
2158+inf:NaN:NaN
2159NaN:0:NaN
2160NaN:2:NaN
2161NaN:inf:NaN
2162NaN:inf:NaN
216312:-inf:NaN
216412:inf:NaN
2165+0:0:NaN
2166+1:0:NaN
2167-1:0:NaN
2168-2:0:NaN
2169-123.45:0:NaN
2170+inf:0:NaN
217112:1:12
2172-12:1:NaN
21738:-1:NaN
2174-8:-1:NaN
2175# cubic root
21768:3:2
2177-8:3:NaN
2178# fourths root
c38b2de2 217916:4:2
218081:4:3
3a427a11 2181# 2 ** 64
c38b2de2 218218446744073709551616:4:65536
218318446744073709551616:8:256
218418446744073709551616:16:16
218518446744073709551616:32:4
218618446744073709551616:64:2
218718446744073709551616:128:1
3a427a11 2188# 213 ** 15
218984274086103068221283760416414557757:15:213
2190# see t/bigroot for more tests
6854fd01 2191&bsqrt
394e6ffb 2192145:12
6854fd01 2193144:12
394e6ffb 2194143:11
6854fd01 219516:4
394e6ffb 2196170:13
2197169:13
2198168:12
6854fd01 21994:2
394e6ffb 22003:1
6854fd01 22012:1
394e6ffb 22029:3
6854fd01 220312:3
2204256:16
2205100000000:10000
22064000000000000:2000000
394e6ffb 2207152399026:12345
2208152399025:12345
2209152399024:12344
3a427a11 2210# 2 ** 64 => 2 ** 32
221118446744073709551616:4294967296
221284274086103068221283760416414557757:290299993288095377
6854fd01 22131:1
22140:0
2215-2:NaN
394e6ffb 2216-123:NaN
6854fd01 2217Nan:NaN
990fb837 2218+inf:inf
2219-inf:NaN
6854fd01 2220&bround
2221$round_mode('trunc')
22220:12:0
2223NaNbround:12:NaN
2224+inf:12:inf
2225-inf:12:-inf
22261234:0:1234
22271234:2:1200
2228123456:4:123400
2229123456:5:123450
2230123456:6:123456
61f5c3f5 2231+10123456789:5:10123000000
6854fd01 2232-10123456789:5:-10123000000
61f5c3f5 2233+10123456789:9:10123456700
6854fd01 2234-10123456789:9:-10123456700
61f5c3f5 2235+101234500:6:101234000
6854fd01 2236-101234500:6:-101234000
61f5c3f5 2237#+101234500:-4:101234000
6854fd01 2238#-101234500:-4:-101234000
2239$round_mode('zero')
61f5c3f5 2240+20123456789:5:20123000000
6854fd01 2241-20123456789:5:-20123000000
61f5c3f5 2242+20123456789:9:20123456800
6854fd01 2243-20123456789:9:-20123456800
61f5c3f5 2244+201234500:6:201234000
6854fd01 2245-201234500:6:-201234000
61f5c3f5 2246#+201234500:-4:201234000
6854fd01 2247#-201234500:-4:-201234000
2248+12345000:4:12340000
2249-12345000:4:-12340000
2250$round_mode('+inf')
61f5c3f5 2251+30123456789:5:30123000000
6854fd01 2252-30123456789:5:-30123000000
61f5c3f5 2253+30123456789:9:30123456800
6854fd01 2254-30123456789:9:-30123456800
61f5c3f5 2255+301234500:6:301235000
6854fd01 2256-301234500:6:-301234000
61f5c3f5 2257#+301234500:-4:301235000
6854fd01 2258#-301234500:-4:-301234000
2259+12345000:4:12350000
2260-12345000:4:-12340000
2261$round_mode('-inf')
61f5c3f5 2262+40123456789:5:40123000000
6854fd01 2263-40123456789:5:-40123000000
61f5c3f5 2264+40123456789:9:40123456800
6854fd01 2265-40123456789:9:-40123456800
61f5c3f5 2266+401234500:6:401234000
2267+401234500:6:401234000
6854fd01 2268#-401234500:-4:-401235000
2269#-401234500:-4:-401235000
2270+12345000:4:12340000
2271-12345000:4:-12350000
2272$round_mode('odd')
61f5c3f5 2273+50123456789:5:50123000000
6854fd01 2274-50123456789:5:-50123000000
61f5c3f5 2275+50123456789:9:50123456800
6854fd01 2276-50123456789:9:-50123456800
61f5c3f5 2277+501234500:6:501235000
6854fd01 2278-501234500:6:-501235000
61f5c3f5 2279#+501234500:-4:501235000
6854fd01 2280#-501234500:-4:-501235000
2281+12345000:4:12350000
2282-12345000:4:-12350000
2283$round_mode('even')
61f5c3f5 2284+60123456789:5:60123000000
6854fd01 2285-60123456789:5:-60123000000
61f5c3f5 2286+60123456789:9:60123456800
6854fd01 2287-60123456789:9:-60123456800
61f5c3f5 2288+601234500:6:601234000
6854fd01 2289-601234500:6:-601234000
61f5c3f5 2290#+601234500:-4:601234000
6854fd01 2291#-601234500:-4:-601234000
2292#-601234500:-9:0
2293#-501234500:-9:0
2294#-601234500:-8:0
2295#-501234500:-8:0
2296+1234567:7:1234567
2297+1234567:6:1234570
2298+12345000:4:12340000
2299-12345000:4:-12340000
2300&is_zero
23010:1
2302NaNzero:0
2303+inf:0
2304-inf:0
2305123:0
2306-1:0
23071:0
2308&is_one
23090:0
2310NaNone:0
2311+inf:0
2312-inf:0
23131:1
23142:0
2315-1:0
2316-2:0
2317# floor and ceil tests are pretty pointless in integer space...but play safe
2318&bfloor
23190:0
2320NaNfloor:NaN
2321+inf:inf
2322-inf:-inf
2323-1:-1
2324-2:-2
23252:2
23263:3
2327abc:NaN
2328&bceil
2329NaNceil:NaN
2330+inf:inf
2331-inf:-inf
23320:0
2333-1:-1
2334-2:-2
23352:2
23363:3
2337abc:NaN
2338&as_hex
2339128:0x80
2340-128:-0x80
23410:0x0
2342-0:0x0
23431:0x1
23440x123456789123456789:0x123456789123456789
2345+inf:inf
2346-inf:-inf
2347NaNas_hex:NaN
2348&as_bin
2349128:0b10000000
2350-128:-0b10000000
23510:0b0
2352-0:0b0
23531:0b1
23540b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 23550x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2356+inf:inf
2357-inf:-inf
2358NaNas_bin:NaN