remove PL_na from typemap
[p5sagit/p5-mst-13.2.git] / lib / Math / BigInt / t / 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
574bacfe 11 plan tests => 1424;
58cde26e 12 }
574bacfe 13my $version = '1.40'; # for $VERSION tests, match current release (by hand!)
58cde26e 14
15##############################################################################
16# for testing inheritance of _swap
17
18package Math::Foo;
19
20use Math::BigInt;
574bacfe 21#use Math::BigInt lib => 'BitVect'; # for testing
58cde26e 22use vars qw/@ISA/;
23@ISA = (qw/Math::BigInt/);
24
25use overload
26# customized overload for sub, since original does not use swap there
27'-' => sub { my @a = ref($_[0])->_swap(@_);
28 $a[0]->bsub($a[1])};
29
30sub _swap
31 {
32 # a fake _swap, which reverses the params
33 my $self = shift; # for override in subclass
34 if ($_[2])
35 {
36 my $c = ref ($_[0] ) || 'Math::Foo';
37 return ( $_[0]->copy(), $_[1] );
38 }
39 else
40 {
41 return ( Math::Foo->new($_[1]), $_[0] );
42 }
43 }
44
45##############################################################################
46package main;
d1f8c7a4 47
748a9306 48use Math::BigInt;
0716bf9b 49#use Math::BigInt lib => 'BitVect'; # for testing
0716bf9b 50
574bacfe 51my $CALC = Math::BigInt::_core_lib(); ok ($CALC,'Math::BigInt::Calc');
748a9306 52
58cde26e 53my (@args,$f,$try,$x,$y,$z,$a,$exp,$ans,$ans1,@a,$m,$e,$round_mode);
54
55while (<DATA>)
56 {
57 chop;
58 next if /^#/; # skip comments
59 if (s/^&//)
60 {
61 $f = $_;
62 }
63 elsif (/^\$/)
64 {
65 $round_mode = $_;
66 $round_mode =~ s/^\$/Math::BigInt->/;
67 # print "$round_mode\n";
68 }
69 else
70 {
71 @args = split(/:/,$_,99);
72 $ans = pop(@args);
73 $try = "\$x = Math::BigInt->new(\"$args[0]\");";
74 if ($f eq "bnorm"){
75 # $try .= '$x+0;';
58cde26e 76 } elsif ($f eq "is_zero") {
77 $try .= '$x->is_zero()+0;';
78 } elsif ($f eq "is_one") {
79 $try .= '$x->is_one()+0;';
80 } elsif ($f eq "is_odd") {
81 $try .= '$x->is_odd()+0;';
82 } elsif ($f eq "is_even") {
83 $try .= '$x->is_even()+0;';
574bacfe 84 } elsif ($f eq "is_negative") {
85 $try .= '$x->is_negative()+0;';
86 } elsif ($f eq "is_positive") {
87 $try .= '$x->is_positive()+0;';
0716bf9b 88 } elsif ($f eq "is_inf") {
89 $try .= "\$x->is_inf('$args[1]')+0;";
58cde26e 90 } elsif ($f eq "binf") {
91 $try .= "\$x->binf('$args[1]');";
574bacfe 92 } elsif ($f eq "bone") {
93 $try .= "\$x->bone('$args[1]');";
94 } elsif ($f eq "bnan") {
95 $try .= "\$x->bnan();";
58cde26e 96 } elsif ($f eq "bfloor") {
97 $try .= '$x->bfloor();';
98 } elsif ($f eq "bceil") {
99 $try .= '$x->bceil();';
58cde26e 100 } elsif ($f eq "bsstr") {
101 $try .= '$x->bsstr();';
102 } elsif ($f eq "bneg") {
574bacfe 103 $try .= '$x->bneg();';
58cde26e 104 } elsif ($f eq "babs") {
574bacfe 105 $try .= '$x->babs();';
58cde26e 106 } elsif ($f eq "binc") {
107 $try .= '++$x;';
108 } elsif ($f eq "bdec") {
109 $try .= '--$x;';
110 }elsif ($f eq "bnot") {
111 $try .= '~$x;';
112 }elsif ($f eq "bsqrt") {
113 $try .= '$x->bsqrt();';
114 }elsif ($f eq "length") {
115 $try .= "\$x->length();";
58cde26e 116 }elsif ($f eq "exponent"){
117 $try .= '$x = $x->exponent()->bstr();';
118 }elsif ($f eq "mantissa"){
119 $try .= '$x = $x->mantissa()->bstr();';
120 }elsif ($f eq "parts"){
121 $try .= "(\$m,\$e) = \$x->parts();";
122 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
123 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
124 $try .= '"$m,$e";';
125 } else {
0716bf9b 126 $try .= "\$y = new Math::BigInt ('$args[1]');";
58cde26e 127 if ($f eq "bcmp"){
128 $try .= '$x <=> $y;';
0716bf9b 129 }elsif ($f eq "bround") {
130 $try .= "$round_mode; \$x->bround(\$y);";
58cde26e 131 }elsif ($f eq "bacmp"){
0716bf9b 132 $try .= "\$x->bacmp(\$y);";
58cde26e 133 }elsif ($f eq "badd"){
134 $try .= "\$x + \$y;";
135 }elsif ($f eq "bsub"){
136 $try .= "\$x - \$y;";
137 }elsif ($f eq "bmul"){
138 $try .= "\$x * \$y;";
139 }elsif ($f eq "bdiv"){
140 $try .= "\$x / \$y;";
574bacfe 141 }elsif ($f eq "bdiv-list"){
142 $try .= 'join (",",$x->bdiv($y));';
58cde26e 143 }elsif ($f eq "bmod"){
144 $try .= "\$x % \$y;";
145 }elsif ($f eq "bgcd")
146 {
147 if (defined $args[2])
148 {
149 $try .= " \$z = new Math::BigInt \"$args[2]\"; ";
150 }
151 $try .= "Math::BigInt::bgcd(\$x, \$y";
152 $try .= ", \$z" if (defined $args[2]);
153 $try .= " );";
154 }
155 elsif ($f eq "blcm")
156 {
157 if (defined $args[2])
158 {
159 $try .= " \$z = new Math::BigInt \"$args[2]\"; ";
160 }
161 $try .= "Math::BigInt::blcm(\$x, \$y";
162 $try .= ", \$z" if (defined $args[2]);
163 $try .= " );";
164 }elsif ($f eq "blsft"){
165 if (defined $args[2])
166 {
167 $try .= "\$x->blsft(\$y,$args[2]);";
168 }
169 else
170 {
171 $try .= "\$x << \$y;";
172 }
173 }elsif ($f eq "brsft"){
174 if (defined $args[2])
175 {
176 $try .= "\$x->brsft(\$y,$args[2]);";
177 }
178 else
179 {
180 $try .= "\$x >> \$y;";
181 }
182 }elsif ($f eq "band"){
183 $try .= "\$x & \$y;";
184 }elsif ($f eq "bior"){
185 $try .= "\$x | \$y;";
186 }elsif ($f eq "bxor"){
187 $try .= "\$x ^ \$y;";
188 }elsif ($f eq "bpow"){
189 $try .= "\$x ** \$y;";
190 }elsif ($f eq "digit"){
191 $try = "\$x = Math::BigInt->new(\"$args[0]\"); \$x->digit($args[1]);";
192 } else { warn "Unknown op '$f'"; }
193 }
194 # print "trying $try\n";
195 $ans1 = eval $try;
196 $ans =~ s/^[+]([0-9])/$1/; # remove leading '+'
197 if ($ans eq "")
198 {
199 ok_undef ($ans1);
200 }
201 else
202 {
203 #print "try: $try ans: $ans1 $ans\n";
204 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
205 }
206 # check internal state of number objects
0716bf9b 207 is_valid($ans1,$f) if ref $ans1;
58cde26e 208 }
209 } # endwhile data tests
210close DATA;
211
574bacfe 212# XXX Tels 06/29/2001 following tests never fail or do not work :( !?
0716bf9b 213
214# test whether use Math::BigInt qw/version/ works
215$try = "use Math::BigInt ($version.'1');";
216$try .= ' $x = Math::BigInt->new(123); $x = "$x";';
58cde26e 217$ans1 = eval $try;
0716bf9b 218ok_undef ( $_ ); # should result in error!
58cde26e 219
0716bf9b 220# test whether constant works or not, also test for qw($version)
221$try = "use Math::BigInt ($version,'babs',':constant');";
222$try .= ' $x = 2**150; babs($x); $x = "$x";';
223$ans1 = eval $try;
58cde26e 224ok ( $ans1, "1427247692705959881058285969449495136382746624");
225
0716bf9b 226# test wether Math::BigInt::Small via use works (w/ dff. spellings of calc)
574bacfe 227#$try = "use Math::BigInt ($version,'lib','Small');";
0716bf9b 228#$try .= ' $x = 2**10; $x = "$x";';
229#$ans1 = eval $try;
230#ok ( $ans1, "1024");
574bacfe 231#$try = "use Math::BigInt ($version,'LiB','Math::BigInt::Small');";
0716bf9b 232#$try .= ' $x = 2**10; $x = "$x";';
233#$ans1 = eval $try;
234#ok ( $ans1, "1024");
235# test wether calc => undef (array element not existing) works
574bacfe 236#$try = "use Math::BigInt ($version,'LIB');";
0716bf9b 237#$try = "require Math::BigInt; Math::BigInt::import($version,'CALC');";
238#$try .= ' $x = Math::BigInt->new(2)**10; $x = "$x";';
239#$ans1 = eval $try;
240#ok ( $ans1, 1024);
241
574bacfe 242# test whether fallback to calc works
243$try = "use Math::BigInt ($version,'lib','foo, bar , ');";
244$try .= ' Math::BigInt::_core_lib();';
245$ans1 = eval $try;
246ok ( $ans1, "Math::BigInt::Calc");
247
58cde26e 248# test some more
249@a = ();
250for (my $i = 1; $i < 10; $i++)
251 {
252 push @a, $i;
253 }
254ok "@a", "1 2 3 4 5 6 7 8 9";
255
574bacfe 256# test whether self-multiplication works correctly (result is 2**64)
58cde26e 257$try = '$x = new Math::BigInt "+4294967296";';
258$try .= '$a = $x->bmul($x);';
259$ans1 = eval $try;
260print "# Tried: '$try'\n" if !ok ($ans1, Math::BigInt->new(2) ** 64);
574bacfe 261# test self-pow
262$try = '$x = Math::BigInt->new(10);';
263$try .= '$a = $x->bpow($x);';
264$ans1 = eval $try;
265print "# Tried: '$try'\n" if !ok ($ans1, Math::BigInt->new(10) ** 10);
58cde26e 266
0716bf9b 267# test whether op destroys args or not (should better not)
58cde26e 268
269$x = new Math::BigInt (3);
270$y = new Math::BigInt (4);
271$z = $x & $y;
272ok ($x,3);
273ok ($y,4);
274ok ($z,0);
275$z = $x | $y;
276ok ($x,3);
277ok ($y,4);
278ok ($z,7);
279$x = new Math::BigInt (1);
280$y = new Math::BigInt (2);
281$z = $x | $y;
282ok ($x,1);
283ok ($y,2);
284ok ($z,3);
285
286$x = new Math::BigInt (5);
287$y = new Math::BigInt (4);
288$z = $x ^ $y;
289ok ($x,5);
290ok ($y,4);
291ok ($z,1);
292
293$x = new Math::BigInt (-5); $y = -$x;
294ok ($x, -5);
295
296$x = new Math::BigInt (-5); $y = abs($x);
297ok ($x, -5);
298
299# check whether overloading cmp works
300$try = "\$x = Math::BigInt->new(0);";
301$try .= "\$y = 10;";
302$try .= "'false' if \$x ne \$y;";
303$ans = eval $try;
304print "# For '$try'\n" if (!ok "$ans" , "false" );
305
306# we cant test for working cmpt with other objects here, we would need a dummy
307# object with stringify overload for this. see Math::String tests
308
309###############################################################################
310# check shortcuts
311$try = "\$x = Math::BigInt->new(1); \$x += 9;";
312$try .= "'ok' if \$x == 10;";
313$ans = eval $try;
314print "# For '$try'\n" if (!ok "$ans" , "ok" );
315
316$try = "\$x = Math::BigInt->new(1); \$x -= 9;";
317$try .= "'ok' if \$x == -8;";
318$ans = eval $try;
319print "# For '$try'\n" if (!ok "$ans" , "ok" );
320
321$try = "\$x = Math::BigInt->new(1); \$x *= 9;";
322$try .= "'ok' if \$x == 9;";
323$ans = eval $try;
324print "# For '$try'\n" if (!ok "$ans" , "ok" );
325
326$try = "\$x = Math::BigInt->new(10); \$x /= 2;";
327$try .= "'ok' if \$x == 5;";
328$ans = eval $try;
329print "# For '$try'\n" if (!ok "$ans" , "ok" );
330
331###############################################################################
332# check reversed order of arguments
333$try = "\$x = Math::BigInt->new(10); \$x = 2 ** \$x;";
334$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
335print "# For '$try'\n" if (!ok "$ans" , "ok" );
336
337$try = "\$x = Math::BigInt->new(10); \$x = 2 * \$x;";
338$try .= "'ok' if \$x == 20;"; $ans = eval $try;
339print "# For '$try'\n" if (!ok "$ans" , "ok" );
340
341$try = "\$x = Math::BigInt->new(10); \$x = 2 + \$x;";
342$try .= "'ok' if \$x == 12;"; $ans = eval $try;
343print "# For '$try'\n" if (!ok "$ans" , "ok" );
344
345$try = "\$x = Math::BigInt->new(10); \$x = 2 - \$x;";
346$try .= "'ok' if \$x == -8;"; $ans = eval $try;
347print "# For '$try'\n" if (!ok "$ans" , "ok" );
348
349$try = "\$x = Math::BigInt->new(10); \$x = 20 / \$x;";
350$try .= "'ok' if \$x == 2;"; $ans = eval $try;
351print "# For '$try'\n" if (!ok "$ans" , "ok" );
352
353###############################################################################
354# check badd(4,5) form
355
356$try = "\$x = Math::BigInt::badd(4,5);";
357$try .= "'ok' if \$x == 9;";
358$ans = eval $try;
359print "# For '$try'\n" if (!ok "$ans" , "ok" );
360
361$try = "\$x = Math::BigInt->badd(4,5);";
362$try .= "'ok' if \$x == 9;";
363$ans = eval $try;
364print "# For '$try'\n" if (!ok "$ans" , "ok" );
365
366###############################################################################
574bacfe 367# the followin tests only make sense with Math::BigInt::Calc
368
369###############################################################################
58cde26e 370# check proper length of internal arrays
371
0716bf9b 372$x = Math::BigInt->new(99999); is_valid($x);
373$x += 1; ok ($x,100000); is_valid($x);
374$x -= 1; ok ($x,99999); is_valid($x);
58cde26e 375
376###############################################################################
574bacfe 377# check numify
58cde26e 378
0716bf9b 379my $BASE = int(1e5); # should access Math::BigInt::Calc::BASE
58cde26e 380$x = Math::BigInt->new($BASE-1); ok ($x->numify(),$BASE-1);
381$x = Math::BigInt->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
382$x = Math::BigInt->new($BASE); ok ($x->numify(),$BASE);
383$x = Math::BigInt->new(-$BASE); ok ($x->numify(),-$BASE);
384$x = Math::BigInt->new( -($BASE*$BASE*1+$BASE*1+1) );
385ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
386
387###############################################################################
388# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
389
390$x = Math::BigInt->new(99998); $x++; $x++; $x++; $x++;
391if ($x > 100000) { ok (1,1) } else { ok ("$x < 100000","$x > 100000"); }
392
393$x = Math::BigInt->new(100003); $x++;
394$y = Math::BigInt->new(1000000);
395if ($x < 1000000) { ok (1,1) } else { ok ("$x > 1000000","$x < 1000000"); }
396
397###############################################################################
398# bug in sub where number with at least 6 trailing zeros after any op failed
399
400$x = Math::BigInt->new(123456); $z = Math::BigInt->new(10000); $z *= 10;
401$x -= $z;
402ok ($z, 100000);
403ok ($x, 23456);
404
405###############################################################################
574bacfe 406# bug in shortcut in mul()
407
408# construct a number with a zero-hole of BASE_LEN
409my $bl = Math::BigInt::Calc::_base_len();
410$x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
411$y = '1' x (2*$bl);
412#print "$x * $y\n";
413$x = Math::BigInt->new($x)->bmul($y);
414# result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
415$y = ''; my $d = '';
416for (my $i = 1; $i <= $bl; $i++)
417 {
418 $y .= $i; $d = $i.$d;
419 }
420#print "$y $d\n";
421$y .= $bl x (3*$bl-1) . $d . '0' x $bl;
422ok ($x,$y);
423
424###############################################################################
58cde26e 425# bug with rest "-0" in div, causing further div()s to fail
426
0716bf9b 427$x = Math::BigInt->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
58cde26e 428
0716bf9b 429ok ($y,'0','not -0'); # not '-0'
58cde26e 430is_valid($y);
431
432###############################################################################
433# check undefs: NOT DONE YET
434
435###############################################################################
436# bool
437
438$x = Math::BigInt->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
439$x = Math::BigInt->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
440
441###############################################################################
442# objectify()
443
444@args = Math::BigInt::objectify(2,4,5);
445ok (scalar @args,3); # 'Math::BigInt', 4, 5
446ok ($args[0],'Math::BigInt');
447ok ($args[1],4);
448ok ($args[2],5);
449
450@args = Math::BigInt::objectify(0,4,5);
451ok (scalar @args,3); # 'Math::BigInt', 4, 5
452ok ($args[0],'Math::BigInt');
453ok ($args[1],4);
454ok ($args[2],5);
455
456@args = Math::BigInt::objectify(2,4,5);
457ok (scalar @args,3); # 'Math::BigInt', 4, 5
458ok ($args[0],'Math::BigInt');
459ok ($args[1],4);
460ok ($args[2],5);
461
462@args = Math::BigInt::objectify(2,4,5,6,7);
463ok (scalar @args,5); # 'Math::BigInt', 4, 5, 6, 7
464ok ($args[0],'Math::BigInt');
465ok ($args[1],4); ok (ref($args[1]),$args[0]);
466ok ($args[2],5); ok (ref($args[2]),$args[0]);
467ok ($args[3],6); ok (ref($args[3]),'');
468ok ($args[4],7); ok (ref($args[4]),'');
469
470@args = Math::BigInt::objectify(2,'Math::BigInt',4,5,6,7);
471ok (scalar @args,5); # 'Math::BigInt', 4, 5, 6, 7
472ok ($args[0],'Math::BigInt');
473ok ($args[1],4); ok (ref($args[1]),$args[0]);
474ok ($args[2],5); ok (ref($args[2]),$args[0]);
475ok ($args[3],6); ok (ref($args[3]),'');
476ok ($args[4],7); ok (ref($args[4]),'');
477
478###############################################################################
b22b3e31 479# test for floating-point input (other tests in bnorm() below)
58cde26e 480
481$z = 1050000000000000; # may be int on systems with 64bit?
0716bf9b 482$x = Math::BigInt->new($z); ok ($x->bsstr(),'105e+13'); # not 1.03e+15
483$z = 1e+129; # definitely a float (may fail on UTS)
484$x = Math::BigInt->new($z); ok ($x->bsstr(),$z);
58cde26e 485
486###############################################################################
487# prime number tests, also test for **= and length()
488# found on: http://www.utm.edu/research/primes/notes/by_year.html
489
490# ((2^148)-1)/17
491$x = Math::BigInt->new(2); $x **= 148; $x++; $x = $x / 17;
492ok ($x,"20988936657440586486151264256610222593863921");
493ok ($x->length(),length "20988936657440586486151264256610222593863921");
494
495# MM7 = 2^127-1
496$x = Math::BigInt->new(2); $x **= 127; $x--;
497ok ($x,"170141183460469231731687303715884105727");
498
499# I am afraid the following is not yet possible due to slowness
500# Also, testing for 2 meg output is a bit hard ;)
501#$x = new Math::BigInt(2); $x **= 6972593; $x--;
502
0716bf9b 503# 593573509*2^332162+1 has exactly 1,000,000 digits
b22b3e31 504# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
58cde26e 505#$x = Math::BigInt->new(2); $x **= 332162; $x *= "593573509"; $x++;
0716bf9b 506#ok ($x->length(),1_000_000);
58cde26e 507
508###############################################################################
509# inheritance and overriding of _swap
510
511$x = Math::Foo->new(5);
512$x = $x - 8; # 8 - 5 instead of 5-8
513ok ($x,3);
514ok (ref($x),'Math::Foo');
515
516$x = Math::Foo->new(5);
517$x = 8 - $x; # 5 - 8 instead of 8 - 5
518ok ($x,-3);
519ok (ref($x),'Math::Foo');
520
521###############################################################################
574bacfe 522# test whether +inf eq inf
523
524$y = 1e1000000; # create inf, since bareword inf does not work
c525946d 525$x = Math::BigInt->new('+inf'); ok_inf ($x,$y);
574bacfe 526
527###############################################################################
58cde26e 528# all tests done
529
58cde26e 530###############################################################################
c525946d 531
532# libc are confused what to call Infinity
533
606f9480 534sub fix_inf {
535 $_[0] =~ s/^(inf(?:inity)?|\+\+)$/Inf/i; # HP-UX calls it "++"
536}
537
c525946d 538sub ok_inf {
539 my ($x, $y) = @_;
540
606f9480 541 fix_inf($x);
542 fix_inf($y);
c525946d 543
544 ok($x, $y);
545}
546
58cde26e 547# Perl 5.005 does not like ok ($x,undef)
548
549sub ok_undef
550 {
551 my $x = shift;
552
553 ok (1,1) and return if !defined $x;
554 ok ($x,'undef');
555 }
556
557###############################################################################
558# sub to check validity of a BigInt internally, to ensure that no op leaves a
559# number object in an invalid state (f.i. "-0")
560
561sub is_valid
562 {
0716bf9b 563 my ($x,$f) = @_;
58cde26e 564
0716bf9b 565 my $e = 0; # error?
58cde26e 566 # ok as reference?
0716bf9b 567 $e = 'Not a reference to Math::BigInt' if !ref($x);
58cde26e 568
569 # has ok sign?
0716bf9b 570 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
571 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
58cde26e 572
0716bf9b 573 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
574 $e = $CALC->_check($x->{value}) if $e eq '0';
58cde26e 575
0716bf9b 576 # test done, see if error did crop up
577 ok (1,1), return if ($e eq '0');
58cde26e 578
0716bf9b 579 ok (1,$e." op '$f'");
a99f8827 580 }
58cde26e 581
748a9306 582__END__
574bacfe 583&is_negative
5840:0
585-1:1
5861:0
587+inf:0
588-inf:1
589NaNneg:0
590&is_positive
5910:1
592-1:0
5931:1
594+inf:1
595-inf:0
596NaNneg:0
0716bf9b 597&is_odd
598abc:0
5990:0
6001:1
6013:1
602-1:1
603-3:1
60410000001:1
60510000002:0
6062:0
607&is_even
608abc:0
6090:1
6101:0
6113:0
612-1:0
613-3:0
61410000001:0
61510000002:1
6162:1
617&bacmp
618+0:-0:0
619+0:+1:-1
620-1:+1:0
621+1:-1:0
622-1:+2:-1
623+2:-1:1
624-123456789:+987654321:-1
625+123456789:-987654321:-1
626+987654321:+123456789:1
627-987654321:+123456789:1
628-123:+4567889:-1
574bacfe 629# NaNs
630acmpNaN:123:
631123:acmpNaN:
632acmpNaN:acmpNaN:
633# infinity
634+inf:+inf:0
635-inf:-inf:0
636+inf:-inf:0
637-inf:+inf:0
638+inf:123:1
639-inf:123:1
640+inf:-123:1
641-inf:-123:1
642# return undef
643+inf:NaN:
644NaN:inf:
645-inf:NaN:
646NaN:-inf:
748a9306 647&bnorm
0716bf9b 648123:123
58cde26e 649# binary input
6500babc:NaN
6510b123:NaN
6520b0:0
653-0b0:0
654-0b1:-1
6550b0001:1
6560b001:1
6570b011:3
6580b101:5
6590b1000000000000000000000000000000:1073741824
574bacfe 6600b_101:NaN
6610b1_0_1:5
58cde26e 662# hex input
663-0x0:0
6640xabcdefgh:NaN
6650x1234:4660
6660xabcdef:11259375
667-0xABCDEF:-11259375
668-0x1234:-4660
6690x12345678:305419896
574bacfe 6700x1_2_3_4_56_78:305419896
6710x_123:NaN
58cde26e 672# inf input
574bacfe 673+inf:inf
58cde26e 674-inf:-inf
6750inf:NaN
676# normal input
677:NaN
748a9306 678abc:NaN
679 1 a:NaN
6801bcd2:NaN
68111111b:NaN
682+1z:NaN
683-1z:NaN
58cde26e 6840:0
685+0:0
686+00:0
687+000:0
688000000000000000000:0
689-0:0
690-0000:0
691+1:1
692+01:1
693+001:1
694+00000100000:100000
695123456789:123456789
748a9306 696-1:-1
697-01:-1
698-001:-1
699-123456789:-123456789
700-00000100000:-100000
58cde26e 7011_2_3:123
702_123:NaN
703_123_:NaN
704_123_:NaN
7051__23:NaN
70610000000000E-1_0:1
7071E2:100
7081E1:10
7091E0:1
710E1:NaN
711E23:NaN
7121.23E2:123
7131.23E1:NaN
7141.23E-1:NaN
715100E-1:10
716# floating point input
7171.01E2:101
7181010E-1:101
719-1010E0:-1010
720-1010E1:-10100
721-1010E-2:NaN
722-1.01E+1:NaN
723-1.01E-1:NaN
574bacfe 7241234.00:1234
725&bnan
7261:NaN
7272:NaN
728abc:NaN
729&bone
7302:+:+1
7312:-:-1
732boneNaN:-:-1
733boneNaN:+:+1
7342:abc:+1
7353::+1
58cde26e 736&binf
574bacfe 7371:+:inf
58cde26e 7382:-:-inf
574bacfe 7393:abc:inf
58cde26e 740&is_inf
741+inf::1
742-inf::1
743abc::0
7441::0
745NaN::0
746-1::0
747+inf:-:0
748+inf:+:1
749-inf:-:1
750-inf:+:0
0716bf9b 751# it must be exactly /^[+-]inf$/
752+infinity::0
753-infinity::0
58cde26e 754&blsft
755abc:abc:NaN
756+2:+2:+8
757+1:+32:+4294967296
758+1:+48:+281474976710656
759+8:-2:NaN
760# excercise base 10
761+12345:4:10:123450000
762-1234:0:10:-1234
763+1234:0:10:+1234
764+2:2:10:200
765+12:2:10:1200
766+1234:-3:10:NaN
7671234567890123:12:10:1234567890123000000000000
768&brsft
769abc:abc:NaN
770+8:+2:+2
771+4294967296:+32:+1
772+281474976710656:+48:+1
773+2:-2:NaN
774# excercise base 10
775-1234:0:10:-1234
776+1234:0:10:+1234
777+200:2:10:2
778+1234:3:10:1
779+1234:2:10:12
780+1234:-3:10:NaN
781310000:4:10:31
78212300000:5:10:123
7831230000000000:10:10:123
78409876123456789067890:12:10:9876123
7851234561234567890123:13:10:123456
786&bsstr
7871e+34:1e+34
788123.456E3:123456e+0
789100:1e+2
790abc:NaN
748a9306 791&bneg
574bacfe 792bnegNaN:NaN
793+inf:-inf
794-inf:inf
748a9306 795abd:NaN
796+0:+0
797+1:-1
798-1:+1
799+123456789:-123456789
800-123456789:+123456789
801&babs
574bacfe 802babsNaN:NaN
803+inf:inf
804-inf:inf
748a9306 805+0:+0
806+1:+1
807-1:+1
808+123456789:+123456789
809-123456789:+123456789
810&bcmp
574bacfe 811bcmpNaN:bcmpNaN:
812bcmpNaN:+0:
813+0:bcmpNaN:
5d7098d5 814+0:+0:0
748a9306 815-1:+0:-1
5d7098d5 816+0:-1:1
817+1:+0:1
748a9306 818+0:+1:-1
819-1:+1:-1
5d7098d5 820+1:-1:1
821-1:-1:0
822+1:+1:0
823+123:+123:0
824+123:+12:1
748a9306 825+12:+123:-1
5d7098d5 826-123:-123:0
748a9306 827-123:-12:-1
5d7098d5 828-12:-123:1
748a9306 829+123:+124:-1
5d7098d5 830+124:+123:1
831-123:-124:1
748a9306 832-124:-123:-1
5d7098d5 833+100:+5:1
58cde26e 834-123456789:+987654321:-1
835+123456789:-987654321:1
836-987654321:+123456789:-1
0716bf9b 837-inf:5432112345:-1
838+inf:5432112345:1
839-inf:-5432112345:-1
840+inf:-5432112345:1
841+inf:+inf:0
842-inf:-inf:0
574bacfe 843+inf:-inf:1
844-inf:+inf:-1
0716bf9b 845# return undef
846+inf:NaN:
574bacfe 847NaN:inf:
0716bf9b 848-inf:NaN:
849NaN:-inf:
58cde26e 850&binc
851abc:NaN
574bacfe 852+inf:inf
853-inf:-inf
58cde26e 854+0:+1
855+1:+2
856-1:+0
857&bdec
858abc:NaN
574bacfe 859+inf:inf
860-inf:-inf
58cde26e 861+0:-1
862+1:+0
863-1:-2
748a9306 864&badd
865abc:abc:NaN
866abc:+0:NaN
867+0:abc:NaN
574bacfe 868+inf:-inf:0
869-inf:+inf:0
870+inf:+inf:inf
871-inf:-inf:-inf
872baddNaN:+inf:NaN
873baddNaN:+inf:NaN
874+inf:baddNaN:NaN
875-inf:baddNaN:NaN
748a9306 876+0:+0:+0
877+1:+0:+1
878+0:+1:+1
879+1:+1:+2
880-1:+0:-1
881+0:-1:-1
882-1:-1:-2
883-1:+1:+0
884+1:-1:+0
885+9:+1:+10
886+99:+1:+100
887+999:+1:+1000
888+9999:+1:+10000
889+99999:+1:+100000
890+999999:+1:+1000000
891+9999999:+1:+10000000
892+99999999:+1:+100000000
893+999999999:+1:+1000000000
894+9999999999:+1:+10000000000
895+99999999999:+1:+100000000000
896+10:-1:+9
897+100:-1:+99
898+1000:-1:+999
899+10000:-1:+9999
900+100000:-1:+99999
901+1000000:-1:+999999
902+10000000:-1:+9999999
903+100000000:-1:+99999999
904+1000000000:-1:+999999999
905+10000000000:-1:+9999999999
906+123456789:+987654321:+1111111110
907-123456789:+987654321:+864197532
908-123456789:-987654321:-1111111110
909+123456789:-987654321:-864197532
910&bsub
911abc:abc:NaN
912abc:+0:NaN
913+0:abc:NaN
574bacfe 914+inf:-inf:inf
915-inf:+inf:-inf
916+inf:+inf:0
917-inf:-inf:0
748a9306 918+0:+0:+0
919+1:+0:+1
920+0:+1:-1
921+1:+1:+0
922-1:+0:-1
923+0:-1:+1
924-1:-1:+0
925-1:+1:-2
926+1:-1:+2
927+9:+1:+8
928+99:+1:+98
929+999:+1:+998
930+9999:+1:+9998
931+99999:+1:+99998
932+999999:+1:+999998
933+9999999:+1:+9999998
934+99999999:+1:+99999998
935+999999999:+1:+999999998
936+9999999999:+1:+9999999998
937+99999999999:+1:+99999999998
938+10:-1:+11
939+100:-1:+101
940+1000:-1:+1001
941+10000:-1:+10001
942+100000:-1:+100001
943+1000000:-1:+1000001
944+10000000:-1:+10000001
945+100000000:-1:+100000001
946+1000000000:-1:+1000000001
947+10000000000:-1:+10000000001
948+123456789:+987654321:-864197532
949-123456789:+987654321:-1111111110
950-123456789:-987654321:+864197532
951+123456789:-987654321:+1111111110
952&bmul
953abc:abc:NaN
954abc:+0:NaN
955+0:abc:NaN
574bacfe 956NaNmul:+inf:NaN
957NaNmul:-inf:NaN
958-inf:NaNmul:NaN
959+inf:NaNmul:NaN
960+inf:+inf:inf
961+inf:-inf:-inf
962-inf:+inf:-inf
963-inf:-inf:inf
748a9306 964+0:+0:+0
965+0:+1:+0
966+1:+0:+0
967+0:-1:+0
968-1:+0:+0
969+123456789123456789:+0:+0
970+0:+123456789123456789:+0
971-1:-1:+1
972-1:+1:-1
973+1:-1:-1
974+1:+1:+1
975+2:+3:+6
976-2:+3:-6
977+2:-3:-6
978-2:-3:+6
979+111:+111:+12321
980+10101:+10101:+102030201
981+1001001:+1001001:+1002003002001
982+100010001:+100010001:+10002000300020001
983+10000100001:+10000100001:+100002000030000200001
984+11111111111:+9:+99999999999
985+22222222222:+9:+199999999998
986+33333333333:+9:+299999999997
987+44444444444:+9:+399999999996
988+55555555555:+9:+499999999995
989+66666666666:+9:+599999999994
990+77777777777:+9:+699999999993
991+88888888888:+9:+799999999992
992+99999999999:+9:+899999999991
58cde26e 993+25:+25:+625
994+12345:+12345:+152399025
995+99999:+11111:+1111088889
574bacfe 996&bdiv-list
997100:20:5,0
9984095:4095:1,0
999-4095:-4095:1,0
10004095:-4095:-1,0
1001-4095:4095:-1,0
748a9306 1002&bdiv
1003abc:abc:NaN
1004abc:+1:abc:NaN
1005+1:abc:NaN
1006+0:+0:NaN
574bacfe 1007+5:0:inf
1008-5:0:-inf
1009+1:+0:inf
748a9306 1010+0:+1:+0
748a9306 1011+0:-1:+0
574bacfe 1012-1:+0:-inf
748a9306 1013+1:+1:+1
1014-1:-1:+1
1015+1:-1:-1
1016-1:+1:-1
1017+1:+2:+0
1018+2:+1:+2
58cde26e 1019+1:+26:+0
748a9306 1020+1000000000:+9:+111111111
1021+2000000000:+9:+222222222
1022+3000000000:+9:+333333333
1023+4000000000:+9:+444444444
1024+5000000000:+9:+555555555
1025+6000000000:+9:+666666666
1026+7000000000:+9:+777777777
1027+8000000000:+9:+888888888
1028+9000000000:+9:+1000000000
1029+35500000:+113:+314159
1030+71000000:+226:+314159
1031+106500000:+339:+314159
1032+1000000000:+3:+333333333
1033+10:+5:+2
1034+100:+4:+25
1035+1000:+8:+125
1036+10000:+16:+625
1037+999999999999:+9:+111111111111
1038+999999999999:+99:+10101010101
1039+999999999999:+999:+1001001001
1040+999999999999:+9999:+100010001
1041+999999999999999:+99999:+10000100001
58cde26e 1042+1111088889:+99999:+11111
1043-5:-3:1
10444:3:1
10451:3:0
1046-2:-3:0
1047-2:3:-1
10481:-3:-1
1049-5:3:-2
10504:-3:-2
574bacfe 1051123:+inf:0
1052123:-inf:0
748a9306 1053&bmod
1054abc:abc:NaN
1055abc:+1:abc:NaN
1056+1:abc:NaN
1057+0:+0:NaN
1058+0:+1:+0
1059+1:+0:NaN
1060+0:-1:+0
1061-1:+0:NaN
1062+1:+1:+0
1063-1:-1:+0
1064+1:-1:+0
1065-1:+1:+0
1066+1:+2:+1
1067+2:+1:+0
1068+1000000000:+9:+1
1069+2000000000:+9:+2
1070+3000000000:+9:+3
1071+4000000000:+9:+4
1072+5000000000:+9:+5
1073+6000000000:+9:+6
1074+7000000000:+9:+7
1075+8000000000:+9:+8
1076+9000000000:+9:+0
1077+35500000:+113:+33
1078+71000000:+226:+66
1079+106500000:+339:+99
1080+1000000000:+3:+1
1081+10:+5:+0
1082+100:+4:+0
1083+1000:+8:+0
1084+10000:+16:+0
1085+999999999999:+9:+0
1086+999999999999:+99:+0
1087+999999999999:+999:+0
1088+999999999999:+9999:+0
1089+999999999999999:+99999:+0
58cde26e 1090-9:+5:+1
1091+9:-5:-1
1092-9:-5:-4
1093-5:3:1
1094-2:3:1
10954:3:1
10961:3:1
1097-5:-3:-2
1098-2:-3:-2
10994:-3:-2
11001:-3:-2
574bacfe 11014095:4095:0
748a9306 1102&bgcd
1103abc:abc:NaN
1104abc:+0:NaN
1105+0:abc:NaN
1106+0:+0:+0
1107+0:+1:+1
1108+1:+0:+1
1109+1:+1:+1
1110+2:+3:+1
1111+3:+2:+1
58cde26e 1112-3:+2:+1
748a9306 1113+100:+625:+25
1114+4096:+81:+1
58cde26e 1115+1034:+804:+2
1116+27:+90:+56:+1
1117+27:+90:+54:+9
1118&blcm
e16b8f49 1119abc:abc:NaN
58cde26e 1120abc:+0:NaN
1121+0:abc:NaN
1122+0:+0:NaN
1123+1:+0:+0
1124+0:+1:+0
1125+27:+90:+270
1126+1034:+804:+415668
e16b8f49 1127&band
1128abc:abc:NaN
58cde26e 1129abc:0:NaN
11300:abc:NaN
0716bf9b 11311:2:0
11323:2:2
e16b8f49 1133+8:+2:+0
1134+281474976710656:+0:+0
1135+281474976710656:+1:+0
1136+281474976710656:+281474976710656:+281474976710656
574bacfe 1137-2:-3:-4
1138-1:-1:-1
1139-6:-6:-6
1140-7:-4:-8
1141-7:4:0
1142-4:7:4
e16b8f49 1143&bior
1144abc:abc:NaN
58cde26e 1145abc:0:NaN
11460:abc:NaN
0716bf9b 11471:2:3
e16b8f49 1148+8:+2:+10
1149+281474976710656:+0:+281474976710656
1150+281474976710656:+1:+281474976710657
1151+281474976710656:+281474976710656:+281474976710656
574bacfe 1152-2:-3:-1
1153-1:-1:-1
1154-6:-6:-6
1155-7:4:-3
1156-4:7:-1
e16b8f49 1157&bxor
1158abc:abc:NaN
58cde26e 1159abc:0:NaN
11600:abc:NaN
0716bf9b 11611:2:3
e16b8f49 1162+8:+2:+10
1163+281474976710656:+0:+281474976710656
1164+281474976710656:+1:+281474976710657
1165+281474976710656:+281474976710656:+0
574bacfe 1166-2:-3:3
1167-1:-1:0
1168-6:-6:0
1169-7:4:-3
1170-4:7:-5
11714:-7:-3
1172-4:-7:5
e16b8f49 1173&bnot
1174abc:NaN
1175+0:-1
1176+8:-9
1177+281474976710656:-281474976710657
574bacfe 1178-1:0
1179-2:1
1180-12:11
58cde26e 1181&digit
11820:0:0
118312:0:2
118412:1:1
1185123:0:3
1186123:1:2
1187123:2:1
1188123:-1:1
1189123:-2:2
1190123:-3:3
1191123456:0:6
1192123456:1:5
1193123456:2:4
1194123456:3:3
1195123456:4:2
1196123456:5:1
1197123456:-1:1
1198123456:-2:2
1199123456:-3:3
1200100000:-3:0
1201100000:0:0
1202100000:1:0
1203&mantissa
1204abc:NaN
12051e4:1
12062e0:2
1207123:123
1208-1:-1
1209-2:-2
1210&exponent
1211abc:NaN
12121e4:4
12132e0:0
1214123:0
1215-1:0
1216-2:0
12170:1
1218&parts
1219abc:NaN,NaN
12201e4:1,4
12212e0:2,0
1222123:123,0
1223-1:-1,0
1224-2:-2,0
12250:0,1
1226&bpow
0716bf9b 1227abc:12:NaN
122812:abc:NaN
58cde26e 12290:0:1
12300:1:0
12310:2:0
12320:-1:NaN
12330:-2:NaN
12341:0:1
12351:1:1
12361:2:1
12371:3:1
12381:-1:1
12391:-2:1
12401:-3:1
12412:0:1
12422:1:2
12432:2:4
12442:3:8
12453:3:27
12462:-1:NaN
1247-2:-1:NaN
12482:-2:NaN
1249-2:-2:NaN
574bacfe 1250+inf:1234500012:inf
0716bf9b 1251-inf:1234500012:-inf
574bacfe 1252+inf:-12345000123:inf
0716bf9b 1253-inf:-12345000123:-inf
58cde26e 1254# 1 ** -x => 1 / (1 ** x)
1255-1:0:1
1256-2:0:1
1257-1:1:-1
1258-1:2:1
1259-1:3:-1
1260-1:4:1
1261-1:5:-1
1262-1:-1:-1
1263-1:-2:1
1264-1:-3:-1
1265-1:-4:1
126610:2:100
126710:3:1000
126810:4:10000
126910:5:100000
127010:6:1000000
127110:7:10000000
127210:8:100000000
127310:9:1000000000
127410:20:100000000000000000000
1275123456:2:15241383936
1276&length
1277100:3
127810:2
12791:1
12800:1
128112345:5
128210000000000000000:17
1283-123:3
1284&bsqrt
1285144:12
128616:4
12874:2
12882:1
128912:3
1290256:16
1291100000000:10000
12924000000000000:2000000
12931:1
12940:0
1295-2:NaN
1296Nan:NaN
1297&bround
1298$round_mode('trunc')
574bacfe 12990:12:0
1300NaNbround:12:NaN
1301+inf:12:inf
1302-inf:12:-inf
58cde26e 13031234:0:1234
13041234:2:1200
1305123456:4:123400
1306123456:5:123450
1307123456:6:123456
1308+10123456789:5:+10123000000
1309-10123456789:5:-10123000000
1310+10123456789:9:+10123456700
1311-10123456789:9:-10123456700
1312+101234500:6:+101234000
1313-101234500:6:-101234000
1314#+101234500:-4:+101234000
1315#-101234500:-4:-101234000
1316$round_mode('zero')
1317+20123456789:5:+20123000000
1318-20123456789:5:-20123000000
1319+20123456789:9:+20123456800
1320-20123456789:9:-20123456800
1321+201234500:6:+201234000
1322-201234500:6:-201234000
1323#+201234500:-4:+201234000
1324#-201234500:-4:-201234000
1325+12345000:4:12340000
1326-12345000:4:-12340000
1327$round_mode('+inf')
1328+30123456789:5:+30123000000
1329-30123456789:5:-30123000000
1330+30123456789:9:+30123456800
1331-30123456789:9:-30123456800
1332+301234500:6:+301235000
1333-301234500:6:-301234000
1334#+301234500:-4:+301235000
1335#-301234500:-4:-301234000
1336+12345000:4:12350000
1337-12345000:4:-12340000
1338$round_mode('-inf')
1339+40123456789:5:+40123000000
1340-40123456789:5:-40123000000
1341+40123456789:9:+40123456800
1342-40123456789:9:-40123456800
1343+401234500:6:+401234000
1344+401234500:6:+401234000
1345#-401234500:-4:-401235000
1346#-401234500:-4:-401235000
1347+12345000:4:12340000
1348-12345000:4:-12350000
1349$round_mode('odd')
1350+50123456789:5:+50123000000
1351-50123456789:5:-50123000000
1352+50123456789:9:+50123456800
1353-50123456789:9:-50123456800
1354+501234500:6:+501235000
1355-501234500:6:-501235000
1356#+501234500:-4:+501235000
1357#-501234500:-4:-501235000
1358+12345000:4:12350000
1359-12345000:4:-12350000
1360$round_mode('even')
1361+60123456789:5:+60123000000
1362-60123456789:5:-60123000000
1363+60123456789:9:+60123456800
1364-60123456789:9:-60123456800
1365+601234500:6:+601234000
1366-601234500:6:-601234000
1367#+601234500:-4:+601234000
1368#-601234500:-4:-601234000
1369#-601234500:-9:0
1370#-501234500:-9:0
1371#-601234500:-8:0
1372#-501234500:-8:0
1373+1234567:7:1234567
1374+1234567:6:1234570
1375+12345000:4:12340000
1376-12345000:4:-12340000
58cde26e 1377&is_zero
13780:1
1379NaNzero:0
574bacfe 1380+inf:0
1381-inf:0
58cde26e 1382123:0
1383-1:0
13841:0
58cde26e 1385&is_one
13860:0
574bacfe 1387NaNone:0
1388+inf:0
1389-inf:0
58cde26e 13901:1
13912:0
1392-1:0
1393-2:0
1394# floor and ceil tests are pretty pointless in integer space...but play safe
1395&bfloor
13960:0
574bacfe 1397NaNfloor:NaN
1398+inf:inf
1399-inf:-inf
f216259d 1400-1:-1
58cde26e 1401-2:-2
14022:2
14033:3
1404abc:NaN
1405&bceil
574bacfe 1406NaNceil:NaN
1407+inf:inf
1408-inf:-inf
58cde26e 14090:0
1410-1:-1
1411-2:-2
14122:2
14133:3
1414abc:NaN