Mention also perl56delta in case someone is upgrading from
[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
5##############################################################################
6# for testing inheritance of _swap
7
8package Math::Foo;
9
10use Math::BigInt;
11#use Math::BigInt lib => 'BitVect'; # for testing
12use vars qw/@ISA/;
13@ISA = (qw/Math::BigInt/);
14
15use overload
16# customized overload for sub, since original does not use swap there
17'-' => sub { my @a = ref($_[0])->_swap(@_);
18 $a[0]->bsub($a[1])};
19
20sub _swap
21 {
22 # a fake _swap, which reverses the params
23 my $self = shift; # for override in subclass
24 if ($_[2])
25 {
26 my $c = ref ($_[0] ) || 'Math::Foo';
27 return ( $_[0]->copy(), $_[1] );
28 }
29 else
30 {
31 return ( Math::Foo->new($_[1]), $_[0] );
32 }
33 }
34
35##############################################################################
36package main;
37
38my $CALC = $class->_core_lib(); ok ($CALC,'Math::BigInt::Calc');
39
40my ($f,$z,$a,$exp,@a,$m,$e,$round_mode);
41
42while (<DATA>)
43 {
44 chop;
45 next if /^#/; # skip comments
46 if (s/^&//)
47 {
48 $f = $_;
49 }
50 elsif (/^\$/)
51 {
52 $round_mode = $_;
53 $round_mode =~ s/^\$/$class\->/;
54 # print "$round_mode\n";
55 }
56 else
57 {
58 @args = split(/:/,$_,99);
59 $ans = pop(@args);
60 $try = "\$x = $class->new(\"$args[0]\");";
61 if ($f eq "bnorm"){
62 $try = "\$x = $class->bnorm(\"$args[0]\");";
027dc388 63 # some is_xxx tests
64 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan)$/) {
65 $try .= "\$x->$f();";
6854fd01 66 } elsif ($f eq "as_hex") {
67 $try .= '$x->as_hex();';
68 } elsif ($f eq "as_bin") {
69 $try .= '$x->as_bin();';
70 } elsif ($f eq "is_inf") {
71 $try .= "\$x->is_inf('$args[1]');";
72 } elsif ($f eq "binf") {
73 $try .= "\$x->binf('$args[1]');";
74 } elsif ($f eq "bone") {
75 $try .= "\$x->bone('$args[1]');";
027dc388 76 # some unary ops
77 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt)$/) {
78 $try .= "\$x->$f();";
6854fd01 79 }elsif ($f eq "length") {
80 $try .= '$x->length();';
81 }elsif ($f eq "exponent"){
82 # ->bstr() to see if an object is returned
83 $try .= '$x = $x->exponent()->bstr();';
84 }elsif ($f eq "mantissa"){
85 # ->bstr() to see if an object is returned
86 $try .= '$x = $x->mantissa()->bstr();';
87 }elsif ($f eq "parts"){
88 $try .= '($m,$e) = $x->parts();';
89 # ->bstr() to see if an object is returned
90 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
91 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
92 $try .= '"$m,$e";';
93 } else {
94 $try .= "\$y = $class->new('$args[1]');";
95 if ($f eq "bcmp"){
96 $try .= '$x <=> $y;';
97 }elsif ($f eq "bround") {
98 $try .= "$round_mode; \$x->bround(\$y);";
99 }elsif ($f eq "bacmp"){
100 $try .= '$x->bacmp($y);';
101 }elsif ($f eq "badd"){
102 $try .= '$x + $y;';
103 }elsif ($f eq "bsub"){
104 $try .= '$x - $y;';
105 }elsif ($f eq "bmul"){
106 $try .= '$x * $y;';
107 }elsif ($f eq "bdiv"){
108 $try .= '$x / $y;';
109 }elsif ($f eq "bdiv-list"){
110 $try .= 'join (",",$x->bdiv($y));';
027dc388 111 # overload via x=
112 }elsif ($f =~ /^.=$/){
113 $try .= "\$x $f \$y;";
114 # overload via x
115 }elsif ($f =~ /^.$/){
116 $try .= "\$x $f \$y;";
6854fd01 117 }elsif ($f eq "bmod"){
118 $try .= '$x % $y;';
119 }elsif ($f eq "bgcd")
120 {
121 if (defined $args[2])
122 {
123 $try .= " \$z = $class->new(\"$args[2]\"); ";
124 }
125 $try .= "$class\::bgcd(\$x, \$y";
126 $try .= ", \$z" if (defined $args[2]);
127 $try .= " );";
128 }
129 elsif ($f eq "blcm")
130 {
131 if (defined $args[2])
132 {
133 $try .= " \$z = $class->new(\"$args[2]\"); ";
134 }
135 $try .= "$class\::blcm(\$x, \$y";
136 $try .= ", \$z" if (defined $args[2]);
137 $try .= " );";
138 }elsif ($f eq "blsft"){
139 if (defined $args[2])
140 {
141 $try .= "\$x->blsft(\$y,$args[2]);";
142 }
143 else
144 {
145 $try .= "\$x << \$y;";
146 }
147 }elsif ($f eq "brsft"){
148 if (defined $args[2])
149 {
150 $try .= "\$x->brsft(\$y,$args[2]);";
151 }
152 else
153 {
154 $try .= "\$x >> \$y;";
155 }
156 }elsif ($f eq "band"){
157 $try .= "\$x & \$y;";
158 }elsif ($f eq "bior"){
159 $try .= "\$x | \$y;";
160 }elsif ($f eq "bxor"){
161 $try .= "\$x ^ \$y;";
162 }elsif ($f eq "bpow"){
163 $try .= "\$x ** \$y;";
164 }elsif ($f eq "digit"){
165 $try = "\$x = $class->new(\"$args[0]\"); \$x->digit($args[1]);";
166 } else { warn "Unknown op '$f'"; }
167 }
168 # print "trying $try\n";
169 $ans1 = eval $try;
170 $ans =~ s/^[+]([0-9])/$1/; # remove leading '+'
171 if ($ans eq "")
172 {
173 ok_undef ($ans1);
174 }
175 else
176 {
177 # print "try: $try ans: $ans1 $ans\n";
178 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
179 }
180 # check internal state of number objects
181 is_valid($ans1,$f) if ref $ans1;
182 }
183 } # endwhile data tests
184close DATA;
185
186# test some more
187@a = ();
188for (my $i = 1; $i < 10; $i++)
189 {
190 push @a, $i;
191 }
192ok "@a", "1 2 3 4 5 6 7 8 9";
193
194# test whether self-multiplication works correctly (result is 2**64)
195$try = "\$x = $class->new('4294967296');";
196$try .= '$a = $x->bmul($x);';
197$ans1 = eval $try;
198print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
199# test self-pow
200$try = "\$x = $class->new(10);";
201$try .= '$a = $x->bpow($x);';
202$ans1 = eval $try;
203print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
204
205# test whether op destroys args or not (should better not)
206
207$x = $class->new(3);
208$y = $class->new(4);
209$z = $x & $y;
210ok ($x,3);
211ok ($y,4);
212ok ($z,0);
213$z = $x | $y;
214ok ($x,3);
215ok ($y,4);
216ok ($z,7);
217$x = $class->new(1);
218$y = $class->new(2);
219$z = $x | $y;
220ok ($x,1);
221ok ($y,2);
222ok ($z,3);
223
224$x = $class->new(5);
225$y = $class->new(4);
226$z = $x ^ $y;
227ok ($x,5);
228ok ($y,4);
229ok ($z,1);
230
231$x = $class->new(-5); $y = -$x;
232ok ($x, -5);
233
234$x = $class->new(-5); $y = abs($x);
235ok ($x, -5);
236
237# check whether overloading cmp works
238$try = "\$x = $class->new(0);";
239$try .= "\$y = 10;";
240$try .= "'false' if \$x ne \$y;";
241$ans = eval $try;
242print "# For '$try'\n" if (!ok "$ans" , "false" );
243
244# we cant test for working cmpt with other objects here, we would need a dummy
245# object with stringify overload for this. see Math::String tests as example
246
247###############################################################################
6854fd01 248# check reversed order of arguments
027dc388 249
6854fd01 250$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
251$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
252print "# For '$try'\n" if (!ok "$ans" , "ok" );
253
254$try = "\$x = $class->new(10); \$x = 2 * \$x;";
255$try .= "'ok' if \$x == 20;"; $ans = eval $try;
256print "# For '$try'\n" if (!ok "$ans" , "ok" );
257
258$try = "\$x = $class->new(10); \$x = 2 + \$x;";
259$try .= "'ok' if \$x == 12;"; $ans = eval $try;
260print "# For '$try'\n" if (!ok "$ans" , "ok" );
261
262$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
263$try .= "'ok' if \$x == -8;"; $ans = eval $try;
264print "# For '$try'\n" if (!ok "$ans" , "ok" );
265
266$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
267$try .= "'ok' if \$x == 2;"; $ans = eval $try;
268print "# For '$try'\n" if (!ok "$ans" , "ok" );
269
027dc388 270$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
271$try .= "'ok' if \$x == 2;"; $ans = eval $try;
272print "# For '$try'\n" if (!ok "$ans" , "ok" );
273
274$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
275$try .= "'ok' if \$x == 4;"; $ans = eval $try;
276print "# For '$try'\n" if (!ok "$ans" , "ok" );
277
278$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
279$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
280print "# For '$try'\n" if (!ok "$ans" , "ok" );
281
282$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
283$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
284print "# For '$try'\n" if (!ok "$ans" , "ok" );
285
6854fd01 286###############################################################################
287# check badd(4,5) form
288
289$try = "\$x = $class\->badd(4,5);";
290$try .= "'ok' if \$x == 9;";
291$ans = eval $try;
292print "# For '$try'\n" if (!ok "$ans" , "ok" );
293
294###############################################################################
295# check undefs: NOT DONE YET
296
297###############################################################################
298# bool
299
300$x = Math::BigInt->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
301$x = Math::BigInt->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
302
303###############################################################################
304# objectify()
305
306@args = Math::BigInt::objectify(2,4,5);
307ok (scalar @args,3); # $class, 4, 5
308ok ($args[0],$class);
309ok ($args[1],4);
310ok ($args[2],5);
311
312@args = Math::BigInt::objectify(0,4,5);
313ok (scalar @args,3); # $class, 4, 5
314ok ($args[0],$class);
315ok ($args[1],4);
316ok ($args[2],5);
317
318@args = Math::BigInt::objectify(2,4,5);
319ok (scalar @args,3); # $class, 4, 5
320ok ($args[0],$class);
321ok ($args[1],4);
322ok ($args[2],5);
323
324@args = Math::BigInt::objectify(2,4,5,6,7);
325ok (scalar @args,5); # $class, 4, 5, 6, 7
326ok ($args[0],$class);
327ok ($args[1],4); ok (ref($args[1]),$args[0]);
328ok ($args[2],5); ok (ref($args[2]),$args[0]);
329ok ($args[3],6); ok (ref($args[3]),'');
330ok ($args[4],7); ok (ref($args[4]),'');
331
332@args = Math::BigInt::objectify(2,$class,4,5,6,7);
333ok (scalar @args,5); # $class, 4, 5, 6, 7
334ok ($args[0],$class);
335ok ($args[1],4); ok (ref($args[1]),$args[0]);
336ok ($args[2],5); ok (ref($args[2]),$args[0]);
337ok ($args[3],6); ok (ref($args[3]),'');
338ok ($args[4],7); ok (ref($args[4]),'');
339
340###############################################################################
341# test for floating-point input (other tests in bnorm() below)
342
343$z = 1050000000000000; # may be int on systems with 64bit?
344$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
345$z = 1e+129; # definitely a float (may fail on UTS)
346# don't compare to $z, since some Perl versions stringify $z into something
347# like '1.e+129' or something equally ugly
348$x = $class->new($z); ok ($x->bsstr(),'1e+129');
349
350###############################################################################
351# prime number tests, also test for **= and length()
352# found on: http://www.utm.edu/research/primes/notes/by_year.html
353
354# ((2^148)-1)/17
355$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
356ok ($x,"20988936657440586486151264256610222593863921");
357ok ($x->length(),length "20988936657440586486151264256610222593863921");
358
359# MM7 = 2^127-1
360$x = $class->new(2); $x **= 127; $x--;
361ok ($x,"170141183460469231731687303715884105727");
362
363$x = $class->new('215960156869840440586892398248');
364($x,$y) = $x->length();
365ok ($x,30); ok ($y,0);
366
367$x = $class->new('1_000_000_000_000');
368($x,$y) = $x->length();
369ok ($x,13); ok ($y,0);
370
371# I am afraid the following is not yet possible due to slowness
372# Also, testing for 2 meg output is a bit hard ;)
373#$x = $class->new(2); $x **= 6972593; $x--;
374
375# 593573509*2^332162+1 has exactly 1,000,000 digits
376# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
377#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
378#ok ($x->length(),1_000_000);
379
380###############################################################################
381# inheritance and overriding of _swap
382
383$x = Math::Foo->new(5);
384$x = $x - 8; # 8 - 5 instead of 5-8
385ok ($x,3);
386ok (ref($x),'Math::Foo');
387
388$x = Math::Foo->new(5);
389$x = 8 - $x; # 5 - 8 instead of 8 - 5
390ok ($x,-3);
391ok (ref($x),'Math::Foo');
392
393###############################################################################
394# Test whether +inf eq inf
395# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
396# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
397# like 1e100000 crash on some platforms. So simple test for the string 'inf'
398$x = $class->new('+inf'); ok ($x,'inf');
399
400###############################################################################
401###############################################################################
402# the followin tests only make sense with Math::BigInt::Calc
403
404exit if $CALC ne 'Math::BigInt::Calc'; # for Pari et al.
405
406###############################################################################
407# check proper length of internal arrays
408
409my $bl = Math::BigInt::Calc::_base_len();
410my $BASE = '9' x $bl;
411my $MAX = $BASE;
412$BASE++;
413
414$x = $class->new($MAX); is_valid($x); # f.i. 9999
415$x += 1; ok ($x,$BASE); is_valid($x); # 10000
416$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
417
418###############################################################################
419# check numify
420
421$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
422$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
423$x = $class->new($BASE); ok ($x->numify(),$BASE);
424$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
425$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
426ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
427
428###############################################################################
429# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
430
431$x = Math::BigInt->new(99998); $x++; $x++; $x++; $x++;
432if ($x > 100000) { ok (1,1) } else { ok ("$x < 100000","$x > 100000"); }
433
434$x = Math::BigInt->new(100003); $x++;
435$y = Math::BigInt->new(1000000);
436if ($x < 1000000) { ok (1,1) } else { ok ("$x > 1000000","$x < 1000000"); }
437
438###############################################################################
439# bug in sub where number with at least 6 trailing zeros after any op failed
440
441$x = Math::BigInt->new(123456); $z = Math::BigInt->new(10000); $z *= 10;
442$x -= $z;
443ok ($z, 100000);
444ok ($x, 23456);
445
446###############################################################################
447# bug in shortcut in mul()
448
449# construct a number with a zero-hole of BASE_LEN
450$x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
451$y = '1' x (2*$bl);
6854fd01 452$x = Math::BigInt->new($x)->bmul($y);
453# result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
454$y = ''; my $d = '';
455for (my $i = 1; $i <= $bl; $i++)
456 {
457 $y .= $i; $d = $i.$d;
458 }
6854fd01 459$y .= $bl x (3*$bl-1) . $d . '0' x $bl;
460ok ($x,$y);
461
462###############################################################################
463# bug with rest "-0" in div, causing further div()s to fail
464
465$x = Math::BigInt->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
466
467ok ($y,'0','not -0'); # not '-0'
468is_valid($y);
469
470### all tests done ############################################################
471
4721;
473
474###############################################################################
475# Perl 5.005 does not like ok ($x,undef)
476
477sub ok_undef
478 {
479 my $x = shift;
480
481 ok (1,1) and return if !defined $x;
482 ok ($x,'undef');
483 }
484
485###############################################################################
486# sub to check validity of a BigInt internally, to ensure that no op leaves a
487# number object in an invalid state (f.i. "-0")
488
489sub is_valid
490 {
491 my ($x,$f) = @_;
492
493 my $e = 0; # error?
494 # ok as reference?
495 $e = 'Not a reference to Math::BigInt' if !ref($x);
496
497 # has ok sign?
498 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
499 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
500
501 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
502 $e = $CALC->_check($x->{value}) if $e eq '0';
503
504 # test done, see if error did crop up
505 ok (1,1), return if ($e eq '0');
506
027dc388 507 ok (1,$e." after op '$f'");
6854fd01 508 }
509
510__DATA__
027dc388 511&.=
5121234:-345:1234-345
513&+=
5141:2:3
515-1:-2:-3
516&-=
5171:2:-1
518-1:-2:1
519&*=
5202:3:6
521-1:5:-5
522&%=
523100:3:1
5248:9:8
525&/=
526100:3:33
527-8:2:-4
528&|=
5292:1:3
530&&=
5315:7:5
532&^=
5335:7:2
6854fd01 534&is_negative
5350:0
536-1:1
5371:0
538+inf:0
539-inf:1
540NaNneg:0
541&is_positive
5420:1
543-1:0
5441:1
545+inf:1
546-inf:0
547NaNneg:0
548&is_odd
549abc:0
5500:0
5511:1
5523:1
553-1:1
554-3:1
55510000001:1
55610000002:0
5572:0
558&is_even
559abc:0
5600:1
5611:0
5623:0
563-1:0
564-3:0
56510000001:0
56610000002:1
5672:1
568&bacmp
569+0:-0:0
570+0:+1:-1
571-1:+1:0
572+1:-1:0
573-1:+2:-1
574+2:-1:1
575-123456789:+987654321:-1
576+123456789:-987654321:-1
577+987654321:+123456789:1
578-987654321:+123456789:1
579-123:+4567889:-1
580# NaNs
581acmpNaN:123:
582123:acmpNaN:
583acmpNaN:acmpNaN:
584# infinity
585+inf:+inf:0
586-inf:-inf:0
587+inf:-inf:0
588-inf:+inf:0
589+inf:123:1
590-inf:123:1
591+inf:-123:1
592-inf:-123:1
593# return undef
594+inf:NaN:
595NaN:inf:
596-inf:NaN:
597NaN:-inf:
598&bnorm
599123:123
600# binary input
6010babc:NaN
6020b123:NaN
6030b0:0
604-0b0:0
605-0b1:-1
6060b0001:1
6070b001:1
6080b011:3
6090b101:5
6100b1000000000000000000000000000000:1073741824
6110b_101:NaN
6120b1_0_1:5
613# hex input
614-0x0:0
6150xabcdefgh:NaN
6160x1234:4660
6170xabcdef:11259375
618-0xABCDEF:-11259375
619-0x1234:-4660
6200x12345678:305419896
6210x1_2_3_4_56_78:305419896
6220x_123:NaN
623# inf input
624inf:inf
625+inf:inf
626-inf:-inf
6270inf:NaN
027dc388 628# abnormal input
6854fd01 629:NaN
630abc:NaN
631 1 a:NaN
6321bcd2:NaN
63311111b:NaN
634+1z:NaN
635-1z:NaN
027dc388 636# only one underscore between two digits
637_123:NaN
638_123_:NaN
639123_:NaN
6401__23:NaN
6411E1__2:NaN
6421_E12:NaN
6431E_12:NaN
6441_E_12:NaN
645+_1E12:NaN
646+0_1E2:100
647+0_0_1E2:100
648-0_0_1E2:-100
649-0_0_1E+0_0_2:-100
650E1:NaN
651E23:NaN
6521.23E1:NaN
6531.23E-1:NaN
654# bug with two E's in number beeing valid
6551e2e3:NaN
6561e2r:NaN
6571e2.0:NaN
658# normal input
6854fd01 6590:0
660+0:0
661+00:0
662+000:0
663000000000000000000:0
664-0:0
665-0000:0
666+1:1
667+01:1
668+001:1
669+00000100000:100000
670123456789:123456789
671-1:-1
672-01:-1
673-001:-1
674-123456789:-123456789
675-00000100000:-100000
6761_2_3:123
6854fd01 67710000000000E-1_0:1
6781E2:100
6791E1:10
6801E0:1
6854fd01 6811.23E2:123
6854fd01 682100E-1:10
683# floating point input
027dc388 684# .2e2:20
6851.E3:1000
6854fd01 6861.01E2:101
6871010E-1:101
688-1010E0:-1010
689-1010E1:-10100
027dc388 6901234.00:1234
691# non-integer numbers
6854fd01 692-1010E-2:NaN
693-1.01E+1:NaN
694-1.01E-1:NaN
6854fd01 695&bnan
6961:NaN
6972:NaN
698abc:NaN
699&bone
7002:+:+1
7012:-:-1
702boneNaN:-:-1
703boneNaN:+:+1
7042:abc:+1
7053::+1
706&binf
7071:+:inf
7082:-:-inf
7093:abc:inf
027dc388 710&is_nan
711123:0
712abc:1
713NaN:1
714-123:0
6854fd01 715&is_inf
716+inf::1
717-inf::1
718abc::0
7191::0
720NaN::0
721-1::0
722+inf:-:0
723+inf:+:1
724-inf:-:1
725-inf:+:0
726# it must be exactly /^[+-]inf$/
727+infinity::0
728-infinity::0
729&blsft
730abc:abc:NaN
731+2:+2:+8
732+1:+32:+4294967296
733+1:+48:+281474976710656
734+8:-2:NaN
735# excercise base 10
736+12345:4:10:123450000
737-1234:0:10:-1234
738+1234:0:10:+1234
739+2:2:10:200
740+12:2:10:1200
741+1234:-3:10:NaN
7421234567890123:12:10:1234567890123000000000000
743&brsft
744abc:abc:NaN
745+8:+2:+2
746+4294967296:+32:+1
747+281474976710656:+48:+1
748+2:-2:NaN
749# excercise base 10
750-1234:0:10:-1234
751+1234:0:10:+1234
752+200:2:10:2
753+1234:3:10:1
754+1234:2:10:12
755+1234:-3:10:NaN
756310000:4:10:31
75712300000:5:10:123
7581230000000000:10:10:123
75909876123456789067890:12:10:9876123
7601234561234567890123:13:10:123456
761&bsstr
7621e+34:1e+34
763123.456E3:123456e+0
764100:1e+2
765abc:NaN
766&bneg
767bnegNaN:NaN
768+inf:-inf
769-inf:inf
770abd:NaN
771+0:+0
772+1:-1
773-1:+1
774+123456789:-123456789
775-123456789:+123456789
776&babs
777babsNaN:NaN
778+inf:inf
779-inf:inf
780+0:+0
781+1:+1
782-1:+1
783+123456789:+123456789
784-123456789:+123456789
785&bcmp
786bcmpNaN:bcmpNaN:
787bcmpNaN:+0:
788+0:bcmpNaN:
789+0:+0:0
790-1:+0:-1
791+0:-1:1
792+1:+0:1
793+0:+1:-1
794-1:+1:-1
795+1:-1:1
796-1:-1:0
797+1:+1:0
798+123:+123:0
799+123:+12:1
800+12:+123:-1
801-123:-123:0
802-123:-12:-1
803-12:-123:1
804+123:+124:-1
805+124:+123:1
806-123:-124:1
807-124:-123:-1
808+100:+5:1
809-123456789:+987654321:-1
810+123456789:-987654321:1
811-987654321:+123456789:-1
812-inf:5432112345:-1
813+inf:5432112345:1
814-inf:-5432112345:-1
815+inf:-5432112345:1
816+inf:+inf:0
817-inf:-inf:0
818+inf:-inf:1
819-inf:+inf:-1
8205:inf:-1
8215:inf:-1
822-5:-inf:1
823-5:-inf:1
824# return undef
825+inf:NaN:
826NaN:inf:
827-inf:NaN:
828NaN:-inf:
829&binc
830abc:NaN
831+inf:inf
832-inf:-inf
833+0:+1
834+1:+2
835-1:+0
836&bdec
837abc:NaN
838+inf:inf
839-inf:-inf
840+0:-1
841+1:+0
842-1:-2
843&badd
844abc:abc:NaN
845abc:+0:NaN
846+0:abc:NaN
847+inf:-inf:0
848-inf:+inf:0
849+inf:+inf:inf
850-inf:-inf:-inf
851baddNaN:+inf:NaN
852baddNaN:+inf:NaN
853+inf:baddNaN:NaN
854-inf:baddNaN:NaN
855+0:+0:+0
856+1:+0:+1
857+0:+1:+1
858+1:+1:+2
859-1:+0:-1
860+0:-1:-1
861-1:-1:-2
862-1:+1:+0
863+1:-1:+0
864+9:+1:+10
865+99:+1:+100
866+999:+1:+1000
867+9999:+1:+10000
868+99999:+1:+100000
869+999999:+1:+1000000
870+9999999:+1:+10000000
871+99999999:+1:+100000000
872+999999999:+1:+1000000000
873+9999999999:+1:+10000000000
874+99999999999:+1:+100000000000
875+10:-1:+9
876+100:-1:+99
877+1000:-1:+999
878+10000:-1:+9999
879+100000:-1:+99999
880+1000000:-1:+999999
881+10000000:-1:+9999999
882+100000000:-1:+99999999
883+1000000000:-1:+999999999
884+10000000000:-1:+9999999999
885+123456789:+987654321:+1111111110
886-123456789:+987654321:+864197532
887-123456789:-987654321:-1111111110
888+123456789:-987654321:-864197532
889&bsub
890abc:abc:NaN
891abc:+0:NaN
892+0:abc:NaN
893+inf:-inf:inf
894-inf:+inf:-inf
895+inf:+inf:0
896-inf:-inf:0
897+0:+0:+0
898+1:+0:+1
899+0:+1:-1
900+1:+1:+0
901-1:+0:-1
902+0:-1:+1
903-1:-1:+0
904-1:+1:-2
905+1:-1:+2
906+9:+1:+8
907+99:+1:+98
908+999:+1:+998
909+9999:+1:+9998
910+99999:+1:+99998
911+999999:+1:+999998
912+9999999:+1:+9999998
913+99999999:+1:+99999998
914+999999999:+1:+999999998
915+9999999999:+1:+9999999998
916+99999999999:+1:+99999999998
917+10:-1:+11
918+100:-1:+101
919+1000:-1:+1001
920+10000:-1:+10001
921+100000:-1:+100001
922+1000000:-1:+1000001
923+10000000:-1:+10000001
924+100000000:-1:+100000001
925+1000000000:-1:+1000000001
926+10000000000:-1:+10000000001
927+123456789:+987654321:-864197532
928-123456789:+987654321:-1111111110
929-123456789:-987654321:+864197532
930+123456789:-987654321:+1111111110
931&bmul
932abc:abc:NaN
933abc:+0:NaN
934+0:abc:NaN
935NaNmul:+inf:NaN
936NaNmul:-inf:NaN
937-inf:NaNmul:NaN
938+inf:NaNmul:NaN
939+inf:+inf:inf
940+inf:-inf:-inf
941-inf:+inf:-inf
942-inf:-inf:inf
943+0:+0:+0
944+0:+1:+0
945+1:+0:+0
946+0:-1:+0
947-1:+0:+0
948+123456789123456789:+0:+0
949+0:+123456789123456789:+0
950-1:-1:+1
951-1:+1:-1
952+1:-1:-1
953+1:+1:+1
954+2:+3:+6
955-2:+3:-6
956+2:-3:-6
957-2:-3:+6
958+111:+111:+12321
959+10101:+10101:+102030201
960+1001001:+1001001:+1002003002001
961+100010001:+100010001:+10002000300020001
962+10000100001:+10000100001:+100002000030000200001
963+11111111111:+9:+99999999999
964+22222222222:+9:+199999999998
965+33333333333:+9:+299999999997
966+44444444444:+9:+399999999996
967+55555555555:+9:+499999999995
968+66666666666:+9:+599999999994
969+77777777777:+9:+699999999993
970+88888888888:+9:+799999999992
971+99999999999:+9:+899999999991
972+25:+25:+625
973+12345:+12345:+152399025
974+99999:+11111:+1111088889
9759999:10000:99990000
97699999:100000:9999900000
977999999:1000000:999999000000
9789999999:10000000:99999990000000
97999999999:100000000:9999999900000000
980999999999:1000000000:999999999000000000
9819999999999:10000000000:99999999990000000000
98299999999999:100000000000:9999999999900000000000
983999999999999:1000000000000:999999999999000000000000
9849999999999999:10000000000000:99999999999990000000000000
98599999999999999:100000000000000:9999999999999900000000000000
986999999999999999:1000000000000000:999999999999999000000000000000
9879999999999999999:10000000000000000:99999999999999990000000000000000
98899999999999999999:100000000000000000:9999999999999999900000000000000000
989999999999999999999:1000000000000000000:999999999999999999000000000000000000
9909999999999999999999:10000000000000000000:99999999999999999990000000000000000000
991&bdiv-list
992100:20:5,0
9934095:4095:1,0
994-4095:-4095:1,0
9954095:-4095:-1,0
996-4095:4095:-1,0
997123:2:61,1
998# inf handling and general remainder
9995:8:0,5
10000:8:0,0
100111:2:5,1
100211:-2:-5,-1
1003-11:2:-5,1
1004# see table in documentation in MBI
10050:inf:0,0
10060:-inf:0,0
10075:inf:0,5
10085:-inf:0,5
1009-5:inf:0,-5
1010-5:-inf:0,-5
1011inf:5:inf,0
1012-inf:5:-inf,0
1013inf:-5:-inf,0
1014-inf:-5:inf,0
10155:5:1,0
1016-5:-5:1,0
1017inf:inf:1,0
1018-inf:-inf:1,0
1019-inf:inf:-1,0
1020inf:-inf:-1,0
10218:0:inf,8
1022inf:0:inf,inf
1023# exceptions to reminder rule
1024-8:0:-inf,-8
1025-inf:0:-inf,-inf
10260:0:NaN,NaN
1027&bdiv
1028abc:abc:NaN
1029abc:+1:NaN
1030+1:abc:NaN
1031+0:+0:NaN
1032# inf handling (see table in doc)
10330:inf:0
10340:-inf:0
10355:inf:0
10365:-inf:0
1037-5:inf:0
1038-5:-inf:0
1039inf:5:inf
1040-inf:5:-inf
1041inf:-5:-inf
1042-inf:-5:inf
10435:5:1
1044-5:-5:1
1045inf:inf:1
1046-inf:-inf:1
1047-inf:inf:-1
1048inf:-inf:-1
10498:0:inf
1050inf:0:inf
1051-8:0:-inf
1052-inf:0:-inf
10530:0:NaN
105411:2:5
1055-11:-2:5
1056-11:2:-5
105711:-2:-5
1058+0:+1:+0
1059+0:-1:+0
1060+1:+1:+1
1061-1:-1:+1
1062+1:-1:-1
1063-1:+1:-1
1064+1:+2:+0
1065+2:+1:+2
1066+1:+26:+0
1067+1000000000:+9:+111111111
1068+2000000000:+9:+222222222
1069+3000000000:+9:+333333333
1070+4000000000:+9:+444444444
1071+5000000000:+9:+555555555
1072+6000000000:+9:+666666666
1073+7000000000:+9:+777777777
1074+8000000000:+9:+888888888
1075+9000000000:+9:+1000000000
1076+35500000:+113:+314159
1077+71000000:+226:+314159
1078+106500000:+339:+314159
1079+1000000000:+3:+333333333
1080+10:+5:+2
1081+100:+4:+25
1082+1000:+8:+125
1083+10000:+16:+625
1084+999999999999:+9:+111111111111
1085+999999999999:+99:+10101010101
1086+999999999999:+999:+1001001001
1087+999999999999:+9999:+100010001
1088+999999999999999:+99999:+10000100001
1089+1111088889:+99999:+11111
1090-5:-3:1
1091-5:3:-1
10924:3:1
10934:-3:-1
10941:3:0
10951:-3:0
1096-2:-3:0
1097-2:3:0
10988:3:2
1099-8:3:-2
110014:-3:-4
1101-14:3:-4
1102-14:-3:4
110314:3:4
1104# bug in Calc with '99999' vs $BASE-1
110510000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1106&bmod
1107# inf handling, see table in doc
11080:inf:0
11090:-inf:0
11105:inf:5
11115:-inf:5
1112-5:inf:-5
1113-5:-inf:-5
1114inf:5:0
1115-inf:5:0
1116inf:-5:0
1117-inf:-5:0
11185:5:0
1119-5:-5:0
1120inf:inf:0
1121-inf:-inf:0
1122-inf:inf:0
1123inf:-inf:0
11248:0:8
1125inf:0:inf
1126# exceptions to reminder rule
1127-inf:0:-inf
1128-8:0:-8
11290:0:NaN
1130abc:abc:NaN
1131abc:+1:abc:NaN
1132+1:abc:NaN
1133+0:+0:NaN
1134+0:+1:+0
1135+1:+0:+1
1136+0:-1:+0
1137-1:+0:-1
1138+1:+1:+0
1139-1:-1:+0
1140+1:-1:+0
1141-1:+1:+0
1142+1:+2:+1
1143+2:+1:+0
1144+1000000000:+9:+1
1145+2000000000:+9:+2
1146+3000000000:+9:+3
1147+4000000000:+9:+4
1148+5000000000:+9:+5
1149+6000000000:+9:+6
1150+7000000000:+9:+7
1151+8000000000:+9:+8
1152+9000000000:+9:+0
1153+35500000:+113:+33
1154+71000000:+226:+66
1155+106500000:+339:+99
1156+1000000000:+3:+1
1157+10:+5:+0
1158+100:+4:+0
1159+1000:+8:+0
1160+10000:+16:+0
1161+999999999999:+9:+0
1162+999999999999:+99:+0
1163+999999999999:+999:+0
1164+999999999999:+9999:+0
1165+999999999999999:+99999:+0
1166-9:+5:+1
1167+9:-5:-1
1168-9:-5:-4
1169-5:3:1
1170-2:3:1
11714:3:1
11721:3:1
1173-5:-3:-2
1174-2:-3:-2
11754:-3:-2
11761:-3:-2
11774095:4095:0
027dc388 1178100041000510123:3:0
1179152403346:12345:4321
6854fd01 1180&bgcd
1181abc:abc:NaN
1182abc:+0:NaN
1183+0:abc:NaN
1184+0:+0:+0
1185+0:+1:+1
1186+1:+0:+1
1187+1:+1:+1
1188+2:+3:+1
1189+3:+2:+1
1190-3:+2:+1
1191+100:+625:+25
1192+4096:+81:+1
1193+1034:+804:+2
1194+27:+90:+56:+1
1195+27:+90:+54:+9
1196&blcm
1197abc:abc:NaN
1198abc:+0:NaN
1199+0:abc:NaN
1200+0:+0:NaN
1201+1:+0:+0
1202+0:+1:+0
1203+27:+90:+270
1204+1034:+804:+415668
1205&band
1206abc:abc:NaN
1207abc:0:NaN
12080:abc:NaN
12091:2:0
12103:2:2
1211+8:+2:+0
1212+281474976710656:+0:+0
1213+281474976710656:+1:+0
1214+281474976710656:+281474976710656:+281474976710656
1215-2:-3:-4
1216-1:-1:-1
1217-6:-6:-6
1218-7:-4:-8
1219-7:4:0
1220-4:7:4
1221&bior
1222abc:abc:NaN
1223abc:0:NaN
12240:abc:NaN
12251:2:3
1226+8:+2:+10
1227+281474976710656:+0:+281474976710656
1228+281474976710656:+1:+281474976710657
1229+281474976710656:+281474976710656:+281474976710656
1230-2:-3:-1
1231-1:-1:-1
1232-6:-6:-6
1233-7:4:-3
1234-4:7:-1
1235&bxor
1236abc:abc:NaN
1237abc:0:NaN
12380:abc:NaN
12391:2:3
1240+8:+2:+10
1241+281474976710656:+0:+281474976710656
1242+281474976710656:+1:+281474976710657
1243+281474976710656:+281474976710656:+0
1244-2:-3:3
1245-1:-1:0
1246-6:-6:0
1247-7:4:-3
1248-4:7:-5
12494:-7:-3
1250-4:-7:5
1251&bnot
1252abc:NaN
1253+0:-1
1254+8:-9
1255+281474976710656:-281474976710657
1256-1:0
1257-2:1
1258-12:11
1259&digit
12600:0:0
126112:0:2
126212:1:1
1263123:0:3
1264123:1:2
1265123:2:1
1266123:-1:1
1267123:-2:2
1268123:-3:3
1269123456:0:6
1270123456:1:5
1271123456:2:4
1272123456:3:3
1273123456:4:2
1274123456:5:1
1275123456:-1:1
1276123456:-2:2
1277123456:-3:3
1278100000:-3:0
1279100000:0:0
1280100000:1:0
1281&mantissa
1282abc:NaN
12831e4:1
12842e0:2
1285123:123
1286-1:-1
1287-2:-2
1288+inf:inf
1289-inf:-inf
1290&exponent
1291abc:NaN
12921e4:4
12932e0:0
1294123:0
1295-1:0
1296-2:0
12970:1
1298+inf:inf
1299-inf:inf
1300&parts
1301abc:NaN,NaN
13021e4:1,4
13032e0:2,0
1304123:123,0
1305-1:-1,0
1306-2:-2,0
13070:0,1
1308+inf:inf,inf
1309-inf:-inf,inf
1310&bpow
1311abc:12:NaN
131212:abc:NaN
13130:0:1
13140:1:0
13150:2:0
13160:-1:NaN
13170:-2:NaN
13181:0:1
13191:1:1
13201:2:1
13211:3:1
13221:-1:1
13231:-2:1
13241:-3:1
13252:0:1
13262:1:2
13272:2:4
13282:3:8
13293:3:27
13302:-1:NaN
1331-2:-1:NaN
13322:-2:NaN
1333-2:-2:NaN
1334+inf:1234500012:inf
1335-inf:1234500012:-inf
1336+inf:-12345000123:inf
1337-inf:-12345000123:-inf
1338# 1 ** -x => 1 / (1 ** x)
1339-1:0:1
1340-2:0:1
1341-1:1:-1
1342-1:2:1
1343-1:3:-1
1344-1:4:1
1345-1:5:-1
1346-1:-1:-1
1347-1:-2:1
1348-1:-3:-1
1349-1:-4:1
135010:2:100
135110:3:1000
135210:4:10000
135310:5:100000
135410:6:1000000
135510:7:10000000
135610:8:100000000
135710:9:1000000000
135810:20:100000000000000000000
1359123456:2:15241383936
1360&length
1361100:3
136210:2
13631:1
13640:1
136512345:5
136610000000000000000:17
1367-123:3
1368215960156869840440586892398248:30
1369&bsqrt
1370144:12
137116:4
13724:2
13732:1
137412:3
1375256:16
1376100000000:10000
13774000000000000:2000000
13781:1
13790:0
1380-2:NaN
1381Nan:NaN
1382&bround
1383$round_mode('trunc')
13840:12:0
1385NaNbround:12:NaN
1386+inf:12:inf
1387-inf:12:-inf
13881234:0:1234
13891234:2:1200
1390123456:4:123400
1391123456:5:123450
1392123456:6:123456
1393+10123456789:5:+10123000000
1394-10123456789:5:-10123000000
1395+10123456789:9:+10123456700
1396-10123456789:9:-10123456700
1397+101234500:6:+101234000
1398-101234500:6:-101234000
1399#+101234500:-4:+101234000
1400#-101234500:-4:-101234000
1401$round_mode('zero')
1402+20123456789:5:+20123000000
1403-20123456789:5:-20123000000
1404+20123456789:9:+20123456800
1405-20123456789:9:-20123456800
1406+201234500:6:+201234000
1407-201234500:6:-201234000
1408#+201234500:-4:+201234000
1409#-201234500:-4:-201234000
1410+12345000:4:12340000
1411-12345000:4:-12340000
1412$round_mode('+inf')
1413+30123456789:5:+30123000000
1414-30123456789:5:-30123000000
1415+30123456789:9:+30123456800
1416-30123456789:9:-30123456800
1417+301234500:6:+301235000
1418-301234500:6:-301234000
1419#+301234500:-4:+301235000
1420#-301234500:-4:-301234000
1421+12345000:4:12350000
1422-12345000:4:-12340000
1423$round_mode('-inf')
1424+40123456789:5:+40123000000
1425-40123456789:5:-40123000000
1426+40123456789:9:+40123456800
1427-40123456789:9:-40123456800
1428+401234500:6:+401234000
1429+401234500:6:+401234000
1430#-401234500:-4:-401235000
1431#-401234500:-4:-401235000
1432+12345000:4:12340000
1433-12345000:4:-12350000
1434$round_mode('odd')
1435+50123456789:5:+50123000000
1436-50123456789:5:-50123000000
1437+50123456789:9:+50123456800
1438-50123456789:9:-50123456800
1439+501234500:6:+501235000
1440-501234500:6:-501235000
1441#+501234500:-4:+501235000
1442#-501234500:-4:-501235000
1443+12345000:4:12350000
1444-12345000:4:-12350000
1445$round_mode('even')
1446+60123456789:5:+60123000000
1447-60123456789:5:-60123000000
1448+60123456789:9:+60123456800
1449-60123456789:9:-60123456800
1450+601234500:6:+601234000
1451-601234500:6:-601234000
1452#+601234500:-4:+601234000
1453#-601234500:-4:-601234000
1454#-601234500:-9:0
1455#-501234500:-9:0
1456#-601234500:-8:0
1457#-501234500:-8:0
1458+1234567:7:1234567
1459+1234567:6:1234570
1460+12345000:4:12340000
1461-12345000:4:-12340000
1462&is_zero
14630:1
1464NaNzero:0
1465+inf:0
1466-inf:0
1467123:0
1468-1:0
14691:0
1470&is_one
14710:0
1472NaNone:0
1473+inf:0
1474-inf:0
14751:1
14762:0
1477-1:0
1478-2:0
1479# floor and ceil tests are pretty pointless in integer space...but play safe
1480&bfloor
14810:0
1482NaNfloor:NaN
1483+inf:inf
1484-inf:-inf
1485-1:-1
1486-2:-2
14872:2
14883:3
1489abc:NaN
1490&bceil
1491NaNceil:NaN
1492+inf:inf
1493-inf:-inf
14940:0
1495-1:-1
1496-2:-2
14972:2
14983:3
1499abc:NaN
1500&as_hex
1501128:0x80
1502-128:-0x80
15030:0x0
1504-0:0x0
15051:0x1
15060x123456789123456789:0x123456789123456789
1507+inf:inf
1508-inf:-inf
1509NaNas_hex:NaN
1510&as_bin
1511128:0b10000000
1512-128:-0b10000000
15130:0b0
1514-0:0b0
15151:0b1
15160b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1517+inf:inf
1518-inf:-inf
1519NaNas_bin:NaN