Doc adjustments for the number localization and setlocale().
[p5sagit/p5-mst-13.2.git] / lib / Math / BigInt / t / bigintpm.inc
CommitLineData
6854fd01 1#include this file into another for subclass testing
2
3my $version = ${"$class\::VERSION"};
4
56d9de68 5use strict;
6
6854fd01 7##############################################################################
8# for testing inheritance of _swap
9
10package Math::Foo;
11
61f5c3f5 12use Math::BigInt lib => $main::CL;
6854fd01 13use vars qw/@ISA/;
14@ISA = (qw/Math::BigInt/);
15
16use overload
17# customized overload for sub, since original does not use swap there
18'-' => sub { my @a = ref($_[0])->_swap(@_);
19 $a[0]->bsub($a[1])};
20
21sub _swap
22 {
23 # a fake _swap, which reverses the params
24 my $self = shift; # for override in subclass
25 if ($_[2])
26 {
27 my $c = ref ($_[0] ) || 'Math::Foo';
28 return ( $_[0]->copy(), $_[1] );
29 }
30 else
31 {
32 return ( Math::Foo->new($_[1]), $_[0] );
33 }
34 }
35
36##############################################################################
37package main;
38
b3abae2a 39my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
6854fd01 40
b3abae2a 41my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
6854fd01 42
43while (<DATA>)
44 {
d614cd8b 45 chomp;
6854fd01 46 next if /^#/; # skip comments
47 if (s/^&//)
48 {
61f5c3f5 49 $f = $_; next;
6854fd01 50 }
51 elsif (/^\$/)
52 {
61f5c3f5 53 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
6854fd01 54 }
61f5c3f5 55
56 @args = split(/:/,$_,99); $ans = pop(@args);
b3abae2a 57 $expected_class = $class;
58 if ($ans =~ /(.*?)=(.*)/)
59 {
60 $expected_class = $2; $ans = $1;
61 }
61f5c3f5 62 $try = "\$x = $class->new(\"$args[0]\");";
63 if ($f eq "bnorm")
6854fd01 64 {
61f5c3f5 65 $try = "\$x = $class->bnorm(\"$args[0]\");";
66 # some is_xxx tests
b3abae2a 67 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
56d9de68 68 $try .= "\$x->$f() || 0;";
61f5c3f5 69 } elsif ($f eq "is_inf") {
70 $try .= "\$x->is_inf('$args[1]');";
71 } elsif ($f eq "binf") {
72 $try .= "\$x->binf('$args[1]');";
73 } elsif ($f eq "bone") {
74 $try .= "\$x->bone('$args[1]');";
56d9de68 75 # some unary ops
b3abae2a 76 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
61f5c3f5 77 $try .= "\$x->$f();";
56d9de68 78 } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
79 $try .= "\$x->$f();";
61f5c3f5 80 } elsif ($f eq "exponent"){
81 # ->bstr() to see if an object is returned
82 $try .= '$x = $x->exponent()->bstr();';
83 } elsif ($f eq "mantissa"){
84 # ->bstr() to see if an object is returned
85 $try .= '$x = $x->mantissa()->bstr();';
86 } elsif ($f eq "parts"){
87 $try .= '($m,$e) = $x->parts();';
88 # ->bstr() to see if an object is returned
89 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
90 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
91 $try .= '"$m,$e";';
50109ad0 92 }elsif ($f eq "bexp"){
93 $try .= "\$x->bexp();";
61f5c3f5 94 } else {
56d9de68 95 # binary ops
61f5c3f5 96 $try .= "\$y = $class->new('$args[1]');";
97 if ($f eq "bcmp")
98 {
a0ac753d 99 $try .= '$x->bcmp($y);';
61f5c3f5 100 } elsif ($f eq "bround") {
6854fd01 101 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5 102 } elsif ($f eq "bacmp"){
103 $try .= '$x->bacmp($y);';
104 } elsif ($f eq "badd"){
105 $try .= '$x + $y;';
106 } elsif ($f eq "bsub"){
107 $try .= '$x - $y;';
108 } elsif ($f eq "bmul"){
109 $try .= '$x * $y;';
110 } elsif ($f eq "bdiv"){
111 $try .= '$x / $y;';
112 } elsif ($f eq "bdiv-list"){
113 $try .= 'join (",",$x->bdiv($y));';
027dc388 114 # overload via x=
61f5c3f5 115 } elsif ($f =~ /^.=$/){
116 $try .= "\$x $f \$y;";
027dc388 117 # overload via x
61f5c3f5 118 } elsif ($f =~ /^.$/){
119 $try .= "\$x $f \$y;";
120 } elsif ($f eq "bmod"){
121 $try .= '$x % $y;';
122 } elsif ($f eq "bgcd")
6854fd01 123 {
124 if (defined $args[2])
125 {
61f5c3f5 126 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 127 }
128 $try .= "$class\::bgcd(\$x, \$y";
129 $try .= ", \$z" if (defined $args[2]);
130 $try .= " );";
131 }
132 elsif ($f eq "blcm")
133 {
134 if (defined $args[2])
135 {
61f5c3f5 136 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 137 }
138 $try .= "$class\::blcm(\$x, \$y";
139 $try .= ", \$z" if (defined $args[2]);
140 $try .= " );";
141 }elsif ($f eq "blsft"){
142 if (defined $args[2])
143 {
144 $try .= "\$x->blsft(\$y,$args[2]);";
145 }
146 else
147 {
148 $try .= "\$x << \$y;";
149 }
150 }elsif ($f eq "brsft"){
151 if (defined $args[2])
152 {
153 $try .= "\$x->brsft(\$y,$args[2]);";
154 }
155 else
156 {
157 $try .= "\$x >> \$y;";
158 }
50109ad0 159 }elsif ($f eq "bnok"){
160 $try .= "\$x->bnok(\$y);";
990fb837 161 }elsif ($f eq "broot"){
162 $try .= "\$x->broot(\$y);";
091c87b1 163 }elsif ($f eq "blog"){
164 $try .= "\$x->blog(\$y);";
6854fd01 165 }elsif ($f eq "band"){
166 $try .= "\$x & \$y;";
167 }elsif ($f eq "bior"){
168 $try .= "\$x | \$y;";
169 }elsif ($f eq "bxor"){
170 $try .= "\$x ^ \$y;";
171 }elsif ($f eq "bpow"){
172 $try .= "\$x ** \$y;";
d614cd8b 173 } elsif( $f eq "bmodinv") {
174 $try .= "\$x->bmodinv(\$y);";
6854fd01 175 }elsif ($f eq "digit"){
56b9c951 176 $try .= "\$x->digit(\$y);";
d614cd8b 177 } else {
178 $try .= "\$z = $class->new(\"$args[2]\");";
179
180 # Functions with three arguments
181 if( $f eq "bmodpow") {
182 $try .= "\$x->bmodpow(\$y,\$z);";
183 } else { warn "Unknown op '$f'"; }
184 }
61f5c3f5 185 } # end else all other ops
186
187 $ans1 = eval $try;
188 # convert hex/binary targets to decimal
189 if ($ans =~ /^(0x0x|0b0b)/)
190 {
191 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 192 }
61f5c3f5 193 if ($ans eq "")
194 {
195 ok_undef ($ans1);
196 }
197 else
198 {
199 # print "try: $try ans: $ans1 $ans\n";
200 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 201 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 202 }
61f5c3f5 203 # check internal state of number objects
204 is_valid($ans1,$f) if ref $ans1;
6854fd01 205 } # endwhile data tests
206close DATA;
207
208# test some more
209@a = ();
210for (my $i = 1; $i < 10; $i++)
211 {
212 push @a, $i;
213 }
214ok "@a", "1 2 3 4 5 6 7 8 9";
215
216# test whether self-multiplication works correctly (result is 2**64)
217$try = "\$x = $class->new('4294967296');";
218$try .= '$a = $x->bmul($x);';
219$ans1 = eval $try;
220print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
221# test self-pow
222$try = "\$x = $class->new(10);";
223$try .= '$a = $x->bpow($x);';
224$ans1 = eval $try;
225print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
226
07d34614 227###############################################################################
6854fd01 228# test whether op destroys args or not (should better not)
229
230$x = $class->new(3);
231$y = $class->new(4);
232$z = $x & $y;
233ok ($x,3);
234ok ($y,4);
235ok ($z,0);
236$z = $x | $y;
237ok ($x,3);
238ok ($y,4);
239ok ($z,7);
240$x = $class->new(1);
241$y = $class->new(2);
242$z = $x | $y;
243ok ($x,1);
244ok ($y,2);
245ok ($z,3);
246
247$x = $class->new(5);
248$y = $class->new(4);
249$z = $x ^ $y;
250ok ($x,5);
251ok ($y,4);
252ok ($z,1);
253
254$x = $class->new(-5); $y = -$x;
255ok ($x, -5);
256
257$x = $class->new(-5); $y = abs($x);
258ok ($x, -5);
259
07d34614 260$x = $class->new(8);
261$y = $class->new(-1);
262$z = $class->new(5033);
263my $u = $x->copy()->bmodpow($y,$z);
264ok ($u,4404);
265ok ($y,-1);
266ok ($z,5033);
267
268$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
269$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
270
271$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
272$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
273$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
274$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
275$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
276
277$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
278$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
279$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
280$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
281$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
282
283$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
284$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
285$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
286$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
287$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
288
289###############################################################################
6854fd01 290# check whether overloading cmp works
291$try = "\$x = $class->new(0);";
292$try .= "\$y = 10;";
293$try .= "'false' if \$x ne \$y;";
294$ans = eval $try;
295print "# For '$try'\n" if (!ok "$ans" , "false" );
296
297# we cant test for working cmpt with other objects here, we would need a dummy
298# object with stringify overload for this. see Math::String tests as example
299
300###############################################################################
6854fd01 301# check reversed order of arguments
027dc388 302
6854fd01 303$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
304$try .= "'ok' if \$x == 1024;"; $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 == 20;"; $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 == 12;"; $ans = eval $try;
313print "# For '$try'\n" if (!ok "$ans" , "ok" );
314
315$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
316$try .= "'ok' if \$x == -8;"; $ans = eval $try;
317print "# For '$try'\n" if (!ok "$ans" , "ok" );
318
319$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
320$try .= "'ok' if \$x == 2;"; $ans = eval $try;
321print "# For '$try'\n" if (!ok "$ans" , "ok" );
322
027dc388 323$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
324$try .= "'ok' if \$x == 2;"; $ans = eval $try;
325print "# For '$try'\n" if (!ok "$ans" , "ok" );
326
327$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
328$try .= "'ok' if \$x == 4;"; $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
335$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
336$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
337print "# For '$try'\n" if (!ok "$ans" , "ok" );
338
6854fd01 339###############################################################################
340# check badd(4,5) form
341
342$try = "\$x = $class\->badd(4,5);";
343$try .= "'ok' if \$x == 9;";
344$ans = eval $try;
345print "# For '$try'\n" if (!ok "$ans" , "ok" );
346
347###############################################################################
348# check undefs: NOT DONE YET
349
350###############################################################################
351# bool
352
f9a08e12 353$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
354$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 355
356###############################################################################
357# objectify()
358
359@args = Math::BigInt::objectify(2,4,5);
360ok (scalar @args,3); # $class, 4, 5
56b9c951 361ok ($args[0] =~ /^Math::BigInt/);
6854fd01 362ok ($args[1],4);
363ok ($args[2],5);
364
365@args = Math::BigInt::objectify(0,4,5);
366ok (scalar @args,3); # $class, 4, 5
56b9c951 367ok ($args[0] =~ /^Math::BigInt/);
6854fd01 368ok ($args[1],4);
369ok ($args[2],5);
370
371@args = Math::BigInt::objectify(2,4,5);
372ok (scalar @args,3); # $class, 4, 5
56b9c951 373ok ($args[0] =~ /^Math::BigInt/);
6854fd01 374ok ($args[1],4);
375ok ($args[2],5);
376
377@args = Math::BigInt::objectify(2,4,5,6,7);
378ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 379ok ($args[0] =~ /^Math::BigInt/);
6854fd01 380ok ($args[1],4); ok (ref($args[1]),$args[0]);
381ok ($args[2],5); ok (ref($args[2]),$args[0]);
382ok ($args[3],6); ok (ref($args[3]),'');
383ok ($args[4],7); ok (ref($args[4]),'');
384
385@args = Math::BigInt::objectify(2,$class,4,5,6,7);
386ok (scalar @args,5); # $class, 4, 5, 6, 7
387ok ($args[0],$class);
388ok ($args[1],4); ok (ref($args[1]),$args[0]);
389ok ($args[2],5); ok (ref($args[2]),$args[0]);
390ok ($args[3],6); ok (ref($args[3]),'');
391ok ($args[4],7); ok (ref($args[4]),'');
392
393###############################################################################
f9a08e12 394# test whether an opp calls objectify properly or not (or at least does what
395# it should do given non-objects, w/ or w/o objectify())
396
397ok ($class->new(123)->badd(123),246);
398ok ($class->badd(123,321),444);
399ok ($class->badd(123,$class->new(321)),444);
400
401ok ($class->new(123)->bsub(122),1);
402ok ($class->bsub(321,123),198);
403ok ($class->bsub(321,$class->new(123)),198);
404
405ok ($class->new(123)->bmul(123),15129);
406ok ($class->bmul(123,123),15129);
407ok ($class->bmul(123,$class->new(123)),15129);
408
409ok ($class->new(15129)->bdiv(123),123);
410ok ($class->bdiv(15129,123),123);
411ok ($class->bdiv(15129,$class->new(123)),123);
412
413ok ($class->new(15131)->bmod(123),2);
414ok ($class->bmod(15131,123),2);
415ok ($class->bmod(15131,$class->new(123)),2);
416
417ok ($class->new(2)->bpow(16),65536);
418ok ($class->bpow(2,16),65536);
419ok ($class->bpow(2,$class->new(16)),65536);
420
421ok ($class->new(2**15)->brsft(1),2**14);
422ok ($class->brsft(2**15,1),2**14);
423ok ($class->brsft(2**15,$class->new(1)),2**14);
424
425ok ($class->new(2**13)->blsft(1),2**14);
426ok ($class->blsft(2**13,1),2**14);
427ok ($class->blsft(2**13,$class->new(1)),2**14);
428
429###############################################################################
6854fd01 430# test for floating-point input (other tests in bnorm() below)
431
432$z = 1050000000000000; # may be int on systems with 64bit?
433$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
434$z = 1e+129; # definitely a float (may fail on UTS)
435# don't compare to $z, since some Perl versions stringify $z into something
436# like '1.e+129' or something equally ugly
437$x = $class->new($z); ok ($x->bsstr(),'1e+129');
438
439###############################################################################
56d9de68 440# test for whitespace inlcuding newlines to be handled correctly
441
442# ok ($Math::BigInt::strict,1); # the default
443
444foreach my $c (
445 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
446 {
447 my $m = $class->new($c);
448 ok ($class->new("$c"),$m);
449 ok ($class->new(" $c"),$m);
450 ok ($class->new("$c "),$m);
451 ok ($class->new(" $c "),$m);
452 ok ($class->new("\n$c"),$m);
453 ok ($class->new("$c\n"),$m);
454 ok ($class->new("\n$c\n"),$m);
455 ok ($class->new(" \n$c\n"),$m);
456 ok ($class->new(" \n$c \n"),$m);
457 ok ($class->new(" \n$c\n "),$m);
458 ok ($class->new(" \n$c\n1"),'NaN');
459 ok ($class->new("1 \n$c\n1"),'NaN');
460 }
461
462###############################################################################
6854fd01 463# prime number tests, also test for **= and length()
464# found on: http://www.utm.edu/research/primes/notes/by_year.html
465
466# ((2^148)-1)/17
467$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
468ok ($x,"20988936657440586486151264256610222593863921");
469ok ($x->length(),length "20988936657440586486151264256610222593863921");
470
471# MM7 = 2^127-1
472$x = $class->new(2); $x **= 127; $x--;
473ok ($x,"170141183460469231731687303715884105727");
474
475$x = $class->new('215960156869840440586892398248');
476($x,$y) = $x->length();
477ok ($x,30); ok ($y,0);
478
479$x = $class->new('1_000_000_000_000');
480($x,$y) = $x->length();
481ok ($x,13); ok ($y,0);
482
2d2b2744 483# test <<=, >>=
484$x = $class->new('2');
485my $y = $class->new('18');
486ok ($x <<= $y, 2 << 18);
487ok ($x, 2 << 18);
488ok ($x >>= $y, 2);
489ok ($x, 2);
490
6854fd01 491# I am afraid the following is not yet possible due to slowness
492# Also, testing for 2 meg output is a bit hard ;)
493#$x = $class->new(2); $x **= 6972593; $x--;
494
495# 593573509*2^332162+1 has exactly 1,000,000 digits
496# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
497#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
498#ok ($x->length(),1_000_000);
499
500###############################################################################
501# inheritance and overriding of _swap
502
503$x = Math::Foo->new(5);
504$x = $x - 8; # 8 - 5 instead of 5-8
505ok ($x,3);
506ok (ref($x),'Math::Foo');
507
508$x = Math::Foo->new(5);
509$x = 8 - $x; # 5 - 8 instead of 8 - 5
510ok ($x,-3);
511ok (ref($x),'Math::Foo');
512
513###############################################################################
514# Test whether +inf eq inf
515# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
516# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
517# like 1e100000 crash on some platforms. So simple test for the string 'inf'
518$x = $class->new('+inf'); ok ($x,'inf');
519
520###############################################################################
521###############################################################################
56d9de68 522# the followin tests only make sense with Math::BigInt::Calc or BareCalc or
523# FastCalc
6854fd01 524
56d9de68 525exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01 526
527###############################################################################
528# check proper length of internal arrays
529
394e6ffb 530my $bl = $CL->_base_len();
6854fd01 531my $BASE = '9' x $bl;
532my $MAX = $BASE;
533$BASE++;
534
535$x = $class->new($MAX); is_valid($x); # f.i. 9999
536$x += 1; ok ($x,$BASE); is_valid($x); # 10000
537$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
538
539###############################################################################
540# check numify
541
542$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
543$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 544
545# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
546$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 547$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
548$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
549ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
550
551###############################################################################
552# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
553
394e6ffb 554$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
555if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
556
557$x = $class->new($BASE+3); $x++;
558if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 559
394e6ffb 560# test for +0 instead of int():
561$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 562
563###############################################################################
56b9c951 564# test bug that $class->digit($string) did not work
565
566ok ($class->digit(123,2),1);
567
568###############################################################################
6854fd01 569# bug in sub where number with at least 6 trailing zeros after any op failed
570
394e6ffb 571$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 572ok ($z, 100000);
573ok ($x, 23456);
574
575###############################################################################
576# bug in shortcut in mul()
577
61f5c3f5 578# construct a number with a zero-hole of BASE_LEN_SMALL
579{
580 my @bl = $CL->_base_len(); my $bl = $bl[4];
581
582 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
583 $y = '1' x (2*$bl);
584 $x = $class->new($x)->bmul($y);
585 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
586 $y = ''; my $d = '';
587 for (my $i = 1; $i <= $bl; $i++)
588 {
589 $y .= $i; $d = $i.$d;
590 }
591 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
592 ok ($x,$y);
593
6854fd01 594
f9a08e12 595 #############################################################################
596 # see if mul shortcut for small numbers works
394e6ffb 597
f9a08e12 598 $x = '9' x $bl;
599 $x = $class->new($x);
600 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
601 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
602}
61f5c3f5 603
394e6ffb 604###############################################################################
6854fd01 605# bug with rest "-0" in div, causing further div()s to fail
606
394e6ffb 607$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 608
61f5c3f5 609ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 610
79c55733 611###############################################################################
f9a08e12 612# bug in $x->bmod($y)
07d34614 613
f9a08e12 614# if $x < 0 and $y > 0
07d34614 615$x = $class->new('-629'); ok ($x->bmod(5033),4404);
616
617###############################################################################
56b9c951 618# bone/binf etc as plain calls (Lite failed them)
619
620ok ($class->bzero(),0);
621ok ($class->bone(),1);
622ok ($class->bone('+'),1);
623ok ($class->bone('-'),-1);
624ok ($class->bnan(),'NaN');
625ok ($class->binf(),'inf');
626ok ($class->binf('+'),'inf');
627ok ($class->binf('-'),'-inf');
628ok ($class->binf('-inf'),'-inf');
629
630###############################################################################
990fb837 631# is_one('-')
632
633ok ($class->new(1)->is_one('-'),0);
634ok ($class->new(-1)->is_one('-'),1);
635ok ($class->new(1)->is_one(),1);
636ok ($class->new(-1)->is_one(),0);
637
638###############################################################################
03874afe 639# [perl #30609] bug with $x -= $x not beeing 0, but 2*$x
640
641$x = $class->new(3); $x -= $x; ok ($x, 0);
642$x = $class->new(-3); $x -= $x; ok ($x, 0);
643$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
644$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
645$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
646
647$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
648$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
649$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
650$x = $class->new(3); $x += $x; ok ($x, 6);
651$x = $class->new(-3); $x += $x; ok ($x, -6);
652
653$x = $class->new(3); $x *= $x; ok ($x, 9);
654$x = $class->new(-3); $x *= $x; ok ($x, 9);
655$x = $class->new(3); $x /= $x; ok ($x, 1);
656$x = $class->new(-3); $x /= $x; ok ($x, 1);
657$x = $class->new(3); $x %= $x; ok ($x, 0);
658$x = $class->new(-3); $x %= $x; ok ($x, 0);
659
660###############################################################################
61f5c3f5 661# all tests done
6854fd01 662
6631;
664
665###############################################################################
61f5c3f5 666###############################################################################
6854fd01 667# Perl 5.005 does not like ok ($x,undef)
668
669sub ok_undef
670 {
671 my $x = shift;
672
673 ok (1,1) and return if !defined $x;
674 ok ($x,'undef');
675 }
676
677###############################################################################
678# sub to check validity of a BigInt internally, to ensure that no op leaves a
679# number object in an invalid state (f.i. "-0")
680
681sub is_valid
682 {
683 my ($x,$f) = @_;
684
685 my $e = 0; # error?
6854fd01 686
56b9c951 687 # allow the check to pass for all Lite, and all MBI and subclasses
688 # ok as reference?
689 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 690
56b9c951 691 if (ref($x) ne 'Math::BigInt::Lite')
692 {
693 # has ok sign?
694 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
695 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
696
697 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
698 $e = $CALC->_check($x->{value}) if $e eq '0';
699 }
6854fd01 700
701 # test done, see if error did crop up
702 ok (1,1), return if ($e eq '0');
703
027dc388 704 ok (1,$e." after op '$f'");
6854fd01 705 }
706
707__DATA__
027dc388 708&.=
7091234:-345:1234-345
710&+=
7111:2:3
712-1:-2:-3
713&-=
7141:2:-1
715-1:-2:1
716&*=
7172:3:6
718-1:5:-5
719&%=
720100:3:1
7218:9:8
07d34614 722-629:5033:4404
027dc388 723&/=
724100:3:33
725-8:2:-4
726&|=
7272:1:3
728&&=
7295:7:5
730&^=
7315:7:2
091c87b1 732&blog
733NaNlog:2:NaN
734122:NaNlog:NaN
735NaNlog1:NaNlog:NaN
736122:inf:NaN
737inf:122:NaN
738122:-inf:NaN
739-inf:122:NaN
740-inf:-inf:NaN
741inf:inf:NaN
7420:4:NaN
743-21:4:NaN
74421:-21:NaN
745# normal results
7461024:2:10
74781:3:4
748# 3.01.. truncate
74982:3:4
750# 3.9... truncate
75180:3:3
75215625:5:6
75315626:5:6
75415624:5:5
8df1e0a2 7551000:10:3
75610000:10:4
757100000:10:5
7581000000:10:6
75910000000:10:7
760100000000:10:8
7618916100448256:12:12
7628916100448257:12:12
7638916100448255:12:11
7642251799813685248:8:17
76572057594037927936:2:56
766144115188075855872:2:57
767288230376151711744:2:58
768576460752303423488:2:59
7694096:2:12
7701329227995784915872903807060280344576:2:120
091c87b1 771# $x == $base => result 1
7723:3:1
773# $x < $base => result 0 ($base ** 0 <= $x)
7743:4:0
775# $x == 1 => result 0
7761:5:0
6854fd01 777&is_negative
7780:0
779-1:1
7801:0
781+inf:0
782-inf:1
783NaNneg:0
784&is_positive
b68b7ab1 7850:0
6854fd01 786-1:0
7871:1
788+inf:1
789-inf:0
790NaNneg:0
b3abae2a 791&is_int
792-inf:0
793+inf:0
794NaNis_int:0
7951:1
7960:1
797123e12:1
6854fd01 798&is_odd
799abc:0
8000:0
8011:1
8023:1
803-1:1
804-3:1
80510000001:1
80610000002:0
8072:0
b3abae2a 808120:0
809121:1
6854fd01 810&is_even
811abc:0
8120:1
8131:0
8143:0
815-1:0
816-3:0
81710000001:0
81810000002:1
8192:1
b3abae2a 820120:1
821121:0
6854fd01 822&bacmp
823+0:-0:0
824+0:+1:-1
825-1:+1:0
826+1:-1:0
827-1:+2:-1
828+2:-1:1
829-123456789:+987654321:-1
830+123456789:-987654321:-1
831+987654321:+123456789:1
832-987654321:+123456789:1
833-123:+4567889:-1
834# NaNs
835acmpNaN:123:
836123:acmpNaN:
837acmpNaN:acmpNaN:
838# infinity
839+inf:+inf:0
840-inf:-inf:0
841+inf:-inf:0
842-inf:+inf:0
843+inf:123:1
844-inf:123:1
845+inf:-123:1
846-inf:-123:1
ef9466ea 847123:-inf:-1
848-123:inf:-1
849-123:-inf:-1
850123:inf:-1
6854fd01 851# return undef
852+inf:NaN:
853NaN:inf:
854-inf:NaN:
855NaN:-inf:
856&bnorm
aef458a0 8570e999:0
8580e-999:0
859-0e999:0
860-0e-999:0
6854fd01 861123:123
862# binary input
8630babc:NaN
8640b123:NaN
8650b0:0
866-0b0:0
867-0b1:-1
8680b0001:1
8690b001:1
8700b011:3
8710b101:5
61f5c3f5 8720b1001:9
8730b10001:17
8740b100001:33
8750b1000001:65
8760b10000001:129
8770b100000001:257
8780b1000000001:513
8790b10000000001:1025
8800b100000000001:2049
8810b1000000000001:4097
8820b10000000000001:8193
8830b100000000000001:16385
8840b1000000000000001:32769
8850b10000000000000001:65537
8860b100000000000000001:131073
8870b1000000000000000001:262145
8880b10000000000000000001:524289
8890b100000000000000000001:1048577
8900b1000000000000000000001:2097153
8910b10000000000000000000001:4194305
8920b100000000000000000000001:8388609
8930b1000000000000000000000001:16777217
8940b10000000000000000000000001:33554433
8950b100000000000000000000000001:67108865
8960b1000000000000000000000000001:134217729
8970b10000000000000000000000000001:268435457
8980b100000000000000000000000000001:536870913
8990b1000000000000000000000000000001:1073741825
9000b10000000000000000000000000000001:2147483649
9010b100000000000000000000000000000001:4294967297
9020b1000000000000000000000000000000001:8589934593
9030b10000000000000000000000000000000001:17179869185
6854fd01 9040b_101:NaN
9050b1_0_1:5
394e6ffb 9060b0_0_0_1:1
6854fd01 907# hex input
908-0x0:0
9090xabcdefgh:NaN
9100x1234:4660
9110xabcdef:11259375
912-0xABCDEF:-11259375
913-0x1234:-4660
9140x12345678:305419896
9150x1_2_3_4_56_78:305419896
394e6ffb 9160xa_b_c_d_e_f:11259375
6854fd01 9170x_123:NaN
61f5c3f5 9180x9:9
9190x11:17
9200x21:33
9210x41:65
9220x81:129
9230x101:257
9240x201:513
9250x401:1025
9260x801:2049
9270x1001:4097
9280x2001:8193
9290x4001:16385
9300x8001:32769
9310x10001:65537
9320x20001:131073
9330x40001:262145
9340x80001:524289
9350x100001:1048577
9360x200001:2097153
9370x400001:4194305
9380x800001:8388609
9390x1000001:16777217
9400x2000001:33554433
9410x4000001:67108865
9420x8000001:134217729
9430x10000001:268435457
9440x20000001:536870913
9450x40000001:1073741825
9460x80000001:2147483649
9470x100000001:4294967297
9480x200000001:8589934593
9490x400000001:17179869185
9500x800000001:34359738369
2d2b2744 951# bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex()
9520x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
6854fd01 953# inf input
954inf:inf
955+inf:inf
956-inf:-inf
9570inf:NaN
027dc388 958# abnormal input
6854fd01 959:NaN
960abc:NaN
961 1 a:NaN
9621bcd2:NaN
96311111b:NaN
964+1z:NaN
965-1z:NaN
027dc388 966# only one underscore between two digits
967_123:NaN
968_123_:NaN
969123_:NaN
9701__23:NaN
9711E1__2:NaN
9721_E12:NaN
9731E_12:NaN
9741_E_12:NaN
975+_1E12:NaN
976+0_1E2:100
977+0_0_1E2:100
978-0_0_1E2:-100
979-0_0_1E+0_0_2:-100
980E1:NaN
981E23:NaN
9821.23E1:NaN
9831.23E-1:NaN
984# bug with two E's in number beeing valid
9851e2e3:NaN
9861e2r:NaN
9871e2.0:NaN
07d34614 988# bug with two '.' in number beeing valid
9891.2.2:NaN
9901.2.3e1:NaN
991-1.2.3:NaN
992-1.2.3e-4:NaN
9931.2e3.4:NaN
9941.2e-3.4:NaN
9951.2.3.4:NaN
9961.2.t:NaN
9971..2:NaN
9981..2e1:NaN
9991..2e1..1:NaN
100012e1..1:NaN
1001..2:NaN
1002.-2:NaN
61f5c3f5 1003# leading zeros
1004012:12
10050123:123
100601234:1234
1007012345:12345
10080123456:123456
100901234567:1234567
1010012345678:12345678
10110123456789:123456789
101201234567891:1234567891
1013012345678912:12345678912
10140123456789123:123456789123
101501234567891234:1234567891234
2d2b2744 1016# some inputs that result in zero
10170e0:0
1018+0e0:0
1019+0e+0:0
1020-0e+0:0
10210e-0:0
1022-0e-0:0
1023+0e-0:0
1024000:0
102500e2:0
102600e02:0
1027000e002:0
1028000e1230:0
102900e-3:0
103000e+3:0
103100e-03:0
103200e+03:0
1033-000:0
1034-00e2:0
1035-00e02:0
1036-000e002:0
1037-000e1230:0
1038-00e-3:0
1039-00e+3:0
1040-00e-03:0
1041-00e+03:0
027dc388 1042# normal input
6854fd01 10430:0
1044+0:0
1045+00:0
1046+000:0
1047000000000000000000:0
1048-0:0
1049-0000:0
1050+1:1
1051+01:1
1052+001:1
1053+00000100000:100000
1054123456789:123456789
1055-1:-1
1056-01:-1
1057-001:-1
1058-123456789:-123456789
1059-00000100000:-100000
10601_2_3:123
6854fd01 106110000000000E-1_0:1
10621E2:100
10631E1:10
10641E0:1
6854fd01 10651.23E2:123
6854fd01 1066100E-1:10
1067# floating point input
027dc388 1068# .2e2:20
10691.E3:1000
6854fd01 10701.01E2:101
10711010E-1:101
1072-1010E0:-1010
1073-1010E1:-10100
027dc388 10741234.00:1234
1075# non-integer numbers
6854fd01 1076-1010E-2:NaN
1077-1.01E+1:NaN
1078-1.01E-1:NaN
6854fd01 1079&bnan
10801:NaN
10812:NaN
1082abc:NaN
1083&bone
61f5c3f5 10842:+:1
6854fd01 10852:-:-1
1086boneNaN:-:-1
61f5c3f5 1087boneNaN:+:1
10882:abc:1
10893::1
6854fd01 1090&binf
10911:+:inf
10922:-:-inf
10933:abc:inf
027dc388 1094&is_nan
1095123:0
1096abc:1
1097NaN:1
1098-123:0
6854fd01 1099&is_inf
1100+inf::1
1101-inf::1
1102abc::0
11031::0
1104NaN::0
1105-1::0
1106+inf:-:0
1107+inf:+:1
1108-inf:-:1
1109-inf:+:0
79c55733 1110-inf:-inf:1
1111-inf:+inf:0
1112+inf:-inf:0
1113+inf:+inf:1
6854fd01 1114# it must be exactly /^[+-]inf$/
1115+infinity::0
1116-infinity::0
1117&blsft
1118abc:abc:NaN
61f5c3f5 1119+2:+2:8
1120+1:+32:4294967296
1121+1:+48:281474976710656
6854fd01 1122+8:-2:NaN
1123# excercise base 10
1124+12345:4:10:123450000
1125-1234:0:10:-1234
61f5c3f5 1126+1234:0:10:1234
6854fd01 1127+2:2:10:200
1128+12:2:10:1200
1129+1234:-3:10:NaN
11301234567890123:12:10:1234567890123000000000000
b3abae2a 1131-3:1:2:-6
1132-5:1:2:-10
1133-2:1:2:-4
1134-102533203:1:2:-205066406
6854fd01 1135&brsft
1136abc:abc:NaN
61f5c3f5 1137+8:+2:2
1138+4294967296:+32:1
1139+281474976710656:+48:1
6854fd01 1140+2:-2:NaN
1141# excercise base 10
1142-1234:0:10:-1234
61f5c3f5 1143+1234:0:10:1234
6854fd01 1144+200:2:10:2
1145+1234:3:10:1
1146+1234:2:10:12
1147+1234:-3:10:NaN
1148310000:4:10:31
114912300000:5:10:123
11501230000000000:10:10:123
115109876123456789067890:12:10:9876123
11521234561234567890123:13:10:123456
b3abae2a 1153820265627:1:2:410132813
1154# test shifting negative numbers in base 2
1155-15:1:2:-8
1156-14:1:2:-7
1157-13:1:2:-7
1158-12:1:2:-6
1159-11:1:2:-6
1160-10:1:2:-5
1161-9:1:2:-5
1162-8:1:2:-4
1163-7:1:2:-4
1164-6:1:2:-3
1165-5:1:2:-3
1166-4:1:2:-2
1167-3:1:2:-2
1168-2:1:2:-1
1169-1:1:2:-1
1170-1640531254:2:2:-410132814
1171-1640531254:1:2:-820265627
1172-820265627:1:2:-410132814
1173-205066405:1:2:-102533203
6854fd01 1174&bsstr
56d9de68 1175+inf:inf
1176-inf:-inf
6854fd01 11771e+34:1e+34
1178123.456E3:123456e+0
1179100:1e+2
56d9de68 1180bsstrabc:NaN
1181-5:-5e+0
1182-100:-1e+2
1183&numify
1184numifyabc:NaN
1185+inf:inf
1186-inf:-inf
11875:5
1188-5:-5
1189100:100
1190-100:-100
6854fd01 1191&bneg
1192bnegNaN:NaN
1193+inf:-inf
1194-inf:inf
1195abd:NaN
61f5c3f5 11960:0
11971:-1
1198-1:1
6854fd01 1199+123456789:-123456789
61f5c3f5 1200-123456789:123456789
6854fd01 1201&babs
1202babsNaN:NaN
1203+inf:inf
1204-inf:inf
61f5c3f5 12050:0
12061:1
1207-1:1
1208+123456789:123456789
1209-123456789:123456789
6854fd01 1210&bcmp
1211bcmpNaN:bcmpNaN:
61f5c3f5 1212bcmpNaN:0:
12130:bcmpNaN:
12140:0:0
1215-1:0:-1
12160:-1:1
12171:0:1
12180:1:-1
1219-1:1:-1
12201:-1:1
6854fd01 1221-1:-1:0
61f5c3f5 12221:1:0
1223123:123:0
1224123:12:1
122512:123:-1
6854fd01 1226-123:-123:0
1227-123:-12:-1
1228-12:-123:1
61f5c3f5 1229123:124:-1
1230124:123:1
6854fd01 1231-123:-124:1
1232-124:-123:-1
61f5c3f5 1233100:5:1
1234-123456789:987654321:-1
6854fd01 1235+123456789:-987654321:1
61f5c3f5 1236-987654321:123456789:-1
6854fd01 1237-inf:5432112345:-1
1238+inf:5432112345:1
1239-inf:-5432112345:-1
1240+inf:-5432112345:1
1241+inf:+inf:0
1242-inf:-inf:0
1243+inf:-inf:1
1244-inf:+inf:-1
12455:inf:-1
12465:inf:-1
1247-5:-inf:1
1248-5:-inf:1
1249# return undef
1250+inf:NaN:
1251NaN:inf:
1252-inf:NaN:
1253NaN:-inf:
1254&binc
1255abc:NaN
1256+inf:inf
1257-inf:-inf
61f5c3f5 1258+0:1
1259+1:2
1260-1:0
6854fd01 1261&bdec
1262abc:NaN
1263+inf:inf
1264-inf:-inf
1265+0:-1
61f5c3f5 1266+1:0
6854fd01 1267-1:-2
1268&badd
1269abc:abc:NaN
61f5c3f5 1270abc:0:NaN
6854fd01 1271+0:abc:NaN
b3abae2a 1272+inf:-inf:NaN
1273-inf:+inf:NaN
6854fd01 1274+inf:+inf:inf
1275-inf:-inf:-inf
1276baddNaN:+inf:NaN
1277baddNaN:+inf:NaN
1278+inf:baddNaN:NaN
1279-inf:baddNaN:NaN
61f5c3f5 12800:0:0
12811:0:1
12820:1:1
12831:1:2
1284-1:0:-1
12850:-1:-1
6854fd01 1286-1:-1:-2
61f5c3f5 1287-1:+1:0
1288+1:-1:0
1289+9:+1:10
1290+99:+1:100
1291+999:+1:1000
1292+9999:+1:10000
1293+99999:+1:100000
1294+999999:+1:1000000
1295+9999999:+1:10000000
1296+99999999:+1:100000000
1297+999999999:+1:1000000000
1298+9999999999:+1:10000000000
1299+99999999999:+1:100000000000
1300+10:-1:9
1301+100:-1:99
1302+1000:-1:999
1303+10000:-1:9999
1304+100000:-1:99999
1305+1000000:-1:999999
1306+10000000:-1:9999999
1307+100000000:-1:99999999
1308+1000000000:-1:999999999
1309+10000000000:-1:9999999999
1310+123456789:987654321:1111111110
1311-123456789:987654321:864197532
6854fd01 1312-123456789:-987654321:-1111111110
1313+123456789:-987654321:-864197532
56b9c951 1314-1:10001:10000
1315-1:100001:100000
1316-1:1000001:1000000
1317-1:10000001:10000000
1318-1:100000001:100000000
1319-1:1000000001:1000000000
1320-1:10000000001:10000000000
1321-1:100000000001:100000000000
1322-1:1000000000001:1000000000000
1323-1:10000000000001:10000000000000
1324-1:-10001:-10002
1325-1:-100001:-100002
1326-1:-1000001:-1000002
1327-1:-10000001:-10000002
1328-1:-100000001:-100000002
1329-1:-1000000001:-1000000002
1330-1:-10000000001:-10000000002
1331-1:-100000000001:-100000000002
1332-1:-1000000000001:-1000000000002
1333-1:-10000000000001:-10000000000002
6854fd01 1334&bsub
1335abc:abc:NaN
1336abc:+0:NaN
1337+0:abc:NaN
1338+inf:-inf:inf
1339-inf:+inf:-inf
b3abae2a 1340+inf:+inf:NaN
1341-inf:-inf:NaN
61f5c3f5 1342+0:+0:0
1343+1:+0:1
6854fd01 1344+0:+1:-1
61f5c3f5 1345+1:+1:0
6854fd01 1346-1:+0:-1
61f5c3f5 1347+0:-1:1
1348-1:-1:0
6854fd01 1349-1:+1:-2
61f5c3f5 1350+1:-1:2
1351+9:+1:8
1352+99:+1:98
1353+999:+1:998
1354+9999:+1:9998
1355+99999:+1:99998
1356+999999:+1:999998
1357+9999999:+1:9999998
1358+99999999:+1:99999998
1359+999999999:+1:999999998
1360+9999999999:+1:9999999998
1361+99999999999:+1:99999999998
1362+10:-1:11
1363+100:-1:101
1364+1000:-1:1001
1365+10000:-1:10001
1366+100000:-1:100001
1367+1000000:-1:1000001
1368+10000000:-1:10000001
1369+100000000:-1:100000001
1370+1000000000:-1:1000000001
1371+10000000000:-1:10000000001
6854fd01 1372+123456789:+987654321:-864197532
1373-123456789:+987654321:-1111111110
61f5c3f5 1374-123456789:-987654321:864197532
1375+123456789:-987654321:1111111110
56b9c951 137610001:1:10000
1377100001:1:100000
13781000001:1:1000000
137910000001:1:10000000
1380100000001:1:100000000
13811000000001:1:1000000000
138210000000001:1:10000000000
1383100000000001:1:100000000000
13841000000000001:1:1000000000000
138510000000000001:1:10000000000000
138610001:-1:10002
1387100001:-1:100002
13881000001:-1:1000002
138910000001:-1:10000002
1390100000001:-1:100000002
13911000000001:-1:1000000002
139210000000001:-1:10000000002
1393100000000001:-1:100000000002
13941000000000001:-1:1000000000002
139510000000000001:-1:10000000000002
6854fd01 1396&bmul
1397abc:abc:NaN
1398abc:+0:NaN
1399+0:abc:NaN
1400NaNmul:+inf:NaN
1401NaNmul:-inf:NaN
1402-inf:NaNmul:NaN
1403+inf:NaNmul:NaN
1404+inf:+inf:inf
1405+inf:-inf:-inf
1406-inf:+inf:-inf
1407-inf:-inf:inf
61f5c3f5 1408+0:+0:0
1409+0:+1:0
1410+1:+0:0
1411+0:-1:0
1412-1:+0:0
1413123456789123456789:0:0
14140:123456789123456789:0
1415-1:-1:1
6854fd01 1416-1:+1:-1
1417+1:-1:-1
61f5c3f5 1418+1:+1:1
1419+2:+3:6
6854fd01 1420-2:+3:-6
1421+2:-3:-6
61f5c3f5 1422-2:-3:6
1423111:111:12321
142410101:10101:102030201
14251001001:1001001:1002003002001
1426100010001:100010001:10002000300020001
142710000100001:10000100001:100002000030000200001
142811111111111:9:99999999999
142922222222222:9:199999999998
143033333333333:9:299999999997
143144444444444:9:399999999996
143255555555555:9:499999999995
143366666666666:9:599999999994
143477777777777:9:699999999993
143588888888888:9:799999999992
143699999999999:9:899999999991
1437+25:+25:625
1438+12345:+12345:152399025
1439+99999:+11111:1111088889
6854fd01 14409999:10000:99990000
144199999:100000:9999900000
1442999999:1000000:999999000000
14439999999:10000000:99999990000000
144499999999:100000000:9999999900000000
1445999999999:1000000000:999999999000000000
14469999999999:10000000000:99999999990000000000
144799999999999:100000000000:9999999999900000000000
1448999999999999:1000000000000:999999999999000000000000
14499999999999999:10000000000000:99999999999990000000000000
145099999999999999:100000000000000:9999999999999900000000000000
1451999999999999999:1000000000000000:999999999999999000000000000000
14529999999999999999:10000000000000000:99999999999999990000000000000000
145399999999999999999:100000000000000000:9999999999999999900000000000000000
1454999999999999999999:1000000000000000000:999999999999999999000000000000000000
14559999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1456&bdiv-list
1457100:20:5,0
14584095:4095:1,0
1459-4095:-4095:1,0
14604095:-4095:-1,0
1461-4095:4095:-1,0
1462123:2:61,1
b3abae2a 14639:5:1,4
14649:4:2,1
6854fd01 1465# inf handling and general remainder
14665:8:0,5
14670:8:0,0
146811:2:5,1
146911:-2:-5,-1
1470-11:2:-5,1
1471# see table in documentation in MBI
14720:inf:0,0
14730:-inf:0,0
14745:inf:0,5
14755:-inf:0,5
1476-5:inf:0,-5
1477-5:-inf:0,-5
1478inf:5:inf,0
1479-inf:5:-inf,0
1480inf:-5:-inf,0
1481-inf:-5:inf,0
14825:5:1,0
1483-5:-5:1,0
b3abae2a 1484inf:inf:NaN,NaN
1485-inf:-inf:NaN,NaN
1486-inf:inf:NaN,NaN
1487inf:-inf:NaN,NaN
6854fd01 14888:0:inf,8
1489inf:0:inf,inf
1490# exceptions to reminder rule
1491-8:0:-inf,-8
1492-inf:0:-inf,-inf
14930:0:NaN,NaN
990fb837 1494# test the shortcut in Calc if @$x == @$yorg
14951234567812345678:123456712345678:10,688888898
149612345671234567:1234561234567:10,58888897
1497123456123456:12345123456:10,4888896
14981234512345:123412345:10,388895
14991234567890999999999:1234567890:1000000000,999999999
15001234567890000000000:1234567890:1000000000,0
15011234567890999999999:9876543210:124999998,9503086419
15021234567890000000000:9876543210:124999998,8503086420
150396969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
7596a890 1504# bug in v1.76
15051267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
b68b7ab1 1506# excercise shortcut for numbers of the same length in div
1507999999999999999999999999999999999:999999999999999999999999999999999:1,0
1508999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1509999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1510999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1511999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1512999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1513999999999999999999999999999999999:333333333333333333333333333333333:3,0
1514999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1515999999999999999999999999999999999:111111111111111111111111111111111:9,0
15169999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
15179999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
15189999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
15199999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
15209999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
15219999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
15229999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
15239999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
15249999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
15259999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
15269999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
6854fd01 1527&bdiv
1528abc:abc:NaN
61f5c3f5 1529abc:1:NaN
15301:abc:NaN
15310:0:NaN
6854fd01 1532# inf handling (see table in doc)
15330:inf:0
15340:-inf:0
15355:inf:0
15365:-inf:0
1537-5:inf:0
1538-5:-inf:0
1539inf:5:inf
1540-inf:5:-inf
1541inf:-5:-inf
1542-inf:-5:inf
15435:5:1
1544-5:-5:1
b3abae2a 1545inf:inf:NaN
1546-inf:-inf:NaN
1547-inf:inf:NaN
1548inf:-inf:NaN
6854fd01 15498:0:inf
1550inf:0:inf
1551-8:0:-inf
1552-inf:0:-inf
15530:0:NaN
155411:2:5
1555-11:-2:5
1556-11:2:-5
155711:-2:-5
61f5c3f5 15580:1:0
15590:-1:0
15601:1:1
1561-1:-1:1
15621:-1:-1
1563-1:1:-1
15641:2:0
15652:1:2
15661:26:0
15671000000000:9:111111111
15682000000000:9:222222222
15693000000000:9:333333333
15704000000000:9:444444444
15715000000000:9:555555555
15726000000000:9:666666666
15737000000000:9:777777777
15748000000000:9:888888888
15759000000000:9:1000000000
157635500000:113:314159
157771000000:226:314159
1578106500000:339:314159
15791000000000:3:333333333
1580+10:+5:2
1581+100:+4:25
1582+1000:+8:125
1583+10000:+16:625
1584999999999999:9:111111111111
1585999999999999:99:10101010101
1586999999999999:999:1001001001
1587999999999999:9999:100010001
1588999999999999999:99999:10000100001
1589+1111088889:99999:11111
6854fd01 1590-5:-3:1
1591-5:3:-1
15924:3:1
15934:-3:-1
15941:3:0
15951:-3:0
1596-2:-3:0
1597-2:3:0
15988:3:2
1599-8:3:-2
160014:-3:-4
1601-14:3:-4
1602-14:-3:4
160314:3:4
1604# bug in Calc with '99999' vs $BASE-1
160510000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1606# test the shortcut in Calc if @$x == @$yorg
16071234567812345678:123456712345678:10
160812345671234567:1234561234567:10
1609123456123456:12345123456:10
16101234512345:123412345:10
16111234567890999999999:1234567890:1000000000
16121234567890000000000:1234567890:1000000000
16131234567890999999999:9876543210:124999998
16141234567890000000000:9876543210:124999998
161596969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1616# bug up to v0.35 in Calc (--$q one too many)
161784696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
161884696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
161984696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
162084696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
b68b7ab1 1621# excercise shortcut for numbers of the same length in div
1622999999999999999999999999999999999:999999999999999999999999999999999:1
1623999999999999999999999999999999999:888888888888888888888888888888888:1
1624999999999999999999999999999999999:777777777777777777777777777777777:1
1625999999999999999999999999999999999:666666666666666666666666666666666:1
1626999999999999999999999999999999999:555555555555555555555555555555555:1
1627999999999999999999999999999999999:444444444444444444444444444444444:2
1628999999999999999999999999999999999:333333333333333333333333333333333:3
1629999999999999999999999999999999999:222222222222222222222222222222222:4
1630999999999999999999999999999999999:111111111111111111111111111111111:9
16319999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
16329999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
16339999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
16349999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
16359999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
16369999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
16379999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
16389999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
16399999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
16409999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
16419999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
a87115f0 1642# bug with shortcut in Calc 0.44
1643949418181818187070707070707070707070:181818181853535353535353535353535353:5
07d34614 1644&bmodinv
1645# format: number:modulus:result
1646# bmodinv Data errors
1647abc:abc:NaN
1648abc:5:NaN
16495:abc:NaN
1650# bmodinv Expected Results from normal use
16511:5:1
16523:5:2
1653-2:5:2
16548:5033:4404
56d9de68 16551234567891:13:6
1656-1234567891:13:7
07d34614 1657324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1658## bmodinv Error cases / useless use of function
07d34614 16593:-5:NaN
1660inf:5:NaN
1ddff52a 16615:inf:NaN
1662-inf:5:NaN
16635:-inf:NaN
07d34614 1664&bmodpow
1665# format: number:exponent:modulus:result
1666# bmodpow Data errors
1667abc:abc:abc:NaN
16685:abc:abc:NaN
1669abc:5:abc:NaN
1670abc:abc:5:NaN
16715:5:abc:NaN
16725:abc:5:NaN
1673abc:5:5:NaN
1674# bmodpow Expected results
16750:0:2:1
16761:0:2:1
16770:0:1:0
16788:7:5032:3840
16798:-1:5033:4404
168098436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1681# bmodpow Error cases
16828:8:-5:NaN
16838:-1:16:NaN
1684inf:5:13:NaN
16855:inf:13:NaN
6854fd01 1686&bmod
1687# inf handling, see table in doc
16880:inf:0
16890:-inf:0
16905:inf:5
16915:-inf:5
1692-5:inf:-5
1693-5:-inf:-5
1694inf:5:0
1695-inf:5:0
1696inf:-5:0
1697-inf:-5:0
16985:5:0
1699-5:-5:0
b3abae2a 1700inf:inf:NaN
1701-inf:-inf:NaN
1702-inf:inf:NaN
1703inf:-inf:NaN
6854fd01 17048:0:8
1705inf:0:inf
1706# exceptions to reminder rule
1707-inf:0:-inf
1708-8:0:-8
17090:0:NaN
1710abc:abc:NaN
61f5c3f5 1711abc:1:abc:NaN
17121:abc:NaN
17130:0:NaN
17140:1:0
17151:0:1
17160:-1:0
1717-1:0:-1
17181:1:0
1719-1:-1:0
17201:-1:0
1721-1:1:0
17221:2:1
17232:1:0
17241000000000:9:1
17252000000000:9:2
17263000000000:9:3
17274000000000:9:4
17285000000000:9:5
17296000000000:9:6
17307000000000:9:7
17318000000000:9:8
17329000000000:9:0
173335500000:113:33
173471000000:226:66
1735106500000:339:99
17361000000000:3:1
173710:5:0
1738100:4:0
17391000:8:0
174010000:16:0
1741999999999999:9:0
1742999999999999:99:0
1743999999999999:999:0
1744999999999999:9999:0
1745999999999999999:99999:0
1746-9:+5:1
6854fd01 1747+9:-5:-1
1748-9:-5:-4
1749-5:3:1
1750-2:3:1
17514:3:1
17521:3:1
1753-5:-3:-2
1754-2:-3:-2
17554:-3:-2
17561:-3:-2
17574095:4095:0
027dc388 1758100041000510123:3:0
1759152403346:12345:4321
b3abae2a 17609:5:4
28df3e88 1761# test shortcuts in Calc
1762# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
17631234:9:1
1764123456:9:3
176512345678:9:0
17661234567891:9:1
1767123456789123:9:6
176812345678912345:9:6
17691234567891234567:9:1
1770123456789123456789:9:0
17711234:10:4
1772123456:10:6
177312345678:10:8
17741234567891:10:1
1775123456789123:10:3
177612345678912345:10:5
17771234567891234567:10:7
1778123456789123456789:10:9
17791234:113:104
1780123456:113:60
178112345678:113:89
17821234567891:113:64
1783123456789123:113:95
178412345678912345:113:53
17851234567891234567:113:56
1786123456789123456789:113:39
07d34614 1787# bug in bmod() not modifying the variable in place
1788-629:5033:4404
aef458a0 1789# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1790# when X == X and X was big
1791111111111111111111111111111111:111111111111111111111111111111:0
179212345678901234567890:12345678901234567890:0
6854fd01 1793&bgcd
9b924220 1794inf:12:NaN
1795-inf:12:NaN
179612:inf:NaN
179712:-inf:NaN
1798inf:inf:NaN
1799inf:-inf:NaN
1800-inf:-inf:NaN
6854fd01 1801abc:abc:NaN
1802abc:+0:NaN
1803+0:abc:NaN
61f5c3f5 1804+0:+0:0
1805+0:+1:1
1806+1:+0:1
1807+1:+1:1
1808+2:+3:1
1809+3:+2:1
1810-3:+2:1
9b924220 1811-3:-2:1
1812-144:-60:12
1813144:-60:12
1814144:60:12
61f5c3f5 1815100:625:25
18164096:81:1
18171034:804:2
181827:90:56:1
181927:90:54:9
6854fd01 1820&blcm
1821abc:abc:NaN
1822abc:+0:NaN
1823+0:abc:NaN
1824+0:+0:NaN
61f5c3f5 1825+1:+0:0
1826+0:+1:0
1827+27:+90:270
1828+1034:+804:415668
6854fd01 1829&band
1830abc:abc:NaN
1831abc:0:NaN
18320:abc:NaN
18331:2:0
18343:2:2
61f5c3f5 1835+8:+2:0
1836+281474976710656:0:0
1837+281474976710656:1:0
1838+281474976710656:+281474976710656:281474976710656
9b924220 1839281474976710656:-1:281474976710656
6854fd01 1840-2:-3:-4
1841-1:-1:-1
1842-6:-6:-6
1843-7:-4:-8
1844-7:4:0
1845-4:7:4
9b924220 1846# negative argument is bitwise shorter than positive [perl #26559]
184730:-3:28
1848123:-1:123
394e6ffb 1849# equal arguments are treated special, so also do some test with unequal ones
18500xFFFF:0xFFFF:0x0xFFFF
18510xFFFFFF:0xFFFFFF:0x0xFFFFFF
18520xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18530xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18540xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18550xF0F0:0xF0F0:0x0xF0F0
18560x0F0F:0x0F0F:0x0x0F0F
18570xF0F0F0:0xF0F0F0:0x0xF0F0F0
18580x0F0F0F:0x0F0F0F:0x0x0F0F0F
18590xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18600x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18610xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18620x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18630xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18640x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18650x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1866&bior
1867abc:abc:NaN
1868abc:0:NaN
18690:abc:NaN
18701:2:3
61f5c3f5 1871+8:+2:10
1872+281474976710656:0:281474976710656
1873+281474976710656:1:281474976710657
1874+281474976710656:281474976710656:281474976710656
6854fd01 1875-2:-3:-1
1876-1:-1:-1
1877-6:-6:-6
1878-7:4:-3
1879-4:7:-1
9b924220 1880+281474976710656:-1:-1
188130:-3:-1
188230:-4:-2
1883300:-76:-68
1884-76:300:-68
394e6ffb 1885# equal arguments are treated special, so also do some test with unequal ones
18860xFFFF:0xFFFF:0x0xFFFF
18870xFFFFFF:0xFFFFFF:0x0xFFFFFF
18880xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18890xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18900xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18910:0xFFFF:0x0xFFFF
18920:0xFFFFFF:0x0xFFFFFF
18930:0xFFFFFFFF:0x0xFFFFFFFF
18940:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18950:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18960xFFFF:0:0x0xFFFF
18970xFFFFFF:0:0x0xFFFFFF
18980xFFFFFFFF:0:0x0xFFFFFFFF
18990xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19000xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19010xF0F0:0xF0F0:0x0xF0F0
19020x0F0F:0x0F0F:0x0x0F0F
19030xF0F0:0x0F0F:0x0xFFFF
19040xF0F0F0:0xF0F0F0:0x0xF0F0F0
19050x0F0F0F:0x0F0F0F:0x0x0F0F0F
19060x0F0F0F:0xF0F0F0:0x0xFFFFFF
19070xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
19080x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
19090x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19100xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
19110x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
19120x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19130xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
19140x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
19150x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
19160x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1917&bxor
1918abc:abc:NaN
1919abc:0:NaN
19200:abc:NaN
19211:2:3
61f5c3f5 1922+8:+2:10
1923+281474976710656:0:281474976710656
1924+281474976710656:1:281474976710657
1925+281474976710656:281474976710656:0
6854fd01 1926-2:-3:3
1927-1:-1:0
1928-6:-6:0
1929-7:4:-3
1930-4:7:-5
19314:-7:-3
1932-4:-7:5
9b924220 193330:-3:-29
193430:-4:-30
1935300:-76:-360
1936-76:300:-360
394e6ffb 1937# equal arguments are treated special, so also do some test with unequal ones
19380xFFFF:0xFFFF:0
19390xFFFFFF:0xFFFFFF:0
19400xFFFFFFFF:0xFFFFFFFF:0
19410xFFFFFFFFFF:0xFFFFFFFFFF:0
19420xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
19430:0xFFFF:0x0xFFFF
19440:0xFFFFFF:0x0xFFFFFF
19450:0xFFFFFFFF:0x0xFFFFFFFF
19460:0xFFFFFFFFFF:0x0xFFFFFFFFFF
19470:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
19480xFFFF:0:0x0xFFFF
19490xFFFFFF:0:0x0xFFFFFF
19500xFFFFFFFF:0:0x0xFFFFFFFF
19510xFFFFFFFFFF:0:0x0xFFFFFFFFFF
19520xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
19530xF0F0:0xF0F0:0
19540x0F0F:0x0F0F:0
19550xF0F0:0x0F0F:0x0xFFFF
19560xF0F0F0:0xF0F0F0:0
19570x0F0F0F:0x0F0F0F:0
19580x0F0F0F:0xF0F0F0:0x0xFFFFFF
19590xF0F0F0F0:0xF0F0F0F0:0
19600x0F0F0F0F:0x0F0F0F0F:0
19610x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
19620xF0F0F0F0F0:0xF0F0F0F0F0:0
19630x0F0F0F0F0F:0x0F0F0F0F0F:0
19640x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
19650xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
19660x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
19670x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1968&bnot
1969abc:NaN
1970+0:-1
1971+8:-9
1972+281474976710656:-281474976710657
1973-1:0
1974-2:1
1975-12:11
1976&digit
19770:0:0
197812:0:2
197912:1:1
1980123:0:3
1981123:1:2
1982123:2:1
1983123:-1:1
1984123:-2:2
1985123:-3:3
1986123456:0:6
1987123456:1:5
1988123456:2:4
1989123456:3:3
1990123456:4:2
1991123456:5:1
1992123456:-1:1
1993123456:-2:2
1994123456:-3:3
1995100000:-3:0
1996100000:0:0
1997100000:1:0
1998&mantissa
1999abc:NaN
20001e4:1
20012e0:2
2002123:123
2003-1:-1
2004-2:-2
2005+inf:inf
2006-inf:-inf
2007&exponent
2008abc:NaN
20091e4:4
20102e0:0
2011123:0
2012-1:0
2013-2:0
20140:1
2015+inf:inf
2016-inf:inf
2017&parts
2018abc:NaN,NaN
20191e4:1,4
20202e0:2,0
2021123:123,0
2022-1:-1,0
2023-2:-2,0
20240:0,1
2025+inf:inf,inf
2026-inf:-inf,inf
b3abae2a 2027&bfac
2028-1:NaN
2029NaNfac:NaN
b282a552 2030+inf:inf
b3abae2a 2031-inf:NaN
20320:1
20331:1
20342:2
20353:6
20364:24
20375:120
20386:720
990fb837 20397:5040
20408:40320
20419:362880
b3abae2a 204210:3628800
204311:39916800
204412:479001600
50109ad0 204520:2432902008176640000
204622:1124000727777607680000
204769:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
6854fd01 2048&bpow
2049abc:12:NaN
205012:abc:NaN
20510:0:1
20520:1:0
20530:2:0
9b924220 20540:-1:inf
20550:-2:inf
6854fd01 20561:0:1
20571:1:1
20581:2:1
20591:3:1
20601:-1:1
20611:-2:1
20621:-3:1
20632:0:1
20642:1:2
20652:2:4
20662:3:8
20673:3:27
2d2b2744 2068-2:2:4
2069-2:3:-8
2070-2:4:16
2071-2:5:-32
6854fd01 20722:-1:NaN
2073-2:-1:NaN
20742:-2:NaN
2075-2:-2:NaN
2d2b2744 2076# inf tests
6854fd01 2077+inf:1234500012:inf
2d2b2744 2078-inf:1234500012:inf
2079-inf:1234500013:-inf
6854fd01 2080+inf:-12345000123:inf
2081-inf:-12345000123:-inf
2d2b2744 2082# -inf * -inf = inf
2083-inf:2:inf
2084-inf:0:NaN
2085-inf:-1:0
2086-inf:inf:NaN
20872:inf:inf
20882:-inf:0
20890:inf:0
20900:-inf:inf
2091-1:-inf:NaN
2092-1:inf:NaN
2093-2:inf:NaN
2094-2:-inf:0
2095NaN:inf:NaN
2096NaN:-inf:NaN
2097-inf:NaN:NaN
2098inf:NaN:NaN
2099inf:-inf:NaN
21001:inf:1
21011:-inf:1
6854fd01 2102# 1 ** -x => 1 / (1 ** x)
2103-1:0:1
2104-2:0:1
2105-1:1:-1
2106-1:2:1
2107-1:3:-1
2108-1:4:1
2109-1:5:-1
2110-1:-1:-1
2111-1:-2:1
2112-1:-3:-1
2113-1:-4:1
211410:2:100
211510:3:1000
211610:4:10000
211710:5:100000
211810:6:1000000
211910:7:10000000
212010:8:100000000
212110:9:1000000000
212210:20:100000000000000000000
2123123456:2:15241383936
9b924220 2124-2:2:4
2125-2:3:-8
2126-2:4:16
2127-2:5:-32
2128-3:2:9
2129-3:3:-27
2130-3:4:81
2131-3:5:-243
6854fd01 2132&length
2133100:3
213410:2
21351:1
21360:1
213712345:5
213810000000000000000:17
2139-123:3
2140215960156869840440586892398248:30
990fb837 2141&broot
2142# sqrt()
2143+0:2:0
2144+1:2:1
2145-1:2:NaN
2146# -$x ** (1/2) => -$y, but not in froot()
2147-123:2:NaN
2148+inf:2:inf
2149-inf:2:NaN
21502:2:1
2151-2:2:NaN
21524:2:2
21539:2:3
215416:2:4
2155100:2:10
2156123:2:11
215715241:2:123
2158144:2:12
215912:2:3
21600.49:2:0
21610.0049:2:0
2162# invalid ones
21631:NaN:NaN
2164-1:NaN:NaN
21650:NaN:NaN
2166-inf:NaN:NaN
2167+inf:NaN:NaN
2168NaN:0:NaN
2169NaN:2:NaN
2170NaN:inf:NaN
2171NaN:inf:NaN
217212:-inf:NaN
217312:inf:NaN
2174+0:0:NaN
2175+1:0:NaN
2176-1:0:NaN
2177-2:0:NaN
2178-123.45:0:NaN
2179+inf:0:NaN
218012:1:12
2181-12:1:NaN
21828:-1:NaN
2183-8:-1:NaN
2184# cubic root
21858:3:2
2186-8:3:NaN
2187# fourths root
c38b2de2 218816:4:2
218981:4:3
3a427a11 2190# 2 ** 64
c38b2de2 219118446744073709551616:4:65536
219218446744073709551616:8:256
219318446744073709551616:16:16
219418446744073709551616:32:4
219518446744073709551616:64:2
219618446744073709551616:128:1
3a427a11 2197# 213 ** 15
219884274086103068221283760416414557757:15:213
50109ad0 2199# see t/bigroot.t for more tests
6854fd01 2200&bsqrt
394e6ffb 2201145:12
6854fd01 2202144:12
394e6ffb 2203143:11
6854fd01 220416:4
394e6ffb 2205170:13
2206169:13
2207168:12
6854fd01 22084:2
394e6ffb 22093:1
6854fd01 22102:1
394e6ffb 22119:3
6854fd01 221212:3
2213256:16
2214100000000:10000
22154000000000000:2000000
394e6ffb 2216152399026:12345
2217152399025:12345
2218152399024:12344
3a427a11 2219# 2 ** 64 => 2 ** 32
222018446744073709551616:4294967296
222184274086103068221283760416414557757:290299993288095377
6854fd01 22221:1
22230:0
2224-2:NaN
394e6ffb 2225-123:NaN
6854fd01 2226Nan:NaN
990fb837 2227+inf:inf
2228-inf:NaN
50109ad0 2229# see t/biglog.t for more tests
2230&bexp
2231NaN:NaN
2232inf:inf
22331:2
22342:7
2235# see t/bignok.t for more tests
2236&bnok
2237+inf:10:inf
2238NaN:NaN:NaN
2239NaN:1:NaN
22401:NaN:NaN
22411:1:1
2242# k > n
22431:2:0
22442:3:0
2245# k < 0
22461:-2:0
2247# 7 over 3 = 35
22487:3:35
22497:6:1
2250100:90:17310309456440
2251100:95:75287520
6854fd01 2252&bround
2253$round_mode('trunc')
22540:12:0
2255NaNbround:12:NaN
2256+inf:12:inf
2257-inf:12:-inf
22581234:0:1234
22591234:2:1200
2260123456:4:123400
2261123456:5:123450
2262123456:6:123456
61f5c3f5 2263+10123456789:5:10123000000
6854fd01 2264-10123456789:5:-10123000000
61f5c3f5 2265+10123456789:9:10123456700
6854fd01 2266-10123456789:9:-10123456700
61f5c3f5 2267+101234500:6:101234000
6854fd01 2268-101234500:6:-101234000
61f5c3f5 2269#+101234500:-4:101234000
6854fd01 2270#-101234500:-4:-101234000
2271$round_mode('zero')
61f5c3f5 2272+20123456789:5:20123000000
6854fd01 2273-20123456789:5:-20123000000
61f5c3f5 2274+20123456789:9:20123456800
6854fd01 2275-20123456789:9:-20123456800
61f5c3f5 2276+201234500:6:201234000
6854fd01 2277-201234500:6:-201234000
61f5c3f5 2278#+201234500:-4:201234000
6854fd01 2279#-201234500:-4:-201234000
2280+12345000:4:12340000
2281-12345000:4:-12340000
2282$round_mode('+inf')
61f5c3f5 2283+30123456789:5:30123000000
6854fd01 2284-30123456789:5:-30123000000
61f5c3f5 2285+30123456789:9:30123456800
6854fd01 2286-30123456789:9:-30123456800
61f5c3f5 2287+301234500:6:301235000
6854fd01 2288-301234500:6:-301234000
61f5c3f5 2289#+301234500:-4:301235000
6854fd01 2290#-301234500:-4:-301234000
2291+12345000:4:12350000
2292-12345000:4:-12340000
2293$round_mode('-inf')
61f5c3f5 2294+40123456789:5:40123000000
6854fd01 2295-40123456789:5:-40123000000
61f5c3f5 2296+40123456789:9:40123456800
6854fd01 2297-40123456789:9:-40123456800
61f5c3f5 2298+401234500:6:401234000
2299+401234500:6:401234000
6854fd01 2300#-401234500:-4:-401235000
2301#-401234500:-4:-401235000
2302+12345000:4:12340000
2303-12345000:4:-12350000
2304$round_mode('odd')
61f5c3f5 2305+50123456789:5:50123000000
6854fd01 2306-50123456789:5:-50123000000
61f5c3f5 2307+50123456789:9:50123456800
6854fd01 2308-50123456789:9:-50123456800
61f5c3f5 2309+501234500:6:501235000
6854fd01 2310-501234500:6:-501235000
61f5c3f5 2311#+501234500:-4:501235000
6854fd01 2312#-501234500:-4:-501235000
2313+12345000:4:12350000
2314-12345000:4:-12350000
2315$round_mode('even')
61f5c3f5 2316+60123456789:5:60123000000
6854fd01 2317-60123456789:5:-60123000000
61f5c3f5 2318+60123456789:9:60123456800
6854fd01 2319-60123456789:9:-60123456800
61f5c3f5 2320+601234500:6:601234000
6854fd01 2321-601234500:6:-601234000
61f5c3f5 2322#+601234500:-4:601234000
6854fd01 2323#-601234500:-4:-601234000
2324#-601234500:-9:0
2325#-501234500:-9:0
2326#-601234500:-8:0
2327#-501234500:-8:0
2328+1234567:7:1234567
2329+1234567:6:1234570
2330+12345000:4:12340000
2331-12345000:4:-12340000
7b29e1e6 2332$round_mode('common')
2333+60123456789:5:60123000000
2334+60123199999:5:60123000000
2335+60123299999:5:60123000000
2336+60123399999:5:60123000000
2337+60123499999:5:60123000000
2338+60123500000:5:60124000000
2339+60123600000:5:60124000000
2340+60123700000:5:60124000000
2341+60123800000:5:60124000000
2342+60123900000:5:60124000000
2343-60123456789:5:-60123000000
2344-60123199999:5:-60123000000
2345-60123299999:5:-60123000000
2346-60123399999:5:-60123000000
2347-60123499999:5:-60123000000
2348-60123500000:5:-60124000000
2349-60123600000:5:-60124000000
2350-60123700000:5:-60124000000
2351-60123800000:5:-60124000000
2352-60123900000:5:-60124000000
6854fd01 2353&is_zero
23540:1
2355NaNzero:0
2356+inf:0
2357-inf:0
2358123:0
2359-1:0
23601:0
2361&is_one
23620:0
2363NaNone:0
2364+inf:0
2365-inf:0
23661:1
23672:0
2368-1:0
2369-2:0
2370# floor and ceil tests are pretty pointless in integer space...but play safe
2371&bfloor
23720:0
2373NaNfloor:NaN
2374+inf:inf
2375-inf:-inf
2376-1:-1
2377-2:-2
23782:2
23793:3
2380abc:NaN
2381&bceil
2382NaNceil:NaN
2383+inf:inf
2384-inf:-inf
23850:0
2386-1:-1
2387-2:-2
23882:2
23893:3
2390abc:NaN
2391&as_hex
2392128:0x80
2393-128:-0x80
23940:0x0
2395-0:0x0
23961:0x1
23970x123456789123456789:0x123456789123456789
2398+inf:inf
2399-inf:-inf
2400NaNas_hex:NaN
2401&as_bin
2402128:0b10000000
2403-128:-0b10000000
24040:0b0
2405-0:0b0
24061:0b1
24070b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 24080x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2409+inf:inf
2410-inf:-inf
2411NaNas_bin:NaN