Happy new year
[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
7810:1
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
6854fd01 1500&bdiv
1501abc:abc:NaN
61f5c3f5 1502abc:1:NaN
15031:abc:NaN
15040:0:NaN
6854fd01 1505# inf handling (see table in doc)
15060:inf:0
15070:-inf:0
15085:inf:0
15095:-inf:0
1510-5:inf:0
1511-5:-inf:0
1512inf:5:inf
1513-inf:5:-inf
1514inf:-5:-inf
1515-inf:-5:inf
15165:5:1
1517-5:-5:1
b3abae2a 1518inf:inf:NaN
1519-inf:-inf:NaN
1520-inf:inf:NaN
1521inf:-inf:NaN
6854fd01 15228:0:inf
1523inf:0:inf
1524-8:0:-inf
1525-inf:0:-inf
15260:0:NaN
152711:2:5
1528-11:-2:5
1529-11:2:-5
153011:-2:-5
61f5c3f5 15310:1:0
15320:-1:0
15331:1:1
1534-1:-1:1
15351:-1:-1
1536-1:1:-1
15371:2:0
15382:1:2
15391:26:0
15401000000000:9:111111111
15412000000000:9:222222222
15423000000000:9:333333333
15434000000000:9:444444444
15445000000000:9:555555555
15456000000000:9:666666666
15467000000000:9:777777777
15478000000000:9:888888888
15489000000000:9:1000000000
154935500000:113:314159
155071000000:226:314159
1551106500000:339:314159
15521000000000:3:333333333
1553+10:+5:2
1554+100:+4:25
1555+1000:+8:125
1556+10000:+16:625
1557999999999999:9:111111111111
1558999999999999:99:10101010101
1559999999999999:999:1001001001
1560999999999999:9999:100010001
1561999999999999999:99999:10000100001
1562+1111088889:99999:11111
6854fd01 1563-5:-3:1
1564-5:3:-1
15654:3:1
15664:-3:-1
15671:3:0
15681:-3:0
1569-2:-3:0
1570-2:3:0
15718:3:2
1572-8:3:-2
157314:-3:-4
1574-14:3:-4
1575-14:-3:4
157614:3:4
1577# bug in Calc with '99999' vs $BASE-1
157810000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1579# test the shortcut in Calc if @$x == @$yorg
15801234567812345678:123456712345678:10
158112345671234567:1234561234567:10
1582123456123456:12345123456:10
15831234512345:123412345:10
15841234567890999999999:1234567890:1000000000
15851234567890000000000:1234567890:1000000000
15861234567890999999999:9876543210:124999998
15871234567890000000000:9876543210:124999998
158896969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1589# bug up to v0.35 in Calc (--$q one too many)
159084696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
159184696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
159284696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
159384696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
07d34614 1594&bmodinv
1595# format: number:modulus:result
1596# bmodinv Data errors
1597abc:abc:NaN
1598abc:5:NaN
15995:abc:NaN
1600# bmodinv Expected Results from normal use
16011:5:1
16023:5:2
1603-2:5:2
16048:5033:4404
56d9de68 16051234567891:13:6
1606-1234567891:13:7
07d34614 1607324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1608## bmodinv Error cases / useless use of function
07d34614 16093:-5:NaN
1610inf:5:NaN
1ddff52a 16115:inf:NaN
1612-inf:5:NaN
16135:-inf:NaN
07d34614 1614&bmodpow
1615# format: number:exponent:modulus:result
1616# bmodpow Data errors
1617abc:abc:abc:NaN
16185:abc:abc:NaN
1619abc:5:abc:NaN
1620abc:abc:5:NaN
16215:5:abc:NaN
16225:abc:5:NaN
1623abc:5:5:NaN
1624# bmodpow Expected results
16250:0:2:1
16261:0:2:1
16270:0:1:0
16288:7:5032:3840
16298:-1:5033:4404
163098436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1631# bmodpow Error cases
16328:8:-5:NaN
16338:-1:16:NaN
1634inf:5:13:NaN
16355:inf:13:NaN
6854fd01 1636&bmod
1637# inf handling, see table in doc
16380:inf:0
16390:-inf:0
16405:inf:5
16415:-inf:5
1642-5:inf:-5
1643-5:-inf:-5
1644inf:5:0
1645-inf:5:0
1646inf:-5:0
1647-inf:-5:0
16485:5:0
1649-5:-5:0
b3abae2a 1650inf:inf:NaN
1651-inf:-inf:NaN
1652-inf:inf:NaN
1653inf:-inf:NaN
6854fd01 16548:0:8
1655inf:0:inf
1656# exceptions to reminder rule
1657-inf:0:-inf
1658-8:0:-8
16590:0:NaN
1660abc:abc:NaN
61f5c3f5 1661abc:1:abc:NaN
16621:abc:NaN
16630:0:NaN
16640:1:0
16651:0:1
16660:-1:0
1667-1:0:-1
16681:1:0
1669-1:-1:0
16701:-1:0
1671-1:1:0
16721:2:1
16732:1:0
16741000000000:9:1
16752000000000:9:2
16763000000000:9:3
16774000000000:9:4
16785000000000:9:5
16796000000000:9:6
16807000000000:9:7
16818000000000:9:8
16829000000000:9:0
168335500000:113:33
168471000000:226:66
1685106500000:339:99
16861000000000:3:1
168710:5:0
1688100:4:0
16891000:8:0
169010000:16:0
1691999999999999:9:0
1692999999999999:99:0
1693999999999999:999:0
1694999999999999:9999:0
1695999999999999999:99999:0
1696-9:+5:1
6854fd01 1697+9:-5:-1
1698-9:-5:-4
1699-5:3:1
1700-2:3:1
17014:3:1
17021:3:1
1703-5:-3:-2
1704-2:-3:-2
17054:-3:-2
17061:-3:-2
17074095:4095:0
027dc388 1708100041000510123:3:0
1709152403346:12345:4321
b3abae2a 17109:5:4
28df3e88 1711# test shortcuts in Calc
1712# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
17131234:9:1
1714123456:9:3
171512345678:9:0
17161234567891:9:1
1717123456789123:9:6
171812345678912345:9:6
17191234567891234567:9:1
1720123456789123456789:9:0
17211234:10:4
1722123456:10:6
172312345678:10:8
17241234567891:10:1
1725123456789123:10:3
172612345678912345:10:5
17271234567891234567:10:7
1728123456789123456789:10:9
17291234:113:104
1730123456:113:60
173112345678:113:89
17321234567891:113:64
1733123456789123:113:95
173412345678912345:113:53
17351234567891234567:113:56
1736123456789123456789:113:39
07d34614 1737# bug in bmod() not modifying the variable in place
1738-629:5033:4404
aef458a0 1739# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1740# when X == X and X was big
1741111111111111111111111111111111:111111111111111111111111111111:0
174212345678901234567890:12345678901234567890:0
6854fd01 1743&bgcd
9b924220 1744inf:12:NaN
1745-inf:12:NaN
174612:inf:NaN
174712:-inf:NaN
1748inf:inf:NaN
1749inf:-inf:NaN
1750-inf:-inf:NaN
6854fd01 1751abc:abc:NaN
1752abc:+0:NaN
1753+0:abc:NaN
61f5c3f5 1754+0:+0:0
1755+0:+1:1
1756+1:+0:1
1757+1:+1:1
1758+2:+3:1
1759+3:+2:1
1760-3:+2:1
9b924220 1761-3:-2:1
1762-144:-60:12
1763144:-60:12
1764144:60:12
61f5c3f5 1765100:625:25
17664096:81:1
17671034:804:2
176827:90:56:1
176927:90:54:9
6854fd01 1770&blcm
1771abc:abc:NaN
1772abc:+0:NaN
1773+0:abc:NaN
1774+0:+0:NaN
61f5c3f5 1775+1:+0:0
1776+0:+1:0
1777+27:+90:270
1778+1034:+804:415668
6854fd01 1779&band
1780abc:abc:NaN
1781abc:0:NaN
17820:abc:NaN
17831:2:0
17843:2:2
61f5c3f5 1785+8:+2:0
1786+281474976710656:0:0
1787+281474976710656:1:0
1788+281474976710656:+281474976710656:281474976710656
9b924220 1789281474976710656:-1:281474976710656
6854fd01 1790-2:-3:-4
1791-1:-1:-1
1792-6:-6:-6
1793-7:-4:-8
1794-7:4:0
1795-4:7:4
9b924220 1796# negative argument is bitwise shorter than positive [perl #26559]
179730:-3:28
1798123:-1:123
394e6ffb 1799# equal arguments are treated special, so also do some test with unequal ones
18000xFFFF:0xFFFF:0x0xFFFF
18010xFFFFFF:0xFFFFFF:0x0xFFFFFF
18020xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18030xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18040xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18050xF0F0:0xF0F0:0x0xF0F0
18060x0F0F:0x0F0F:0x0x0F0F
18070xF0F0F0:0xF0F0F0:0x0xF0F0F0
18080x0F0F0F:0x0F0F0F:0x0x0F0F0F
18090xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18100x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18110xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18120x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18130xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18140x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18150x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1816&bior
1817abc:abc:NaN
1818abc:0:NaN
18190:abc:NaN
18201:2:3
61f5c3f5 1821+8:+2:10
1822+281474976710656:0:281474976710656
1823+281474976710656:1:281474976710657
1824+281474976710656:281474976710656:281474976710656
6854fd01 1825-2:-3:-1
1826-1:-1:-1
1827-6:-6:-6
1828-7:4:-3
1829-4:7:-1
9b924220 1830+281474976710656:-1:-1
183130:-3:-1
183230:-4:-2
1833300:-76:-68
1834-76:300:-68
394e6ffb 1835# equal arguments are treated special, so also do some test with unequal ones
18360xFFFF:0xFFFF:0x0xFFFF
18370xFFFFFF:0xFFFFFF:0x0xFFFFFF
18380xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18390xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18400xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18410:0xFFFF:0x0xFFFF
18420:0xFFFFFF:0x0xFFFFFF
18430:0xFFFFFFFF:0x0xFFFFFFFF
18440:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18450:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18460xFFFF:0:0x0xFFFF
18470xFFFFFF:0:0x0xFFFFFF
18480xFFFFFFFF:0:0x0xFFFFFFFF
18490xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18500xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18510xF0F0:0xF0F0:0x0xF0F0
18520x0F0F:0x0F0F:0x0x0F0F
18530xF0F0:0x0F0F:0x0xFFFF
18540xF0F0F0:0xF0F0F0:0x0xF0F0F0
18550x0F0F0F:0x0F0F0F:0x0x0F0F0F
18560x0F0F0F:0xF0F0F0:0x0xFFFFFF
18570xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18580x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18590x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
18600xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18610x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18620x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
18630xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18640x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18650x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
18660x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1867&bxor
1868abc:abc:NaN
1869abc:0:NaN
18700:abc:NaN
18711:2:3
61f5c3f5 1872+8:+2:10
1873+281474976710656:0:281474976710656
1874+281474976710656:1:281474976710657
1875+281474976710656:281474976710656:0
6854fd01 1876-2:-3:3
1877-1:-1:0
1878-6:-6:0
1879-7:4:-3
1880-4:7:-5
18814:-7:-3
1882-4:-7:5
9b924220 188330:-3:-29
188430:-4:-30
1885300:-76:-360
1886-76:300:-360
394e6ffb 1887# equal arguments are treated special, so also do some test with unequal ones
18880xFFFF:0xFFFF:0
18890xFFFFFF:0xFFFFFF:0
18900xFFFFFFFF:0xFFFFFFFF:0
18910xFFFFFFFFFF:0xFFFFFFFFFF:0
18920xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
18930:0xFFFF:0x0xFFFF
18940:0xFFFFFF:0x0xFFFFFF
18950:0xFFFFFFFF:0x0xFFFFFFFF
18960:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18970:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18980xFFFF:0:0x0xFFFF
18990xFFFFFF:0:0x0xFFFFFF
19000xFFFFFFFF:0:0x0xFFFFFFFF
19010xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19020xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19030xF0F0:0xF0F0:0
19040x0F0F:0x0F0F:0
19050xF0F0:0x0F0F:0x0xFFFF
19060xF0F0F0:0xF0F0F0:0
19070x0F0F0F:0x0F0F0F:0
19080x0F0F0F:0xF0F0F0:0x0xFFFFFF
19090xF0F0F0F0:0xF0F0F0F0:0
19100x0F0F0F0F:0x0F0F0F0F:0
19110x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19120xF0F0F0F0F0:0xF0F0F0F0F0:0
19130x0F0F0F0F0F:0x0F0F0F0F0F:0
19140x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19150xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
19160x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
19170x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1918&bnot
1919abc:NaN
1920+0:-1
1921+8:-9
1922+281474976710656:-281474976710657
1923-1:0
1924-2:1
1925-12:11
1926&digit
19270:0:0
192812:0:2
192912:1:1
1930123:0:3
1931123:1:2
1932123:2:1
1933123:-1:1
1934123:-2:2
1935123:-3:3
1936123456:0:6
1937123456:1:5
1938123456:2:4
1939123456:3:3
1940123456:4:2
1941123456:5:1
1942123456:-1:1
1943123456:-2:2
1944123456:-3:3
1945100000:-3:0
1946100000:0:0
1947100000:1:0
1948&mantissa
1949abc:NaN
19501e4:1
19512e0:2
1952123:123
1953-1:-1
1954-2:-2
1955+inf:inf
1956-inf:-inf
1957&exponent
1958abc:NaN
19591e4:4
19602e0:0
1961123:0
1962-1:0
1963-2:0
19640:1
1965+inf:inf
1966-inf:inf
1967&parts
1968abc:NaN,NaN
19691e4:1,4
19702e0:2,0
1971123:123,0
1972-1:-1,0
1973-2:-2,0
19740:0,1
1975+inf:inf,inf
1976-inf:-inf,inf
b3abae2a 1977&bfac
1978-1:NaN
1979NaNfac:NaN
b282a552 1980+inf:inf
b3abae2a 1981-inf:NaN
19820:1
19831:1
19842:2
19853:6
19864:24
19875:120
19886:720
990fb837 19897:5040
19908:40320
19919:362880
b3abae2a 199210:3628800
199311:39916800
199412:479001600
6854fd01 1995&bpow
1996abc:12:NaN
199712:abc:NaN
19980:0:1
19990:1:0
20000:2:0
9b924220 20010:-1:inf
20020:-2:inf
6854fd01 20031:0:1
20041:1:1
20051:2:1
20061:3:1
20071:-1:1
20081:-2:1
20091:-3:1
20102:0:1
20112:1:2
20122:2:4
20132:3:8
20143:3:27
2d2b2744 2015-2:2:4
2016-2:3:-8
2017-2:4:16
2018-2:5:-32
6854fd01 20192:-1:NaN
2020-2:-1:NaN
20212:-2:NaN
2022-2:-2:NaN
2d2b2744 2023# inf tests
6854fd01 2024+inf:1234500012:inf
2d2b2744 2025-inf:1234500012:inf
2026-inf:1234500013:-inf
6854fd01 2027+inf:-12345000123:inf
2028-inf:-12345000123:-inf
2d2b2744 2029# -inf * -inf = inf
2030-inf:2:inf
2031-inf:0:NaN
2032-inf:-1:0
2033-inf:inf:NaN
20342:inf:inf
20352:-inf:0
20360:inf:0
20370:-inf:inf
2038-1:-inf:NaN
2039-1:inf:NaN
2040-2:inf:NaN
2041-2:-inf:0
2042NaN:inf:NaN
2043NaN:-inf:NaN
2044-inf:NaN:NaN
2045inf:NaN:NaN
2046inf:-inf:NaN
20471:inf:1
20481:-inf:1
6854fd01 2049# 1 ** -x => 1 / (1 ** x)
2050-1:0:1
2051-2:0:1
2052-1:1:-1
2053-1:2:1
2054-1:3:-1
2055-1:4:1
2056-1:5:-1
2057-1:-1:-1
2058-1:-2:1
2059-1:-3:-1
2060-1:-4:1
206110:2:100
206210:3:1000
206310:4:10000
206410:5:100000
206510:6:1000000
206610:7:10000000
206710:8:100000000
206810:9:1000000000
206910:20:100000000000000000000
2070123456:2:15241383936
9b924220 2071-2:2:4
2072-2:3:-8
2073-2:4:16
2074-2:5:-32
2075-3:2:9
2076-3:3:-27
2077-3:4:81
2078-3:5:-243
6854fd01 2079&length
2080100:3
208110:2
20821:1
20830:1
208412345:5
208510000000000000000:17
2086-123:3
2087215960156869840440586892398248:30
990fb837 2088&broot
2089# sqrt()
2090+0:2:0
2091+1:2:1
2092-1:2:NaN
2093# -$x ** (1/2) => -$y, but not in froot()
2094-123:2:NaN
2095+inf:2:inf
2096-inf:2:NaN
20972:2:1
2098-2:2:NaN
20994:2:2
21009:2:3
210116:2:4
2102100:2:10
2103123:2:11
210415241:2:123
2105144:2:12
210612:2:3
21070.49:2:0
21080.0049:2:0
2109# invalid ones
21101:NaN:NaN
2111-1:NaN:NaN
21120:NaN:NaN
2113-inf:NaN:NaN
2114+inf:NaN:NaN
2115NaN:0:NaN
2116NaN:2:NaN
2117NaN:inf:NaN
2118NaN:inf:NaN
211912:-inf:NaN
212012:inf:NaN
2121+0:0:NaN
2122+1:0:NaN
2123-1:0:NaN
2124-2:0:NaN
2125-123.45:0:NaN
2126+inf:0:NaN
212712:1:12
2128-12:1:NaN
21298:-1:NaN
2130-8:-1:NaN
2131# cubic root
21328:3:2
2133-8:3:NaN
2134# fourths root
c38b2de2 213516:4:2
213681:4:3
3a427a11 2137# 2 ** 64
c38b2de2 213818446744073709551616:4:65536
213918446744073709551616:8:256
214018446744073709551616:16:16
214118446744073709551616:32:4
214218446744073709551616:64:2
214318446744073709551616:128:1
3a427a11 2144# 213 ** 15
214584274086103068221283760416414557757:15:213
2146# see t/bigroot for more tests
6854fd01 2147&bsqrt
394e6ffb 2148145:12
6854fd01 2149144:12
394e6ffb 2150143:11
6854fd01 215116:4
394e6ffb 2152170:13
2153169:13
2154168:12
6854fd01 21554:2
394e6ffb 21563:1
6854fd01 21572:1
394e6ffb 21589:3
6854fd01 215912:3
2160256:16
2161100000000:10000
21624000000000000:2000000
394e6ffb 2163152399026:12345
2164152399025:12345
2165152399024:12344
3a427a11 2166# 2 ** 64 => 2 ** 32
216718446744073709551616:4294967296
216884274086103068221283760416414557757:290299993288095377
6854fd01 21691:1
21700:0
2171-2:NaN
394e6ffb 2172-123:NaN
6854fd01 2173Nan:NaN
990fb837 2174+inf:inf
2175-inf:NaN
6854fd01 2176&bround
2177$round_mode('trunc')
21780:12:0
2179NaNbround:12:NaN
2180+inf:12:inf
2181-inf:12:-inf
21821234:0:1234
21831234:2:1200
2184123456:4:123400
2185123456:5:123450
2186123456:6:123456
61f5c3f5 2187+10123456789:5:10123000000
6854fd01 2188-10123456789:5:-10123000000
61f5c3f5 2189+10123456789:9:10123456700
6854fd01 2190-10123456789:9:-10123456700
61f5c3f5 2191+101234500:6:101234000
6854fd01 2192-101234500:6:-101234000
61f5c3f5 2193#+101234500:-4:101234000
6854fd01 2194#-101234500:-4:-101234000
2195$round_mode('zero')
61f5c3f5 2196+20123456789:5:20123000000
6854fd01 2197-20123456789:5:-20123000000
61f5c3f5 2198+20123456789:9:20123456800
6854fd01 2199-20123456789:9:-20123456800
61f5c3f5 2200+201234500:6:201234000
6854fd01 2201-201234500:6:-201234000
61f5c3f5 2202#+201234500:-4:201234000
6854fd01 2203#-201234500:-4:-201234000
2204+12345000:4:12340000
2205-12345000:4:-12340000
2206$round_mode('+inf')
61f5c3f5 2207+30123456789:5:30123000000
6854fd01 2208-30123456789:5:-30123000000
61f5c3f5 2209+30123456789:9:30123456800
6854fd01 2210-30123456789:9:-30123456800
61f5c3f5 2211+301234500:6:301235000
6854fd01 2212-301234500:6:-301234000
61f5c3f5 2213#+301234500:-4:301235000
6854fd01 2214#-301234500:-4:-301234000
2215+12345000:4:12350000
2216-12345000:4:-12340000
2217$round_mode('-inf')
61f5c3f5 2218+40123456789:5:40123000000
6854fd01 2219-40123456789:5:-40123000000
61f5c3f5 2220+40123456789:9:40123456800
6854fd01 2221-40123456789:9:-40123456800
61f5c3f5 2222+401234500:6:401234000
2223+401234500:6:401234000
6854fd01 2224#-401234500:-4:-401235000
2225#-401234500:-4:-401235000
2226+12345000:4:12340000
2227-12345000:4:-12350000
2228$round_mode('odd')
61f5c3f5 2229+50123456789:5:50123000000
6854fd01 2230-50123456789:5:-50123000000
61f5c3f5 2231+50123456789:9:50123456800
6854fd01 2232-50123456789:9:-50123456800
61f5c3f5 2233+501234500:6:501235000
6854fd01 2234-501234500:6:-501235000
61f5c3f5 2235#+501234500:-4:501235000
6854fd01 2236#-501234500:-4:-501235000
2237+12345000:4:12350000
2238-12345000:4:-12350000
2239$round_mode('even')
61f5c3f5 2240+60123456789:5:60123000000
6854fd01 2241-60123456789:5:-60123000000
61f5c3f5 2242+60123456789:9:60123456800
6854fd01 2243-60123456789:9:-60123456800
61f5c3f5 2244+601234500:6:601234000
6854fd01 2245-601234500:6:-601234000
61f5c3f5 2246#+601234500:-4:601234000
6854fd01 2247#-601234500:-4:-601234000
2248#-601234500:-9:0
2249#-501234500:-9:0
2250#-601234500:-8:0
2251#-501234500:-8:0
2252+1234567:7:1234567
2253+1234567:6:1234570
2254+12345000:4:12340000
2255-12345000:4:-12340000
2256&is_zero
22570:1
2258NaNzero:0
2259+inf:0
2260-inf:0
2261123:0
2262-1:0
22631:0
2264&is_one
22650:0
2266NaNone:0
2267+inf:0
2268-inf:0
22691:1
22702:0
2271-1:0
2272-2:0
2273# floor and ceil tests are pretty pointless in integer space...but play safe
2274&bfloor
22750:0
2276NaNfloor:NaN
2277+inf:inf
2278-inf:-inf
2279-1:-1
2280-2:-2
22812:2
22823:3
2283abc:NaN
2284&bceil
2285NaNceil:NaN
2286+inf:inf
2287-inf:-inf
22880:0
2289-1:-1
2290-2:-2
22912:2
22923:3
2293abc:NaN
2294&as_hex
2295128:0x80
2296-128:-0x80
22970:0x0
2298-0:0x0
22991:0x1
23000x123456789123456789:0x123456789123456789
2301+inf:inf
2302-inf:-inf
2303NaNas_hex:NaN
2304&as_bin
2305128:0b10000000
2306-128:-0b10000000
23070:0b0
2308-0:0b0
23091:0b1
23100b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 23110x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2312+inf:inf
2313-inf:-inf
2314NaNas_bin:NaN