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