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