Math::BigInt 1.35 from Tels.
[p5sagit/p5-mst-13.2.git] / t / lib / bigintpm.t
CommitLineData
58cde26e 1#!/usr/bin/perl -w
748a9306 2
58cde26e 3use strict;
4use Test;
5
6BEGIN
7 {
8 $| = 1;
9 # chdir 't' if -d 't';
10 unshift @INC, '../lib'; # for running manually
11 plan tests => 1190;
12 }
13
14##############################################################################
15# for testing inheritance of _swap
16
17package Math::Foo;
18
19use Math::BigInt;
20use vars qw/@ISA/;
21@ISA = (qw/Math::BigInt/);
22
23use overload
24# customized overload for sub, since original does not use swap there
25'-' => sub { my @a = ref($_[0])->_swap(@_);
26 $a[0]->bsub($a[1])};
27
28sub _swap
29 {
30 # a fake _swap, which reverses the params
31 my $self = shift; # for override in subclass
32 if ($_[2])
33 {
34 my $c = ref ($_[0] ) || 'Math::Foo';
35 return ( $_[0]->copy(), $_[1] );
36 }
37 else
38 {
39 return ( Math::Foo->new($_[1]), $_[0] );
40 }
41 }
42
43##############################################################################
44package main;
d1f8c7a4 45
748a9306 46use Math::BigInt;
47
58cde26e 48my (@args,$f,$try,$x,$y,$z,$a,$exp,$ans,$ans1,@a,$m,$e,$round_mode);
49
50while (<DATA>)
51 {
52 chop;
53 next if /^#/; # skip comments
54 if (s/^&//)
55 {
56 $f = $_;
57 }
58 elsif (/^\$/)
59 {
60 $round_mode = $_;
61 $round_mode =~ s/^\$/Math::BigInt->/;
62 # print "$round_mode\n";
63 }
64 else
65 {
66 @args = split(/:/,$_,99);
67 $ans = pop(@args);
68 $try = "\$x = Math::BigInt->new(\"$args[0]\");";
69 if ($f eq "bnorm"){
70 # $try .= '$x+0;';
71 } elsif ($f eq "_set") {
72 $try .= '$x->_set($args[1]); "$x";';
73 } elsif ($f eq "is_zero") {
74 $try .= '$x->is_zero()+0;';
75 } elsif ($f eq "is_one") {
76 $try .= '$x->is_one()+0;';
77 } elsif ($f eq "is_odd") {
78 $try .= '$x->is_odd()+0;';
79 } elsif ($f eq "is_even") {
80 $try .= '$x->is_even()+0;';
81 } elsif ($f eq "binf") {
82 $try .= "\$x->binf('$args[1]');";
83 } elsif ($f eq "bfloor") {
84 $try .= '$x->bfloor();';
85 } elsif ($f eq "bceil") {
86 $try .= '$x->bceil();';
87 } elsif ($f eq "is_inf") {
88 $try .= "\$x->is_inf('$args[1]')+0;";
89 } elsif ($f eq "bsstr") {
90 $try .= '$x->bsstr();';
91 } elsif ($f eq "bneg") {
92 $try .= '-$x;';
93 } elsif ($f eq "babs") {
94 $try .= 'abs $x;';
95 } elsif ($f eq "binc") {
96 $try .= '++$x;';
97 } elsif ($f eq "bdec") {
98 $try .= '--$x;';
99 }elsif ($f eq "bnot") {
100 $try .= '~$x;';
101 }elsif ($f eq "bsqrt") {
102 $try .= '$x->bsqrt();';
103 }elsif ($f eq "length") {
104 $try .= "\$x->length();";
105 }elsif ($f eq "bround") {
106 $try .= "$round_mode; \$x->bround($args[1]);";
107 }elsif ($f eq "exponent"){
108 $try .= '$x = $x->exponent()->bstr();';
109 }elsif ($f eq "mantissa"){
110 $try .= '$x = $x->mantissa()->bstr();';
111 }elsif ($f eq "parts"){
112 $try .= "(\$m,\$e) = \$x->parts();";
113 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
114 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
115 $try .= '"$m,$e";';
116 } else {
117 $try .= "\$y = new Math::BigInt \"$args[1]\";";
118 if ($f eq "bcmp"){
119 $try .= '$x <=> $y;';
120 }elsif ($f eq "bacmp"){
121 $try .= '$x->bacmp($y);';
122 }elsif ($f eq "badd"){
123 $try .= "\$x + \$y;";
124 }elsif ($f eq "bsub"){
125 $try .= "\$x - \$y;";
126 }elsif ($f eq "bmul"){
127 $try .= "\$x * \$y;";
128 }elsif ($f eq "bdiv"){
129 $try .= "\$x / \$y;";
130 }elsif ($f eq "bmod"){
131 $try .= "\$x % \$y;";
132 }elsif ($f eq "bgcd")
133 {
134 if (defined $args[2])
135 {
136 $try .= " \$z = new Math::BigInt \"$args[2]\"; ";
137 }
138 $try .= "Math::BigInt::bgcd(\$x, \$y";
139 $try .= ", \$z" if (defined $args[2]);
140 $try .= " );";
141 }
142 elsif ($f eq "blcm")
143 {
144 if (defined $args[2])
145 {
146 $try .= " \$z = new Math::BigInt \"$args[2]\"; ";
147 }
148 $try .= "Math::BigInt::blcm(\$x, \$y";
149 $try .= ", \$z" if (defined $args[2]);
150 $try .= " );";
151 }elsif ($f eq "blsft"){
152 if (defined $args[2])
153 {
154 $try .= "\$x->blsft(\$y,$args[2]);";
155 }
156 else
157 {
158 $try .= "\$x << \$y;";
159 }
160 }elsif ($f eq "brsft"){
161 if (defined $args[2])
162 {
163 $try .= "\$x->brsft(\$y,$args[2]);";
164 }
165 else
166 {
167 $try .= "\$x >> \$y;";
168 }
169 }elsif ($f eq "band"){
170 $try .= "\$x & \$y;";
171 }elsif ($f eq "bior"){
172 $try .= "\$x | \$y;";
173 }elsif ($f eq "bxor"){
174 $try .= "\$x ^ \$y;";
175 }elsif ($f eq "bpow"){
176 $try .= "\$x ** \$y;";
177 }elsif ($f eq "digit"){
178 $try = "\$x = Math::BigInt->new(\"$args[0]\"); \$x->digit($args[1]);";
179 } else { warn "Unknown op '$f'"; }
180 }
181 # print "trying $try\n";
182 $ans1 = eval $try;
183 $ans =~ s/^[+]([0-9])/$1/; # remove leading '+'
184 if ($ans eq "")
185 {
186 ok_undef ($ans1);
187 }
188 else
189 {
190 #print "try: $try ans: $ans1 $ans\n";
191 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
192 }
193 # check internal state of number objects
194 is_valid($ans1) if ref $ans1;
195 }
196 } # endwhile data tests
197close DATA;
198
199# test whether constant works or not
200$try = "use Math::BigInt (1.31,'babs',':constant');";
201$try .= ' $x = 2**150; babs($x); $x = "$x";';
202$ans1 = eval $try;
203
204ok ( $ans1, "1427247692705959881058285969449495136382746624");
205
206# test some more
207@a = ();
208for (my $i = 1; $i < 10; $i++)
209 {
210 push @a, $i;
211 }
212ok "@a", "1 2 3 4 5 6 7 8 9";
213
214# test whether selfmultiplication works correctly (result is 2**64)
215$try = '$x = new Math::BigInt "+4294967296";';
216$try .= '$a = $x->bmul($x);';
217$ans1 = eval $try;
218print "# Tried: '$try'\n" if !ok ($ans1, Math::BigInt->new(2) ** 64);
219
220# test whether op detroys args or not (should better not)
221
222$x = new Math::BigInt (3);
223$y = new Math::BigInt (4);
224$z = $x & $y;
225ok ($x,3);
226ok ($y,4);
227ok ($z,0);
228$z = $x | $y;
229ok ($x,3);
230ok ($y,4);
231ok ($z,7);
232$x = new Math::BigInt (1);
233$y = new Math::BigInt (2);
234$z = $x | $y;
235ok ($x,1);
236ok ($y,2);
237ok ($z,3);
238
239$x = new Math::BigInt (5);
240$y = new Math::BigInt (4);
241$z = $x ^ $y;
242ok ($x,5);
243ok ($y,4);
244ok ($z,1);
245
246$x = new Math::BigInt (-5); $y = -$x;
247ok ($x, -5);
248
249$x = new Math::BigInt (-5); $y = abs($x);
250ok ($x, -5);
251
252# check whether overloading cmp works
253$try = "\$x = Math::BigInt->new(0);";
254$try .= "\$y = 10;";
255$try .= "'false' if \$x ne \$y;";
256$ans = eval $try;
257print "# For '$try'\n" if (!ok "$ans" , "false" );
258
259# we cant test for working cmpt with other objects here, we would need a dummy
260# object with stringify overload for this. see Math::String tests
261
262###############################################################################
263# check shortcuts
264$try = "\$x = Math::BigInt->new(1); \$x += 9;";
265$try .= "'ok' if \$x == 10;";
266$ans = eval $try;
267print "# For '$try'\n" if (!ok "$ans" , "ok" );
268
269$try = "\$x = Math::BigInt->new(1); \$x -= 9;";
270$try .= "'ok' if \$x == -8;";
271$ans = eval $try;
272print "# For '$try'\n" if (!ok "$ans" , "ok" );
273
274$try = "\$x = Math::BigInt->new(1); \$x *= 9;";
275$try .= "'ok' if \$x == 9;";
276$ans = eval $try;
277print "# For '$try'\n" if (!ok "$ans" , "ok" );
278
279$try = "\$x = Math::BigInt->new(10); \$x /= 2;";
280$try .= "'ok' if \$x == 5;";
281$ans = eval $try;
282print "# For '$try'\n" if (!ok "$ans" , "ok" );
283
284###############################################################################
285# check reversed order of arguments
286$try = "\$x = Math::BigInt->new(10); \$x = 2 ** \$x;";
287$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
288print "# For '$try'\n" if (!ok "$ans" , "ok" );
289
290$try = "\$x = Math::BigInt->new(10); \$x = 2 * \$x;";
291$try .= "'ok' if \$x == 20;"; $ans = eval $try;
292print "# For '$try'\n" if (!ok "$ans" , "ok" );
293
294$try = "\$x = Math::BigInt->new(10); \$x = 2 + \$x;";
295$try .= "'ok' if \$x == 12;"; $ans = eval $try;
296print "# For '$try'\n" if (!ok "$ans" , "ok" );
297
298$try = "\$x = Math::BigInt->new(10); \$x = 2 - \$x;";
299$try .= "'ok' if \$x == -8;"; $ans = eval $try;
300print "# For '$try'\n" if (!ok "$ans" , "ok" );
301
302$try = "\$x = Math::BigInt->new(10); \$x = 20 / \$x;";
303$try .= "'ok' if \$x == 2;"; $ans = eval $try;
304print "# For '$try'\n" if (!ok "$ans" , "ok" );
305
306###############################################################################
307# check badd(4,5) form
308
309$try = "\$x = Math::BigInt::badd(4,5);";
310$try .= "'ok' if \$x == 9;";
311$ans = eval $try;
312print "# For '$try'\n" if (!ok "$ans" , "ok" );
313
314$try = "\$x = Math::BigInt->badd(4,5);";
315$try .= "'ok' if \$x == 9;";
316$ans = eval $try;
317print "# For '$try'\n" if (!ok "$ans" , "ok" );
318
319###############################################################################
320# check proper length of internal arrays
321
322$x = Math::BigInt->new(99999);
323ok ($x,99999);
324ok (scalar @{$x->{value}}, 1);
325$x += 1;
326ok ($x,100000);
327ok (scalar @{$x->{value}}, 2);
328$x -= 1;
329ok ($x,99999);
330ok (scalar @{$x->{value}}, 1);
331
332###############################################################################
333# check numify
334
335my $BASE = int(1e5);
336$x = Math::BigInt->new($BASE-1); ok ($x->numify(),$BASE-1);
337$x = Math::BigInt->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
338$x = Math::BigInt->new($BASE); ok ($x->numify(),$BASE);
339$x = Math::BigInt->new(-$BASE); ok ($x->numify(),-$BASE);
340$x = Math::BigInt->new( -($BASE*$BASE*1+$BASE*1+1) );
341ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
342
343###############################################################################
344# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
345
346$x = Math::BigInt->new(99998); $x++; $x++; $x++; $x++;
347if ($x > 100000) { ok (1,1) } else { ok ("$x < 100000","$x > 100000"); }
348
349$x = Math::BigInt->new(100003); $x++;
350$y = Math::BigInt->new(1000000);
351if ($x < 1000000) { ok (1,1) } else { ok ("$x > 1000000","$x < 1000000"); }
352
353###############################################################################
354# bug in sub where number with at least 6 trailing zeros after any op failed
355
356$x = Math::BigInt->new(123456); $z = Math::BigInt->new(10000); $z *= 10;
357$x -= $z;
358ok ($z, 100000);
359ok ($x, 23456);
360
361###############################################################################
362# bug with rest "-0" in div, causing further div()s to fail
363
364$x = Math::BigInt->new(-322056000); ($x,$y) = $x->bdiv('-12882240');
365
366ok ($y,'0'); # not '-0'
367is_valid($y);
368
369###############################################################################
370# check undefs: NOT DONE YET
371
372###############################################################################
373# bool
374
375$x = Math::BigInt->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
376$x = Math::BigInt->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
377
378###############################################################################
379# objectify()
380
381@args = Math::BigInt::objectify(2,4,5);
382ok (scalar @args,3); # 'Math::BigInt', 4, 5
383ok ($args[0],'Math::BigInt');
384ok ($args[1],4);
385ok ($args[2],5);
386
387@args = Math::BigInt::objectify(0,4,5);
388ok (scalar @args,3); # 'Math::BigInt', 4, 5
389ok ($args[0],'Math::BigInt');
390ok ($args[1],4);
391ok ($args[2],5);
392
393@args = Math::BigInt::objectify(2,4,5);
394ok (scalar @args,3); # 'Math::BigInt', 4, 5
395ok ($args[0],'Math::BigInt');
396ok ($args[1],4);
397ok ($args[2],5);
398
399@args = Math::BigInt::objectify(2,4,5,6,7);
400ok (scalar @args,5); # 'Math::BigInt', 4, 5, 6, 7
401ok ($args[0],'Math::BigInt');
402ok ($args[1],4); ok (ref($args[1]),$args[0]);
403ok ($args[2],5); ok (ref($args[2]),$args[0]);
404ok ($args[3],6); ok (ref($args[3]),'');
405ok ($args[4],7); ok (ref($args[4]),'');
406
407@args = Math::BigInt::objectify(2,'Math::BigInt',4,5,6,7);
408ok (scalar @args,5); # 'Math::BigInt', 4, 5, 6, 7
409ok ($args[0],'Math::BigInt');
410ok ($args[1],4); ok (ref($args[1]),$args[0]);
411ok ($args[2],5); ok (ref($args[2]),$args[0]);
412ok ($args[3],6); ok (ref($args[3]),'');
413ok ($args[4],7); ok (ref($args[4]),'');
414
415###############################################################################
416# test for flaoting-point input (other tests in bnorm() below)
417
418$z = 1050000000000000; # may be int on systems with 64bit?
419$x = Math::BigInt->new($z); ok ($x->bsstr(),'105e+13'); # not 1.03e+15?
420$z = 1e+129; # definitely a float
421$x = Math::BigInt->new($z); ok ($x->bsstr(),$z);
422
423###############################################################################
424# prime number tests, also test for **= and length()
425# found on: http://www.utm.edu/research/primes/notes/by_year.html
426
427# ((2^148)-1)/17
428$x = Math::BigInt->new(2); $x **= 148; $x++; $x = $x / 17;
429ok ($x,"20988936657440586486151264256610222593863921");
430ok ($x->length(),length "20988936657440586486151264256610222593863921");
431
432# MM7 = 2^127-1
433$x = Math::BigInt->new(2); $x **= 127; $x--;
434ok ($x,"170141183460469231731687303715884105727");
435
436# I am afraid the following is not yet possible due to slowness
437# Also, testing for 2 meg output is a bit hard ;)
438#$x = new Math::BigInt(2); $x **= 6972593; $x--;
439
440# 593573509*2^332162+1 has exactly 100.000 digits
441# takes over 16 mins and still not complete, so can not be done yet ;)
442#$x = Math::BigInt->new(2); $x **= 332162; $x *= "593573509"; $x++;
443#ok ($x->digits(),100000);
444
445###############################################################################
446# inheritance and overriding of _swap
447
448$x = Math::Foo->new(5);
449$x = $x - 8; # 8 - 5 instead of 5-8
450ok ($x,3);
451ok (ref($x),'Math::Foo');
452
453$x = Math::Foo->new(5);
454$x = 8 - $x; # 5 - 8 instead of 8 - 5
455ok ($x,-3);
456ok (ref($x),'Math::Foo');
457
458###############################################################################
459# all tests done
460
461# devel test, see whether valid catches errors
462#$x = Math::BigInt->new(0);
463#$x->{sign} = '-';
464#is_valid($x); # nok
465#
466#$x->{sign} = 'e';
467#is_valid($x); # nok
468#
469#$x->{value}->[0] = undef;
470#is_valid($x); # nok
471#
472#$x->{value}->[0] = 1e6;
473#is_valid($x); # nok
474#
475#$x->{value}->[0] = -2;
476#is_valid($x); # nok
477#
478#$x->{sign} = '+';
479#is_valid($x); # ok
480
481###############################################################################
482# Perl 5.005 does not like ok ($x,undef)
483
484sub ok_undef
485 {
486 my $x = shift;
487
488 ok (1,1) and return if !defined $x;
489 ok ($x,'undef');
490 }
491
492###############################################################################
493# sub to check validity of a BigInt internally, to ensure that no op leaves a
494# number object in an invalid state (f.i. "-0")
495
496sub is_valid
497 {
498 my $x = shift;
499
500 my $error = ["",];
501
502 # ok as reference?
503 is_okay('ref($x)','Math::BigInt',ref($x),$error);
504
505 # has ok sign?
506 is_okay('$x->{sign}',"'+', '-', '-inf', '+inf' or 'NaN'",$x->{sign},$error)
507 if $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
508
509 # is not -0?
510 if (($x->{sign} eq '-') && (@{$x->{value}} == 1) && ($x->{value}->[0] == 0))
511 {
512 is_okay("\$x ne '-0'","0",$x,$error);
513 }
514 # all parts are valid?
515 my $i = 0; my $j = scalar @{$x->{value}}; my $e; my $try;
516 while ($i < $j)
517 {
518 $e = $x->{value}->[$i]; $e = 'undef' unless defined $e;
519 $try = '=~ /^[\+]?[0-9]+\$/; '."($f, $x, $e)";
520 last if $e !~ /^[+]?[0-9]+$/;
521 $try = ' < 0 || >= 1e5; '."($f, $x, $e)";
522 last if $e <0 || $e >= 1e5;
523 # this test is disabled, since new/bnorm and certain ops (like early out
524 # in add/sub) are allowed/expected to leave '00000' in some elements
525 #$try = '=~ /^00+/; '."($f, $x, $e)";
526 #last if $e =~ /^00+/;
527 $i++;
528 }
529 is_okay("\$x->{value}->[$i] $try","not $e",$e,$error)
530 if $i < $j; # trough all?
531
532 # see whether errors crop up
533 $error->[1] = 'undef' unless defined $error->[1];
534 if ($error->[0] ne "")
535 {
536 ok ($error->[1],$error->[2]);
537 print "# Tried: $error->[0]\n";
538 }
539 else
540 {
541 ok (1,1);
542 }
543 }
544
545sub is_okay
546 {
547 my ($tried,$expected,$try,$error) = @_;
548
549 return if $error->[0] ne ""; # error, no further testing
550
551 @$error = ( $tried, $try, $expected ) if $try ne $expected;
a99f8827 552 }
58cde26e 553
748a9306 554__END__
555&bnorm
58cde26e 556# binary input
5570babc:NaN
5580b123:NaN
5590b0:0
560-0b0:0
561-0b1:-1
5620b0001:1
5630b001:1
5640b011:3
5650b101:5
5660b1000000000000000000000000000000:1073741824
567# hex input
568-0x0:0
5690xabcdefgh:NaN
5700x1234:4660
5710xabcdef:11259375
572-0xABCDEF:-11259375
573-0x1234:-4660
5740x12345678:305419896
575# inf input
576+inf:+inf
577-inf:-inf
5780inf:NaN
579# normal input
580:NaN
748a9306 581abc:NaN
582 1 a:NaN
5831bcd2:NaN
58411111b:NaN
585+1z:NaN
586-1z:NaN
58cde26e 5870:0
588+0:0
589+00:0
590+000:0
591000000000000000000:0
592-0:0
593-0000:0
594+1:1
595+01:1
596+001:1
597+00000100000:100000
598123456789:123456789
748a9306 599-1:-1
600-01:-1
601-001:-1
602-123456789:-123456789
603-00000100000:-100000
58cde26e 6041_2_3:123
605_123:NaN
606_123_:NaN
607_123_:NaN
6081__23:NaN
60910000000000E-1_0:1
6101E2:100
6111E1:10
6121E0:1
613E1:NaN
614E23:NaN
6151.23E2:123
6161.23E1:NaN
6171.23E-1:NaN
618100E-1:10
619# floating point input
6201.01E2:101
6211010E-1:101
622-1010E0:-1010
623-1010E1:-10100
624-1010E-2:NaN
625-1.01E+1:NaN
626-1.01E-1:NaN
627&binf
6281:+:+inf
6292:-:-inf
6303:abc:+inf
631&is_inf
632+inf::1
633-inf::1
634abc::0
6351::0
636NaN::0
637-1::0
638+inf:-:0
639+inf:+:1
640-inf:-:1
641-inf:+:0
642&blsft
643abc:abc:NaN
644+2:+2:+8
645+1:+32:+4294967296
646+1:+48:+281474976710656
647+8:-2:NaN
648# excercise base 10
649+12345:4:10:123450000
650-1234:0:10:-1234
651+1234:0:10:+1234
652+2:2:10:200
653+12:2:10:1200
654+1234:-3:10:NaN
6551234567890123:12:10:1234567890123000000000000
656&brsft
657abc:abc:NaN
658+8:+2:+2
659+4294967296:+32:+1
660+281474976710656:+48:+1
661+2:-2:NaN
662# excercise base 10
663-1234:0:10:-1234
664+1234:0:10:+1234
665+200:2:10:2
666+1234:3:10:1
667+1234:2:10:12
668+1234:-3:10:NaN
669310000:4:10:31
67012300000:5:10:123
6711230000000000:10:10:123
67209876123456789067890:12:10:9876123
6731234561234567890123:13:10:123456
674&bsstr
6751e+34:1e+34
676123.456E3:123456e+0
677100:1e+2
678abc:NaN
748a9306 679&bneg
680abd:NaN
681+0:+0
682+1:-1
683-1:+1
684+123456789:-123456789
685-123456789:+123456789
686&babs
687abc:NaN
688+0:+0
689+1:+1
690-1:+1
691+123456789:+123456789
692-123456789:+123456789
693&bcmp
5d7098d5 694abc:abc:
695abc:+0:
696+0:abc:
697+0:+0:0
748a9306 698-1:+0:-1
5d7098d5 699+0:-1:1
700+1:+0:1
748a9306 701+0:+1:-1
702-1:+1:-1
5d7098d5 703+1:-1:1
704-1:-1:0
705+1:+1:0
706+123:+123:0
707+123:+12:1
748a9306 708+12:+123:-1
5d7098d5 709-123:-123:0
748a9306 710-123:-12:-1
5d7098d5 711-12:-123:1
748a9306 712+123:+124:-1
5d7098d5 713+124:+123:1
714-123:-124:1
748a9306 715-124:-123:-1
5d7098d5 716+100:+5:1
58cde26e 717-123456789:+987654321:-1
718+123456789:-987654321:1
719-987654321:+123456789:-1
720&bacmp
721+0:-0:0
722+0:+1:-1
723-1:+1:0
724+1:-1:0
725-1:+2:-1
726+2:-1:1
727-123456789:+987654321:-1
728+123456789:-987654321:-1
729-987654321:+123456789:1
730&binc
731abc:NaN
732+0:+1
733+1:+2
734-1:+0
735&bdec
736abc:NaN
737+0:-1
738+1:+0
739-1:-2
748a9306 740&badd
741abc:abc:NaN
742abc:+0:NaN
743+0:abc:NaN
744+0:+0:+0
745+1:+0:+1
746+0:+1:+1
747+1:+1:+2
748-1:+0:-1
749+0:-1:-1
750-1:-1:-2
751-1:+1:+0
752+1:-1:+0
753+9:+1:+10
754+99:+1:+100
755+999:+1:+1000
756+9999:+1:+10000
757+99999:+1:+100000
758+999999:+1:+1000000
759+9999999:+1:+10000000
760+99999999:+1:+100000000
761+999999999:+1:+1000000000
762+9999999999:+1:+10000000000
763+99999999999:+1:+100000000000
764+10:-1:+9
765+100:-1:+99
766+1000:-1:+999
767+10000:-1:+9999
768+100000:-1:+99999
769+1000000:-1:+999999
770+10000000:-1:+9999999
771+100000000:-1:+99999999
772+1000000000:-1:+999999999
773+10000000000:-1:+9999999999
774+123456789:+987654321:+1111111110
775-123456789:+987654321:+864197532
776-123456789:-987654321:-1111111110
777+123456789:-987654321:-864197532
778&bsub
779abc:abc:NaN
780abc:+0:NaN
781+0:abc:NaN
782+0:+0:+0
783+1:+0:+1
784+0:+1:-1
785+1:+1:+0
786-1:+0:-1
787+0:-1:+1
788-1:-1:+0
789-1:+1:-2
790+1:-1:+2
791+9:+1:+8
792+99:+1:+98
793+999:+1:+998
794+9999:+1:+9998
795+99999:+1:+99998
796+999999:+1:+999998
797+9999999:+1:+9999998
798+99999999:+1:+99999998
799+999999999:+1:+999999998
800+9999999999:+1:+9999999998
801+99999999999:+1:+99999999998
802+10:-1:+11
803+100:-1:+101
804+1000:-1:+1001
805+10000:-1:+10001
806+100000:-1:+100001
807+1000000:-1:+1000001
808+10000000:-1:+10000001
809+100000000:-1:+100000001
810+1000000000:-1:+1000000001
811+10000000000:-1:+10000000001
812+123456789:+987654321:-864197532
813-123456789:+987654321:-1111111110
814-123456789:-987654321:+864197532
815+123456789:-987654321:+1111111110
816&bmul
817abc:abc:NaN
818abc:+0:NaN
819+0:abc:NaN
820+0:+0:+0
821+0:+1:+0
822+1:+0:+0
823+0:-1:+0
824-1:+0:+0
825+123456789123456789:+0:+0
826+0:+123456789123456789:+0
827-1:-1:+1
828-1:+1:-1
829+1:-1:-1
830+1:+1:+1
831+2:+3:+6
832-2:+3:-6
833+2:-3:-6
834-2:-3:+6
835+111:+111:+12321
836+10101:+10101:+102030201
837+1001001:+1001001:+1002003002001
838+100010001:+100010001:+10002000300020001
839+10000100001:+10000100001:+100002000030000200001
840+11111111111:+9:+99999999999
841+22222222222:+9:+199999999998
842+33333333333:+9:+299999999997
843+44444444444:+9:+399999999996
844+55555555555:+9:+499999999995
845+66666666666:+9:+599999999994
846+77777777777:+9:+699999999993
847+88888888888:+9:+799999999992
848+99999999999:+9:+899999999991
58cde26e 849+25:+25:+625
850+12345:+12345:+152399025
851+99999:+11111:+1111088889
748a9306 852&bdiv
853abc:abc:NaN
854abc:+1:abc:NaN
855+1:abc:NaN
856+0:+0:NaN
857+0:+1:+0
858+1:+0:NaN
859+0:-1:+0
860-1:+0:NaN
861+1:+1:+1
862-1:-1:+1
863+1:-1:-1
864-1:+1:-1
865+1:+2:+0
866+2:+1:+2
58cde26e 867+1:+26:+0
748a9306 868+1000000000:+9:+111111111
869+2000000000:+9:+222222222
870+3000000000:+9:+333333333
871+4000000000:+9:+444444444
872+5000000000:+9:+555555555
873+6000000000:+9:+666666666
874+7000000000:+9:+777777777
875+8000000000:+9:+888888888
876+9000000000:+9:+1000000000
877+35500000:+113:+314159
878+71000000:+226:+314159
879+106500000:+339:+314159
880+1000000000:+3:+333333333
881+10:+5:+2
882+100:+4:+25
883+1000:+8:+125
884+10000:+16:+625
885+999999999999:+9:+111111111111
886+999999999999:+99:+10101010101
887+999999999999:+999:+1001001001
888+999999999999:+9999:+100010001
889+999999999999999:+99999:+10000100001
58cde26e 890+1111088889:+99999:+11111
891-5:-3:1
8924:3:1
8931:3:0
894-2:-3:0
895-2:3:-1
8961:-3:-1
897-5:3:-2
8984:-3:-2
748a9306 899&bmod
900abc:abc:NaN
901abc:+1:abc:NaN
902+1:abc:NaN
903+0:+0:NaN
904+0:+1:+0
905+1:+0:NaN
906+0:-1:+0
907-1:+0:NaN
908+1:+1:+0
909-1:-1:+0
910+1:-1:+0
911-1:+1:+0
912+1:+2:+1
913+2:+1:+0
914+1000000000:+9:+1
915+2000000000:+9:+2
916+3000000000:+9:+3
917+4000000000:+9:+4
918+5000000000:+9:+5
919+6000000000:+9:+6
920+7000000000:+9:+7
921+8000000000:+9:+8
922+9000000000:+9:+0
923+35500000:+113:+33
924+71000000:+226:+66
925+106500000:+339:+99
926+1000000000:+3:+1
927+10:+5:+0
928+100:+4:+0
929+1000:+8:+0
930+10000:+16:+0
931+999999999999:+9:+0
932+999999999999:+99:+0
933+999999999999:+999:+0
934+999999999999:+9999:+0
935+999999999999999:+99999:+0
58cde26e 936-9:+5:+1
937+9:-5:-1
938-9:-5:-4
939-5:3:1
940-2:3:1
9414:3:1
9421:3:1
943-5:-3:-2
944-2:-3:-2
9454:-3:-2
9461:-3:-2
748a9306 947&bgcd
948abc:abc:NaN
949abc:+0:NaN
950+0:abc:NaN
951+0:+0:+0
952+0:+1:+1
953+1:+0:+1
954+1:+1:+1
955+2:+3:+1
956+3:+2:+1
58cde26e 957-3:+2:+1
748a9306 958+100:+625:+25
959+4096:+81:+1
58cde26e 960+1034:+804:+2
961+27:+90:+56:+1
962+27:+90:+54:+9
963&blcm
e16b8f49 964abc:abc:NaN
58cde26e 965abc:+0:NaN
966+0:abc:NaN
967+0:+0:NaN
968+1:+0:+0
969+0:+1:+0
970+27:+90:+270
971+1034:+804:+415668
e16b8f49 972&band
973abc:abc:NaN
58cde26e 974abc:0:NaN
9750:abc:NaN
e16b8f49 976+8:+2:+0
977+281474976710656:+0:+0
978+281474976710656:+1:+0
979+281474976710656:+281474976710656:+281474976710656
980&bior
981abc:abc:NaN
58cde26e 982abc:0:NaN
9830:abc:NaN
e16b8f49 984+8:+2:+10
985+281474976710656:+0:+281474976710656
986+281474976710656:+1:+281474976710657
987+281474976710656:+281474976710656:+281474976710656
988&bxor
989abc:abc:NaN
58cde26e 990abc:0:NaN
9910:abc:NaN
e16b8f49 992+8:+2:+10
993+281474976710656:+0:+281474976710656
994+281474976710656:+1:+281474976710657
995+281474976710656:+281474976710656:+0
996&bnot
997abc:NaN
998+0:-1
999+8:-9
1000+281474976710656:-281474976710657
58cde26e 1001&digit
10020:0:0
100312:0:2
100412:1:1
1005123:0:3
1006123:1:2
1007123:2:1
1008123:-1:1
1009123:-2:2
1010123:-3:3
1011123456:0:6
1012123456:1:5
1013123456:2:4
1014123456:3:3
1015123456:4:2
1016123456:5:1
1017123456:-1:1
1018123456:-2:2
1019123456:-3:3
1020100000:-3:0
1021100000:0:0
1022100000:1:0
1023&mantissa
1024abc:NaN
10251e4:1
10262e0:2
1027123:123
1028-1:-1
1029-2:-2
1030&exponent
1031abc:NaN
10321e4:4
10332e0:0
1034123:0
1035-1:0
1036-2:0
10370:1
1038&parts
1039abc:NaN,NaN
10401e4:1,4
10412e0:2,0
1042123:123,0
1043-1:-1,0
1044-2:-2,0
10450:0,1
1046&bpow
10470:0:1
10480:1:0
10490:2:0
10500:-1:NaN
10510:-2:NaN
10521:0:1
10531:1:1
10541:2:1
10551:3:1
10561:-1:1
10571:-2:1
10581:-3:1
10592:0:1
10602:1:2
10612:2:4
10622:3:8
10633:3:27
10642:-1:NaN
1065-2:-1:NaN
10662:-2:NaN
1067-2:-2:NaN
1068# 1 ** -x => 1 / (1 ** x)
1069-1:0:1
1070-2:0:1
1071-1:1:-1
1072-1:2:1
1073-1:3:-1
1074-1:4:1
1075-1:5:-1
1076-1:-1:-1
1077-1:-2:1
1078-1:-3:-1
1079-1:-4:1
108010:2:100
108110:3:1000
108210:4:10000
108310:5:100000
108410:6:1000000
108510:7:10000000
108610:8:100000000
108710:9:1000000000
108810:20:100000000000000000000
1089123456:2:15241383936
1090&length
1091100:3
109210:2
10931:1
10940:1
109512345:5
109610000000000000000:17
1097-123:3
1098&bsqrt
1099144:12
110016:4
11014:2
11022:1
110312:3
1104256:16
1105100000000:10000
11064000000000000:2000000
11071:1
11080:0
1109-2:NaN
1110Nan:NaN
1111&bround
1112$round_mode('trunc')
11131234:0:1234
11141234:2:1200
1115123456:4:123400
1116123456:5:123450
1117123456:6:123456
1118+10123456789:5:+10123000000
1119-10123456789:5:-10123000000
1120+10123456789:9:+10123456700
1121-10123456789:9:-10123456700
1122+101234500:6:+101234000
1123-101234500:6:-101234000
1124#+101234500:-4:+101234000
1125#-101234500:-4:-101234000
1126$round_mode('zero')
1127+20123456789:5:+20123000000
1128-20123456789:5:-20123000000
1129+20123456789:9:+20123456800
1130-20123456789:9:-20123456800
1131+201234500:6:+201234000
1132-201234500:6:-201234000
1133#+201234500:-4:+201234000
1134#-201234500:-4:-201234000
1135+12345000:4:12340000
1136-12345000:4:-12340000
1137$round_mode('+inf')
1138+30123456789:5:+30123000000
1139-30123456789:5:-30123000000
1140+30123456789:9:+30123456800
1141-30123456789:9:-30123456800
1142+301234500:6:+301235000
1143-301234500:6:-301234000
1144#+301234500:-4:+301235000
1145#-301234500:-4:-301234000
1146+12345000:4:12350000
1147-12345000:4:-12340000
1148$round_mode('-inf')
1149+40123456789:5:+40123000000
1150-40123456789:5:-40123000000
1151+40123456789:9:+40123456800
1152-40123456789:9:-40123456800
1153+401234500:6:+401234000
1154+401234500:6:+401234000
1155#-401234500:-4:-401235000
1156#-401234500:-4:-401235000
1157+12345000:4:12340000
1158-12345000:4:-12350000
1159$round_mode('odd')
1160+50123456789:5:+50123000000
1161-50123456789:5:-50123000000
1162+50123456789:9:+50123456800
1163-50123456789:9:-50123456800
1164+501234500:6:+501235000
1165-501234500:6:-501235000
1166#+501234500:-4:+501235000
1167#-501234500:-4:-501235000
1168+12345000:4:12350000
1169-12345000:4:-12350000
1170$round_mode('even')
1171+60123456789:5:+60123000000
1172-60123456789:5:-60123000000
1173+60123456789:9:+60123456800
1174-60123456789:9:-60123456800
1175+601234500:6:+601234000
1176-601234500:6:-601234000
1177#+601234500:-4:+601234000
1178#-601234500:-4:-601234000
1179#-601234500:-9:0
1180#-501234500:-9:0
1181#-601234500:-8:0
1182#-501234500:-8:0
1183+1234567:7:1234567
1184+1234567:6:1234570
1185+12345000:4:12340000
1186-12345000:4:-12340000
1187&is_odd
1188abc:0
11890:0
11901:1
11913:1
1192-1:1
1193-3:1
119410000001:1
119510000002:0
11962:0
1197&is_even
1198abc:0
11990:1
12001:0
12013:0
1202-1:0
1203-3:0
120410000001:0
120510000002:1
12062:1
1207&is_zero
12080:1
1209NaNzero:0
1210123:0
1211-1:0
12121:0
1213&_set
12142:-1:-1
1215-2:1:1
1216NaN:2:2
12172:abc:NaN
1218&is_one
12190:0
12201:1
12212:0
1222-1:0
1223-2:0
1224# floor and ceil tests are pretty pointless in integer space...but play safe
1225&bfloor
12260:0
f216259d 1227-1:-1
58cde26e 1228-2:-2
12292:2
12303:3
1231abc:NaN
1232&bceil
12330:0
1234-1:-1
1235-2:-2
12362:2
12373:3
1238abc:NaN