This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Math::BigInt 1.68.
[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 # all tests done
628
629 1;
630
631 ###############################################################################
632 ###############################################################################
633 # Perl 5.005 does not like ok ($x,undef)
634
635 sub ok_undef
636   {
637   my $x = shift;
638
639   ok (1,1) and return if !defined $x;
640   ok ($x,'undef');
641   }
642
643 ###############################################################################
644 # sub to check validity of a BigInt internally, to ensure that no op leaves a
645 # number object in an invalid state (f.i. "-0")
646
647 sub is_valid
648   {
649   my ($x,$f) = @_;
650
651   my $e = 0;                    # error?
652
653   # allow the check to pass for all Lite, and all MBI and subclasses
654   # ok as reference? 
655   $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
656
657   if (ref($x) ne 'Math::BigInt::Lite')
658     {
659     # has ok sign?
660     $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
661      if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
662   
663     $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
664     $e = $CALC->_check($x->{value}) if $e eq '0';
665     }
666
667   # test done, see if error did crop up
668   ok (1,1), return if ($e eq '0');
669
670   ok (1,$e." after op '$f'");
671   }
672
673 __DATA__
674 &.=
675 1234:-345:1234-345
676 &+=
677 1:2:3
678 -1:-2:-3
679 &-=
680 1:2:-1
681 -1:-2:1
682 &*=
683 2:3:6
684 -1:5:-5
685 &%=
686 100:3:1
687 8:9:8
688 -629:5033:4404
689 &/=
690 100:3:33
691 -8:2:-4
692 &|=
693 2:1:3
694 &&=
695 5:7:5
696 &^=
697 5:7:2
698 &blog
699 NaNlog:2:NaN
700 122:NaNlog:NaN
701 NaNlog1:NaNlog:NaN
702 122:inf:NaN
703 inf:122:NaN
704 122:-inf:NaN
705 -inf:122:NaN
706 -inf:-inf:NaN
707 inf:inf:NaN
708 0:4:NaN
709 -21:4:NaN
710 21:-21:NaN
711 # normal results
712 1024:2:10
713 81:3:4
714 # 3.01.. truncate
715 82:3:4
716 # 3.9... truncate
717 80:3:3
718 15625:5:6
719 15626:5:6
720 15624:5:5
721 1000:10:3
722 10000:10:4
723 100000:10:5
724 1000000:10:6
725 10000000:10:7
726 100000000:10:8
727 8916100448256:12:12
728 8916100448257:12:12
729 8916100448255:12:11
730 2251799813685248:8:17
731 72057594037927936:2:56
732 144115188075855872:2:57
733 288230376151711744:2:58
734 576460752303423488:2:59
735 4096:2:12
736 1329227995784915872903807060280344576:2:120
737 # $x == $base => result 1
738 3:3:1
739 # $x < $base => result 0 ($base ** 0 <= $x)
740 3:4:0
741 # $x == 1 => result 0
742 1:5:0
743 &is_negative
744 0:0
745 -1:1
746 1:0
747 +inf:0
748 -inf:1
749 NaNneg:0
750 &is_positive
751 0:1
752 -1:0
753 1:1
754 +inf:1
755 -inf:0
756 NaNneg:0
757 &is_int
758 -inf:0
759 +inf:0
760 NaNis_int:0
761 1:1
762 0:1
763 123e12:1
764 &is_odd
765 abc:0
766 0:0
767 1:1
768 3:1
769 -1:1
770 -3:1
771 10000001:1
772 10000002:0
773 2:0
774 120:0
775 121:1
776 &is_even
777 abc:0
778 0:1
779 1:0
780 3:0
781 -1:0
782 -3:0
783 10000001:0
784 10000002:1
785 2:1
786 120:1
787 121:0
788 &bacmp
789 +0:-0:0
790 +0:+1:-1
791 -1:+1:0
792 +1:-1:0
793 -1:+2:-1
794 +2:-1:1
795 -123456789:+987654321:-1
796 +123456789:-987654321:-1
797 +987654321:+123456789:1
798 -987654321:+123456789:1
799 -123:+4567889:-1
800 # NaNs
801 acmpNaN:123:
802 123:acmpNaN:
803 acmpNaN:acmpNaN:
804 # infinity
805 +inf:+inf:0
806 -inf:-inf:0
807 +inf:-inf:0
808 -inf:+inf:0
809 +inf:123:1
810 -inf:123:1
811 +inf:-123:1
812 -inf:-123:1
813 # return undef
814 +inf:NaN:
815 NaN:inf:
816 -inf:NaN:
817 NaN:-inf:
818 &bnorm
819 0e999:0
820 0e-999:0
821 -0e999:0
822 -0e-999:0
823 123:123
824 # binary input
825 0babc:NaN
826 0b123:NaN
827 0b0:0
828 -0b0:0
829 -0b1:-1
830 0b0001:1
831 0b001:1
832 0b011:3
833 0b101:5
834 0b1001:9
835 0b10001:17
836 0b100001:33
837 0b1000001:65
838 0b10000001:129
839 0b100000001:257
840 0b1000000001:513
841 0b10000000001:1025
842 0b100000000001:2049
843 0b1000000000001:4097
844 0b10000000000001:8193
845 0b100000000000001:16385
846 0b1000000000000001:32769
847 0b10000000000000001:65537
848 0b100000000000000001:131073
849 0b1000000000000000001:262145
850 0b10000000000000000001:524289
851 0b100000000000000000001:1048577
852 0b1000000000000000000001:2097153
853 0b10000000000000000000001:4194305
854 0b100000000000000000000001:8388609
855 0b1000000000000000000000001:16777217
856 0b10000000000000000000000001:33554433
857 0b100000000000000000000000001:67108865
858 0b1000000000000000000000000001:134217729
859 0b10000000000000000000000000001:268435457
860 0b100000000000000000000000000001:536870913
861 0b1000000000000000000000000000001:1073741825
862 0b10000000000000000000000000000001:2147483649
863 0b100000000000000000000000000000001:4294967297
864 0b1000000000000000000000000000000001:8589934593
865 0b10000000000000000000000000000000001:17179869185
866 0b_101:NaN
867 0b1_0_1:5
868 0b0_0_0_1:1
869 # hex input
870 -0x0:0
871 0xabcdefgh:NaN
872 0x1234:4660
873 0xabcdef:11259375
874 -0xABCDEF:-11259375
875 -0x1234:-4660
876 0x12345678:305419896
877 0x1_2_3_4_56_78:305419896
878 0xa_b_c_d_e_f:11259375
879 0x_123:NaN
880 0x9:9
881 0x11:17
882 0x21:33
883 0x41:65
884 0x81:129
885 0x101:257
886 0x201:513
887 0x401:1025
888 0x801:2049
889 0x1001:4097
890 0x2001:8193
891 0x4001:16385
892 0x8001:32769
893 0x10001:65537
894 0x20001:131073
895 0x40001:262145
896 0x80001:524289
897 0x100001:1048577
898 0x200001:2097153
899 0x400001:4194305
900 0x800001:8388609
901 0x1000001:16777217
902 0x2000001:33554433
903 0x4000001:67108865
904 0x8000001:134217729
905 0x10000001:268435457
906 0x20000001:536870913
907 0x40000001:1073741825
908 0x80000001:2147483649
909 0x100000001:4294967297
910 0x200000001:8589934593
911 0x400000001:17179869185
912 0x800000001:34359738369
913 # inf input
914 inf:inf
915 +inf:inf
916 -inf:-inf
917 0inf:NaN
918 # abnormal input
919 :NaN
920 abc:NaN
921    1 a:NaN
922 1bcd2:NaN
923 11111b:NaN
924 +1z:NaN
925 -1z:NaN
926 # only one underscore between two digits
927 _123:NaN
928 _123_:NaN
929 123_:NaN
930 1__23:NaN
931 1E1__2:NaN
932 1_E12:NaN
933 1E_12:NaN
934 1_E_12:NaN
935 +_1E12:NaN
936 +0_1E2:100
937 +0_0_1E2:100
938 -0_0_1E2:-100
939 -0_0_1E+0_0_2:-100
940 E1:NaN
941 E23:NaN
942 1.23E1:NaN
943 1.23E-1:NaN
944 # bug with two E's in number beeing valid
945 1e2e3:NaN
946 1e2r:NaN
947 1e2.0:NaN
948 # bug with two '.' in number beeing valid
949 1.2.2:NaN
950 1.2.3e1:NaN
951 -1.2.3:NaN
952 -1.2.3e-4:NaN
953 1.2e3.4:NaN
954 1.2e-3.4:NaN
955 1.2.3.4:NaN
956 1.2.t:NaN
957 1..2:NaN
958 1..2e1:NaN
959 1..2e1..1:NaN
960 12e1..1:NaN
961 ..2:NaN
962 .-2:NaN
963 # leading zeros
964 012:12
965 0123:123
966 01234:1234
967 012345:12345
968 0123456:123456
969 01234567:1234567
970 012345678:12345678
971 0123456789:123456789
972 01234567891:1234567891
973 012345678912:12345678912
974 0123456789123:123456789123
975 01234567891234:1234567891234
976 # normal input
977 0:0
978 +0:0
979 +00:0
980 +000:0
981 000000000000000000:0
982 -0:0
983 -0000:0
984 +1:1
985 +01:1
986 +001:1
987 +00000100000:100000
988 123456789:123456789
989 -1:-1
990 -01:-1
991 -001:-1
992 -123456789:-123456789
993 -00000100000:-100000
994 1_2_3:123
995 10000000000E-1_0:1
996 1E2:100
997 1E1:10
998 1E0:1
999 1.23E2:123
1000 100E-1:10
1001 # floating point input
1002 # .2e2:20
1003 1.E3:1000
1004 1.01E2:101
1005 1010E-1:101
1006 -1010E0:-1010
1007 -1010E1:-10100
1008 1234.00:1234
1009 # non-integer numbers
1010 -1010E-2:NaN
1011 -1.01E+1:NaN
1012 -1.01E-1:NaN
1013 &bnan
1014 1:NaN
1015 2:NaN
1016 abc:NaN
1017 &bone
1018 2:+:1
1019 2:-:-1
1020 boneNaN:-:-1
1021 boneNaN:+:1
1022 2:abc:1
1023 3::1
1024 &binf
1025 1:+:inf
1026 2:-:-inf
1027 3:abc:inf
1028 &is_nan
1029 123:0
1030 abc:1
1031 NaN:1
1032 -123:0
1033 &is_inf
1034 +inf::1
1035 -inf::1
1036 abc::0
1037 1::0
1038 NaN::0
1039 -1::0
1040 +inf:-:0
1041 +inf:+:1
1042 -inf:-:1
1043 -inf:+:0
1044 -inf:-inf:1
1045 -inf:+inf:0
1046 +inf:-inf:0
1047 +inf:+inf:1
1048 # it must be exactly /^[+-]inf$/
1049 +infinity::0
1050 -infinity::0
1051 &blsft
1052 abc:abc:NaN
1053 +2:+2:8
1054 +1:+32:4294967296
1055 +1:+48:281474976710656
1056 +8:-2:NaN
1057 # excercise base 10
1058 +12345:4:10:123450000
1059 -1234:0:10:-1234
1060 +1234:0:10:1234
1061 +2:2:10:200
1062 +12:2:10:1200
1063 +1234:-3:10:NaN
1064 1234567890123:12:10:1234567890123000000000000
1065 -3:1:2:-6
1066 -5:1:2:-10
1067 -2:1:2:-4
1068 -102533203:1:2:-205066406
1069 &brsft
1070 abc:abc:NaN
1071 +8:+2:2
1072 +4294967296:+32:1
1073 +281474976710656:+48:1
1074 +2:-2:NaN
1075 # excercise base 10
1076 -1234:0:10:-1234
1077 +1234:0:10:1234
1078 +200:2:10:2
1079 +1234:3:10:1
1080 +1234:2:10:12
1081 +1234:-3:10:NaN
1082 310000:4:10:31
1083 12300000:5:10:123
1084 1230000000000:10:10:123
1085 09876123456789067890:12:10:9876123
1086 1234561234567890123:13:10:123456
1087 820265627:1:2:410132813
1088 # test shifting negative numbers in base 2
1089 -15:1:2:-8
1090 -14:1:2:-7
1091 -13:1:2:-7
1092 -12:1:2:-6
1093 -11:1:2:-6
1094 -10:1:2:-5
1095 -9:1:2:-5
1096 -8:1:2:-4
1097 -7:1:2:-4
1098 -6:1:2:-3
1099 -5:1:2:-3
1100 -4:1:2:-2
1101 -3:1:2:-2
1102 -2:1:2:-1
1103 -1:1:2:-1
1104 -1640531254:2:2:-410132814
1105 -1640531254:1:2:-820265627
1106 -820265627:1:2:-410132814
1107 -205066405:1:2:-102533203
1108 &bsstr
1109 +inf:inf
1110 -inf:-inf
1111 1e+34:1e+34
1112 123.456E3:123456e+0
1113 100:1e+2
1114 bsstrabc:NaN
1115 -5:-5e+0
1116 -100:-1e+2
1117 &numify
1118 numifyabc:NaN
1119 +inf:inf
1120 -inf:-inf
1121 5:5
1122 -5:-5
1123 100:100
1124 -100:-100
1125 &bneg
1126 bnegNaN:NaN
1127 +inf:-inf
1128 -inf:inf
1129 abd:NaN
1130 0:0
1131 1:-1
1132 -1:1
1133 +123456789:-123456789
1134 -123456789:123456789
1135 &babs
1136 babsNaN:NaN
1137 +inf:inf
1138 -inf:inf
1139 0:0
1140 1:1
1141 -1:1
1142 +123456789:123456789
1143 -123456789:123456789
1144 &bcmp
1145 bcmpNaN:bcmpNaN:
1146 bcmpNaN:0:
1147 0:bcmpNaN:
1148 0:0:0
1149 -1:0:-1
1150 0:-1:1
1151 1:0:1
1152 0:1:-1
1153 -1:1:-1
1154 1:-1:1
1155 -1:-1:0
1156 1:1:0
1157 123:123:0
1158 123:12:1
1159 12:123:-1
1160 -123:-123:0
1161 -123:-12:-1
1162 -12:-123:1
1163 123:124:-1
1164 124:123:1
1165 -123:-124:1
1166 -124:-123:-1
1167 100:5:1
1168 -123456789:987654321:-1
1169 +123456789:-987654321:1
1170 -987654321:123456789:-1
1171 -inf:5432112345:-1
1172 +inf:5432112345:1
1173 -inf:-5432112345:-1
1174 +inf:-5432112345:1
1175 +inf:+inf:0
1176 -inf:-inf:0
1177 +inf:-inf:1
1178 -inf:+inf:-1
1179 5:inf:-1
1180 5:inf:-1
1181 -5:-inf:1
1182 -5:-inf:1
1183 # return undef
1184 +inf:NaN:
1185 NaN:inf:
1186 -inf:NaN:
1187 NaN:-inf:
1188 &binc
1189 abc:NaN
1190 +inf:inf
1191 -inf:-inf
1192 +0:1
1193 +1:2
1194 -1:0
1195 &bdec
1196 abc:NaN
1197 +inf:inf
1198 -inf:-inf
1199 +0:-1
1200 +1:0
1201 -1:-2
1202 &badd
1203 abc:abc:NaN
1204 abc:0:NaN
1205 +0:abc:NaN
1206 +inf:-inf:NaN
1207 -inf:+inf:NaN
1208 +inf:+inf:inf
1209 -inf:-inf:-inf
1210 baddNaN:+inf:NaN
1211 baddNaN:+inf:NaN
1212 +inf:baddNaN:NaN
1213 -inf:baddNaN:NaN
1214 0:0:0
1215 1:0:1
1216 0:1:1
1217 1:1:2
1218 -1:0:-1
1219 0:-1:-1
1220 -1:-1:-2
1221 -1:+1:0
1222 +1:-1:0
1223 +9:+1:10
1224 +99:+1:100
1225 +999:+1:1000
1226 +9999:+1:10000
1227 +99999:+1:100000
1228 +999999:+1:1000000
1229 +9999999:+1:10000000
1230 +99999999:+1:100000000
1231 +999999999:+1:1000000000
1232 +9999999999:+1:10000000000
1233 +99999999999:+1:100000000000
1234 +10:-1:9
1235 +100:-1:99
1236 +1000:-1:999
1237 +10000:-1:9999
1238 +100000:-1:99999
1239 +1000000:-1:999999
1240 +10000000:-1:9999999
1241 +100000000:-1:99999999
1242 +1000000000:-1:999999999
1243 +10000000000:-1:9999999999
1244 +123456789:987654321:1111111110
1245 -123456789:987654321:864197532
1246 -123456789:-987654321:-1111111110
1247 +123456789:-987654321:-864197532
1248 -1:10001:10000
1249 -1:100001:100000
1250 -1:1000001:1000000
1251 -1:10000001:10000000
1252 -1:100000001:100000000
1253 -1:1000000001:1000000000
1254 -1:10000000001:10000000000
1255 -1:100000000001:100000000000
1256 -1:1000000000001:1000000000000
1257 -1:10000000000001:10000000000000
1258 -1:-10001:-10002
1259 -1:-100001:-100002
1260 -1:-1000001:-1000002
1261 -1:-10000001:-10000002
1262 -1:-100000001:-100000002
1263 -1:-1000000001:-1000000002
1264 -1:-10000000001:-10000000002
1265 -1:-100000000001:-100000000002
1266 -1:-1000000000001:-1000000000002
1267 -1:-10000000000001:-10000000000002
1268 &bsub
1269 abc:abc:NaN
1270 abc:+0:NaN
1271 +0:abc:NaN
1272 +inf:-inf:inf
1273 -inf:+inf:-inf
1274 +inf:+inf:NaN
1275 -inf:-inf:NaN
1276 +0:+0:0
1277 +1:+0:1
1278 +0:+1:-1
1279 +1:+1:0
1280 -1:+0:-1
1281 +0:-1:1
1282 -1:-1:0
1283 -1:+1:-2
1284 +1:-1:2
1285 +9:+1:8
1286 +99:+1:98
1287 +999:+1:998
1288 +9999:+1:9998
1289 +99999:+1:99998
1290 +999999:+1:999998
1291 +9999999:+1:9999998
1292 +99999999:+1:99999998
1293 +999999999:+1:999999998
1294 +9999999999:+1:9999999998
1295 +99999999999:+1:99999999998
1296 +10:-1:11
1297 +100:-1:101
1298 +1000:-1:1001
1299 +10000:-1:10001
1300 +100000:-1:100001
1301 +1000000:-1:1000001
1302 +10000000:-1:10000001
1303 +100000000:-1:100000001
1304 +1000000000:-1:1000000001
1305 +10000000000:-1:10000000001
1306 +123456789:+987654321:-864197532
1307 -123456789:+987654321:-1111111110
1308 -123456789:-987654321:864197532
1309 +123456789:-987654321:1111111110
1310 10001:1:10000
1311 100001:1:100000
1312 1000001:1:1000000
1313 10000001:1:10000000
1314 100000001:1:100000000
1315 1000000001:1:1000000000
1316 10000000001:1:10000000000
1317 100000000001:1:100000000000
1318 1000000000001:1:1000000000000
1319 10000000000001:1:10000000000000
1320 10001:-1:10002
1321 100001:-1:100002
1322 1000001:-1:1000002
1323 10000001:-1:10000002
1324 100000001:-1:100000002
1325 1000000001:-1:1000000002
1326 10000000001:-1:10000000002
1327 100000000001:-1:100000000002
1328 1000000000001:-1:1000000000002
1329 10000000000001:-1:10000000000002
1330 &bmul
1331 abc:abc:NaN
1332 abc:+0:NaN
1333 +0:abc:NaN
1334 NaNmul:+inf:NaN
1335 NaNmul:-inf:NaN
1336 -inf:NaNmul:NaN
1337 +inf:NaNmul:NaN
1338 +inf:+inf:inf
1339 +inf:-inf:-inf
1340 -inf:+inf:-inf
1341 -inf:-inf:inf
1342 +0:+0:0
1343 +0:+1:0
1344 +1:+0:0
1345 +0:-1:0
1346 -1:+0:0
1347 123456789123456789:0:0
1348 0:123456789123456789:0
1349 -1:-1:1
1350 -1:+1:-1
1351 +1:-1:-1
1352 +1:+1:1
1353 +2:+3:6
1354 -2:+3:-6
1355 +2:-3:-6
1356 -2:-3:6
1357 111:111:12321
1358 10101:10101:102030201
1359 1001001:1001001:1002003002001
1360 100010001:100010001:10002000300020001
1361 10000100001:10000100001:100002000030000200001
1362 11111111111:9:99999999999
1363 22222222222:9:199999999998
1364 33333333333:9:299999999997
1365 44444444444:9:399999999996
1366 55555555555:9:499999999995
1367 66666666666:9:599999999994
1368 77777777777:9:699999999993
1369 88888888888:9:799999999992
1370 99999999999:9:899999999991
1371 +25:+25:625
1372 +12345:+12345:152399025
1373 +99999:+11111:1111088889
1374 9999:10000:99990000
1375 99999:100000:9999900000
1376 999999:1000000:999999000000
1377 9999999:10000000:99999990000000
1378 99999999:100000000:9999999900000000
1379 999999999:1000000000:999999999000000000
1380 9999999999:10000000000:99999999990000000000
1381 99999999999:100000000000:9999999999900000000000
1382 999999999999:1000000000000:999999999999000000000000
1383 9999999999999:10000000000000:99999999999990000000000000
1384 99999999999999:100000000000000:9999999999999900000000000000
1385 999999999999999:1000000000000000:999999999999999000000000000000
1386 9999999999999999:10000000000000000:99999999999999990000000000000000
1387 99999999999999999:100000000000000000:9999999999999999900000000000000000
1388 999999999999999999:1000000000000000000:999999999999999999000000000000000000
1389 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1390 &bdiv-list
1391 100:20:5,0
1392 4095:4095:1,0
1393 -4095:-4095:1,0
1394 4095:-4095:-1,0
1395 -4095:4095:-1,0
1396 123:2:61,1
1397 9:5:1,4
1398 9:4:2,1
1399 # inf handling and general remainder
1400 5:8:0,5
1401 0:8:0,0
1402 11:2:5,1
1403 11:-2:-5,-1
1404 -11:2:-5,1
1405 # see table in documentation in MBI
1406 0:inf:0,0
1407 0:-inf:0,0
1408 5:inf:0,5
1409 5:-inf:0,5
1410 -5:inf:0,-5
1411 -5:-inf:0,-5
1412 inf:5:inf,0
1413 -inf:5:-inf,0
1414 inf:-5:-inf,0
1415 -inf:-5:inf,0
1416 5:5:1,0
1417 -5:-5:1,0
1418 inf:inf:NaN,NaN
1419 -inf:-inf:NaN,NaN
1420 -inf:inf:NaN,NaN
1421 inf:-inf:NaN,NaN
1422 8:0:inf,8
1423 inf:0:inf,inf
1424 # exceptions to reminder rule
1425 -8:0:-inf,-8
1426 -inf:0:-inf,-inf
1427 0:0:NaN,NaN
1428 # test the shortcut in Calc if @$x == @$yorg
1429 1234567812345678:123456712345678:10,688888898
1430 12345671234567:1234561234567:10,58888897
1431 123456123456:12345123456:10,4888896
1432 1234512345:123412345:10,388895
1433 1234567890999999999:1234567890:1000000000,999999999
1434 1234567890000000000:1234567890:1000000000,0
1435 1234567890999999999:9876543210:124999998,9503086419
1436 1234567890000000000:9876543210:124999998,8503086420
1437 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
1438 &bdiv
1439 abc:abc:NaN
1440 abc:1:NaN
1441 1:abc:NaN
1442 0:0:NaN
1443 # inf handling (see table in doc)
1444 0:inf:0
1445 0:-inf:0
1446 5:inf:0
1447 5:-inf:0
1448 -5:inf:0
1449 -5:-inf:0
1450 inf:5:inf
1451 -inf:5:-inf
1452 inf:-5:-inf
1453 -inf:-5:inf
1454 5:5:1
1455 -5:-5:1
1456 inf:inf:NaN
1457 -inf:-inf:NaN
1458 -inf:inf:NaN
1459 inf:-inf:NaN
1460 8:0:inf
1461 inf:0:inf
1462 -8:0:-inf
1463 -inf:0:-inf
1464 0:0:NaN
1465 11:2:5
1466 -11:-2:5
1467 -11:2:-5
1468 11:-2:-5
1469 0:1:0
1470 0:-1:0
1471 1:1:1
1472 -1:-1:1
1473 1:-1:-1
1474 -1:1:-1
1475 1:2:0
1476 2:1:2
1477 1:26:0
1478 1000000000:9:111111111
1479 2000000000:9:222222222
1480 3000000000:9:333333333
1481 4000000000:9:444444444
1482 5000000000:9:555555555
1483 6000000000:9:666666666
1484 7000000000:9:777777777
1485 8000000000:9:888888888
1486 9000000000:9:1000000000
1487 35500000:113:314159
1488 71000000:226:314159
1489 106500000:339:314159
1490 1000000000:3:333333333
1491 +10:+5:2
1492 +100:+4:25
1493 +1000:+8:125
1494 +10000:+16:625
1495 999999999999:9:111111111111
1496 999999999999:99:10101010101
1497 999999999999:999:1001001001
1498 999999999999:9999:100010001
1499 999999999999999:99999:10000100001
1500 +1111088889:99999:11111
1501 -5:-3:1
1502 -5:3:-1
1503 4:3:1
1504 4:-3:-1
1505 1:3:0
1506 1:-3:0
1507 -2:-3:0
1508 -2:3:0
1509 8:3:2
1510 -8:3:-2
1511 14:-3:-4
1512 -14:3:-4
1513 -14:-3:4
1514 14:3:4
1515 # bug in Calc with '99999' vs $BASE-1
1516 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
1517 # test the shortcut in Calc if @$x == @$yorg
1518 1234567812345678:123456712345678:10
1519 12345671234567:1234561234567:10
1520 123456123456:12345123456:10
1521 1234512345:123412345:10
1522 1234567890999999999:1234567890:1000000000
1523 1234567890000000000:1234567890:1000000000
1524 1234567890999999999:9876543210:124999998
1525 1234567890000000000:9876543210:124999998
1526 96969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
1527 # bug up to v0.35 in Calc (--$q one too many)
1528 84696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
1529 84696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
1530 84696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
1531 84696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
1532 &bmodinv
1533 # format: number:modulus:result
1534 # bmodinv Data errors
1535 abc:abc:NaN
1536 abc:5:NaN
1537 5:abc:NaN
1538 # bmodinv Expected Results from normal use
1539 1:5:1
1540 3:5:2
1541 -2:5:2
1542 8:5033:4404
1543 1234567891:13:6
1544 -1234567891:13:7
1545 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
1546 ## bmodinv Error cases / useless use of function
1547 3:-5:NaN
1548 inf:5:NaN
1549 5:inf:NaN
1550 -inf:5:NaN
1551 5:-inf:NaN
1552 &bmodpow
1553 # format: number:exponent:modulus:result
1554 # bmodpow Data errors
1555 abc:abc:abc:NaN
1556 5:abc:abc:NaN
1557 abc:5:abc:NaN
1558 abc:abc:5:NaN
1559 5:5:abc:NaN
1560 5:abc:5:NaN
1561 abc:5:5:NaN
1562 # bmodpow Expected results
1563 0:0:2:1
1564 1:0:2:1
1565 0:0:1:0
1566 8:7:5032:3840
1567 8:-1:5033:4404
1568 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1569 # bmodpow Error cases
1570 8:8:-5:NaN
1571 8:-1:16:NaN
1572 inf:5:13:NaN
1573 5:inf:13:NaN
1574 &bmod
1575 # inf handling, see table in doc
1576 0:inf:0
1577 0:-inf:0
1578 5:inf:5
1579 5:-inf:5
1580 -5:inf:-5
1581 -5:-inf:-5
1582 inf:5:0
1583 -inf:5:0
1584 inf:-5:0
1585 -inf:-5:0
1586 5:5:0
1587 -5:-5:0
1588 inf:inf:NaN
1589 -inf:-inf:NaN
1590 -inf:inf:NaN
1591 inf:-inf:NaN
1592 8:0:8
1593 inf:0:inf
1594 # exceptions to reminder rule
1595 -inf:0:-inf
1596 -8:0:-8
1597 0:0:NaN
1598 abc:abc:NaN
1599 abc:1:abc:NaN
1600 1:abc:NaN
1601 0:0:NaN
1602 0:1:0
1603 1:0:1
1604 0:-1:0
1605 -1:0:-1
1606 1:1:0
1607 -1:-1:0
1608 1:-1:0
1609 -1:1:0
1610 1:2:1
1611 2:1:0
1612 1000000000:9:1
1613 2000000000:9:2
1614 3000000000:9:3
1615 4000000000:9:4
1616 5000000000:9:5
1617 6000000000:9:6
1618 7000000000:9:7
1619 8000000000:9:8
1620 9000000000:9:0
1621 35500000:113:33
1622 71000000:226:66
1623 106500000:339:99
1624 1000000000:3:1
1625 10:5:0
1626 100:4:0
1627 1000:8:0
1628 10000:16:0
1629 999999999999:9:0
1630 999999999999:99:0
1631 999999999999:999:0
1632 999999999999:9999:0
1633 999999999999999:99999:0
1634 -9:+5:1
1635 +9:-5:-1
1636 -9:-5:-4
1637 -5:3:1
1638 -2:3:1
1639 4:3:1
1640 1:3:1
1641 -5:-3:-2
1642 -2:-3:-2
1643 4:-3:-2
1644 1:-3:-2
1645 4095:4095:0
1646 100041000510123:3:0
1647 152403346:12345:4321
1648 9:5:4
1649 # test shortcuts in Calc
1650 # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
1651 1234:9:1
1652 123456:9:3
1653 12345678:9:0
1654 1234567891:9:1
1655 123456789123:9:6
1656 12345678912345:9:6
1657 1234567891234567:9:1
1658 123456789123456789:9:0
1659 1234:10:4
1660 123456:10:6
1661 12345678:10:8
1662 1234567891:10:1
1663 123456789123:10:3
1664 12345678912345:10:5
1665 1234567891234567:10:7
1666 123456789123456789:10:9
1667 1234:113:104
1668 123456:113:60
1669 12345678:113:89
1670 1234567891:113:64
1671 123456789123:113:95
1672 12345678912345:113:53
1673 1234567891234567:113:56
1674 123456789123456789:113:39
1675 # bug in bmod() not modifying the variable in place
1676 -629:5033:4404
1677 # bug in bmod() in Calc in the _div_use_div() shortcut code path,
1678 # when X == X and X was big 
1679 111111111111111111111111111111:111111111111111111111111111111:0
1680 12345678901234567890:12345678901234567890:0
1681 &bgcd
1682 abc:abc:NaN
1683 abc:+0:NaN
1684 +0:abc:NaN
1685 +0:+0:0
1686 +0:+1:1
1687 +1:+0:1
1688 +1:+1:1
1689 +2:+3:1
1690 +3:+2:1
1691 -3:+2:1
1692 100:625:25
1693 4096:81:1
1694 1034:804:2
1695 27:90:56:1
1696 27:90:54:9
1697 &blcm
1698 abc:abc:NaN
1699 abc:+0:NaN
1700 +0:abc:NaN
1701 +0:+0:NaN
1702 +1:+0:0
1703 +0:+1:0
1704 +27:+90:270
1705 +1034:+804:415668
1706 &band
1707 abc:abc:NaN
1708 abc:0:NaN
1709 0:abc:NaN
1710 1:2:0
1711 3:2:2
1712 +8:+2:0
1713 +281474976710656:0:0
1714 +281474976710656:1:0
1715 +281474976710656:+281474976710656:281474976710656
1716 -2:-3:-4
1717 -1:-1:-1
1718 -6:-6:-6
1719 -7:-4:-8
1720 -7:4:0
1721 -4:7:4
1722 # equal arguments are treated special, so also do some test with unequal ones
1723 0xFFFF:0xFFFF:0x0xFFFF
1724 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1725 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1726 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1727 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1728 0xF0F0:0xF0F0:0x0xF0F0
1729 0x0F0F:0x0F0F:0x0x0F0F
1730 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1731 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1732 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1733 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1734 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1735 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1736 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1737 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1738 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1739 &bior
1740 abc:abc:NaN
1741 abc:0:NaN
1742 0:abc:NaN
1743 1:2:3
1744 +8:+2:10
1745 +281474976710656:0:281474976710656
1746 +281474976710656:1:281474976710657
1747 +281474976710656:281474976710656:281474976710656
1748 -2:-3:-1
1749 -1:-1:-1
1750 -6:-6:-6
1751 -7:4:-3
1752 -4:7:-1
1753 # equal arguments are treated special, so also do some test with unequal ones
1754 0xFFFF:0xFFFF:0x0xFFFF
1755 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1756 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1757 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1758 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1759 0:0xFFFF:0x0xFFFF
1760 0:0xFFFFFF:0x0xFFFFFF
1761 0:0xFFFFFFFF:0x0xFFFFFFFF
1762 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1763 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1764 0xFFFF:0:0x0xFFFF
1765 0xFFFFFF:0:0x0xFFFFFF
1766 0xFFFFFFFF:0:0x0xFFFFFFFF
1767 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1768 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1769 0xF0F0:0xF0F0:0x0xF0F0
1770 0x0F0F:0x0F0F:0x0x0F0F
1771 0xF0F0:0x0F0F:0x0xFFFF
1772 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1773 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1774 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1775 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1776 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1777 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1778 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1779 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1780 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1781 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1782 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1783 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1784 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1785 &bxor
1786 abc:abc:NaN
1787 abc:0:NaN
1788 0:abc:NaN
1789 1:2:3
1790 +8:+2:10
1791 +281474976710656:0:281474976710656
1792 +281474976710656:1:281474976710657
1793 +281474976710656:281474976710656:0
1794 -2:-3:3
1795 -1:-1:0
1796 -6:-6:0
1797 -7:4:-3
1798 -4:7:-5
1799 4:-7:-3
1800 -4:-7:5
1801 # equal arguments are treated special, so also do some test with unequal ones
1802 0xFFFF:0xFFFF:0
1803 0xFFFFFF:0xFFFFFF:0
1804 0xFFFFFFFF:0xFFFFFFFF:0
1805 0xFFFFFFFFFF:0xFFFFFFFFFF:0
1806 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
1807 0:0xFFFF:0x0xFFFF
1808 0:0xFFFFFF:0x0xFFFFFF
1809 0:0xFFFFFFFF:0x0xFFFFFFFF
1810 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1811 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1812 0xFFFF:0:0x0xFFFF
1813 0xFFFFFF:0:0x0xFFFFFF
1814 0xFFFFFFFF:0:0x0xFFFFFFFF
1815 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1816 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1817 0xF0F0:0xF0F0:0
1818 0x0F0F:0x0F0F:0
1819 0xF0F0:0x0F0F:0x0xFFFF
1820 0xF0F0F0:0xF0F0F0:0
1821 0x0F0F0F:0x0F0F0F:0
1822 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1823 0xF0F0F0F0:0xF0F0F0F0:0
1824 0x0F0F0F0F:0x0F0F0F0F:0
1825 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1826 0xF0F0F0F0F0:0xF0F0F0F0F0:0
1827 0x0F0F0F0F0F:0x0F0F0F0F0F:0
1828 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1829 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
1830 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
1831 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1832 &bnot
1833 abc:NaN
1834 +0:-1
1835 +8:-9
1836 +281474976710656:-281474976710657
1837 -1:0
1838 -2:1
1839 -12:11
1840 &digit
1841 0:0:0
1842 12:0:2
1843 12:1:1
1844 123:0:3
1845 123:1:2
1846 123:2:1
1847 123:-1:1
1848 123:-2:2
1849 123:-3:3
1850 123456:0:6
1851 123456:1:5
1852 123456:2:4
1853 123456:3:3
1854 123456:4:2
1855 123456:5:1
1856 123456:-1:1
1857 123456:-2:2
1858 123456:-3:3
1859 100000:-3:0
1860 100000:0:0
1861 100000:1:0
1862 &mantissa
1863 abc:NaN
1864 1e4:1
1865 2e0:2
1866 123:123
1867 -1:-1
1868 -2:-2
1869 +inf:inf
1870 -inf:-inf
1871 &exponent
1872 abc:NaN
1873 1e4:4
1874 2e0:0
1875 123:0
1876 -1:0
1877 -2:0
1878 0:1
1879 +inf:inf
1880 -inf:inf
1881 &parts
1882 abc:NaN,NaN
1883 1e4:1,4
1884 2e0:2,0
1885 123:123,0
1886 -1:-1,0
1887 -2:-2,0
1888 0:0,1
1889 +inf:inf,inf
1890 -inf:-inf,inf
1891 &bfac
1892 -1:NaN
1893 NaNfac:NaN
1894 +inf:inf
1895 -inf:NaN
1896 0:1
1897 1:1
1898 2:2
1899 3:6
1900 4:24
1901 5:120
1902 6:720
1903 7:5040
1904 8:40320
1905 9:362880
1906 10:3628800
1907 11:39916800
1908 12:479001600
1909 &bpow
1910 abc:12:NaN
1911 12:abc:NaN
1912 0:0:1
1913 0:1:0
1914 0:2:0
1915 0:-1:NaN
1916 0:-2:NaN
1917 1:0:1
1918 1:1:1
1919 1:2:1
1920 1:3:1
1921 1:-1:1
1922 1:-2:1
1923 1:-3:1
1924 2:0:1
1925 2:1:2
1926 2:2:4
1927 2:3:8
1928 3:3:27
1929 2:-1:NaN
1930 -2:-1:NaN
1931 2:-2:NaN
1932 -2:-2:NaN
1933 +inf:1234500012:inf
1934 -inf:1234500012:-inf
1935 +inf:-12345000123:inf
1936 -inf:-12345000123:-inf
1937 # 1 ** -x => 1 / (1 ** x)
1938 -1:0:1
1939 -2:0:1
1940 -1:1:-1
1941 -1:2:1
1942 -1:3:-1
1943 -1:4:1
1944 -1:5:-1
1945 -1:-1:-1
1946 -1:-2:1
1947 -1:-3:-1
1948 -1:-4:1
1949 10:2:100
1950 10:3:1000
1951 10:4:10000
1952 10:5:100000
1953 10:6:1000000
1954 10:7:10000000
1955 10:8:100000000
1956 10:9:1000000000
1957 10:20:100000000000000000000
1958 123456:2:15241383936
1959 &length
1960 100:3
1961 10:2
1962 1:1
1963 0:1
1964 12345:5
1965 10000000000000000:17
1966 -123:3
1967 215960156869840440586892398248:30
1968 &broot
1969 # sqrt()
1970 +0:2:0
1971 +1:2:1
1972 -1:2:NaN
1973 # -$x ** (1/2) => -$y, but not in froot()
1974 -123:2:NaN
1975 +inf:2:inf
1976 -inf:2:NaN
1977 2:2:1
1978 -2:2:NaN
1979 4:2:2
1980 9:2:3
1981 16:2:4
1982 100:2:10
1983 123:2:11
1984 15241:2:123
1985 144:2:12
1986 12:2:3
1987 0.49:2:0
1988 0.0049:2:0
1989 # invalid ones
1990 1:NaN:NaN
1991 -1:NaN:NaN
1992 0:NaN:NaN
1993 -inf:NaN:NaN
1994 +inf:NaN:NaN
1995 NaN:0:NaN
1996 NaN:2:NaN
1997 NaN:inf:NaN
1998 NaN:inf:NaN
1999 12:-inf:NaN
2000 12:inf:NaN
2001 +0:0:NaN
2002 +1:0:NaN
2003 -1:0:NaN
2004 -2:0:NaN
2005 -123.45:0:NaN
2006 +inf:0:NaN
2007 12:1:12
2008 -12:1:NaN
2009 8:-1:NaN
2010 -8:-1:NaN
2011 # cubic root
2012 8:3:2
2013 -8:3:NaN
2014 # fourths root
2015 16:4:2
2016 81:4:3
2017 # 2 ** 64
2018 18446744073709551616:4:65536
2019 18446744073709551616:8:256
2020 18446744073709551616:16:16
2021 18446744073709551616:32:4
2022 18446744073709551616:64:2
2023 18446744073709551616:128:1
2024 # 213 ** 15
2025 84274086103068221283760416414557757:15:213
2026 # see t/bigroot for more tests
2027 &bsqrt
2028 145:12
2029 144:12
2030 143:11
2031 16:4
2032 170:13
2033 169:13
2034 168:12
2035 4:2
2036 3:1
2037 2:1
2038 9:3
2039 12:3
2040 256:16
2041 100000000:10000
2042 4000000000000:2000000
2043 152399026:12345
2044 152399025:12345
2045 152399024:12344
2046 # 2 ** 64 => 2 ** 32
2047 18446744073709551616:4294967296
2048 84274086103068221283760416414557757:290299993288095377
2049 1:1
2050 0:0
2051 -2:NaN
2052 -123:NaN
2053 Nan:NaN
2054 +inf:inf
2055 -inf:NaN
2056 &bround
2057 $round_mode('trunc')
2058 0:12:0
2059 NaNbround:12:NaN
2060 +inf:12:inf
2061 -inf:12:-inf
2062 1234:0:1234
2063 1234:2:1200
2064 123456:4:123400
2065 123456:5:123450
2066 123456:6:123456
2067 +10123456789:5:10123000000
2068 -10123456789:5:-10123000000
2069 +10123456789:9:10123456700
2070 -10123456789:9:-10123456700
2071 +101234500:6:101234000
2072 -101234500:6:-101234000
2073 #+101234500:-4:101234000
2074 #-101234500:-4:-101234000
2075 $round_mode('zero')
2076 +20123456789:5:20123000000
2077 -20123456789:5:-20123000000
2078 +20123456789:9:20123456800
2079 -20123456789:9:-20123456800
2080 +201234500:6:201234000
2081 -201234500:6:-201234000
2082 #+201234500:-4:201234000
2083 #-201234500:-4:-201234000
2084 +12345000:4:12340000
2085 -12345000:4:-12340000
2086 $round_mode('+inf')
2087 +30123456789:5:30123000000
2088 -30123456789:5:-30123000000
2089 +30123456789:9:30123456800
2090 -30123456789:9:-30123456800
2091 +301234500:6:301235000
2092 -301234500:6:-301234000
2093 #+301234500:-4:301235000
2094 #-301234500:-4:-301234000
2095 +12345000:4:12350000
2096 -12345000:4:-12340000
2097 $round_mode('-inf')
2098 +40123456789:5:40123000000
2099 -40123456789:5:-40123000000
2100 +40123456789:9:40123456800
2101 -40123456789:9:-40123456800
2102 +401234500:6:401234000
2103 +401234500:6:401234000
2104 #-401234500:-4:-401235000
2105 #-401234500:-4:-401235000
2106 +12345000:4:12340000
2107 -12345000:4:-12350000
2108 $round_mode('odd')
2109 +50123456789:5:50123000000
2110 -50123456789:5:-50123000000
2111 +50123456789:9:50123456800
2112 -50123456789:9:-50123456800
2113 +501234500:6:501235000
2114 -501234500:6:-501235000
2115 #+501234500:-4:501235000
2116 #-501234500:-4:-501235000
2117 +12345000:4:12350000
2118 -12345000:4:-12350000
2119 $round_mode('even')
2120 +60123456789:5:60123000000
2121 -60123456789:5:-60123000000
2122 +60123456789:9:60123456800
2123 -60123456789:9:-60123456800
2124 +601234500:6:601234000
2125 -601234500:6:-601234000
2126 #+601234500:-4:601234000
2127 #-601234500:-4:-601234000
2128 #-601234500:-9:0
2129 #-501234500:-9:0
2130 #-601234500:-8:0
2131 #-501234500:-8:0
2132 +1234567:7:1234567
2133 +1234567:6:1234570
2134 +12345000:4:12340000
2135 -12345000:4:-12340000
2136 &is_zero
2137 0:1
2138 NaNzero:0
2139 +inf:0
2140 -inf:0
2141 123:0
2142 -1:0
2143 1:0
2144 &is_one
2145 0:0
2146 NaNone:0
2147 +inf:0
2148 -inf:0
2149 1:1
2150 2:0
2151 -1:0
2152 -2:0
2153 # floor and ceil tests are pretty pointless in integer space...but play safe
2154 &bfloor
2155 0:0
2156 NaNfloor:NaN
2157 +inf:inf
2158 -inf:-inf
2159 -1:-1
2160 -2:-2
2161 2:2
2162 3:3
2163 abc:NaN
2164 &bceil
2165 NaNceil:NaN
2166 +inf:inf
2167 -inf:-inf
2168 0:0
2169 -1:-1
2170 -2:-2
2171 2:2
2172 3:3
2173 abc:NaN
2174 &as_hex
2175 128:0x80
2176 -128:-0x80
2177 0:0x0
2178 -0:0x0
2179 1:0x1
2180 0x123456789123456789:0x123456789123456789
2181 +inf:inf
2182 -inf:-inf
2183 NaNas_hex:NaN
2184 &as_bin
2185 128:0b10000000
2186 -128:-0b10000000
2187 0:0b0
2188 -0:0b0
2189 1:0b1
2190 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
2191 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
2192 +inf:inf
2193 -inf:-inf
2194 NaNas_bin:NaN