This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Math::BigInt 1.47.
[perl5.git] / lib / Math / BigInt / t / bigintpm.inc
1 #include this file into another for subclass testing
2
3 my $version = ${"$class\::VERSION"};
4
5 ##############################################################################
6 # for testing inheritance of _swap
7
8 package Math::Foo;
9
10 use Math::BigInt;
11 #use Math::BigInt lib => 'BitVect';     # for testing
12 use vars qw/@ISA/;
13 @ISA = (qw/Math::BigInt/);
14
15 use 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
20 sub _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 ##############################################################################
36 package main;
37
38 my $CALC = $class->_core_lib(); ok ($CALC,'Math::BigInt::Calc');
39
40 my ($f,$z,$a,$exp,@a,$m,$e,$round_mode);
41
42 while (<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]\");";
63     # some is_xxx tests
64     } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan)$/) {
65       $try .= "\$x->$f();";
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]');";
76     # some unary ops
77     } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt)$/) {
78       $try .= "\$x->$f();";
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));';
111       # overload via x=
112       }elsif ($f =~ /^.=$/){
113         $try .= "\$x $f \$y;";
114       # overload via x
115       }elsif ($f =~ /^.$/){
116         $try .= "\$x $f \$y;";
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
184 close DATA;
185
186 # test some more
187 @a = ();
188 for (my $i = 1; $i < 10; $i++) 
189   {
190   push @a, $i;
191   }
192 ok "@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;
198 print "# 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;
203 print "# 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;
210 ok ($x,3);
211 ok ($y,4);
212 ok ($z,0);
213 $z = $x | $y;
214 ok ($x,3);
215 ok ($y,4);
216 ok ($z,7);
217 $x = $class->new(1);
218 $y = $class->new(2);
219 $z = $x | $y;
220 ok ($x,1);
221 ok ($y,2);
222 ok ($z,3);
223
224 $x = $class->new(5);
225 $y = $class->new(4);
226 $z = $x ^ $y;
227 ok ($x,5);
228 ok ($y,4);
229 ok ($z,1);
230
231 $x = $class->new(-5); $y = -$x;
232 ok ($x, -5);
233
234 $x = $class->new(-5); $y = abs($x);
235 ok ($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;
242 print "# 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 ###############################################################################
248 # check reversed order of arguments
249
250 $try = "\$x = $class->new(10); \$x = 2 ** \$x;";
251 $try .= "'ok' if \$x == 1024;"; $ans = eval $try;
252 print "# 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;
256 print "# 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;
260 print "# 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;
264 print "# 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;
268 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
269
270 $try = "\$x = $class\->new(3); \$x = 20 % \$x;";
271 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
272 print "# 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;
276 print "# 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;
280 print "# 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;
284 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
285
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;
292 print "# 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);
307 ok (scalar @args,3);            # $class, 4, 5
308 ok ($args[0],$class);
309 ok ($args[1],4);
310 ok ($args[2],5);
311
312 @args = Math::BigInt::objectify(0,4,5);
313 ok (scalar @args,3);            # $class, 4, 5
314 ok ($args[0],$class);
315 ok ($args[1],4);
316 ok ($args[2],5);
317
318 @args = Math::BigInt::objectify(2,4,5);
319 ok (scalar @args,3);            # $class, 4, 5
320 ok ($args[0],$class);
321 ok ($args[1],4);
322 ok ($args[2],5);
323
324 @args = Math::BigInt::objectify(2,4,5,6,7);
325 ok (scalar @args,5);            # $class, 4, 5, 6, 7
326 ok ($args[0],$class);
327 ok ($args[1],4); ok (ref($args[1]),$args[0]);
328 ok ($args[2],5); ok (ref($args[2]),$args[0]);
329 ok ($args[3],6); ok (ref($args[3]),'');
330 ok ($args[4],7); ok (ref($args[4]),'');
331
332 @args = Math::BigInt::objectify(2,$class,4,5,6,7);
333 ok (scalar @args,5);            # $class, 4, 5, 6, 7
334 ok ($args[0],$class);
335 ok ($args[1],4); ok (ref($args[1]),$args[0]);
336 ok ($args[2],5); ok (ref($args[2]),$args[0]);
337 ok ($args[3],6); ok (ref($args[3]),'');
338 ok ($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;
356 ok ($x,"20988936657440586486151264256610222593863921");
357 ok ($x->length(),length "20988936657440586486151264256610222593863921");
358
359 # MM7 = 2^127-1
360 $x = $class->new(2); $x **= 127; $x--;
361 ok ($x,"170141183460469231731687303715884105727");
362
363 $x = $class->new('215960156869840440586892398248');
364 ($x,$y) = $x->length();
365 ok ($x,30); ok ($y,0);
366
367 $x = $class->new('1_000_000_000_000');
368 ($x,$y) = $x->length();
369 ok ($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
385 ok ($x,3);
386 ok (ref($x),'Math::Foo');
387
388 $x = Math::Foo->new(5);
389 $x = 8 - $x;            # 5 - 8 instead of 8 - 5
390 ok ($x,-3);
391 ok (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
404 exit if $CALC ne 'Math::BigInt::Calc'; # for Pari et al.
405
406 ###############################################################################
407 # check proper length of internal arrays
408
409 my $bl = Math::BigInt::Calc::_base_len();
410 my $BASE = '9' x $bl;
411 my $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) ); 
426 ok($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++;
432 if ($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);
436 if ($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;
443 ok ($z, 100000);
444 ok ($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);
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 = '';
455 for (my $i = 1; $i <= $bl; $i++)
456   {
457   $y .= $i; $d = $i.$d;
458   }
459 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
460 ok ($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
467 ok ($y,'0','not -0');   # not '-0'
468 is_valid($y);
469
470 ### all tests done ############################################################
471
472 1;
473
474 ###############################################################################
475 # Perl 5.005 does not like ok ($x,undef)
476
477 sub 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
489 sub 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
507   ok (1,$e." after op '$f'");
508   }
509
510 __DATA__
511 &.=
512 1234:-345:1234-345
513 &+=
514 1:2:3
515 -1:-2:-3
516 &-=
517 1:2:-1
518 -1:-2:1
519 &*=
520 2:3:6
521 -1:5:-5
522 &%=
523 100:3:1
524 8:9:8
525 &/=
526 100:3:33
527 -8:2:-4
528 &|=
529 2:1:3
530 &&=
531 5:7:5
532 &^=
533 5:7:2
534 &is_negative
535 0:0
536 -1:1
537 1:0
538 +inf:0
539 -inf:1
540 NaNneg:0
541 &is_positive
542 0:1
543 -1:0
544 1:1
545 +inf:1
546 -inf:0
547 NaNneg:0
548 &is_odd
549 abc:0
550 0:0
551 1:1
552 3:1
553 -1:1
554 -3:1
555 10000001:1
556 10000002:0
557 2:0
558 &is_even
559 abc:0
560 0:1
561 1:0
562 3:0
563 -1:0
564 -3:0
565 10000001:0
566 10000002:1
567 2: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
581 acmpNaN:123:
582 123:acmpNaN:
583 acmpNaN: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:
595 NaN:inf:
596 -inf:NaN:
597 NaN:-inf:
598 &bnorm
599 123:123
600 # binary input
601 0babc:NaN
602 0b123:NaN
603 0b0:0
604 -0b0:0
605 -0b1:-1
606 0b0001:1
607 0b001:1
608 0b011:3
609 0b101:5
610 0b1000000000000000000000000000000:1073741824
611 0b_101:NaN
612 0b1_0_1:5
613 # hex input
614 -0x0:0
615 0xabcdefgh:NaN
616 0x1234:4660
617 0xabcdef:11259375
618 -0xABCDEF:-11259375
619 -0x1234:-4660
620 0x12345678:305419896
621 0x1_2_3_4_56_78:305419896
622 0x_123:NaN
623 # inf input
624 inf:inf
625 +inf:inf
626 -inf:-inf
627 0inf:NaN
628 # abnormal input
629 :NaN
630 abc:NaN
631    1 a:NaN
632 1bcd2:NaN
633 11111b:NaN
634 +1z:NaN
635 -1z:NaN
636 # only one underscore between two digits
637 _123:NaN
638 _123_:NaN
639 123_:NaN
640 1__23:NaN
641 1E1__2:NaN
642 1_E12:NaN
643 1E_12:NaN
644 1_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
650 E1:NaN
651 E23:NaN
652 1.23E1:NaN
653 1.23E-1:NaN
654 # bug with two E's in number beeing valid
655 1e2e3:NaN
656 1e2r:NaN
657 1e2.0:NaN
658 # normal input
659 0:0
660 +0:0
661 +00:0
662 +000:0
663 000000000000000000:0
664 -0:0
665 -0000:0
666 +1:1
667 +01:1
668 +001:1
669 +00000100000:100000
670 123456789:123456789
671 -1:-1
672 -01:-1
673 -001:-1
674 -123456789:-123456789
675 -00000100000:-100000
676 1_2_3:123
677 10000000000E-1_0:1
678 1E2:100
679 1E1:10
680 1E0:1
681 1.23E2:123
682 100E-1:10
683 # floating point input
684 # .2e2:20
685 1.E3:1000
686 1.01E2:101
687 1010E-1:101
688 -1010E0:-1010
689 -1010E1:-10100
690 1234.00:1234
691 # non-integer numbers
692 -1010E-2:NaN
693 -1.01E+1:NaN
694 -1.01E-1:NaN
695 &bnan
696 1:NaN
697 2:NaN
698 abc:NaN
699 &bone
700 2:+:+1
701 2:-:-1
702 boneNaN:-:-1
703 boneNaN:+:+1
704 2:abc:+1
705 3::+1
706 &binf
707 1:+:inf
708 2:-:-inf
709 3:abc:inf
710 &is_nan
711 123:0
712 abc:1
713 NaN:1
714 -123:0
715 &is_inf
716 +inf::1
717 -inf::1
718 abc::0
719 1::0
720 NaN::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
730 abc: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
742 1234567890123:12:10:1234567890123000000000000
743 &brsft
744 abc: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
756 310000:4:10:31
757 12300000:5:10:123
758 1230000000000:10:10:123
759 09876123456789067890:12:10:9876123
760 1234561234567890123:13:10:123456
761 &bsstr
762 1e+34:1e+34
763 123.456E3:123456e+0
764 100:1e+2
765 abc:NaN
766 &bneg
767 bnegNaN:NaN
768 +inf:-inf
769 -inf:inf
770 abd:NaN
771 +0:+0
772 +1:-1
773 -1:+1
774 +123456789:-123456789
775 -123456789:+123456789
776 &babs
777 babsNaN:NaN
778 +inf:inf
779 -inf:inf
780 +0:+0
781 +1:+1
782 -1:+1
783 +123456789:+123456789
784 -123456789:+123456789
785 &bcmp
786 bcmpNaN:bcmpNaN:
787 bcmpNaN:+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
820 5:inf:-1
821 5:inf:-1
822 -5:-inf:1
823 -5:-inf:1
824 # return undef
825 +inf:NaN:
826 NaN:inf:
827 -inf:NaN:
828 NaN:-inf:
829 &binc
830 abc:NaN
831 +inf:inf
832 -inf:-inf
833 +0:+1
834 +1:+2
835 -1:+0
836 &bdec
837 abc:NaN
838 +inf:inf
839 -inf:-inf
840 +0:-1
841 +1:+0
842 -1:-2
843 &badd
844 abc:abc:NaN
845 abc:+0:NaN
846 +0:abc:NaN
847 +inf:-inf:0
848 -inf:+inf:0
849 +inf:+inf:inf
850 -inf:-inf:-inf
851 baddNaN:+inf:NaN
852 baddNaN:+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
890 abc:abc:NaN
891 abc:+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
932 abc:abc:NaN
933 abc:+0:NaN
934 +0:abc:NaN
935 NaNmul:+inf:NaN
936 NaNmul:-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
975 9999:10000:99990000
976 99999:100000:9999900000
977 999999:1000000:999999000000
978 9999999:10000000:99999990000000
979 99999999:100000000:9999999900000000
980 999999999:1000000000:999999999000000000
981 9999999999:10000000000:99999999990000000000
982 99999999999:100000000000:9999999999900000000000
983 999999999999:1000000000000:999999999999000000000000
984 9999999999999:10000000000000:99999999999990000000000000
985 99999999999999:100000000000000:9999999999999900000000000000
986 999999999999999:1000000000000000:999999999999999000000000000000
987 9999999999999999:10000000000000000:99999999999999990000000000000000
988 99999999999999999:100000000000000000:9999999999999999900000000000000000
989 999999999999999999:1000000000000000000:999999999999999999000000000000000000
990 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
991 &bdiv-list
992 100:20:5,0
993 4095:4095:1,0
994 -4095:-4095:1,0
995 4095:-4095:-1,0
996 -4095:4095:-1,0
997 123:2:61,1
998 # inf handling and general remainder
999 5:8:0,5
1000 0:8:0,0
1001 11:2:5,1
1002 11:-2:-5,-1
1003 -11:2:-5,1
1004 # see table in documentation in MBI
1005 0:inf:0,0
1006 0:-inf:0,0
1007 5:inf:0,5
1008 5:-inf:0,5
1009 -5:inf:0,-5
1010 -5:-inf:0,-5
1011 inf:5:inf,0
1012 -inf:5:-inf,0
1013 inf:-5:-inf,0
1014 -inf:-5:inf,0
1015 5:5:1,0
1016 -5:-5:1,0
1017 inf:inf:1,0
1018 -inf:-inf:1,0
1019 -inf:inf:-1,0
1020 inf:-inf:-1,0
1021 8:0:inf,8
1022 inf:0:inf,inf
1023 # exceptions to reminder rule
1024 -8:0:-inf,-8
1025 -inf:0:-inf,-inf
1026 0:0:NaN,NaN
1027 &bdiv
1028 abc:abc:NaN
1029 abc:+1:NaN
1030 +1:abc:NaN
1031 +0:+0:NaN
1032 # inf handling (see table in doc)
1033 0:inf:0
1034 0:-inf:0
1035 5:inf:0
1036 5:-inf:0
1037 -5:inf:0
1038 -5:-inf:0
1039 inf:5:inf
1040 -inf:5:-inf
1041 inf:-5:-inf
1042 -inf:-5:inf
1043 5:5:1
1044 -5:-5:1
1045 inf:inf:1
1046 -inf:-inf:1
1047 -inf:inf:-1
1048 inf:-inf:-1
1049 8:0:inf
1050 inf:0:inf
1051 -8:0:-inf
1052 -inf:0:-inf
1053 0:0:NaN
1054 11:2:5
1055 -11:-2:5
1056 -11:2:-5
1057 11:-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
1092 4:3:1
1093 4:-3:-1
1094 1:3:0
1095 1:-3:0
1096 -2:-3:0
1097 -2:3:0
1098 8:3:2
1099 -8:3:-2
1100 14:-3:-4
1101 -14:3:-4
1102 -14:-3:4
1103 14:3:4
1104 # bug in Calc with '99999' vs $BASE-1
1105 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1106 &bmod
1107 # inf handling, see table in doc
1108 0:inf:0
1109 0:-inf:0
1110 5:inf:5
1111 5:-inf:5
1112 -5:inf:-5
1113 -5:-inf:-5
1114 inf:5:0
1115 -inf:5:0
1116 inf:-5:0
1117 -inf:-5:0
1118 5:5:0
1119 -5:-5:0
1120 inf:inf:0
1121 -inf:-inf:0
1122 -inf:inf:0
1123 inf:-inf:0
1124 8:0:8
1125 inf:0:inf
1126 # exceptions to reminder rule
1127 -inf:0:-inf
1128 -8:0:-8
1129 0:0:NaN
1130 abc:abc:NaN
1131 abc:+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
1171 4:3:1
1172 1:3:1
1173 -5:-3:-2
1174 -2:-3:-2
1175 4:-3:-2
1176 1:-3:-2
1177 4095:4095:0
1178 100041000510123:3:0
1179 152403346:12345:4321
1180 &bgcd
1181 abc:abc:NaN
1182 abc:+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
1197 abc:abc:NaN
1198 abc:+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
1206 abc:abc:NaN
1207 abc:0:NaN
1208 0:abc:NaN
1209 1:2:0
1210 3: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
1222 abc:abc:NaN
1223 abc:0:NaN
1224 0:abc:NaN
1225 1: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
1236 abc:abc:NaN
1237 abc:0:NaN
1238 0:abc:NaN
1239 1: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
1249 4:-7:-3
1250 -4:-7:5
1251 &bnot
1252 abc:NaN
1253 +0:-1
1254 +8:-9
1255 +281474976710656:-281474976710657
1256 -1:0
1257 -2:1
1258 -12:11
1259 &digit
1260 0:0:0
1261 12:0:2
1262 12:1:1
1263 123:0:3
1264 123:1:2
1265 123:2:1
1266 123:-1:1
1267 123:-2:2
1268 123:-3:3
1269 123456:0:6
1270 123456:1:5
1271 123456:2:4
1272 123456:3:3
1273 123456:4:2
1274 123456:5:1
1275 123456:-1:1
1276 123456:-2:2
1277 123456:-3:3
1278 100000:-3:0
1279 100000:0:0
1280 100000:1:0
1281 &mantissa
1282 abc:NaN
1283 1e4:1
1284 2e0:2
1285 123:123
1286 -1:-1
1287 -2:-2
1288 +inf:inf
1289 -inf:-inf
1290 &exponent
1291 abc:NaN
1292 1e4:4
1293 2e0:0
1294 123:0
1295 -1:0
1296 -2:0
1297 0:1
1298 +inf:inf
1299 -inf:inf
1300 &parts
1301 abc:NaN,NaN
1302 1e4:1,4
1303 2e0:2,0
1304 123:123,0
1305 -1:-1,0
1306 -2:-2,0
1307 0:0,1
1308 +inf:inf,inf
1309 -inf:-inf,inf
1310 &bpow
1311 abc:12:NaN
1312 12:abc:NaN
1313 0:0:1
1314 0:1:0
1315 0:2:0
1316 0:-1:NaN
1317 0:-2:NaN
1318 1:0:1
1319 1:1:1
1320 1:2:1
1321 1:3:1
1322 1:-1:1
1323 1:-2:1
1324 1:-3:1
1325 2:0:1
1326 2:1:2
1327 2:2:4
1328 2:3:8
1329 3:3:27
1330 2:-1:NaN
1331 -2:-1:NaN
1332 2:-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
1350 10:2:100
1351 10:3:1000
1352 10:4:10000
1353 10:5:100000
1354 10:6:1000000
1355 10:7:10000000
1356 10:8:100000000
1357 10:9:1000000000
1358 10:20:100000000000000000000
1359 123456:2:15241383936
1360 &length
1361 100:3
1362 10:2
1363 1:1
1364 0:1
1365 12345:5
1366 10000000000000000:17
1367 -123:3
1368 215960156869840440586892398248:30
1369 &bsqrt
1370 144:12
1371 16:4
1372 4:2
1373 2:1
1374 12:3
1375 256:16
1376 100000000:10000
1377 4000000000000:2000000
1378 1:1
1379 0:0
1380 -2:NaN
1381 Nan:NaN
1382 &bround
1383 $round_mode('trunc')
1384 0:12:0
1385 NaNbround:12:NaN
1386 +inf:12:inf
1387 -inf:12:-inf
1388 1234:0:1234
1389 1234:2:1200
1390 123456:4:123400
1391 123456:5:123450
1392 123456: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
1463 0:1
1464 NaNzero:0
1465 +inf:0
1466 -inf:0
1467 123:0
1468 -1:0
1469 1:0
1470 &is_one
1471 0:0
1472 NaNone:0
1473 +inf:0
1474 -inf:0
1475 1:1
1476 2:0
1477 -1:0
1478 -2:0
1479 # floor and ceil tests are pretty pointless in integer space...but play safe
1480 &bfloor
1481 0:0
1482 NaNfloor:NaN
1483 +inf:inf
1484 -inf:-inf
1485 -1:-1
1486 -2:-2
1487 2:2
1488 3:3
1489 abc:NaN
1490 &bceil
1491 NaNceil:NaN
1492 +inf:inf
1493 -inf:-inf
1494 0:0
1495 -1:-1
1496 -2:-2
1497 2:2
1498 3:3
1499 abc:NaN
1500 &as_hex
1501 128:0x80
1502 -128:-0x80
1503 0:0x0
1504 -0:0x0
1505 1:0x1
1506 0x123456789123456789:0x123456789123456789
1507 +inf:inf
1508 -inf:-inf
1509 NaNas_hex:NaN
1510 &as_bin
1511 128:0b10000000
1512 -128:-0b10000000
1513 0:0b0
1514 -0:0b0
1515 1:0b1
1516 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1517 +inf:inf
1518 -inf:-inf
1519 NaNas_bin:NaN