This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Math::BigInt 1.59.
[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 lib => $main::CL;
11 use vars qw/@ISA/;
12 @ISA = (qw/Math::BigInt/);
13
14 use overload
15 # customized overload for sub, since original does not use swap there
16 '-'     =>      sub { my @a = ref($_[0])->_swap(@_);
17                    $a[0]->bsub($a[1])};
18
19 sub _swap
20   {
21   # a fake _swap, which reverses the params
22   my $self = shift;                     # for override in subclass
23   if ($_[2])
24     {
25     my $c = ref ($_[0] ) || 'Math::Foo';
26     return ( $_[0]->copy(), $_[1] );
27     }
28   else
29     {
30     return ( Math::Foo->new($_[1]), $_[0] );
31     }
32   }
33
34 ##############################################################################
35 package main;
36
37 my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
38
39 my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
40
41 while (<DATA>) 
42   {
43   chomp;
44   next if /^#/; # skip comments
45   if (s/^&//) 
46     {
47     $f = $_; next;
48     }
49   elsif (/^\$/) 
50     {
51     $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
52     }
53
54   @args = split(/:/,$_,99); $ans = pop(@args);
55   $expected_class = $class;
56   if ($ans =~ /(.*?)=(.*)/)
57     {
58     $expected_class = $2; $ans = $1;
59     }
60   $try = "\$x = $class->new(\"$args[0]\");";
61   if ($f eq "bnorm")
62     {
63     $try = "\$x = $class->bnorm(\"$args[0]\");";
64   # some is_xxx tests
65    } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
66     $try .= "\$x->$f();";
67    } elsif ($f eq "as_hex") {
68     $try .= '$x->as_hex();';
69    } elsif ($f eq "as_bin") {
70     $try .= '$x->as_bin();';
71    } elsif ($f eq "is_inf") {
72     $try .= "\$x->is_inf('$args[1]');";
73    } elsif ($f eq "binf") {
74     $try .= "\$x->binf('$args[1]');";
75    } elsif ($f eq "bone") {
76     $try .= "\$x->bone('$args[1]');";
77    # some unary ops
78    } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
79     $try .= "\$x->$f();";
80    } elsif ($f eq "length") {
81     $try .= '$x->length();';
82    } elsif ($f eq "exponent"){
83     # ->bstr() to see if an object is returned
84     $try .= '$x = $x->exponent()->bstr();';
85    } elsif ($f eq "mantissa"){
86     # ->bstr() to see if an object is returned
87     $try .= '$x = $x->mantissa()->bstr();';
88    } elsif ($f eq "parts"){
89     $try .= '($m,$e) = $x->parts();'; 
90     # ->bstr() to see if an object is returned
91     $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
92     $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
93     $try .= '"$m,$e";';
94    } else {
95     $try .= "\$y = $class->new('$args[1]');";
96     if ($f eq "bcmp")
97       {
98       $try .= '$x <=> $y;';
99       } elsif ($f eq "bround") {
100       $try .= "$round_mode; \$x->bround(\$y);";
101       } elsif ($f eq "bacmp"){
102       $try .= '$x->bacmp($y);';
103       } elsif ($f eq "badd"){
104       $try .= '$x + $y;';
105       } elsif ($f eq "bsub"){
106       $try .= '$x - $y;';
107       } elsif ($f eq "bmul"){
108       $try .= '$x * $y;';
109       } elsif ($f eq "bdiv"){
110       $try .= '$x / $y;';
111       } elsif ($f eq "bdiv-list"){
112       $try .= 'join (",",$x->bdiv($y));';
113       # overload via x=
114       } elsif ($f =~ /^.=$/){
115       $try .= "\$x $f \$y;";
116       # overload via x
117       } elsif ($f =~ /^.$/){
118       $try .= "\$x $f \$y;";
119       } elsif ($f eq "bmod"){
120       $try .= '$x % $y;';
121       } elsif ($f eq "bgcd")
122         {
123         if (defined $args[2])
124           {
125           $try .= " \$z = $class->new('$args[2]'); ";
126           }
127         $try .= "$class\::bgcd(\$x, \$y";
128         $try .= ", \$z" if (defined $args[2]);
129         $try .= " );";
130         }
131       elsif ($f eq "blcm")
132         {
133         if (defined $args[2])
134           {
135           $try .= " \$z = $class->new('$args[2]'); ";
136           }
137         $try .= "$class\::blcm(\$x, \$y";
138         $try .= ", \$z" if (defined $args[2]);
139         $try .= " );";
140       }elsif ($f eq "blsft"){
141         if (defined $args[2])
142           {
143           $try .= "\$x->blsft(\$y,$args[2]);";
144           }
145         else
146           {
147           $try .= "\$x << \$y;";
148           }
149       }elsif ($f eq "brsft"){
150         if (defined $args[2])
151           {
152           $try .= "\$x->brsft(\$y,$args[2]);";
153           }
154         else
155           {
156           $try .= "\$x >> \$y;";
157           }
158       }elsif ($f eq "band"){
159         $try .= "\$x & \$y;";
160       }elsif ($f eq "bior"){
161         $try .= "\$x | \$y;";
162       }elsif ($f eq "bxor"){
163         $try .= "\$x ^ \$y;";
164       }elsif ($f eq "bpow"){
165         $try .= "\$x ** \$y;";
166       } elsif( $f eq "bmodinv") {
167        $try .= "\$x->bmodinv(\$y);";
168       }elsif ($f eq "digit"){
169         $try .= "\$x->digit(\$y);";
170       } else {
171        $try .= "\$z = $class->new(\"$args[2]\");";
172
173        # Functions with three arguments
174        if( $f eq "bmodpow") {
175          $try .= "\$x->bmodpow(\$y,\$z);";
176        } else { warn "Unknown op '$f'"; }
177       }
178     } # end else all other ops
179
180   $ans1 = eval $try;
181   # convert hex/binary targets to decimal       
182   if ($ans =~ /^(0x0x|0b0b)/)
183     {
184     $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
185     }
186   if ($ans eq "")
187     {
188     ok_undef ($ans1); 
189     }
190   else
191     {
192     # print "try: $try ans: $ans1 $ans\n";
193     print "# Tried: '$try'\n" if !ok ($ans1, $ans);
194     ok (ref($ans),$expected_class) if $expected_class ne $class;
195     }
196   # check internal state of number objects
197   is_valid($ans1,$f) if ref $ans1; 
198   } # endwhile data tests
199 close DATA;
200
201 # test some more
202 @a = ();
203 for (my $i = 1; $i < 10; $i++) 
204   {
205   push @a, $i;
206   }
207 ok "@a", "1 2 3 4 5 6 7 8 9";
208
209 # test whether self-multiplication works correctly (result is 2**64)
210 $try = "\$x = $class->new('4294967296');";
211 $try .= '$a = $x->bmul($x);';
212 $ans1 = eval $try;
213 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
214 # test self-pow
215 $try = "\$x = $class->new(10);";
216 $try .= '$a = $x->bpow($x);';
217 $ans1 = eval $try;
218 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
219
220 ###############################################################################
221 # test whether op destroys args or not (should better not)
222
223 $x = $class->new(3);
224 $y = $class->new(4);
225 $z = $x & $y;
226 ok ($x,3);
227 ok ($y,4);
228 ok ($z,0);
229 $z = $x | $y;
230 ok ($x,3);
231 ok ($y,4);
232 ok ($z,7);
233 $x = $class->new(1);
234 $y = $class->new(2);
235 $z = $x | $y;
236 ok ($x,1);
237 ok ($y,2);
238 ok ($z,3);
239
240 $x = $class->new(5);
241 $y = $class->new(4);
242 $z = $x ^ $y;
243 ok ($x,5);
244 ok ($y,4);
245 ok ($z,1);
246
247 $x = $class->new(-5); $y = -$x;
248 ok ($x, -5);
249
250 $x = $class->new(-5); $y = abs($x);
251 ok ($x, -5);
252
253 $x = $class->new(8);
254 $y = $class->new(-1);
255 $z = $class->new(5033);
256 my $u = $x->copy()->bmodpow($y,$z);
257 ok ($u,4404);
258 ok ($y,-1);
259 ok ($z,5033);
260
261 $x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
262 $x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
263
264 $x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
265 $x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
266 $x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
267 $x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
268 $x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
269
270 $x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
271 $x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
272 $x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
273 $x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
274 $x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
275
276 $x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
277 $x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
278 $x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
279 $x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
280 $x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
281
282 ###############################################################################
283 # check whether overloading cmp works
284 $try = "\$x = $class->new(0);";
285 $try .= "\$y = 10;";
286 $try .= "'false' if \$x ne \$y;";
287 $ans = eval $try;
288 print "# For '$try'\n" if (!ok "$ans" , "false" ); 
289
290 # we cant test for working cmpt with other objects here, we would need a dummy
291 # object with stringify overload for this. see Math::String tests as example
292
293 ###############################################################################
294 # check reversed order of arguments
295
296 $try = "\$x = $class->new(10); \$x = 2 ** \$x;";
297 $try .= "'ok' if \$x == 1024;"; $ans = eval $try;
298 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
299
300 $try = "\$x = $class->new(10); \$x = 2 * \$x;";
301 $try .= "'ok' if \$x == 20;"; $ans = eval $try;
302 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
303
304 $try = "\$x = $class->new(10); \$x = 2 + \$x;";
305 $try .= "'ok' if \$x == 12;"; $ans = eval $try;
306 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
307
308 $try = "\$x = $class\->new(10); \$x = 2 - \$x;";
309 $try .= "'ok' if \$x == -8;"; $ans = eval $try;
310 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
311
312 $try = "\$x = $class\->new(10); \$x = 20 / \$x;";
313 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
314 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
315
316 $try = "\$x = $class\->new(3); \$x = 20 % \$x;";
317 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
318 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
319
320 $try = "\$x = $class\->new(7); \$x = 20 & \$x;";
321 $try .= "'ok' if \$x == 4;"; $ans = eval $try;
322 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
323
324 $try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
325 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
326 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
327
328 $try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
329 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
330 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
331
332 ###############################################################################
333 # check badd(4,5) form
334
335 $try = "\$x = $class\->badd(4,5);";
336 $try .= "'ok' if \$x == 9;";
337 $ans = eval $try;
338 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
339
340 ###############################################################################
341 # check undefs: NOT DONE YET
342
343 ###############################################################################
344 # bool
345
346 $x = Math::BigInt->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
347 $x = Math::BigInt->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
348
349 ###############################################################################
350 # objectify()
351
352 @args = Math::BigInt::objectify(2,4,5);
353 ok (scalar @args,3);            # $class, 4, 5
354 ok ($args[0] =~ /^Math::BigInt/);
355 ok ($args[1],4);
356 ok ($args[2],5);
357
358 @args = Math::BigInt::objectify(0,4,5);
359 ok (scalar @args,3);            # $class, 4, 5
360 ok ($args[0] =~ /^Math::BigInt/);
361 ok ($args[1],4);
362 ok ($args[2],5);
363
364 @args = Math::BigInt::objectify(2,4,5);
365 ok (scalar @args,3);            # $class, 4, 5
366 ok ($args[0] =~ /^Math::BigInt/);
367 ok ($args[1],4);
368 ok ($args[2],5);
369
370 @args = Math::BigInt::objectify(2,4,5,6,7);
371 ok (scalar @args,5);            # $class, 4, 5, 6, 7
372 ok ($args[0] =~ /^Math::BigInt/);
373 ok ($args[1],4); ok (ref($args[1]),$args[0]);
374 ok ($args[2],5); ok (ref($args[2]),$args[0]);
375 ok ($args[3],6); ok (ref($args[3]),'');
376 ok ($args[4],7); ok (ref($args[4]),'');
377
378 @args = Math::BigInt::objectify(2,$class,4,5,6,7);
379 ok (scalar @args,5);            # $class, 4, 5, 6, 7
380 ok ($args[0],$class);
381 ok ($args[1],4); ok (ref($args[1]),$args[0]);
382 ok ($args[2],5); ok (ref($args[2]),$args[0]);
383 ok ($args[3],6); ok (ref($args[3]),'');
384 ok ($args[4],7); ok (ref($args[4]),'');
385
386 ###############################################################################
387 # test for floating-point input (other tests in bnorm() below)
388
389 $z = 1050000000000000;          # may be int on systems with 64bit?
390 $x = $class->new($z); ok ($x->bsstr(),'105e+13');       # not 1.05e+15
391 $z = 1e+129;                    # definitely a float (may fail on UTS)
392 # don't compare to $z, since some Perl versions stringify $z into something
393 # like '1.e+129' or something equally ugly
394 $x = $class->new($z); ok ($x->bsstr(),'1e+129');
395
396 ###############################################################################
397 # prime number tests, also test for **= and length()
398 # found on: http://www.utm.edu/research/primes/notes/by_year.html
399
400 # ((2^148)-1)/17
401 $x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
402 ok ($x,"20988936657440586486151264256610222593863921");
403 ok ($x->length(),length "20988936657440586486151264256610222593863921");
404
405 # MM7 = 2^127-1
406 $x = $class->new(2); $x **= 127; $x--;
407 ok ($x,"170141183460469231731687303715884105727");
408
409 $x = $class->new('215960156869840440586892398248');
410 ($x,$y) = $x->length();
411 ok ($x,30); ok ($y,0);
412
413 $x = $class->new('1_000_000_000_000');
414 ($x,$y) = $x->length();
415 ok ($x,13); ok ($y,0);
416
417 # I am afraid the following is not yet possible due to slowness
418 # Also, testing for 2 meg output is a bit hard ;)
419 #$x = $class->new(2); $x **= 6972593; $x--;
420
421 # 593573509*2^332162+1 has exactly 1,000,000 digits
422 # takes about 24 mins on 300 Mhz, so cannot be done yet ;)
423 #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
424 #ok ($x->length(),1_000_000);
425
426 ###############################################################################
427 # inheritance and overriding of _swap
428
429 $x = Math::Foo->new(5);
430 $x = $x - 8;            # 8 - 5 instead of 5-8
431 ok ($x,3);
432 ok (ref($x),'Math::Foo');
433
434 $x = Math::Foo->new(5);
435 $x = 8 - $x;            # 5 - 8 instead of 8 - 5
436 ok ($x,-3);
437 ok (ref($x),'Math::Foo');
438
439 ###############################################################################
440 # Test whether +inf eq inf
441 # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
442 # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
443 # like 1e100000 crash on some platforms. So simple test for the string 'inf'
444 $x = $class->new('+inf'); ok ($x,'inf');
445
446 ###############################################################################
447 ###############################################################################
448 # the followin tests only make sense with Math::BigInt::Calc or BareCalc
449
450 exit if $CALC !~ /^Math::BigInt::(Calc|BareCalc)$/; # for Pari et al.
451
452 ###############################################################################
453 # check proper length of internal arrays
454
455 my $bl = $CL->_base_len();
456 my $BASE = '9' x $bl;
457 my $MAX = $BASE;
458 $BASE++;
459
460 $x = $class->new($MAX); is_valid($x);   # f.i. 9999
461 $x += 1; ok ($x,$BASE); is_valid($x);   # 10000
462 $x -= 1; ok ($x,$MAX); is_valid($x);    # 9999 again
463
464 ###############################################################################
465 # check numify
466
467 $x = $class->new($BASE-1);     ok ($x->numify(),$BASE-1); 
468 $x = $class->new(-($BASE-1));  ok ($x->numify(),-($BASE-1)); 
469
470 # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
471 $x = $class->new($BASE);       ok ($x->numify()+0,$BASE+0);     
472 $x = $class->new(-$BASE);      ok ($x->numify(),-$BASE);
473 $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) ); 
474 ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); 
475
476 ###############################################################################
477 # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
478
479 $x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
480 if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
481
482 $x = $class->new($BASE+3); $x++;
483 if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
484
485 # test for +0 instead of int(): 
486 $x = $class->new($MAX); ok ($x->length(), length($MAX));
487
488 ###############################################################################
489 # test bug that $class->digit($string) did not work
490
491 ok ($class->digit(123,2),1);
492
493 ###############################################################################
494 # bug in sub where number with at least 6 trailing zeros after any op failed
495
496 $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
497 ok ($z, 100000);
498 ok ($x, 23456);
499
500 ###############################################################################
501 # bug in shortcut in mul()
502
503 # construct a number with a zero-hole of BASE_LEN_SMALL
504 {
505  my @bl = $CL->_base_len(); my $bl = $bl[4];
506
507  $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
508  $y = '1' x (2*$bl);
509  $x = $class->new($x)->bmul($y);
510  # result is 123..$bl .  $bl x (3*bl-1) . $bl...321 . '0' x $bl
511  $y = ''; my $d = '';
512  for (my $i = 1; $i <= $bl; $i++)
513    {
514    $y .= $i; $d = $i.$d;
515    }
516  $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
517  ok ($x,$y);
518
519
520 ###############################################################################
521 # see if mul shortcut for small numbers works
522
523 $x = '9' x $bl;
524 $x = $class->new($x); 
525 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
526 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
527
528  }
529
530 ###############################################################################
531 # bug with rest "-0" in div, causing further div()s to fail
532
533 $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
534
535 ok ($y,'0'); is_valid($y);      # $y not '-0'
536
537 ###############################################################################
538 # bug in $x->bmod($y) if $x < 0 and $y > 0
539
540 $x = $class->new('-629'); ok ($x->bmod(5033),4404);
541
542 ###############################################################################
543 # bone/binf etc as plain calls (Lite failed them)
544
545 ok ($class->bzero(),0);
546 ok ($class->bone(),1);
547 ok ($class->bone('+'),1);
548 ok ($class->bone('-'),-1);
549 ok ($class->bnan(),'NaN');
550 ok ($class->binf(),'inf');
551 ok ($class->binf('+'),'inf');
552 ok ($class->binf('-'),'-inf');
553 ok ($class->binf('-inf'),'-inf');
554
555 ###############################################################################
556 # all tests done
557
558 1;
559
560 ###############################################################################
561 ###############################################################################
562 # Perl 5.005 does not like ok ($x,undef)
563
564 sub ok_undef
565   {
566   my $x = shift;
567
568   ok (1,1) and return if !defined $x;
569   ok ($x,'undef');
570   }
571
572 ###############################################################################
573 # sub to check validity of a BigInt internally, to ensure that no op leaves a
574 # number object in an invalid state (f.i. "-0")
575
576 sub is_valid
577   {
578   my ($x,$f) = @_;
579
580   my $e = 0;                    # error?
581
582   # allow the check to pass for all Lite, and all MBI and subclasses
583   # ok as reference? 
584   $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
585
586   if (ref($x) ne 'Math::BigInt::Lite')
587     {
588     # has ok sign?
589     $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
590      if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
591   
592     $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
593     $e = $CALC->_check($x->{value}) if $e eq '0';
594     }
595
596   # test done, see if error did crop up
597   ok (1,1), return if ($e eq '0');
598
599   ok (1,$e." after op '$f'");
600   }
601
602 __DATA__
603 &.=
604 1234:-345:1234-345
605 &+=
606 1:2:3
607 -1:-2:-3
608 &-=
609 1:2:-1
610 -1:-2:1
611 &*=
612 2:3:6
613 -1:5:-5
614 &%=
615 100:3:1
616 8:9:8
617 -629:5033:4404
618 &/=
619 100:3:33
620 -8:2:-4
621 &|=
622 2:1:3
623 &&=
624 5:7:5
625 &^=
626 5:7:2
627 &is_negative
628 0:0
629 -1:1
630 1:0
631 +inf:0
632 -inf:1
633 NaNneg:0
634 &is_positive
635 0:1
636 -1:0
637 1:1
638 +inf:1
639 -inf:0
640 NaNneg:0
641 &is_int
642 -inf:0
643 +inf:0
644 NaNis_int:0
645 1:1
646 0:1
647 123e12:1
648 &is_odd
649 abc:0
650 0:0
651 1:1
652 3:1
653 -1:1
654 -3:1
655 10000001:1
656 10000002:0
657 2:0
658 120:0
659 121:1
660 &is_even
661 abc:0
662 0:1
663 1:0
664 3:0
665 -1:0
666 -3:0
667 10000001:0
668 10000002:1
669 2:1
670 120:1
671 121:0
672 &bacmp
673 +0:-0:0
674 +0:+1:-1
675 -1:+1:0
676 +1:-1:0
677 -1:+2:-1
678 +2:-1:1
679 -123456789:+987654321:-1
680 +123456789:-987654321:-1
681 +987654321:+123456789:1
682 -987654321:+123456789:1
683 -123:+4567889:-1
684 # NaNs
685 acmpNaN:123:
686 123:acmpNaN:
687 acmpNaN:acmpNaN:
688 # infinity
689 +inf:+inf:0
690 -inf:-inf:0
691 +inf:-inf:0
692 -inf:+inf:0
693 +inf:123:1
694 -inf:123:1
695 +inf:-123:1
696 -inf:-123:1
697 # return undef
698 +inf:NaN:
699 NaN:inf:
700 -inf:NaN:
701 NaN:-inf:
702 &bnorm
703 123:123
704 # binary input
705 0babc:NaN
706 0b123:NaN
707 0b0:0
708 -0b0:0
709 -0b1:-1
710 0b0001:1
711 0b001:1
712 0b011:3
713 0b101:5
714 0b1001:9
715 0b10001:17
716 0b100001:33
717 0b1000001:65
718 0b10000001:129
719 0b100000001:257
720 0b1000000001:513
721 0b10000000001:1025
722 0b100000000001:2049
723 0b1000000000001:4097
724 0b10000000000001:8193
725 0b100000000000001:16385
726 0b1000000000000001:32769
727 0b10000000000000001:65537
728 0b100000000000000001:131073
729 0b1000000000000000001:262145
730 0b10000000000000000001:524289
731 0b100000000000000000001:1048577
732 0b1000000000000000000001:2097153
733 0b10000000000000000000001:4194305
734 0b100000000000000000000001:8388609
735 0b1000000000000000000000001:16777217
736 0b10000000000000000000000001:33554433
737 0b100000000000000000000000001:67108865
738 0b1000000000000000000000000001:134217729
739 0b10000000000000000000000000001:268435457
740 0b100000000000000000000000000001:536870913
741 0b1000000000000000000000000000001:1073741825
742 0b10000000000000000000000000000001:2147483649
743 0b100000000000000000000000000000001:4294967297
744 0b1000000000000000000000000000000001:8589934593
745 0b10000000000000000000000000000000001:17179869185
746 0b_101:NaN
747 0b1_0_1:5
748 0b0_0_0_1:1
749 # hex input
750 -0x0:0
751 0xabcdefgh:NaN
752 0x1234:4660
753 0xabcdef:11259375
754 -0xABCDEF:-11259375
755 -0x1234:-4660
756 0x12345678:305419896
757 0x1_2_3_4_56_78:305419896
758 0xa_b_c_d_e_f:11259375
759 0x_123:NaN
760 0x9:9
761 0x11:17
762 0x21:33
763 0x41:65
764 0x81:129
765 0x101:257
766 0x201:513
767 0x401:1025
768 0x801:2049
769 0x1001:4097
770 0x2001:8193
771 0x4001:16385
772 0x8001:32769
773 0x10001:65537
774 0x20001:131073
775 0x40001:262145
776 0x80001:524289
777 0x100001:1048577
778 0x200001:2097153
779 0x400001:4194305
780 0x800001:8388609
781 0x1000001:16777217
782 0x2000001:33554433
783 0x4000001:67108865
784 0x8000001:134217729
785 0x10000001:268435457
786 0x20000001:536870913
787 0x40000001:1073741825
788 0x80000001:2147483649
789 0x100000001:4294967297
790 0x200000001:8589934593
791 0x400000001:17179869185
792 0x800000001:34359738369
793 # inf input
794 inf:inf
795 +inf:inf
796 -inf:-inf
797 0inf:NaN
798 # abnormal input
799 :NaN
800 abc:NaN
801    1 a:NaN
802 1bcd2:NaN
803 11111b:NaN
804 +1z:NaN
805 -1z:NaN
806 # only one underscore between two digits
807 _123:NaN
808 _123_:NaN
809 123_:NaN
810 1__23:NaN
811 1E1__2:NaN
812 1_E12:NaN
813 1E_12:NaN
814 1_E_12:NaN
815 +_1E12:NaN
816 +0_1E2:100
817 +0_0_1E2:100
818 -0_0_1E2:-100
819 -0_0_1E+0_0_2:-100
820 E1:NaN
821 E23:NaN
822 1.23E1:NaN
823 1.23E-1:NaN
824 # bug with two E's in number beeing valid
825 1e2e3:NaN
826 1e2r:NaN
827 1e2.0:NaN
828 # bug with two '.' in number beeing valid
829 1.2.2:NaN
830 1.2.3e1:NaN
831 -1.2.3:NaN
832 -1.2.3e-4:NaN
833 1.2e3.4:NaN
834 1.2e-3.4:NaN
835 1.2.3.4:NaN
836 1.2.t:NaN
837 1..2:NaN
838 1..2e1:NaN
839 1..2e1..1:NaN
840 12e1..1:NaN
841 ..2:NaN
842 .-2:NaN
843 # leading zeros
844 012:12
845 0123:123
846 01234:1234
847 012345:12345
848 0123456:123456
849 01234567:1234567
850 012345678:12345678
851 0123456789:123456789
852 01234567891:1234567891
853 012345678912:12345678912
854 0123456789123:123456789123
855 01234567891234:1234567891234
856 # normal input
857 0:0
858 +0:0
859 +00:0
860 +000:0
861 000000000000000000:0
862 -0:0
863 -0000:0
864 +1:1
865 +01:1
866 +001:1
867 +00000100000:100000
868 123456789:123456789
869 -1:-1
870 -01:-1
871 -001:-1
872 -123456789:-123456789
873 -00000100000:-100000
874 1_2_3:123
875 10000000000E-1_0:1
876 1E2:100
877 1E1:10
878 1E0:1
879 1.23E2:123
880 100E-1:10
881 # floating point input
882 # .2e2:20
883 1.E3:1000
884 1.01E2:101
885 1010E-1:101
886 -1010E0:-1010
887 -1010E1:-10100
888 1234.00:1234
889 # non-integer numbers
890 -1010E-2:NaN
891 -1.01E+1:NaN
892 -1.01E-1:NaN
893 &bnan
894 1:NaN
895 2:NaN
896 abc:NaN
897 &bone
898 2:+:1
899 2:-:-1
900 boneNaN:-:-1
901 boneNaN:+:1
902 2:abc:1
903 3::1
904 &binf
905 1:+:inf
906 2:-:-inf
907 3:abc:inf
908 &is_nan
909 123:0
910 abc:1
911 NaN:1
912 -123:0
913 &is_inf
914 +inf::1
915 -inf::1
916 abc::0
917 1::0
918 NaN::0
919 -1::0
920 +inf:-:0
921 +inf:+:1
922 -inf:-:1
923 -inf:+:0
924 -inf:-inf:1
925 -inf:+inf:0
926 +inf:-inf:0
927 +inf:+inf:1
928 # it must be exactly /^[+-]inf$/
929 +infinity::0
930 -infinity::0
931 &blsft
932 abc:abc:NaN
933 +2:+2:8
934 +1:+32:4294967296
935 +1:+48:281474976710656
936 +8:-2:NaN
937 # excercise base 10
938 +12345:4:10:123450000
939 -1234:0:10:-1234
940 +1234:0:10:1234
941 +2:2:10:200
942 +12:2:10:1200
943 +1234:-3:10:NaN
944 1234567890123:12:10:1234567890123000000000000
945 -3:1:2:-6
946 -5:1:2:-10
947 -2:1:2:-4
948 -102533203:1:2:-205066406
949 &brsft
950 abc:abc:NaN
951 +8:+2:2
952 +4294967296:+32:1
953 +281474976710656:+48:1
954 +2:-2:NaN
955 # excercise base 10
956 -1234:0:10:-1234
957 +1234:0:10:1234
958 +200:2:10:2
959 +1234:3:10:1
960 +1234:2:10:12
961 +1234:-3:10:NaN
962 310000:4:10:31
963 12300000:5:10:123
964 1230000000000:10:10:123
965 09876123456789067890:12:10:9876123
966 1234561234567890123:13:10:123456
967 820265627:1:2:410132813
968 # test shifting negative numbers in base 2
969 -15:1:2:-8
970 -14:1:2:-7
971 -13:1:2:-7
972 -12:1:2:-6
973 -11:1:2:-6
974 -10:1:2:-5
975 -9:1:2:-5
976 -8:1:2:-4
977 -7:1:2:-4
978 -6:1:2:-3
979 -5:1:2:-3
980 -4:1:2:-2
981 -3:1:2:-2
982 -2:1:2:-1
983 -1:1:2:-1
984 -1640531254:2:2:-410132814
985 -1640531254:1:2:-820265627
986 -820265627:1:2:-410132814
987 -205066405:1:2:-102533203
988 &bsstr
989 1e+34:1e+34
990 123.456E3:123456e+0
991 100:1e+2
992 abc:NaN
993 &bneg
994 bnegNaN:NaN
995 +inf:-inf
996 -inf:inf
997 abd:NaN
998 0:0
999 1:-1
1000 -1:1
1001 +123456789:-123456789
1002 -123456789:123456789
1003 &babs
1004 babsNaN:NaN
1005 +inf:inf
1006 -inf:inf
1007 0:0
1008 1:1
1009 -1:1
1010 +123456789:123456789
1011 -123456789:123456789
1012 &bcmp
1013 bcmpNaN:bcmpNaN:
1014 bcmpNaN:0:
1015 0:bcmpNaN:
1016 0:0:0
1017 -1:0:-1
1018 0:-1:1
1019 1:0:1
1020 0:1:-1
1021 -1:1:-1
1022 1:-1:1
1023 -1:-1:0
1024 1:1:0
1025 123:123:0
1026 123:12:1
1027 12:123:-1
1028 -123:-123:0
1029 -123:-12:-1
1030 -12:-123:1
1031 123:124:-1
1032 124:123:1
1033 -123:-124:1
1034 -124:-123:-1
1035 100:5:1
1036 -123456789:987654321:-1
1037 +123456789:-987654321:1
1038 -987654321:123456789:-1
1039 -inf:5432112345:-1
1040 +inf:5432112345:1
1041 -inf:-5432112345:-1
1042 +inf:-5432112345:1
1043 +inf:+inf:0
1044 -inf:-inf:0
1045 +inf:-inf:1
1046 -inf:+inf:-1
1047 5:inf:-1
1048 5:inf:-1
1049 -5:-inf:1
1050 -5:-inf:1
1051 # return undef
1052 +inf:NaN:
1053 NaN:inf:
1054 -inf:NaN:
1055 NaN:-inf:
1056 &binc
1057 abc:NaN
1058 +inf:inf
1059 -inf:-inf
1060 +0:1
1061 +1:2
1062 -1:0
1063 &bdec
1064 abc:NaN
1065 +inf:inf
1066 -inf:-inf
1067 +0:-1
1068 +1:0
1069 -1:-2
1070 &badd
1071 abc:abc:NaN
1072 abc:0:NaN
1073 +0:abc:NaN
1074 +inf:-inf:NaN
1075 -inf:+inf:NaN
1076 +inf:+inf:inf
1077 -inf:-inf:-inf
1078 baddNaN:+inf:NaN
1079 baddNaN:+inf:NaN
1080 +inf:baddNaN:NaN
1081 -inf:baddNaN:NaN
1082 0:0:0
1083 1:0:1
1084 0:1:1
1085 1:1:2
1086 -1:0:-1
1087 0:-1:-1
1088 -1:-1:-2
1089 -1:+1:0
1090 +1:-1:0
1091 +9:+1:10
1092 +99:+1:100
1093 +999:+1:1000
1094 +9999:+1:10000
1095 +99999:+1:100000
1096 +999999:+1:1000000
1097 +9999999:+1:10000000
1098 +99999999:+1:100000000
1099 +999999999:+1:1000000000
1100 +9999999999:+1:10000000000
1101 +99999999999:+1:100000000000
1102 +10:-1:9
1103 +100:-1:99
1104 +1000:-1:999
1105 +10000:-1:9999
1106 +100000:-1:99999
1107 +1000000:-1:999999
1108 +10000000:-1:9999999
1109 +100000000:-1:99999999
1110 +1000000000:-1:999999999
1111 +10000000000:-1:9999999999
1112 +123456789:987654321:1111111110
1113 -123456789:987654321:864197532
1114 -123456789:-987654321:-1111111110
1115 +123456789:-987654321:-864197532
1116 -1:10001:10000
1117 -1:100001:100000
1118 -1:1000001:1000000
1119 -1:10000001:10000000
1120 -1:100000001:100000000
1121 -1:1000000001:1000000000
1122 -1:10000000001:10000000000
1123 -1:100000000001:100000000000
1124 -1:1000000000001:1000000000000
1125 -1:10000000000001:10000000000000
1126 -1:-10001:-10002
1127 -1:-100001:-100002
1128 -1:-1000001:-1000002
1129 -1:-10000001:-10000002
1130 -1:-100000001:-100000002
1131 -1:-1000000001:-1000000002
1132 -1:-10000000001:-10000000002
1133 -1:-100000000001:-100000000002
1134 -1:-1000000000001:-1000000000002
1135 -1:-10000000000001:-10000000000002
1136 &bsub
1137 abc:abc:NaN
1138 abc:+0:NaN
1139 +0:abc:NaN
1140 +inf:-inf:inf
1141 -inf:+inf:-inf
1142 +inf:+inf:NaN
1143 -inf:-inf:NaN
1144 +0:+0:0
1145 +1:+0:1
1146 +0:+1:-1
1147 +1:+1:0
1148 -1:+0:-1
1149 +0:-1:1
1150 -1:-1:0
1151 -1:+1:-2
1152 +1:-1:2
1153 +9:+1:8
1154 +99:+1:98
1155 +999:+1:998
1156 +9999:+1:9998
1157 +99999:+1:99998
1158 +999999:+1:999998
1159 +9999999:+1:9999998
1160 +99999999:+1:99999998
1161 +999999999:+1:999999998
1162 +9999999999:+1:9999999998
1163 +99999999999:+1:99999999998
1164 +10:-1:11
1165 +100:-1:101
1166 +1000:-1:1001
1167 +10000:-1:10001
1168 +100000:-1:100001
1169 +1000000:-1:1000001
1170 +10000000:-1:10000001
1171 +100000000:-1:100000001
1172 +1000000000:-1:1000000001
1173 +10000000000:-1:10000000001
1174 +123456789:+987654321:-864197532
1175 -123456789:+987654321:-1111111110
1176 -123456789:-987654321:864197532
1177 +123456789:-987654321:1111111110
1178 10001:1:10000
1179 100001:1:100000
1180 1000001:1:1000000
1181 10000001:1:10000000
1182 100000001:1:100000000
1183 1000000001:1:1000000000
1184 10000000001:1:10000000000
1185 100000000001:1:100000000000
1186 1000000000001:1:1000000000000
1187 10000000000001:1:10000000000000
1188 10001:-1:10002
1189 100001:-1:100002
1190 1000001:-1:1000002
1191 10000001:-1:10000002
1192 100000001:-1:100000002
1193 1000000001:-1:1000000002
1194 10000000001:-1:10000000002
1195 100000000001:-1:100000000002
1196 1000000000001:-1:1000000000002
1197 10000000000001:-1:10000000000002
1198 &bmul
1199 abc:abc:NaN
1200 abc:+0:NaN
1201 +0:abc:NaN
1202 NaNmul:+inf:NaN
1203 NaNmul:-inf:NaN
1204 -inf:NaNmul:NaN
1205 +inf:NaNmul:NaN
1206 +inf:+inf:inf
1207 +inf:-inf:-inf
1208 -inf:+inf:-inf
1209 -inf:-inf:inf
1210 +0:+0:0
1211 +0:+1:0
1212 +1:+0:0
1213 +0:-1:0
1214 -1:+0:0
1215 123456789123456789:0:0
1216 0:123456789123456789:0
1217 -1:-1:1
1218 -1:+1:-1
1219 +1:-1:-1
1220 +1:+1:1
1221 +2:+3:6
1222 -2:+3:-6
1223 +2:-3:-6
1224 -2:-3:6
1225 111:111:12321
1226 10101:10101:102030201
1227 1001001:1001001:1002003002001
1228 100010001:100010001:10002000300020001
1229 10000100001:10000100001:100002000030000200001
1230 11111111111:9:99999999999
1231 22222222222:9:199999999998
1232 33333333333:9:299999999997
1233 44444444444:9:399999999996
1234 55555555555:9:499999999995
1235 66666666666:9:599999999994
1236 77777777777:9:699999999993
1237 88888888888:9:799999999992
1238 99999999999:9:899999999991
1239 +25:+25:625
1240 +12345:+12345:152399025
1241 +99999:+11111:1111088889
1242 9999:10000:99990000
1243 99999:100000:9999900000
1244 999999:1000000:999999000000
1245 9999999:10000000:99999990000000
1246 99999999:100000000:9999999900000000
1247 999999999:1000000000:999999999000000000
1248 9999999999:10000000000:99999999990000000000
1249 99999999999:100000000000:9999999999900000000000
1250 999999999999:1000000000000:999999999999000000000000
1251 9999999999999:10000000000000:99999999999990000000000000
1252 99999999999999:100000000000000:9999999999999900000000000000
1253 999999999999999:1000000000000000:999999999999999000000000000000
1254 9999999999999999:10000000000000000:99999999999999990000000000000000
1255 99999999999999999:100000000000000000:9999999999999999900000000000000000
1256 999999999999999999:1000000000000000000:999999999999999999000000000000000000
1257 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1258 &bdiv-list
1259 100:20:5,0
1260 4095:4095:1,0
1261 -4095:-4095:1,0
1262 4095:-4095:-1,0
1263 -4095:4095:-1,0
1264 123:2:61,1
1265 9:5:1,4
1266 9:4:2,1
1267 # inf handling and general remainder
1268 5:8:0,5
1269 0:8:0,0
1270 11:2:5,1
1271 11:-2:-5,-1
1272 -11:2:-5,1
1273 # see table in documentation in MBI
1274 0:inf:0,0
1275 0:-inf:0,0
1276 5:inf:0,5
1277 5:-inf:0,5
1278 -5:inf:0,-5
1279 -5:-inf:0,-5
1280 inf:5:inf,0
1281 -inf:5:-inf,0
1282 inf:-5:-inf,0
1283 -inf:-5:inf,0
1284 5:5:1,0
1285 -5:-5:1,0
1286 inf:inf:NaN,NaN
1287 -inf:-inf:NaN,NaN
1288 -inf:inf:NaN,NaN
1289 inf:-inf:NaN,NaN
1290 8:0:inf,8
1291 inf:0:inf,inf
1292 # exceptions to reminder rule
1293 -8:0:-inf,-8
1294 -inf:0:-inf,-inf
1295 0:0:NaN,NaN
1296 &bdiv
1297 abc:abc:NaN
1298 abc:1:NaN
1299 1:abc:NaN
1300 0:0:NaN
1301 # inf handling (see table in doc)
1302 0:inf:0
1303 0:-inf:0
1304 5:inf:0
1305 5:-inf:0
1306 -5:inf:0
1307 -5:-inf:0
1308 inf:5:inf
1309 -inf:5:-inf
1310 inf:-5:-inf
1311 -inf:-5:inf
1312 5:5:1
1313 -5:-5:1
1314 inf:inf:NaN
1315 -inf:-inf:NaN
1316 -inf:inf:NaN
1317 inf:-inf:NaN
1318 8:0:inf
1319 inf:0:inf
1320 -8:0:-inf
1321 -inf:0:-inf
1322 0:0:NaN
1323 11:2:5
1324 -11:-2:5
1325 -11:2:-5
1326 11:-2:-5
1327 0:1:0
1328 0:-1:0
1329 1:1:1
1330 -1:-1:1
1331 1:-1:-1
1332 -1:1:-1
1333 1:2:0
1334 2:1:2
1335 1:26:0
1336 1000000000:9:111111111
1337 2000000000:9:222222222
1338 3000000000:9:333333333
1339 4000000000:9:444444444
1340 5000000000:9:555555555
1341 6000000000:9:666666666
1342 7000000000:9:777777777
1343 8000000000:9:888888888
1344 9000000000:9:1000000000
1345 35500000:113:314159
1346 71000000:226:314159
1347 106500000:339:314159
1348 1000000000:3:333333333
1349 +10:+5:2
1350 +100:+4:25
1351 +1000:+8:125
1352 +10000:+16:625
1353 999999999999:9:111111111111
1354 999999999999:99:10101010101
1355 999999999999:999:1001001001
1356 999999999999:9999:100010001
1357 999999999999999:99999:10000100001
1358 +1111088889:99999:11111
1359 -5:-3:1
1360 -5:3:-1
1361 4:3:1
1362 4:-3:-1
1363 1:3:0
1364 1:-3:0
1365 -2:-3:0
1366 -2:3:0
1367 8:3:2
1368 -8:3:-2
1369 14:-3:-4
1370 -14:3:-4
1371 -14:-3:4
1372 14:3:4
1373 # bug in Calc with '99999' vs $BASE-1
1374 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1375 &bmodinv
1376 # format: number:modulus:result
1377 # bmodinv Data errors
1378 abc:abc:NaN
1379 abc:5:NaN
1380 5:abc:NaN
1381 # bmodinv Expected Results from normal use
1382 1:5:1
1383 3:5:2
1384 -2:5:2
1385 8:5033:4404
1386 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
1387 ## bmodinv Error cases / useless use of function
1388 3:-5:NaN
1389 inf:5:NaN
1390 5:inf:NaN
1391 -inf:5:NaN
1392 5:-inf:NaN
1393 &bmodpow
1394 # format: number:exponent:modulus:result
1395 # bmodpow Data errors
1396 abc:abc:abc:NaN
1397 5:abc:abc:NaN
1398 abc:5:abc:NaN
1399 abc:abc:5:NaN
1400 5:5:abc:NaN
1401 5:abc:5:NaN
1402 abc:5:5:NaN
1403 # bmodpow Expected results
1404 0:0:2:1
1405 1:0:2:1
1406 0:0:1:0
1407 8:7:5032:3840
1408 8:-1:5033:4404
1409 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1410 # bmodpow Error cases
1411 8:8:-5:NaN
1412 8:-1:16:NaN
1413 inf:5:13:NaN
1414 5:inf:13:NaN
1415 &bmod
1416 # inf handling, see table in doc
1417 0:inf:0
1418 0:-inf:0
1419 5:inf:5
1420 5:-inf:5
1421 -5:inf:-5
1422 -5:-inf:-5
1423 inf:5:0
1424 -inf:5:0
1425 inf:-5:0
1426 -inf:-5:0
1427 5:5:0
1428 -5:-5:0
1429 inf:inf:NaN
1430 -inf:-inf:NaN
1431 -inf:inf:NaN
1432 inf:-inf:NaN
1433 8:0:8
1434 inf:0:inf
1435 # exceptions to reminder rule
1436 -inf:0:-inf
1437 -8:0:-8
1438 0:0:NaN
1439 abc:abc:NaN
1440 abc:1:abc:NaN
1441 1:abc:NaN
1442 0:0:NaN
1443 0:1:0
1444 1:0:1
1445 0:-1:0
1446 -1:0:-1
1447 1:1:0
1448 -1:-1:0
1449 1:-1:0
1450 -1:1:0
1451 1:2:1
1452 2:1:0
1453 1000000000:9:1
1454 2000000000:9:2
1455 3000000000:9:3
1456 4000000000:9:4
1457 5000000000:9:5
1458 6000000000:9:6
1459 7000000000:9:7
1460 8000000000:9:8
1461 9000000000:9:0
1462 35500000:113:33
1463 71000000:226:66
1464 106500000:339:99
1465 1000000000:3:1
1466 10:5:0
1467 100:4:0
1468 1000:8:0
1469 10000:16:0
1470 999999999999:9:0
1471 999999999999:99:0
1472 999999999999:999:0
1473 999999999999:9999:0
1474 999999999999999:99999:0
1475 -9:+5:1
1476 +9:-5:-1
1477 -9:-5:-4
1478 -5:3:1
1479 -2:3:1
1480 4:3:1
1481 1:3:1
1482 -5:-3:-2
1483 -2:-3:-2
1484 4:-3:-2
1485 1:-3:-2
1486 4095:4095:0
1487 100041000510123:3:0
1488 152403346:12345:4321
1489 9:5:4
1490 # test shortcuts in Calc
1491 # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
1492 1234:9:1
1493 123456:9:3
1494 12345678:9:0
1495 1234567891:9:1
1496 123456789123:9:6
1497 12345678912345:9:6
1498 1234567891234567:9:1
1499 123456789123456789:9:0
1500 1234:10:4
1501 123456:10:6
1502 12345678:10:8
1503 1234567891:10:1
1504 123456789123:10:3
1505 12345678912345:10:5
1506 1234567891234567:10:7
1507 123456789123456789:10:9
1508 1234:113:104
1509 123456:113:60
1510 12345678:113:89
1511 1234567891:113:64
1512 123456789123:113:95
1513 12345678912345:113:53
1514 1234567891234567:113:56
1515 123456789123456789:113:39
1516 # bug in bmod() not modifying the variable in place
1517 -629:5033:4404
1518 &bgcd
1519 abc:abc:NaN
1520 abc:+0:NaN
1521 +0:abc:NaN
1522 +0:+0:0
1523 +0:+1:1
1524 +1:+0:1
1525 +1:+1:1
1526 +2:+3:1
1527 +3:+2:1
1528 -3:+2:1
1529 100:625:25
1530 4096:81:1
1531 1034:804:2
1532 27:90:56:1
1533 27:90:54:9
1534 &blcm
1535 abc:abc:NaN
1536 abc:+0:NaN
1537 +0:abc:NaN
1538 +0:+0:NaN
1539 +1:+0:0
1540 +0:+1:0
1541 +27:+90:270
1542 +1034:+804:415668
1543 &band
1544 abc:abc:NaN
1545 abc:0:NaN
1546 0:abc:NaN
1547 1:2:0
1548 3:2:2
1549 +8:+2:0
1550 +281474976710656:0:0
1551 +281474976710656:1:0
1552 +281474976710656:+281474976710656:281474976710656
1553 -2:-3:-4
1554 -1:-1:-1
1555 -6:-6:-6
1556 -7:-4:-8
1557 -7:4:0
1558 -4:7:4
1559 # equal arguments are treated special, so also do some test with unequal ones
1560 0xFFFF:0xFFFF:0x0xFFFF
1561 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1562 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1563 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1564 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1565 0xF0F0:0xF0F0:0x0xF0F0
1566 0x0F0F:0x0F0F:0x0x0F0F
1567 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1568 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1569 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1570 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1571 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1572 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1573 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1574 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1575 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1576 &bior
1577 abc:abc:NaN
1578 abc:0:NaN
1579 0:abc:NaN
1580 1:2:3
1581 +8:+2:10
1582 +281474976710656:0:281474976710656
1583 +281474976710656:1:281474976710657
1584 +281474976710656:281474976710656:281474976710656
1585 -2:-3:-1
1586 -1:-1:-1
1587 -6:-6:-6
1588 -7:4:-3
1589 -4:7:-1
1590 # equal arguments are treated special, so also do some test with unequal ones
1591 0xFFFF:0xFFFF:0x0xFFFF
1592 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1593 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1594 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1595 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1596 0:0xFFFF:0x0xFFFF
1597 0:0xFFFFFF:0x0xFFFFFF
1598 0:0xFFFFFFFF:0x0xFFFFFFFF
1599 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1600 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1601 0xFFFF:0:0x0xFFFF
1602 0xFFFFFF:0:0x0xFFFFFF
1603 0xFFFFFFFF:0:0x0xFFFFFFFF
1604 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1605 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1606 0xF0F0:0xF0F0:0x0xF0F0
1607 0x0F0F:0x0F0F:0x0x0F0F
1608 0xF0F0:0x0F0F:0x0xFFFF
1609 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1610 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1611 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1612 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1613 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1614 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1615 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1616 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1617 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1618 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1619 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1620 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1621 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1622 &bxor
1623 abc:abc:NaN
1624 abc:0:NaN
1625 0:abc:NaN
1626 1:2:3
1627 +8:+2:10
1628 +281474976710656:0:281474976710656
1629 +281474976710656:1:281474976710657
1630 +281474976710656:281474976710656:0
1631 -2:-3:3
1632 -1:-1:0
1633 -6:-6:0
1634 -7:4:-3
1635 -4:7:-5
1636 4:-7:-3
1637 -4:-7:5
1638 # equal arguments are treated special, so also do some test with unequal ones
1639 0xFFFF:0xFFFF:0
1640 0xFFFFFF:0xFFFFFF:0
1641 0xFFFFFFFF:0xFFFFFFFF:0
1642 0xFFFFFFFFFF:0xFFFFFFFFFF:0
1643 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
1644 0:0xFFFF:0x0xFFFF
1645 0:0xFFFFFF:0x0xFFFFFF
1646 0:0xFFFFFFFF:0x0xFFFFFFFF
1647 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1648 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1649 0xFFFF:0:0x0xFFFF
1650 0xFFFFFF:0:0x0xFFFFFF
1651 0xFFFFFFFF:0:0x0xFFFFFFFF
1652 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1653 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1654 0xF0F0:0xF0F0:0
1655 0x0F0F:0x0F0F:0
1656 0xF0F0:0x0F0F:0x0xFFFF
1657 0xF0F0F0:0xF0F0F0:0
1658 0x0F0F0F:0x0F0F0F:0
1659 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1660 0xF0F0F0F0:0xF0F0F0F0:0
1661 0x0F0F0F0F:0x0F0F0F0F:0
1662 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1663 0xF0F0F0F0F0:0xF0F0F0F0F0:0
1664 0x0F0F0F0F0F:0x0F0F0F0F0F:0
1665 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1666 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
1667 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
1668 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1669 &bnot
1670 abc:NaN
1671 +0:-1
1672 +8:-9
1673 +281474976710656:-281474976710657
1674 -1:0
1675 -2:1
1676 -12:11
1677 &digit
1678 0:0:0
1679 12:0:2
1680 12:1:1
1681 123:0:3
1682 123:1:2
1683 123:2:1
1684 123:-1:1
1685 123:-2:2
1686 123:-3:3
1687 123456:0:6
1688 123456:1:5
1689 123456:2:4
1690 123456:3:3
1691 123456:4:2
1692 123456:5:1
1693 123456:-1:1
1694 123456:-2:2
1695 123456:-3:3
1696 100000:-3:0
1697 100000:0:0
1698 100000:1:0
1699 &mantissa
1700 abc:NaN
1701 1e4:1
1702 2e0:2
1703 123:123
1704 -1:-1
1705 -2:-2
1706 +inf:inf
1707 -inf:-inf
1708 &exponent
1709 abc:NaN
1710 1e4:4
1711 2e0:0
1712 123:0
1713 -1:0
1714 -2:0
1715 0:1
1716 +inf:inf
1717 -inf:inf
1718 &parts
1719 abc:NaN,NaN
1720 1e4:1,4
1721 2e0:2,0
1722 123:123,0
1723 -1:-1,0
1724 -2:-2,0
1725 0:0,1
1726 +inf:inf,inf
1727 -inf:-inf,inf
1728 &bfac
1729 -1:NaN
1730 NaNfac:NaN
1731 +inf:NaN
1732 -inf:NaN
1733 0:1
1734 1:1
1735 2:2
1736 3:6
1737 4:24
1738 5:120
1739 6:720
1740 10:3628800
1741 11:39916800
1742 12:479001600
1743 &bpow
1744 abc:12:NaN
1745 12:abc:NaN
1746 0:0:1
1747 0:1:0
1748 0:2:0
1749 0:-1:NaN
1750 0:-2:NaN
1751 1:0:1
1752 1:1:1
1753 1:2:1
1754 1:3:1
1755 1:-1:1
1756 1:-2:1
1757 1:-3:1
1758 2:0:1
1759 2:1:2
1760 2:2:4
1761 2:3:8
1762 3:3:27
1763 2:-1:NaN
1764 -2:-1:NaN
1765 2:-2:NaN
1766 -2:-2:NaN
1767 +inf:1234500012:inf
1768 -inf:1234500012:-inf
1769 +inf:-12345000123:inf
1770 -inf:-12345000123:-inf
1771 # 1 ** -x => 1 / (1 ** x)
1772 -1:0:1
1773 -2:0:1
1774 -1:1:-1
1775 -1:2:1
1776 -1:3:-1
1777 -1:4:1
1778 -1:5:-1
1779 -1:-1:-1
1780 -1:-2:1
1781 -1:-3:-1
1782 -1:-4:1
1783 10:2:100
1784 10:3:1000
1785 10:4:10000
1786 10:5:100000
1787 10:6:1000000
1788 10:7:10000000
1789 10:8:100000000
1790 10:9:1000000000
1791 10:20:100000000000000000000
1792 123456:2:15241383936
1793 &length
1794 100:3
1795 10:2
1796 1:1
1797 0:1
1798 12345:5
1799 10000000000000000:17
1800 -123:3
1801 215960156869840440586892398248:30
1802 &bsqrt
1803 145:12
1804 144:12
1805 143:11
1806 16:4
1807 170:13
1808 169:13
1809 168:12
1810 4:2
1811 3:1
1812 2:1
1813 9:3
1814 12:3
1815 256:16
1816 100000000:10000
1817 4000000000000:2000000
1818 152399026:12345
1819 152399025:12345
1820 152399024:12344
1821 1:1
1822 0:0
1823 -2:NaN
1824 -123:NaN
1825 Nan:NaN
1826 +inf:NaN
1827 &bround
1828 $round_mode('trunc')
1829 0:12:0
1830 NaNbround:12:NaN
1831 +inf:12:inf
1832 -inf:12:-inf
1833 1234:0:1234
1834 1234:2:1200
1835 123456:4:123400
1836 123456:5:123450
1837 123456:6:123456
1838 +10123456789:5:10123000000
1839 -10123456789:5:-10123000000
1840 +10123456789:9:10123456700
1841 -10123456789:9:-10123456700
1842 +101234500:6:101234000
1843 -101234500:6:-101234000
1844 #+101234500:-4:101234000
1845 #-101234500:-4:-101234000
1846 $round_mode('zero')
1847 +20123456789:5:20123000000
1848 -20123456789:5:-20123000000
1849 +20123456789:9:20123456800
1850 -20123456789:9:-20123456800
1851 +201234500:6:201234000
1852 -201234500:6:-201234000
1853 #+201234500:-4:201234000
1854 #-201234500:-4:-201234000
1855 +12345000:4:12340000
1856 -12345000:4:-12340000
1857 $round_mode('+inf')
1858 +30123456789:5:30123000000
1859 -30123456789:5:-30123000000
1860 +30123456789:9:30123456800
1861 -30123456789:9:-30123456800
1862 +301234500:6:301235000
1863 -301234500:6:-301234000
1864 #+301234500:-4:301235000
1865 #-301234500:-4:-301234000
1866 +12345000:4:12350000
1867 -12345000:4:-12340000
1868 $round_mode('-inf')
1869 +40123456789:5:40123000000
1870 -40123456789:5:-40123000000
1871 +40123456789:9:40123456800
1872 -40123456789:9:-40123456800
1873 +401234500:6:401234000
1874 +401234500:6:401234000
1875 #-401234500:-4:-401235000
1876 #-401234500:-4:-401235000
1877 +12345000:4:12340000
1878 -12345000:4:-12350000
1879 $round_mode('odd')
1880 +50123456789:5:50123000000
1881 -50123456789:5:-50123000000
1882 +50123456789:9:50123456800
1883 -50123456789:9:-50123456800
1884 +501234500:6:501235000
1885 -501234500:6:-501235000
1886 #+501234500:-4:501235000
1887 #-501234500:-4:-501235000
1888 +12345000:4:12350000
1889 -12345000:4:-12350000
1890 $round_mode('even')
1891 +60123456789:5:60123000000
1892 -60123456789:5:-60123000000
1893 +60123456789:9:60123456800
1894 -60123456789:9:-60123456800
1895 +601234500:6:601234000
1896 -601234500:6:-601234000
1897 #+601234500:-4:601234000
1898 #-601234500:-4:-601234000
1899 #-601234500:-9:0
1900 #-501234500:-9:0
1901 #-601234500:-8:0
1902 #-501234500:-8:0
1903 +1234567:7:1234567
1904 +1234567:6:1234570
1905 +12345000:4:12340000
1906 -12345000:4:-12340000
1907 &is_zero
1908 0:1
1909 NaNzero:0
1910 +inf:0
1911 -inf:0
1912 123:0
1913 -1:0
1914 1:0
1915 &is_one
1916 0:0
1917 NaNone:0
1918 +inf:0
1919 -inf:0
1920 1:1
1921 2:0
1922 -1:0
1923 -2:0
1924 # floor and ceil tests are pretty pointless in integer space...but play safe
1925 &bfloor
1926 0:0
1927 NaNfloor:NaN
1928 +inf:inf
1929 -inf:-inf
1930 -1:-1
1931 -2:-2
1932 2:2
1933 3:3
1934 abc:NaN
1935 &bceil
1936 NaNceil:NaN
1937 +inf:inf
1938 -inf:-inf
1939 0:0
1940 -1:-1
1941 -2:-2
1942 2:2
1943 3:3
1944 abc:NaN
1945 &as_hex
1946 128:0x80
1947 -128:-0x80
1948 0:0x0
1949 -0:0x0
1950 1:0x1
1951 0x123456789123456789:0x123456789123456789
1952 +inf:inf
1953 -inf:-inf
1954 NaNas_hex:NaN
1955 &as_bin
1956 128:0b10000000
1957 -128:-0b10000000
1958 0:0b0
1959 -0:0b0
1960 1:0b1
1961 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1962 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
1963 +inf:inf
1964 -inf:-inf
1965 NaNas_bin:NaN