fix bigint testsuite
[p5sagit/p5-mst-13.2.git] / lib / Math / BigInt / t / bigintpm.inc
1 #include this file into another for subclass testing
2
3 my $version = ${"$class\::VERSION"};
4
5 use strict;
6
7 ##############################################################################
8 # for testing inheritance of _swap
9
10 package Math::Foo;
11
12 use Math::BigInt lib => $main::CL;
13 use vars qw/@ISA/;
14 @ISA = (qw/Math::BigInt/);
15
16 use overload
17 # customized overload for sub, since original does not use swap there
18 '-'     =>      sub { my @a = ref($_[0])->_swap(@_);
19                    $a[0]->bsub($a[1])};
20
21 sub _swap
22   {
23   # a fake _swap, which reverses the params
24   my $self = shift;                     # for override in subclass
25   if ($_[2])
26     {
27     my $c = ref ($_[0] ) || 'Math::Foo';
28     return ( $_[0]->copy(), $_[1] );
29     }
30   else
31     {
32     return ( Math::Foo->new($_[1]), $_[0] );
33     }
34   }
35
36 ##############################################################################
37 package main;
38
39 my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
40
41 my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
42
43 while (<DATA>) 
44   {
45   $_ =~ s/[\n\r]//g;    # remove newlines
46   next if /^#/; # skip comments
47   if (s/^&//) 
48     {
49     $f = $_; next;
50     }
51   elsif (/^\$/) 
52     {
53     $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
54     }
55
56   @args = split(/:/,$_,99); $ans = pop(@args);
57   $expected_class = $class;
58   if ($ans =~ /(.*?)=(.*)/)
59     {
60     $expected_class = $2; $ans = $1;
61     }
62   $try = "\$x = $class->new(\"$args[0]\");";
63   if ($f eq "bnorm")
64     {
65     $try = "\$x = $class->bnorm(\"$args[0]\");";
66   # some is_xxx tests
67    } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
68     $try .= "\$x->$f() || 0;";
69    } elsif ($f eq "is_inf") {
70     $try .= "\$x->is_inf('$args[1]');";
71    } elsif ($f eq "binf") {
72     $try .= "\$x->binf('$args[1]');";
73    } elsif ($f eq "bone") {
74     $try .= "\$x->bone('$args[1]');";
75   # some unary ops
76    } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
77     $try .= "\$x->$f();";
78    } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
79     $try .= "\$x->$f();";
80    } elsif ($f eq "exponent"){
81     # ->bstr() to see if an object is returned
82     $try .= '$x = $x->exponent()->bstr();';
83    } elsif ($f eq "mantissa"){
84     # ->bstr() to see if an object is returned
85     $try .= '$x = $x->mantissa()->bstr();';
86    } elsif ($f eq "parts"){
87     $try .= '($m,$e) = $x->parts();'; 
88     # ->bstr() to see if an object is returned
89     $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
90     $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
91     $try .= '"$m,$e";';
92    }elsif ($f eq "bexp"){
93     $try .= "\$x->bexp();";
94    } elsif ($f eq "bpi"){
95     $try .= "$class\->bpi(\$x);";
96    } else {
97     # binary ops
98     $try .= "\$y = $class->new('$args[1]');";
99     if ($f eq "bcmp")
100       {
101       $try .= '$x->bcmp($y);';
102       } elsif ($f eq "bround") {
103       $try .= "$round_mode; \$x->bround(\$y);";
104       } elsif ($f eq "bacmp"){
105       $try .= '$x->bacmp($y);';
106       } elsif ($f eq "badd"){
107       $try .= '$x + $y;';
108       } elsif ($f eq "bsub"){
109       $try .= '$x - $y;';
110       } elsif ($f eq "bmul"){
111       $try .= '$x * $y;';
112       } elsif ($f eq "bdiv"){
113       $try .= '$x / $y;';
114       } elsif ($f eq "bdiv-list"){
115       $try .= 'join (",",$x->bdiv($y));';
116       # overload via x=
117       } elsif ($f =~ /^.=$/){
118       $try .= "\$x $f \$y;";
119       # overload via x
120       } elsif ($f =~ /^.$/){
121       $try .= "\$x $f \$y;";
122       } elsif ($f eq "bmod"){
123       $try .= '$x % $y;';
124       } elsif ($f eq "bgcd")
125         {
126         if (defined $args[2])
127           {
128           $try .= " \$z = $class->new('$args[2]'); ";
129           }
130         $try .= "$class\::bgcd(\$x, \$y";
131         $try .= ", \$z" if (defined $args[2]);
132         $try .= " );";
133         }
134       elsif ($f eq "blcm")
135         {
136         if (defined $args[2])
137           {
138           $try .= " \$z = $class->new('$args[2]'); ";
139           }
140         $try .= "$class\::blcm(\$x, \$y";
141         $try .= ", \$z" if (defined $args[2]);
142         $try .= " );";
143       }elsif ($f eq "blsft"){
144         if (defined $args[2])
145           {
146           $try .= "\$x->blsft(\$y,$args[2]);";
147           }
148         else
149           {
150           $try .= "\$x << \$y;";
151           }
152       }elsif ($f eq "brsft"){
153         if (defined $args[2])
154           {
155           $try .= "\$x->brsft(\$y,$args[2]);";
156           }
157         else
158           {
159           $try .= "\$x >> \$y;";
160           }
161       }elsif ($f eq "bnok"){
162         $try .= "\$x->bnok(\$y);";
163       }elsif ($f eq "broot"){
164         $try .= "\$x->broot(\$y);";
165       }elsif ($f eq "blog"){
166         $try .= "\$x->blog(\$y);";
167       }elsif ($f eq "band"){
168         $try .= "\$x & \$y;";
169       }elsif ($f eq "bior"){
170         $try .= "\$x | \$y;";
171       }elsif ($f eq "bxor"){
172         $try .= "\$x ^ \$y;";
173       }elsif ($f eq "bpow"){
174         $try .= "\$x ** \$y;";
175       } elsif( $f eq "bmodinv") {
176        $try .= "\$x->bmodinv(\$y);";
177       }elsif ($f eq "digit"){
178         $try .= "\$x->digit(\$y);";
179       }elsif ($f eq "batan2"){
180         $try .= "\$x->batan2(\$y);";
181       } else {
182        # Functions with three arguments
183        $try .= "\$z = $class->new(\"$args[2]\");";
184
185        if( $f eq "bmodpow") {
186          $try .= "\$x->bmodpow(\$y,\$z);";
187       } elsif ($f eq "bmuladd"){
188          $try .= "\$x->bmuladd(\$y,\$z);";
189        } else { warn "Unknown op '$f'"; }
190       }
191     } # end else all other ops
192
193   $ans1 = eval $try;
194   # convert hex/binary targets to decimal       
195   if ($ans =~ /^(0x0x|0b0b)/)
196     {
197     $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
198     }
199   if ($ans eq "")
200     {
201     ok_undef ($ans1); 
202     }
203   else
204     {
205     # print "try: $try ans: $ans1 $ans\n";
206     print "# Tried: '$try'\n" if !ok ($ans1, $ans);
207     ok (ref($ans),$expected_class) if $expected_class ne $class;
208     }
209   # check internal state of number objects
210   is_valid($ans1,$f) if ref $ans1; 
211   } # endwhile data tests
212 close DATA;
213
214 # test some more
215 @a = ();
216 for (my $i = 1; $i < 10; $i++) 
217   {
218   push @a, $i;
219   }
220 ok "@a", "1 2 3 4 5 6 7 8 9";
221
222 # test whether self-multiplication works correctly (result is 2**64)
223 $try = "\$x = $class->new('4294967296');";
224 $try .= '$a = $x->bmul($x);';
225 $ans1 = eval $try;
226 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
227 # test self-pow
228 $try = "\$x = $class->new(10);";
229 $try .= '$a = $x->bpow($x);';
230 $ans1 = eval $try;
231 print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
232
233 ###############################################################################
234 # test whether op destroys args or not (should better not)
235
236 $x = $class->new(3);
237 $y = $class->new(4);
238 $z = $x & $y;
239 ok ($x,3);
240 ok ($y,4);
241 ok ($z,0);
242 $z = $x | $y;
243 ok ($x,3);
244 ok ($y,4);
245 ok ($z,7);
246 $x = $class->new(1);
247 $y = $class->new(2);
248 $z = $x | $y;
249 ok ($x,1);
250 ok ($y,2);
251 ok ($z,3);
252
253 $x = $class->new(5);
254 $y = $class->new(4);
255 $z = $x ^ $y;
256 ok ($x,5);
257 ok ($y,4);
258 ok ($z,1);
259
260 $x = $class->new(-5); $y = -$x;
261 ok ($x, -5);
262
263 $x = $class->new(-5); $y = abs($x);
264 ok ($x, -5);
265
266 $x = $class->new(8);
267 $y = $class->new(-1);
268 $z = $class->new(5033);
269 my $u = $x->copy()->bmodpow($y,$z);
270 ok ($u,4404);
271 ok ($y,-1);
272 ok ($z,5033);
273
274 $x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
275 $x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
276
277 $x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
278 $x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
279 $x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
280 $x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
281 $x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
282
283 $x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
284 $x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
285 $x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
286 $x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
287 $x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
288
289 $x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
290 $x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
291 $x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
292 $x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
293 $x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
294
295 ###############################################################################
296 # check whether overloading cmp works
297 $try = "\$x = $class->new(0);";
298 $try .= "\$y = 10;";
299 $try .= "'false' if \$x ne \$y;";
300 $ans = eval $try;
301 print "# For '$try'\n" if (!ok "$ans" , "false" ); 
302
303 # we cant test for working cmpt with other objects here, we would need a dummy
304 # object with stringify overload for this. see Math::String tests as example
305
306 ###############################################################################
307 # check reversed order of arguments
308
309 $try = "\$x = $class->new(10); \$x = 2 ** \$x;";
310 $try .= "'ok' if \$x == 1024;"; $ans = eval $try;
311 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
312
313 $try = "\$x = $class->new(10); \$x = 2 * \$x;";
314 $try .= "'ok' if \$x == 20;"; $ans = eval $try;
315 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
316
317 $try = "\$x = $class->new(10); \$x = 2 + \$x;";
318 $try .= "'ok' if \$x == 12;"; $ans = eval $try;
319 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
320
321 $try = "\$x = $class\->new(10); \$x = 2 - \$x;";
322 $try .= "'ok' if \$x == -8;"; $ans = eval $try;
323 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
324
325 $try = "\$x = $class\->new(10); \$x = 20 / \$x;";
326 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
327 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
328
329 $try = "\$x = $class\->new(3); \$x = 20 % \$x;";
330 $try .= "'ok' if \$x == 2;"; $ans = eval $try;
331 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
332
333 $try = "\$x = $class\->new(7); \$x = 20 & \$x;";
334 $try .= "'ok' if \$x == 4;"; $ans = eval $try;
335 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
336
337 $try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
338 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
339 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
340
341 $try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
342 $try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
343 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
344
345 ###############################################################################
346 # check badd(4,5) form
347
348 $try = "\$x = $class\->badd(4,5);";
349 $try .= "'ok' if \$x == 9;";
350 $ans = eval $try;
351 print "# For '$try'\n" if (!ok "$ans" , "ok" ); 
352
353 ###############################################################################
354 # check undefs: NOT DONE YET
355
356 ###############################################################################
357 # bool
358
359 $x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
360 $x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
361
362 ###############################################################################
363 # objectify()
364
365 @args = Math::BigInt::objectify(2,4,5);
366 ok (scalar @args,3);            # $class, 4, 5
367 ok ($args[0] =~ /^Math::BigInt/);
368 ok ($args[1],4);
369 ok ($args[2],5);
370
371 @args = Math::BigInt::objectify(0,4,5);
372 ok (scalar @args,3);            # $class, 4, 5
373 ok ($args[0] =~ /^Math::BigInt/);
374 ok ($args[1],4);
375 ok ($args[2],5);
376
377 @args = Math::BigInt::objectify(2,4,5);
378 ok (scalar @args,3);            # $class, 4, 5
379 ok ($args[0] =~ /^Math::BigInt/);
380 ok ($args[1],4);
381 ok ($args[2],5);
382
383 @args = Math::BigInt::objectify(2,4,5,6,7);
384 ok (scalar @args,5);            # $class, 4, 5, 6, 7
385 ok ($args[0] =~ /^Math::BigInt/);
386 ok ($args[1],4); ok (ref($args[1]),$args[0]);
387 ok ($args[2],5); ok (ref($args[2]),$args[0]);
388 ok ($args[3],6); ok (ref($args[3]),'');
389 ok ($args[4],7); ok (ref($args[4]),'');
390
391 @args = Math::BigInt::objectify(2,$class,4,5,6,7);
392 ok (scalar @args,5);            # $class, 4, 5, 6, 7
393 ok ($args[0],$class);
394 ok ($args[1],4); ok (ref($args[1]),$args[0]);
395 ok ($args[2],5); ok (ref($args[2]),$args[0]);
396 ok ($args[3],6); ok (ref($args[3]),'');
397 ok ($args[4],7); ok (ref($args[4]),'');
398
399 ###############################################################################
400 # test whether an opp calls objectify properly or not (or at least does what
401 # it should do given non-objects, w/ or w/o objectify())
402
403 ok ($class->new(123)->badd(123),246);
404 ok ($class->badd(123,321),444);
405 ok ($class->badd(123,$class->new(321)),444);
406
407 ok ($class->new(123)->bsub(122),1);
408 ok ($class->bsub(321,123),198);
409 ok ($class->bsub(321,$class->new(123)),198);
410
411 ok ($class->new(123)->bmul(123),15129);
412 ok ($class->bmul(123,123),15129);
413 ok ($class->bmul(123,$class->new(123)),15129);
414
415 ok ($class->new(15129)->bdiv(123),123);
416 ok ($class->bdiv(15129,123),123);
417 ok ($class->bdiv(15129,$class->new(123)),123);
418
419 ok ($class->new(15131)->bmod(123),2);
420 ok ($class->bmod(15131,123),2);
421 ok ($class->bmod(15131,$class->new(123)),2);
422
423 ok ($class->new(2)->bpow(16),65536);
424 ok ($class->bpow(2,16),65536);
425 ok ($class->bpow(2,$class->new(16)),65536);
426
427 ok ($class->new(2**15)->brsft(1),2**14);
428 ok ($class->brsft(2**15,1),2**14);
429 ok ($class->brsft(2**15,$class->new(1)),2**14);
430
431 ok ($class->new(2**13)->blsft(1),2**14);
432 ok ($class->blsft(2**13,1),2**14);
433 ok ($class->blsft(2**13,$class->new(1)),2**14);
434
435 ###############################################################################
436 # test for floating-point input (other tests in bnorm() below)
437
438 $z = 1050000000000000;          # may be int on systems with 64bit?
439 $x = $class->new($z); ok ($x->bsstr(),'105e+13');       # not 1.05e+15
440 $z = 1e+129;                    # definitely a float (may fail on UTS)
441 # don't compare to $z, since some Perl versions stringify $z into something
442 # like '1.e+129' or something equally ugly
443 $x = $class->new($z); ok ($x->bsstr(),'1e+129');
444
445 ###############################################################################
446 # test for whitespace inlcuding newlines to be handled correctly
447
448 # ok ($Math::BigInt::strict,1);         # the default
449
450 foreach my $c (
451   qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
452   {
453   my $m = $class->new($c);
454   ok ($class->new("$c"),$m);
455   ok ($class->new(" $c"),$m);
456   ok ($class->new("$c "),$m);
457   ok ($class->new(" $c "),$m);
458   ok ($class->new("\n$c"),$m);
459   ok ($class->new("$c\n"),$m);
460   ok ($class->new("\n$c\n"),$m);
461   ok ($class->new(" \n$c\n"),$m);
462   ok ($class->new(" \n$c \n"),$m);
463   ok ($class->new(" \n$c\n "),$m);
464   ok ($class->new(" \n$c\n1"),'NaN');
465   ok ($class->new("1 \n$c\n1"),'NaN');
466   }
467
468 ###############################################################################
469 # prime number tests, also test for **= and length()
470 # found on: http://www.utm.edu/research/primes/notes/by_year.html
471
472 # ((2^148)-1)/17
473 $x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
474 ok ($x,"20988936657440586486151264256610222593863921");
475 ok ($x->length(),length "20988936657440586486151264256610222593863921");
476
477 # MM7 = 2^127-1
478 $x = $class->new(2); $x **= 127; $x--;
479 ok ($x,"170141183460469231731687303715884105727");
480
481 $x = $class->new('215960156869840440586892398248');
482 ($x,$y) = $x->length();
483 ok ($x,30); ok ($y,0);
484
485 $x = $class->new('1_000_000_000_000');
486 ($x,$y) = $x->length();
487 ok ($x,13); ok ($y,0);
488
489 # test <<=, >>=
490 $x = $class->new('2');
491 my $y = $class->new('18');
492 ok ($x <<= $y, 2 << 18);
493 ok ($x, 2 << 18);
494 ok ($x >>= $y, 2);
495 ok ($x, 2);
496
497 # I am afraid the following is not yet possible due to slowness
498 # Also, testing for 2 meg output is a bit hard ;)
499 #$x = $class->new(2); $x **= 6972593; $x--;
500
501 # 593573509*2^332162+1 has exactly 1,000,000 digits
502 # takes about 24 mins on 300 Mhz, so cannot be done yet ;)
503 #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
504 #ok ($x->length(),1_000_000);
505
506 ###############################################################################
507 # inheritance and overriding of _swap
508
509 $x = Math::Foo->new(5);
510 $x = $x - 8;            # 8 - 5 instead of 5-8
511 ok ($x,3);
512 ok (ref($x),'Math::Foo');
513
514 $x = Math::Foo->new(5);
515 $x = 8 - $x;            # 5 - 8 instead of 8 - 5
516 ok ($x,-3);
517 ok (ref($x),'Math::Foo');
518
519 ###############################################################################
520 # Test whether +inf eq inf
521 # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
522 # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
523 # like 1e100000 crash on some platforms. So simple test for the string 'inf'
524 $x = $class->new('+inf'); ok ($x,'inf');
525
526 ###############################################################################
527 ###############################################################################
528 # the followin tests only make sense with Math::BigInt::Calc or BareCalc or
529 # FastCalc
530
531 exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
532
533 ###############################################################################
534 # check proper length of internal arrays
535
536 my $bl = $CL->_base_len();
537 my $BASE = '9' x $bl;
538 my $MAX = $BASE;
539 $BASE++;
540
541 $x = $class->new($MAX); is_valid($x);   # f.i. 9999
542 $x += 1; ok ($x,$BASE); is_valid($x);   # 10000
543 $x -= 1; ok ($x,$MAX); is_valid($x);    # 9999 again
544
545 ###############################################################################
546 # check numify
547
548 $x = $class->new($BASE-1);     ok ($x->numify(),$BASE-1); 
549 $x = $class->new(-($BASE-1));  ok ($x->numify(),-($BASE-1)); 
550
551 # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
552 $x = $class->new($BASE);       ok ($x->numify()+0,$BASE+0);     
553 $x = $class->new(-$BASE);      ok ($x->numify(),-$BASE);
554 $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) ); 
555 ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); 
556
557 ###############################################################################
558 # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
559
560 $x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
561 if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
562
563 $x = $class->new($BASE+3); $x++;
564 if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
565
566 # test for +0 instead of int(): 
567 $x = $class->new($MAX); ok ($x->length(), length($MAX));
568
569 ###############################################################################
570 # test bug that $class->digit($string) did not work
571
572 ok ($class->digit(123,2),1);
573
574 ###############################################################################
575 # bug in sub where number with at least 6 trailing zeros after any op failed
576
577 $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
578 ok ($z, 100000);
579 ok ($x, 23456);
580
581 ###############################################################################
582 # bug in shortcut in mul()
583
584 # construct a number with a zero-hole of BASE_LEN_SMALL
585 {
586  my @bl = $CL->_base_len(); my $bl = $bl[4];
587
588  $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
589  $y = '1' x (2*$bl);
590  $x = $class->new($x)->bmul($y);
591  # result is 123..$bl .  $bl x (3*bl-1) . $bl...321 . '0' x $bl
592  $y = ''; my $d = '';
593  for (my $i = 1; $i <= $bl; $i++)
594    {
595    $y .= $i; $d = $i.$d;
596    }
597  $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
598  ok ($x,$y);
599
600
601   #############################################################################
602   # see if mul shortcut for small numbers works
603
604   $x = '9' x $bl;
605   $x = $class->new($x); 
606   # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
607   ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
608 }
609
610 ###############################################################################
611 # bug with rest "-0" in div, causing further div()s to fail
612
613 $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
614
615 ok ($y,'0'); is_valid($y);      # $y not '-0'
616
617 ###############################################################################
618 # bug in $x->bmod($y)
619
620 # if $x < 0 and $y > 0
621 $x = $class->new('-629'); ok ($x->bmod(5033),4404);
622
623 ###############################################################################
624 # bone/binf etc as plain calls (Lite failed them)
625
626 ok ($class->bzero(),0);
627 ok ($class->bone(),1);
628 ok ($class->bone('+'),1);
629 ok ($class->bone('-'),-1);
630 ok ($class->bnan(),'NaN');
631 ok ($class->binf(),'inf');
632 ok ($class->binf('+'),'inf');
633 ok ($class->binf('-'),'-inf');
634 ok ($class->binf('-inf'),'-inf');
635
636 ###############################################################################
637 # is_one('-')
638
639 ok ($class->new(1)->is_one('-'),0);
640 ok ($class->new(-1)->is_one('-'),1);
641 ok ($class->new(1)->is_one(),1);
642 ok ($class->new(-1)->is_one(),0);
643
644 ###############################################################################
645 # [perl #30609] bug with $x -= $x not beeing 0, but 2*$x
646
647 $x = $class->new(3);  $x -= $x; ok ($x, 0);
648 $x = $class->new(-3); $x -= $x; ok ($x, 0);
649 $x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
650 $x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
651 $x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
652
653 $x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
654 $x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
655 $x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
656 $x = $class->new(3);  $x += $x; ok ($x, 6);
657 $x = $class->new(-3); $x += $x; ok ($x, -6);
658
659 $x = $class->new(3);  $x *= $x; ok ($x, 9);
660 $x = $class->new(-3); $x *= $x; ok ($x, 9);
661 $x = $class->new(3);  $x /= $x; ok ($x, 1);
662 $x = $class->new(-3); $x /= $x; ok ($x, 1);
663 $x = $class->new(3);  $x %= $x; ok ($x, 0);
664 $x = $class->new(-3); $x %= $x; ok ($x, 0);
665
666 ###############################################################################
667 # all tests done
668
669 1;
670
671 ###############################################################################
672 ###############################################################################
673 # Perl 5.005 does not like ok ($x,undef)
674
675 sub ok_undef
676   {
677   my $x = shift;
678
679   ok (1,1) and return if !defined $x;
680   ok ($x,'undef');
681   }
682
683 ###############################################################################
684 # sub to check validity of a BigInt internally, to ensure that no op leaves a
685 # number object in an invalid state (f.i. "-0")
686
687 sub is_valid
688   {
689   my ($x,$f) = @_;
690
691   my $e = 0;                    # error?
692
693   # allow the check to pass for all Lite, and all MBI and subclasses
694   # ok as reference? 
695   $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
696
697   if (ref($x) ne 'Math::BigInt::Lite')
698     {
699     # has ok sign?
700     $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
701      if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
702   
703     $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
704     $e = $CALC->_check($x->{value}) if $e eq '0';
705     }
706
707   # test done, see if error did crop up
708   ok (1,1), return if ($e eq '0');
709
710   ok (1,$e." after op '$f'");
711   }
712
713 __DATA__
714 &.=
715 1234:-345:1234-345
716 &+=
717 1:2:3
718 -1:-2:-3
719 &-=
720 1:2:-1
721 -1:-2:1
722 &*=
723 2:3:6
724 -1:5:-5
725 &%=
726 100:3:1
727 8:9:8
728 -629:5033:4404
729 &/=
730 100:3:33
731 -8:2:-4
732 &|=
733 2:1:3
734 &&=
735 5:7:5
736 &^=
737 5:7:2
738 &blog
739 NaNlog:2:NaN
740 122:NaNlog:NaN
741 NaNlog1:NaNlog:NaN
742 122:inf:NaN
743 inf:122:NaN
744 122:-inf:NaN
745 -inf:122:NaN
746 -inf:-inf:NaN
747 inf:inf:NaN
748 0:4:NaN
749 -21:4:NaN
750 21:-21:NaN
751 # normal results
752 1024:2:10
753 81:3:4
754 # 3.01.. truncate
755 82:3:4
756 # 3.9... truncate
757 80:3:3
758 15625:5:6
759 15626:5:6
760 15624:5:5
761 1000:10:3
762 10000:10:4
763 100000:10:5
764 1000000:10:6
765 10000000:10:7
766 100000000:10:8
767 8916100448256:12:12
768 8916100448257:12:12
769 8916100448255:12:11
770 2251799813685248:8:17
771 72057594037927936:2:56
772 144115188075855872:2:57
773 288230376151711744:2:58
774 576460752303423488:2:59
775 4096:2:12
776 1329227995784915872903807060280344576:2:120
777 # $x == $base => result 1
778 3:3:1
779 # $x < $base => result 0 ($base ** 0 <= $x)
780 3:4:0
781 # $x == 1 => result 0
782 1:5:0
783 &is_negative
784 0:0
785 -1:1
786 1:0
787 +inf:0
788 -inf:1
789 NaNneg:0
790 &is_positive
791 0:0
792 -1:0
793 1:1
794 +inf:1
795 -inf:0
796 NaNneg:0
797 &is_int
798 -inf:0
799 +inf:0
800 NaNis_int:0
801 1:1
802 0:1
803 123e12:1
804 &is_odd
805 abc:0
806 0:0
807 1:1
808 3:1
809 -1:1
810 -3:1
811 10000001:1
812 10000002:0
813 2:0
814 120:0
815 121:1
816 &is_even
817 abc:0
818 0:1
819 1:0
820 3:0
821 -1:0
822 -3:0
823 10000001:0
824 10000002:1
825 2:1
826 120:1
827 121:0
828 &bacmp
829 +0:-0:0
830 +0:+1:-1
831 -1:+1:0
832 +1:-1:0
833 -1:+2:-1
834 +2:-1:1
835 -123456789:+987654321:-1
836 +123456789:-987654321:-1
837 +987654321:+123456789:1
838 -987654321:+123456789:1
839 -123:+4567889:-1
840 # NaNs
841 acmpNaN:123:
842 123:acmpNaN:
843 acmpNaN:acmpNaN:
844 # infinity
845 +inf:+inf:0
846 -inf:-inf:0
847 +inf:-inf:0
848 -inf:+inf:0
849 +inf:123:1
850 -inf:123:1
851 +inf:-123:1
852 -inf:-123:1
853 123:-inf:-1
854 -123:inf:-1
855 -123:-inf:-1
856 123:inf:-1
857 # return undef
858 +inf:NaN:
859 NaN:inf:
860 -inf:NaN:
861 NaN:-inf:
862 &bnorm
863 0e999:0
864 0e-999:0
865 -0e999:0
866 -0e-999:0
867 123:123
868 # binary input
869 0babc:NaN
870 0b123:NaN
871 0b0:0
872 -0b0:0
873 -0b1:-1
874 0b0001:1
875 0b001:1
876 0b011:3
877 0b101:5
878 0b1001:9
879 0b10001:17
880 0b100001:33
881 0b1000001:65
882 0b10000001:129
883 0b100000001:257
884 0b1000000001:513
885 0b10000000001:1025
886 0b100000000001:2049
887 0b1000000000001:4097
888 0b10000000000001:8193
889 0b100000000000001:16385
890 0b1000000000000001:32769
891 0b10000000000000001:65537
892 0b100000000000000001:131073
893 0b1000000000000000001:262145
894 0b10000000000000000001:524289
895 0b100000000000000000001:1048577
896 0b1000000000000000000001:2097153
897 0b10000000000000000000001:4194305
898 0b100000000000000000000001:8388609
899 0b1000000000000000000000001:16777217
900 0b10000000000000000000000001:33554433
901 0b100000000000000000000000001:67108865
902 0b1000000000000000000000000001:134217729
903 0b10000000000000000000000000001:268435457
904 0b100000000000000000000000000001:536870913
905 0b1000000000000000000000000000001:1073741825
906 0b10000000000000000000000000000001:2147483649
907 0b100000000000000000000000000000001:4294967297
908 0b1000000000000000000000000000000001:8589934593
909 0b10000000000000000000000000000000001:17179869185
910 0b_101:NaN
911 0b1_0_1:5
912 0b0_0_0_1:1
913 # hex input
914 -0x0:0
915 0xabcdefgh:NaN
916 0x1234:4660
917 0xabcdef:11259375
918 -0xABCDEF:-11259375
919 -0x1234:-4660
920 0x12345678:305419896
921 0x1_2_3_4_56_78:305419896
922 0xa_b_c_d_e_f:11259375
923 0x_123:NaN
924 0x9:9
925 0x11:17
926 0x21:33
927 0x41:65
928 0x81:129
929 0x101:257
930 0x201:513
931 0x401:1025
932 0x801:2049
933 0x1001:4097
934 0x2001:8193
935 0x4001:16385
936 0x8001:32769
937 0x10001:65537
938 0x20001:131073
939 0x40001:262145
940 0x80001:524289
941 0x100001:1048577
942 0x200001:2097153
943 0x400001:4194305
944 0x800001:8388609
945 0x1000001:16777217
946 0x2000001:33554433
947 0x4000001:67108865
948 0x8000001:134217729
949 0x10000001:268435457
950 0x20000001:536870913
951 0x40000001:1073741825
952 0x80000001:2147483649
953 0x100000001:4294967297
954 0x200000001:8589934593
955 0x400000001:17179869185
956 0x800000001:34359738369
957 # bug found by Mark Lakata in Calc.pm creating too big one-element numbers in _from_hex()
958 0x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
959 # inf input
960 inf:inf
961 +inf:inf
962 -inf:-inf
963 0inf:NaN
964 # abnormal input
965 :NaN
966 abc:NaN
967    1 a:NaN
968 1bcd2:NaN
969 11111b:NaN
970 +1z:NaN
971 -1z:NaN
972 # only one underscore between two digits
973 _123:NaN
974 _123_:NaN
975 123_:NaN
976 1__23:NaN
977 1E1__2:NaN
978 1_E12:NaN
979 1E_12:NaN
980 1_E_12:NaN
981 +_1E12:NaN
982 +0_1E2:100
983 +0_0_1E2:100
984 -0_0_1E2:-100
985 -0_0_1E+0_0_2:-100
986 E1:NaN
987 E23:NaN
988 1.23E1:NaN
989 1.23E-1:NaN
990 # bug with two E's in number beeing valid
991 1e2e3:NaN
992 1e2r:NaN
993 1e2.0:NaN
994 # bug with two '.' in number beeing valid
995 1.2.2:NaN
996 1.2.3e1:NaN
997 -1.2.3:NaN
998 -1.2.3e-4:NaN
999 1.2e3.4:NaN
1000 1.2e-3.4:NaN
1001 1.2.3.4:NaN
1002 1.2.t:NaN
1003 1..2:NaN
1004 1..2e1:NaN
1005 1..2e1..1:NaN
1006 12e1..1:NaN
1007 ..2:NaN
1008 .-2:NaN
1009 # leading zeros
1010 012:12
1011 0123:123
1012 01234:1234
1013 012345:12345
1014 0123456:123456
1015 01234567:1234567
1016 012345678:12345678
1017 0123456789:123456789
1018 01234567891:1234567891
1019 012345678912:12345678912
1020 0123456789123:123456789123
1021 01234567891234:1234567891234
1022 # some inputs that result in zero
1023 0e0:0
1024 +0e0:0
1025 +0e+0:0
1026 -0e+0:0
1027 0e-0:0
1028 -0e-0:0
1029 +0e-0:0
1030 000:0
1031 00e2:0
1032 00e02:0
1033 000e002:0
1034 000e1230:0
1035 00e-3:0
1036 00e+3:0
1037 00e-03:0
1038 00e+03:0
1039 -000:0
1040 -00e2:0
1041 -00e02:0
1042 -000e002:0
1043 -000e1230:0
1044 -00e-3:0
1045 -00e+3:0
1046 -00e-03:0
1047 -00e+03:0
1048 # normal input
1049 0:0
1050 +0:0
1051 +00:0
1052 +000:0
1053 000000000000000000:0
1054 -0:0
1055 -0000:0
1056 +1:1
1057 +01:1
1058 +001:1
1059 +00000100000:100000
1060 123456789:123456789
1061 -1:-1
1062 -01:-1
1063 -001:-1
1064 -123456789:-123456789
1065 -00000100000:-100000
1066 1_2_3:123
1067 10000000000E-1_0:1
1068 1E2:100
1069 1E1:10
1070 1E0:1
1071 1.23E2:123
1072 100E-1:10
1073 # floating point input
1074 # .2e2:20
1075 1.E3:1000
1076 1.01E2:101
1077 1010E-1:101
1078 -1010E0:-1010
1079 -1010E1:-10100
1080 1234.00:1234
1081 # non-integer numbers
1082 -1010E-2:NaN
1083 -1.01E+1:NaN
1084 -1.01E-1:NaN
1085 &bnan
1086 1:NaN
1087 2:NaN
1088 abc:NaN
1089 &bone
1090 2:+:1
1091 2:-:-1
1092 boneNaN:-:-1
1093 boneNaN:+:1
1094 2:abc:1
1095 3::1
1096 &binf
1097 1:+:inf
1098 2:-:-inf
1099 3:abc:inf
1100 &is_nan
1101 123:0
1102 abc:1
1103 NaN:1
1104 -123:0
1105 &is_inf
1106 +inf::1
1107 -inf::1
1108 abc::0
1109 1::0
1110 NaN::0
1111 -1::0
1112 +inf:-:0
1113 +inf:+:1
1114 -inf:-:1
1115 -inf:+:0
1116 -inf:-inf:1
1117 -inf:+inf:0
1118 +inf:-inf:0
1119 +inf:+inf:1
1120 # it must be exactly /^[+-]inf$/
1121 +infinity::0
1122 -infinity::0
1123 &blsft
1124 abc:abc:NaN
1125 +2:+2:8
1126 +1:+32:4294967296
1127 +1:+48:281474976710656
1128 +8:-2:NaN
1129 # excercise base 10
1130 +12345:4:10:123450000
1131 -1234:0:10:-1234
1132 +1234:0:10:1234
1133 +2:2:10:200
1134 +12:2:10:1200
1135 +1234:-3:10:NaN
1136 1234567890123:12:10:1234567890123000000000000
1137 -3:1:2:-6
1138 -5:1:2:-10
1139 -2:1:2:-4
1140 -102533203:1:2:-205066406
1141 &brsft
1142 abc:abc:NaN
1143 +8:+2:2
1144 +4294967296:+32:1
1145 +281474976710656:+48:1
1146 +2:-2:NaN
1147 # excercise base 10
1148 -1234:0:10:-1234
1149 +1234:0:10:1234
1150 +200:2:10:2
1151 +1234:3:10:1
1152 +1234:2:10:12
1153 +1234:-3:10:NaN
1154 310000:4:10:31
1155 12300000:5:10:123
1156 1230000000000:10:10:123
1157 09876123456789067890:12:10:9876123
1158 1234561234567890123:13:10:123456
1159 820265627:1:2:410132813
1160 # test shifting negative numbers in base 2
1161 -15:1:2:-8
1162 -14:1:2:-7
1163 -13:1:2:-7
1164 -12:1:2:-6
1165 -11:1:2:-6
1166 -10:1:2:-5
1167 -9:1:2:-5
1168 -8:1:2:-4
1169 -7:1:2:-4
1170 -6:1:2:-3
1171 -5:1:2:-3
1172 -4:1:2:-2
1173 -3:1:2:-2
1174 -2:1:2:-1
1175 -1:1:2:-1
1176 -1640531254:2:2:-410132814
1177 -1640531254:1:2:-820265627
1178 -820265627:1:2:-410132814
1179 -205066405:1:2:-102533203
1180 &bsstr
1181 +inf:inf
1182 -inf:-inf
1183 1e+34:1e+34
1184 123.456E3:123456e+0
1185 100:1e+2
1186 bsstrabc:NaN
1187 -5:-5e+0
1188 -100:-1e+2
1189 &numify
1190 numifyabc:NaN
1191 +inf:inf
1192 -inf:-inf
1193 5:5
1194 -5:-5
1195 100:100
1196 -100:-100
1197 &bneg
1198 bnegNaN:NaN
1199 +inf:-inf
1200 -inf:inf
1201 abd:NaN
1202 0:0
1203 1:-1
1204 -1:1
1205 +123456789:-123456789
1206 -123456789:123456789
1207 &babs
1208 babsNaN:NaN
1209 +inf:inf
1210 -inf:inf
1211 0:0
1212 1:1
1213 -1:1
1214 +123456789:123456789
1215 -123456789:123456789
1216 &bcmp
1217 bcmpNaN:bcmpNaN:
1218 bcmpNaN:0:
1219 0:bcmpNaN:
1220 0:0:0
1221 -1:0:-1
1222 0:-1:1
1223 1:0:1
1224 0:1:-1
1225 -1:1:-1
1226 1:-1:1
1227 -1:-1:0
1228 1:1:0
1229 123:123:0
1230 123:12:1
1231 12:123:-1
1232 -123:-123:0
1233 -123:-12:-1
1234 -12:-123:1
1235 123:124:-1
1236 124:123:1
1237 -123:-124:1
1238 -124:-123:-1
1239 100:5:1
1240 -123456789:987654321:-1
1241 +123456789:-987654321:1
1242 -987654321:123456789:-1
1243 -inf:5432112345:-1
1244 +inf:5432112345:1
1245 -inf:-5432112345:-1
1246 +inf:-5432112345:1
1247 +inf:+inf:0
1248 -inf:-inf:0
1249 +inf:-inf:1
1250 -inf:+inf:-1
1251 5:inf:-1
1252 5:inf:-1
1253 -5:-inf:1
1254 -5:-inf:1
1255 # return undef
1256 +inf:NaN:
1257 NaN:inf:
1258 -inf:NaN:
1259 NaN:-inf:
1260 &binc
1261 abc:NaN
1262 +inf:inf
1263 -inf:-inf
1264 +0:1
1265 +1:2
1266 -1:0
1267 &bdec
1268 abc:NaN
1269 +inf:inf
1270 -inf:-inf
1271 +0:-1
1272 +1:0
1273 -1:-2
1274 &badd
1275 abc:abc:NaN
1276 abc:0:NaN
1277 +0:abc:NaN
1278 +inf:-inf:NaN
1279 -inf:+inf:NaN
1280 +inf:+inf:inf
1281 -inf:-inf:-inf
1282 baddNaN:+inf:NaN
1283 baddNaN:+inf:NaN
1284 +inf:baddNaN:NaN
1285 -inf:baddNaN:NaN
1286 0:0:0
1287 1:0:1
1288 0:1:1
1289 1:1:2
1290 -1:0:-1
1291 0:-1:-1
1292 -1:-1:-2
1293 -1:+1:0
1294 +1:-1:0
1295 +9:+1:10
1296 +99:+1:100
1297 +999:+1:1000
1298 +9999:+1:10000
1299 +99999:+1:100000
1300 +999999:+1:1000000
1301 +9999999:+1:10000000
1302 +99999999:+1:100000000
1303 +999999999:+1:1000000000
1304 +9999999999:+1:10000000000
1305 +99999999999:+1:100000000000
1306 +10:-1:9
1307 +100:-1:99
1308 +1000:-1:999
1309 +10000:-1:9999
1310 +100000:-1:99999
1311 +1000000:-1:999999
1312 +10000000:-1:9999999
1313 +100000000:-1:99999999
1314 +1000000000:-1:999999999
1315 +10000000000:-1:9999999999
1316 +123456789:987654321:1111111110
1317 -123456789:987654321:864197532
1318 -123456789:-987654321:-1111111110
1319 +123456789:-987654321:-864197532
1320 -1:10001:10000
1321 -1:100001:100000
1322 -1:1000001:1000000
1323 -1:10000001:10000000
1324 -1:100000001:100000000
1325 -1:1000000001:1000000000
1326 -1:10000000001:10000000000
1327 -1:100000000001:100000000000
1328 -1:1000000000001:1000000000000
1329 -1:10000000000001:10000000000000
1330 -1:-10001:-10002
1331 -1:-100001:-100002
1332 -1:-1000001:-1000002
1333 -1:-10000001:-10000002
1334 -1:-100000001:-100000002
1335 -1:-1000000001:-1000000002
1336 -1:-10000000001:-10000000002
1337 -1:-100000000001:-100000000002
1338 -1:-1000000000001:-1000000000002
1339 -1:-10000000000001:-10000000000002
1340 &bsub
1341 abc:abc:NaN
1342 abc:+0:NaN
1343 +0:abc:NaN
1344 +inf:-inf:inf
1345 -inf:+inf:-inf
1346 +inf:+inf:NaN
1347 -inf:-inf:NaN
1348 +0:+0:0
1349 +1:+0:1
1350 +0:+1:-1
1351 +1:+1:0
1352 -1:+0:-1
1353 +0:-1:1
1354 -1:-1:0
1355 -1:+1:-2
1356 +1:-1:2
1357 +9:+1:8
1358 +99:+1:98
1359 +999:+1:998
1360 +9999:+1:9998
1361 +99999:+1:99998
1362 +999999:+1:999998
1363 +9999999:+1:9999998
1364 +99999999:+1:99999998
1365 +999999999:+1:999999998
1366 +9999999999:+1:9999999998
1367 +99999999999:+1:99999999998
1368 +10:-1:11
1369 +100:-1:101
1370 +1000:-1:1001
1371 +10000:-1:10001
1372 +100000:-1:100001
1373 +1000000:-1:1000001
1374 +10000000:-1:10000001
1375 +100000000:-1:100000001
1376 +1000000000:-1:1000000001
1377 +10000000000:-1:10000000001
1378 +123456789:+987654321:-864197532
1379 -123456789:+987654321:-1111111110
1380 -123456789:-987654321:864197532
1381 +123456789:-987654321:1111111110
1382 10001:1:10000
1383 100001:1:100000
1384 1000001:1:1000000
1385 10000001:1:10000000
1386 100000001:1:100000000
1387 1000000001:1:1000000000
1388 10000000001:1:10000000000
1389 100000000001:1:100000000000
1390 1000000000001:1:1000000000000
1391 10000000000001:1:10000000000000
1392 10001:-1:10002
1393 100001:-1:100002
1394 1000001:-1:1000002
1395 10000001:-1:10000002
1396 100000001:-1:100000002
1397 1000000001:-1:1000000002
1398 10000000001:-1:10000000002
1399 100000000001:-1:100000000002
1400 1000000000001:-1:1000000000002
1401 10000000000001:-1:10000000000002
1402 &bmuladd
1403 abc:abc:0:NaN
1404 abc:+0:0:NaN
1405 +0:abc:0:NaN
1406 +0:0:abc:NaN
1407 NaNmul:+inf:0:NaN
1408 NaNmul:-inf:0:NaN
1409 -inf:NaNmul:0:NaN
1410 +inf:NaNmul:0:NaN
1411 +inf:+inf:0:inf
1412 +inf:-inf:0:-inf
1413 -inf:+inf:0:-inf
1414 -inf:-inf:0:inf
1415 +0:+0:0:0
1416 +0:+1:0:0
1417 +1:+0:0:0
1418 +0:-1:0:0
1419 -1:+0:0:0
1420 123456789123456789:0:0:0
1421 0:123456789123456789:0:0
1422 -1:-1:0:1
1423 -1:-1:0:1
1424 -1:+1:0:-1
1425 +1:-1:0:-1
1426 +1:+1:0:1
1427 +2:+3:0:6
1428 -2:+3:0:-6
1429 +2:-3:0:-6
1430 -2:-3:0:6
1431 111:111:0:12321
1432 10101:10101:0:102030201
1433 1001001:1001001:0:1002003002001
1434 100010001:100010001:0:10002000300020001
1435 10000100001:10000100001:0:100002000030000200001
1436 11111111111:9:0:99999999999
1437 22222222222:9:0:199999999998
1438 33333333333:9:0:299999999997
1439 44444444444:9:0:399999999996
1440 55555555555:9:0:499999999995
1441 66666666666:9:0:599999999994
1442 77777777777:9:0:699999999993
1443 88888888888:9:0:799999999992
1444 99999999999:9:0:899999999991
1445 11111111111:9:1:100000000000
1446 22222222222:9:1:199999999999
1447 33333333333:9:1:299999999998
1448 44444444444:9:1:399999999997
1449 55555555555:9:1:499999999996
1450 66666666666:9:1:599999999995
1451 77777777777:9:1:699999999994
1452 88888888888:9:1:799999999993
1453 99999999999:9:1:899999999992
1454 -3:-4:-5:7
1455 3:-4:-5:-17
1456 -3:4:-5:-17
1457 3:4:-5:7
1458 -3:4:5:-7
1459 3:-4:5:-7
1460 9999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890
1461 2:3:12345678901234567890:12345678901234567896
1462 &bmul
1463 abc:abc:NaN
1464 abc:+0:NaN
1465 +0:abc:NaN
1466 NaNmul:+inf:NaN
1467 NaNmul:-inf:NaN
1468 -inf:NaNmul:NaN
1469 +inf:NaNmul:NaN
1470 +inf:+inf:inf
1471 +inf:-inf:-inf
1472 -inf:+inf:-inf
1473 -inf:-inf:inf
1474 +0:+0:0
1475 +0:+1:0
1476 +1:+0:0
1477 +0:-1:0
1478 -1:+0:0
1479 123456789123456789:0:0
1480 0:123456789123456789:0
1481 -1:-1:1
1482 -1:+1:-1
1483 +1:-1:-1
1484 +1:+1:1
1485 +2:+3:6
1486 -2:+3:-6
1487 +2:-3:-6
1488 -2:-3:6
1489 111:111:12321
1490 10101:10101:102030201
1491 1001001:1001001:1002003002001
1492 100010001:100010001:10002000300020001
1493 10000100001:10000100001:100002000030000200001
1494 11111111111:9:99999999999
1495 22222222222:9:199999999998
1496 33333333333:9:299999999997
1497 44444444444:9:399999999996
1498 55555555555:9:499999999995
1499 66666666666:9:599999999994
1500 77777777777:9:699999999993
1501 88888888888:9:799999999992
1502 99999999999:9:899999999991
1503 +25:+25:625
1504 +12345:+12345:152399025
1505 +99999:+11111:1111088889
1506 9999:10000:99990000
1507 99999:100000:9999900000
1508 999999:1000000:999999000000
1509 9999999:10000000:99999990000000
1510 99999999:100000000:9999999900000000
1511 999999999:1000000000:999999999000000000
1512 9999999999:10000000000:99999999990000000000
1513 99999999999:100000000000:9999999999900000000000
1514 999999999999:1000000000000:999999999999000000000000
1515 9999999999999:10000000000000:99999999999990000000000000
1516 99999999999999:100000000000000:9999999999999900000000000000
1517 999999999999999:1000000000000000:999999999999999000000000000000
1518 9999999999999999:10000000000000000:99999999999999990000000000000000
1519 99999999999999999:100000000000000000:9999999999999999900000000000000000
1520 999999999999999999:1000000000000000000:999999999999999999000000000000000000
1521 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1522 &bdiv-list
1523 100:20:5,0
1524 4095:4095:1,0
1525 -4095:-4095:1,0
1526 4095:-4095:-1,0
1527 -4095:4095:-1,0
1528 123:2:61,1
1529 9:5:1,4
1530 9:4:2,1
1531 # inf handling and general remainder
1532 5:8:0,5
1533 0:8:0,0
1534 11:2:5,1
1535 11:-2:-5,-1
1536 -11:2:-5,1
1537 # see table in documentation in MBI
1538 0:inf:0,0
1539 0:-inf:0,0
1540 5:inf:0,5
1541 5:-inf:0,5
1542 -5:inf:0,-5
1543 -5:-inf:0,-5
1544 inf:5:inf,0
1545 -inf:5:-inf,0
1546 inf:-5:-inf,0
1547 -inf:-5:inf,0
1548 5:5:1,0
1549 -5:-5:1,0
1550 inf:inf:NaN,NaN
1551 -inf:-inf:NaN,NaN
1552 -inf:inf:NaN,NaN
1553 inf:-inf:NaN,NaN
1554 8:0:inf,8
1555 inf:0:inf,inf
1556 # exceptions to reminder rule
1557 -8:0:-inf,-8
1558 -inf:0:-inf,-inf
1559 0:0:NaN,NaN
1560 # test the shortcut in Calc if @$x == @$yorg
1561 1234567812345678:123456712345678:10,688888898
1562 12345671234567:1234561234567:10,58888897
1563 123456123456:12345123456:10,4888896
1564 1234512345:123412345:10,388895
1565 1234567890999999999:1234567890:1000000000,999999999
1566 1234567890000000000:1234567890:1000000000,0
1567 1234567890999999999:9876543210:124999998,9503086419
1568 1234567890000000000:9876543210:124999998,8503086420
1569 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
1570 # bug in v1.76
1571 1267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
1572 # excercise shortcut for numbers of the same length in div
1573 999999999999999999999999999999999:999999999999999999999999999999999:1,0
1574 999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1575 999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1576 999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1577 999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1578 999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1579 999999999999999999999999999999999:333333333333333333333333333333333:3,0
1580 999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1581 999999999999999999999999999999999:111111111111111111111111111111111:9,0
1582 9999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
1583 9999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
1584 9999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
1585 9999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
1586 9999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
1587 9999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
1588 9999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
1589 9999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
1590 9999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
1591 9999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
1592 9999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
1593 &bdiv
1594 abc:abc:NaN
1595 abc:1:NaN
1596 1:abc:NaN
1597 0:0:NaN
1598 # inf handling (see table in doc)
1599 0:inf:0
1600 0:-inf:0
1601 5:inf:0
1602 5:-inf:0
1603 -5:inf:0
1604 -5:-inf:0
1605 inf:5:inf
1606 -inf:5:-inf
1607 inf:-5:-inf
1608 -inf:-5:inf
1609 5:5:1
1610 -5:-5:1
1611 inf:inf:NaN
1612 -inf:-inf:NaN
1613 -inf:inf:NaN
1614 inf:-inf:NaN
1615 8:0:inf
1616 inf:0:inf
1617 -8:0:-inf
1618 -inf:0:-inf
1619 0:0:NaN
1620 11:2:5
1621 -11:-2:5
1622 -11:2:-5
1623 11:-2:-5
1624 0:1:0
1625 0:-1:0
1626 1:1:1
1627 -1:-1:1
1628 1:-1:-1
1629 -1:1:-1
1630 1:2:0
1631 2:1:2
1632 1:26:0
1633 1000000000:9:111111111
1634 2000000000:9:222222222
1635 3000000000:9:333333333
1636 4000000000:9:444444444
1637 5000000000:9:555555555
1638 6000000000:9:666666666
1639 7000000000:9:777777777
1640 8000000000:9:888888888
1641 9000000000:9:1000000000
1642 35500000:113:314159
1643 71000000:226:314159
1644 106500000:339:314159
1645 1000000000:3:333333333
1646 +10:+5:2
1647 +100:+4:25
1648 +1000:+8:125
1649 +10000:+16:625
1650 999999999999:9:111111111111
1651 999999999999:99:10101010101
1652 999999999999:999:1001001001
1653 999999999999:9999:100010001
1654 999999999999999:99999:10000100001
1655 +1111088889:99999:11111
1656 -5:-3:1
1657 -5:3:-1
1658 4:3:1
1659 4:-3:-1
1660 1:3:0
1661 1:-3:0
1662 -2:-3:0
1663 -2:3:0
1664 8:3:2
1665 -8:3:-2
1666 14:-3:-4
1667 -14:3:-4
1668 -14:-3:4
1669 14:3:4
1670 # bug in Calc with '99999' vs $BASE-1
1671 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1672 # test the shortcut in Calc if @$x == @$yorg
1673 1234567812345678:123456712345678:10
1674 12345671234567:1234561234567:10
1675 123456123456:12345123456:10
1676 1234512345:123412345:10
1677 1234567890999999999:1234567890:1000000000
1678 1234567890000000000:1234567890:1000000000
1679 1234567890999999999:9876543210:124999998
1680 1234567890000000000:9876543210:124999998
1681 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
1682 # bug up to v0.35 in Calc (--$q one too many)
1683 84696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
1684 84696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
1685 84696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
1686 84696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
1687 # excercise shortcut for numbers of the same length in div
1688 999999999999999999999999999999999:999999999999999999999999999999999:1
1689 999999999999999999999999999999999:888888888888888888888888888888888:1
1690 999999999999999999999999999999999:777777777777777777777777777777777:1
1691 999999999999999999999999999999999:666666666666666666666666666666666:1
1692 999999999999999999999999999999999:555555555555555555555555555555555:1
1693 999999999999999999999999999999999:444444444444444444444444444444444:2
1694 999999999999999999999999999999999:333333333333333333333333333333333:3
1695 999999999999999999999999999999999:222222222222222222222222222222222:4
1696 999999999999999999999999999999999:111111111111111111111111111111111:9
1697 9999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
1698 9999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
1699 9999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
1700 9999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
1701 9999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
1702 9999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
1703 9999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
1704 9999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
1705 9999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
1706 9999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
1707 9999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
1708 # bug with shortcut in Calc 0.44
1709 949418181818187070707070707070707070:181818181853535353535353535353535353:5
1710 &bmodinv
1711 # format: number:modulus:result
1712 # bmodinv Data errors
1713 abc:abc:NaN
1714 abc:5:NaN
1715 5:abc:NaN
1716 # bmodinv Expected Results from normal use
1717 1:5:1
1718 3:5:2
1719 -2:5:2
1720 8:5033:4404
1721 1234567891:13:6
1722 -1234567891:13:7
1723 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
1724 ## bmodinv Error cases / useless use of function
1725 3:-5:NaN
1726 inf:5:NaN
1727 5:inf:NaN
1728 -inf:5:NaN
1729 5:-inf:NaN
1730 &bmodpow
1731 # format: number:exponent:modulus:result
1732 # bmodpow Data errors
1733 abc:abc:abc:NaN
1734 5:abc:abc:NaN
1735 abc:5:abc:NaN
1736 abc:abc:5:NaN
1737 5:5:abc:NaN
1738 5:abc:5:NaN
1739 abc:5:5:NaN
1740 # bmodpow Expected results
1741 0:0:2:1
1742 1:0:2:1
1743 0:0:1:0
1744 8:7:5032:3840
1745 8:-1:5033:4404
1746 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1747 # bmodpow Error cases
1748 8:8:-5:NaN
1749 8:-1:16:NaN
1750 inf:5:13:NaN
1751 5:inf:13:NaN
1752 &bmod
1753 # inf handling, see table in doc
1754 0:inf:0
1755 0:-inf:0
1756 5:inf:5
1757 5:-inf:5
1758 -5:inf:-5
1759 -5:-inf:-5
1760 inf:5:0
1761 -inf:5:0
1762 inf:-5:0
1763 -inf:-5:0
1764 5:5:0
1765 -5:-5:0
1766 inf:inf:NaN
1767 -inf:-inf:NaN
1768 -inf:inf:NaN
1769 inf:-inf:NaN
1770 8:0:8
1771 inf:0:inf
1772 # exceptions to reminder rule
1773 -inf:0:-inf
1774 -8:0:-8
1775 0:0:NaN
1776 abc:abc:NaN
1777 abc:1:abc:NaN
1778 1:abc:NaN
1779 0:0:NaN
1780 0:1:0
1781 1:0:1
1782 0:-1:0
1783 -1:0:-1
1784 1:1:0
1785 -1:-1:0
1786 1:-1:0
1787 -1:1:0
1788 1:2:1
1789 2:1:0
1790 1000000000:9:1
1791 2000000000:9:2
1792 3000000000:9:3
1793 4000000000:9:4
1794 5000000000:9:5
1795 6000000000:9:6
1796 7000000000:9:7
1797 8000000000:9:8
1798 9000000000:9:0
1799 35500000:113:33
1800 71000000:226:66
1801 106500000:339:99
1802 1000000000:3:1
1803 10:5:0
1804 100:4:0
1805 1000:8:0
1806 10000:16:0
1807 999999999999:9:0
1808 999999999999:99:0
1809 999999999999:999:0
1810 999999999999:9999:0
1811 999999999999999:99999:0
1812 -9:+5:1
1813 +9:-5:-1
1814 -9:-5:-4
1815 -5:3:1
1816 -2:3:1
1817 4:3:1
1818 1:3:1
1819 -5:-3:-2
1820 -2:-3:-2
1821 4:-3:-2
1822 1:-3:-2
1823 4095:4095:0
1824 100041000510123:3:0
1825 152403346:12345:4321
1826 9:5:4
1827 # test shortcuts in Calc
1828 # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
1829 1234:9:1
1830 123456:9:3
1831 12345678:9:0
1832 1234567891:9:1
1833 123456789123:9:6
1834 12345678912345:9:6
1835 1234567891234567:9:1
1836 123456789123456789:9:0
1837 1234:10:4
1838 123456:10:6
1839 12345678:10:8
1840 1234567891:10:1
1841 123456789123:10:3
1842 12345678912345:10:5
1843 1234567891234567:10:7
1844 123456789123456789:10:9
1845 1234:113:104
1846 123456:113:60
1847 12345678:113:89
1848 1234567891:113:64
1849 123456789123:113:95
1850 12345678912345:113:53
1851 1234567891234567:113:56
1852 123456789123456789:113:39
1853 # bug in bmod() not modifying the variable in place
1854 -629:5033:4404
1855 # bug in bmod() in Calc in the _div_use_div() shortcut code path,
1856 # when X == X and X was big 
1857 111111111111111111111111111111:111111111111111111111111111111:0
1858 12345678901234567890:12345678901234567890:0
1859 &bgcd
1860 inf:12:NaN
1861 -inf:12:NaN
1862 12:inf:NaN
1863 12:-inf:NaN
1864 inf:inf:NaN
1865 inf:-inf:NaN
1866 -inf:-inf:NaN
1867 abc:abc:NaN
1868 abc:+0:NaN
1869 +0:abc:NaN
1870 +0:+0:0
1871 +0:+1:1
1872 +1:+0:1
1873 +1:+1:1
1874 +2:+3:1
1875 +3:+2:1
1876 -3:+2:1
1877 -3:-2:1
1878 -144:-60:12
1879 144:-60:12
1880 144:60:12
1881 100:625:25
1882 4096:81:1
1883 1034:804:2
1884 27:90:56:1
1885 27:90:54:9
1886 &blcm
1887 abc:abc:NaN
1888 abc:+0:NaN
1889 +0:abc:NaN
1890 +0:+0:NaN
1891 +1:+0:0
1892 +0:+1:0
1893 +27:+90:270
1894 +1034:+804:415668
1895 &band
1896 abc:abc:NaN
1897 abc:0:NaN
1898 0:abc:NaN
1899 1:2:0
1900 3:2:2
1901 +8:+2:0
1902 +281474976710656:0:0
1903 +281474976710656:1:0
1904 +281474976710656:+281474976710656:281474976710656
1905 281474976710656:-1:281474976710656
1906 -2:-3:-4
1907 -1:-1:-1
1908 -6:-6:-6
1909 -7:-4:-8
1910 -7:4:0
1911 -4:7:4
1912 # negative argument is bitwise shorter than positive [perl #26559]
1913 30:-3:28
1914 123:-1:123
1915 # equal arguments are treated special, so also do some test with unequal ones
1916 0xFFFF:0xFFFF:0x0xFFFF
1917 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1918 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1919 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1920 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1921 0xF0F0:0xF0F0:0x0xF0F0
1922 0x0F0F:0x0F0F:0x0x0F0F
1923 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1924 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1925 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1926 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1927 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1928 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1929 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1930 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1931 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1932 &bior
1933 abc:abc:NaN
1934 abc:0:NaN
1935 0:abc:NaN
1936 1:2:3
1937 +8:+2:10
1938 +281474976710656:0:281474976710656
1939 +281474976710656:1:281474976710657
1940 +281474976710656:281474976710656:281474976710656
1941 -2:-3:-1
1942 -1:-1:-1
1943 -6:-6:-6
1944 -7:4:-3
1945 -4:7:-1
1946 +281474976710656:-1:-1
1947 30:-3:-1
1948 30:-4:-2
1949 300:-76:-68
1950 -76:300:-68
1951 # equal arguments are treated special, so also do some test with unequal ones
1952 0xFFFF:0xFFFF:0x0xFFFF
1953 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1954 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1955 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1956 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1957 0:0xFFFF:0x0xFFFF
1958 0:0xFFFFFF:0x0xFFFFFF
1959 0:0xFFFFFFFF:0x0xFFFFFFFF
1960 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1961 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1962 0xFFFF:0:0x0xFFFF
1963 0xFFFFFF:0:0x0xFFFFFF
1964 0xFFFFFFFF:0:0x0xFFFFFFFF
1965 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1966 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1967 0xF0F0:0xF0F0:0x0xF0F0
1968 0x0F0F:0x0F0F:0x0x0F0F
1969 0xF0F0:0x0F0F:0x0xFFFF
1970 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1971 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1972 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1973 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1974 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1975 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1976 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1977 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1978 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1979 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1980 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1981 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1982 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1983 &bxor
1984 abc:abc:NaN
1985 abc:0:NaN
1986 0:abc:NaN
1987 1:2:3
1988 +8:+2:10
1989 +281474976710656:0:281474976710656
1990 +281474976710656:1:281474976710657
1991 +281474976710656:281474976710656:0
1992 -2:-3:3
1993 -1:-1:0
1994 -6:-6:0
1995 -7:4:-3
1996 -4:7:-5
1997 4:-7:-3
1998 -4:-7:5
1999 30:-3:-29
2000 30:-4:-30
2001 300:-76:-360
2002 -76:300:-360
2003 # equal arguments are treated special, so also do some test with unequal ones
2004 0xFFFF:0xFFFF:0
2005 0xFFFFFF:0xFFFFFF:0
2006 0xFFFFFFFF:0xFFFFFFFF:0
2007 0xFFFFFFFFFF:0xFFFFFFFFFF:0
2008 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
2009 0:0xFFFF:0x0xFFFF
2010 0:0xFFFFFF:0x0xFFFFFF
2011 0:0xFFFFFFFF:0x0xFFFFFFFF
2012 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
2013 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
2014 0xFFFF:0:0x0xFFFF
2015 0xFFFFFF:0:0x0xFFFFFF
2016 0xFFFFFFFF:0:0x0xFFFFFFFF
2017 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
2018 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
2019 0xF0F0:0xF0F0:0
2020 0x0F0F:0x0F0F:0
2021 0xF0F0:0x0F0F:0x0xFFFF
2022 0xF0F0F0:0xF0F0F0:0
2023 0x0F0F0F:0x0F0F0F:0
2024 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
2025 0xF0F0F0F0:0xF0F0F0F0:0
2026 0x0F0F0F0F:0x0F0F0F0F:0
2027 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
2028 0xF0F0F0F0F0:0xF0F0F0F0F0:0
2029 0x0F0F0F0F0F:0x0F0F0F0F0F:0
2030 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
2031 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
2032 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
2033 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
2034 &bnot
2035 abc:NaN
2036 +0:-1
2037 +8:-9
2038 +281474976710656:-281474976710657
2039 -1:0
2040 -2:1
2041 -12:11
2042 &digit
2043 0:0:0
2044 12:0:2
2045 12:1:1
2046 123:0:3
2047 123:1:2
2048 123:2:1
2049 123:-1:1
2050 123:-2:2
2051 123:-3:3
2052 123456:0:6
2053 123456:1:5
2054 123456:2:4
2055 123456:3:3
2056 123456:4:2
2057 123456:5:1
2058 123456:-1:1
2059 123456:-2:2
2060 123456:-3:3
2061 100000:-3:0
2062 100000:0:0
2063 100000:1:0
2064 &mantissa
2065 abc:NaN
2066 1e4:1
2067 2e0:2
2068 123:123
2069 -1:-1
2070 -2:-2
2071 +inf:inf
2072 -inf:-inf
2073 &exponent
2074 abc:NaN
2075 1e4:4
2076 2e0:0
2077 123:0
2078 -1:0
2079 -2:0
2080 0:1
2081 +inf:inf
2082 -inf:inf
2083 &parts
2084 abc:NaN,NaN
2085 1e4:1,4
2086 2e0:2,0
2087 123:123,0
2088 -1:-1,0
2089 -2:-2,0
2090 0:0,1
2091 +inf:inf,inf
2092 -inf:-inf,inf
2093 &bfac
2094 -1:NaN
2095 NaNfac:NaN
2096 +inf:inf
2097 -inf:NaN
2098 0:1
2099 1:1
2100 2:2
2101 3:6
2102 4:24
2103 5:120
2104 6:720
2105 7:5040
2106 8:40320
2107 9:362880
2108 10:3628800
2109 11:39916800
2110 12:479001600
2111 20:2432902008176640000
2112 22:1124000727777607680000
2113 69:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
2114 &bpow
2115 abc:12:NaN
2116 12:abc:NaN
2117 0:0:1
2118 0:1:0
2119 0:2:0
2120 0:-1:inf
2121 0:-2:inf
2122 1:0:1
2123 1:1:1
2124 1:2:1
2125 1:3:1
2126 1:-1:1
2127 1:-2:1
2128 1:-3:1
2129 2:0:1
2130 2:1:2
2131 2:2:4
2132 2:3:8
2133 3:3:27
2134 -2:2:4
2135 -2:3:-8
2136 -2:4:16
2137 -2:5:-32
2138 2:-1:NaN
2139 -2:-1:NaN
2140 2:-2:NaN
2141 -2:-2:NaN
2142 # inf tests
2143 +inf:1234500012:inf
2144 -inf:1234500012:inf
2145 -inf:1234500013:-inf
2146 +inf:-12345000123:inf
2147 -inf:-12345000123:-inf
2148 #  -inf * -inf = inf
2149 -inf:2:inf
2150 -inf:0:NaN
2151 -inf:-1:0
2152 -inf:inf:NaN
2153 2:inf:inf
2154 2:-inf:0
2155 0:inf:0
2156 0:-inf:inf
2157 -1:-inf:NaN
2158 -1:inf:NaN
2159 -2:inf:NaN
2160 -2:-inf:0
2161 NaN:inf:NaN
2162 NaN:-inf:NaN
2163 -inf:NaN:NaN
2164 inf:NaN:NaN
2165 inf:-inf:NaN
2166 1:inf:1
2167 1:-inf:1
2168 # 1 ** -x => 1 / (1 ** x)
2169 -1:0:1
2170 -2:0:1
2171 -1:1:-1
2172 -1:2:1
2173 -1:3:-1
2174 -1:4:1
2175 -1:5:-1
2176 -1:-1:-1
2177 -1:-2:1
2178 -1:-3:-1
2179 -1:-4:1
2180 10:2:100
2181 10:3:1000
2182 10:4:10000
2183 10:5:100000
2184 10:6:1000000
2185 10:7:10000000
2186 10:8:100000000
2187 10:9:1000000000
2188 10:20:100000000000000000000
2189 123456:2:15241383936
2190 -2:2:4
2191 -2:3:-8
2192 -2:4:16
2193 -2:5:-32
2194 -3:2:9
2195 -3:3:-27
2196 -3:4:81
2197 -3:5:-243
2198 &length
2199 100:3
2200 10:2
2201 1:1
2202 0:1
2203 12345:5
2204 10000000000000000:17
2205 -123:3
2206 215960156869840440586892398248:30
2207 &broot
2208 # sqrt()
2209 +0:2:0
2210 +1:2:1
2211 -1:2:NaN
2212 # -$x ** (1/2) => -$y, but not in froot()
2213 -123:2:NaN
2214 +inf:2:inf
2215 -inf:2:NaN
2216 2:2:1
2217 -2:2:NaN
2218 4:2:2
2219 9:2:3
2220 16:2:4
2221 100:2:10
2222 123:2:11
2223 15241:2:123
2224 144:2:12
2225 12:2:3
2226 0.49:2:0
2227 0.0049:2:0
2228 # invalid ones
2229 1:NaN:NaN
2230 -1:NaN:NaN
2231 0:NaN:NaN
2232 -inf:NaN:NaN
2233 +inf:NaN:NaN
2234 NaN:0:NaN
2235 NaN:2:NaN
2236 NaN:inf:NaN
2237 NaN:inf:NaN
2238 12:-inf:NaN
2239 12:inf:NaN
2240 +0:0:NaN
2241 +1:0:NaN
2242 -1:0:NaN
2243 -2:0:NaN
2244 -123.45:0:NaN
2245 +inf:0:NaN
2246 12:1:12
2247 -12:1:NaN
2248 8:-1:NaN
2249 -8:-1:NaN
2250 # cubic root
2251 8:3:2
2252 -8:3:NaN
2253 # fourths root
2254 16:4:2
2255 81:4:3
2256 # 2 ** 64
2257 18446744073709551616:4:65536
2258 18446744073709551616:8:256
2259 18446744073709551616:16:16
2260 18446744073709551616:32:4
2261 18446744073709551616:64:2
2262 18446744073709551616:128:1
2263 # 213 ** 15
2264 84274086103068221283760416414557757:15:213
2265 # see t/bigroot.t for more tests
2266 &bsqrt
2267 145:12
2268 144:12
2269 143:11
2270 16:4
2271 170:13
2272 169:13
2273 168:12
2274 4:2
2275 3:1
2276 2:1
2277 9:3
2278 12:3
2279 256:16
2280 100000000:10000
2281 4000000000000:2000000
2282 152399026:12345
2283 152399025:12345
2284 152399024:12344
2285 # 2 ** 64 => 2 ** 32
2286 18446744073709551616:4294967296
2287 84274086103068221283760416414557757:290299993288095377
2288 1:1
2289 0:0
2290 -2:NaN
2291 -123:NaN
2292 Nan:NaN
2293 +inf:inf
2294 -inf:NaN
2295 # see t/biglog.t for more tests
2296 &bexp
2297 NaN:NaN
2298 inf:inf
2299 1:2
2300 2:7
2301 &batan2
2302 NaN:1:10:NaN
2303 NaN:NaN:10:NaN
2304 1:NaN:10:NaN
2305 inf:1:14:1
2306 -inf:1:14:-1
2307 1:5:13:0
2308 1:5:14:0
2309 0:0:10:0
2310 0:1:14:0
2311 0:2:14:0
2312 1:0:14:1
2313 5:0:14:1
2314 -1:0:11:-1
2315 -2:0:77:-1
2316 2:0:77:1
2317 -1:5:14:0
2318 1:5:14:0
2319 -1:8:14:0
2320 1:8:14:0
2321 -1:1:14:0
2322 &bpi
2323 77:3
2324 +0:3
2325 11:3
2326 # see t/bignok.t for more tests
2327 &bnok
2328 +inf:10:inf
2329 NaN:NaN:NaN
2330 NaN:1:NaN
2331 1:NaN:NaN
2332 1:1:1
2333 # k > n
2334 1:2:0
2335 2:3:0
2336 # k < 0
2337 1:-2:0
2338 # 7 over 3 = 35
2339 7:3:35
2340 7:6:1
2341 100:90:17310309456440
2342 100:95:75287520
2343 &bround
2344 $round_mode('trunc')
2345 0:12:0
2346 NaNbround:12:NaN
2347 +inf:12:inf
2348 -inf:12:-inf
2349 1234:0:1234
2350 1234:2:1200
2351 123456:4:123400
2352 123456:5:123450
2353 123456:6:123456
2354 +10123456789:5:10123000000
2355 -10123456789:5:-10123000000
2356 +10123456789:9:10123456700
2357 -10123456789:9:-10123456700
2358 +101234500:6:101234000
2359 -101234500:6:-101234000
2360 #+101234500:-4:101234000
2361 #-101234500:-4:-101234000
2362 $round_mode('zero')
2363 +20123456789:5:20123000000
2364 -20123456789:5:-20123000000
2365 +20123456789:9:20123456800
2366 -20123456789:9:-20123456800
2367 +201234500:6:201234000
2368 -201234500:6:-201234000
2369 #+201234500:-4:201234000
2370 #-201234500:-4:-201234000
2371 +12345000:4:12340000
2372 -12345000:4:-12340000
2373 $round_mode('+inf')
2374 +30123456789:5:30123000000
2375 -30123456789:5:-30123000000
2376 +30123456789:9:30123456800
2377 -30123456789:9:-30123456800
2378 +301234500:6:301235000
2379 -301234500:6:-301234000
2380 #+301234500:-4:301235000
2381 #-301234500:-4:-301234000
2382 +12345000:4:12350000
2383 -12345000:4:-12340000
2384 $round_mode('-inf')
2385 +40123456789:5:40123000000
2386 -40123456789:5:-40123000000
2387 +40123456789:9:40123456800
2388 -40123456789:9:-40123456800
2389 +401234500:6:401234000
2390 +401234500:6:401234000
2391 #-401234500:-4:-401235000
2392 #-401234500:-4:-401235000
2393 +12345000:4:12340000
2394 -12345000:4:-12350000
2395 $round_mode('odd')
2396 +50123456789:5:50123000000
2397 -50123456789:5:-50123000000
2398 +50123456789:9:50123456800
2399 -50123456789:9:-50123456800
2400 +501234500:6:501235000
2401 -501234500:6:-501235000
2402 #+501234500:-4:501235000
2403 #-501234500:-4:-501235000
2404 +12345000:4:12350000
2405 -12345000:4:-12350000
2406 $round_mode('even')
2407 +60123456789:5:60123000000
2408 -60123456789:5:-60123000000
2409 +60123456789:9:60123456800
2410 -60123456789:9:-60123456800
2411 +601234500:6:601234000
2412 -601234500:6:-601234000
2413 #+601234500:-4:601234000
2414 #-601234500:-4:-601234000
2415 #-601234500:-9:0
2416 #-501234500:-9:0
2417 #-601234500:-8:0
2418 #-501234500:-8:0
2419 +1234567:7:1234567
2420 +1234567:6:1234570
2421 +12345000:4:12340000
2422 -12345000:4:-12340000
2423 $round_mode('common')
2424 +60123456789:5:60123000000
2425 +60123199999:5:60123000000
2426 +60123299999:5:60123000000
2427 +60123399999:5:60123000000
2428 +60123499999:5:60123000000
2429 +60123500000:5:60124000000
2430 +60123600000:5:60124000000
2431 +60123700000:5:60124000000
2432 +60123800000:5:60124000000
2433 +60123900000:5:60124000000
2434 -60123456789:5:-60123000000
2435 -60123199999:5:-60123000000
2436 -60123299999:5:-60123000000
2437 -60123399999:5:-60123000000
2438 -60123499999:5:-60123000000
2439 -60123500000:5:-60124000000
2440 -60123600000:5:-60124000000
2441 -60123700000:5:-60124000000
2442 -60123800000:5:-60124000000
2443 -60123900000:5:-60124000000
2444 &is_zero
2445 0:1
2446 NaNzero:0
2447 +inf:0
2448 -inf:0
2449 123:0
2450 -1:0
2451 1:0
2452 &is_one
2453 0:0
2454 NaNone:0
2455 +inf:0
2456 -inf:0
2457 1:1
2458 2:0
2459 -1:0
2460 -2:0
2461 # floor and ceil tests are pretty pointless in integer space...but play safe
2462 &bfloor
2463 0:0
2464 NaNfloor:NaN
2465 +inf:inf
2466 -inf:-inf
2467 -1:-1
2468 -2:-2
2469 2:2
2470 3:3
2471 abc:NaN
2472 &bceil
2473 NaNceil:NaN
2474 +inf:inf
2475 -inf:-inf
2476 0:0
2477 -1:-1
2478 -2:-2
2479 2:2
2480 3:3
2481 abc:NaN
2482 &as_hex
2483 128:0x80
2484 -128:-0x80
2485 0:0x0
2486 -0:0x0
2487 1:0x1
2488 0x123456789123456789:0x123456789123456789
2489 +inf:inf
2490 -inf:-inf
2491 NaNas_hex:NaN
2492 &as_bin
2493 128:0b10000000
2494 -128:-0b10000000
2495 0:0b0
2496 -0:0b0
2497 1:0b1
2498 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
2499 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
2500 +inf:inf
2501 -inf:-inf
2502 NaNas_bin:NaN