This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
6dcaa7527ecbf81c56e7683a3135700efa72ed24
[perl5.git] / lib / Math / BigInt / t / upgrade.inc
1 #include this file into another for subclass testing
2
3 # This file is nearly identical to bigintpm.t, except that certain results
4 # are _requird_ to be different due to "upgrading" or "promoting" to BigFloat.
5 # The reverse is not true, any unmarked results can be either BigInt or
6 # BigFloat, depending on how good the internal optimization is.
7
8 # Plaese note that the testcount goes up by two for each extra result marked
9 # with ^, since then we test whether it has the proper class and that it left
10 # the upgrade variable alone.
11
12 my $version = ${"$class\::VERSION"};
13
14 ##############################################################################
15 # for testing inheritance of _swap
16
17 package Math::Foo;
18
19 use Math::BigInt lib => $main::CL;
20 use vars qw/@ISA/;
21 @ISA = (qw/Math::BigInt/);
22
23 use overload
24 # customized overload for sub, since original does not use swap there
25 '-'     =>      sub { my @a = ref($_[0])->_swap(@_);
26                    $a[0]->bsub($a[1])};
27
28 sub _swap
29   {
30   # a fake _swap, which reverses the params
31   my $self = shift;                     # for override in subclass
32   if ($_[2])
33     {
34     my $c = ref ($_[0] ) || 'Math::Foo';
35     return ( $_[0]->copy(), $_[1] );
36     }
37   else
38     {
39     return ( Math::Foo->new($_[1]), $_[0] );
40     }
41   }
42
43 ##############################################################################
44 package main;
45
46 my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
47
48 my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
49
50 while (<DATA>) 
51   {
52   chop;
53   next if /^#/; # skip comments
54   if (s/^&//) 
55     {
56     $f = $_; next;
57     }
58   elsif (/^\$/) 
59     {
60     $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
61     }
62
63   @args = split(/:/,$_,99); $ans = pop(@args);
64   $expected_class = $class;
65   if ($ans =~ /\^$/)
66     {
67     $expected_class = $ECL; $ans =~ s/\^$//;
68     }
69   $try = "\$x = $class->new(\"$args[0]\");";
70   if ($f eq "bnorm")
71     {
72     $try = "\$x = $class->bnorm(\"$args[0]\");";
73   # some is_xxx tests
74    } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
75     $try .= "\$x->$f();";
76    } elsif ($f eq "as_hex") {
77     $try .= '$x->as_hex();';
78    } elsif ($f eq "as_bin") {
79     $try .= '$x->as_bin();';
80    } elsif ($f eq "is_inf") {
81     $try .= "\$x->is_inf('$args[1]');";
82    } elsif ($f eq "binf") {
83     $try .= "\$x->binf('$args[1]');";
84    } elsif ($f eq "bone") {
85     $try .= "\$x->bone('$args[1]');";
86    # some unary ops
87    } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
88     $try .= "\$x->$f();";
89    } elsif ($f eq "length") {
90     $try .= '$x->length();';
91    } elsif ($f eq "exponent"){
92     # ->bstr() to see if an object is returned
93     $try .= '$x = $x->exponent()->bstr();';
94    } elsif ($f eq "mantissa"){
95     # ->bstr() to see if an object is returned
96     $try .= '$x = $x->mantissa()->bstr();';
97    } elsif ($f eq "parts"){
98     $try .= '($m,$e) = $x->parts();'; 
99     # ->bstr() to see if an object is returned
100     $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
101     $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
102     $try .= '"$m,$e";';
103    } else {
104     $try .= "\$y = $class->new('$args[1]');";
105     if ($f eq "bcmp")
106       {
107       $try .= '$x <=> $y;';
108       } elsif ($f eq "bround") {
109       $try .= "$round_mode; \$x->bround(\$y);";
110       } elsif ($f eq "bacmp"){
111       $try .= '$x->bacmp($y);';
112       } elsif ($f eq "badd"){
113       $try .= '$x + $y;';
114       } elsif ($f eq "bsub"){
115       $try .= '$x - $y;';
116       } elsif ($f eq "bmul"){
117       $try .= '$x * $y;';
118       } elsif ($f eq "bdiv"){
119       $try .= '$x / $y;';
120       } elsif ($f eq "bdiv-list"){
121       $try .= 'join (",",$x->bdiv($y));';
122       # overload via x=
123       } elsif ($f =~ /^.=$/){
124       $try .= "\$x $f \$y;";
125       # overload via x
126       } elsif ($f =~ /^.$/){
127       $try .= "\$x $f \$y;";
128       } elsif ($f eq "bmod"){
129       $try .= '$x % $y;';
130       } elsif ($f eq "bgcd")
131         {
132         if (defined $args[2])
133           {
134           $try .= " \$z = $class->new('$args[2]'); ";
135           }
136         $try .= "$class\::bgcd(\$x, \$y";
137         $try .= ", \$z" if (defined $args[2]);
138         $try .= " );";
139         }
140       elsif ($f eq "blcm")
141         {
142         if (defined $args[2])
143           {
144           $try .= " \$z = $class->new('$args[2]'); ";
145           }
146         $try .= "$class\::blcm(\$x, \$y";
147         $try .= ", \$z" if (defined $args[2]);
148         $try .= " );";
149       }elsif ($f eq "blsft"){
150         if (defined $args[2])
151           {
152           $try .= "\$x->blsft(\$y,$args[2]);";
153           }
154         else
155           {
156           $try .= "\$x << \$y;";
157           }
158       }elsif ($f eq "brsft"){
159         if (defined $args[2])
160           {
161           $try .= "\$x->brsft(\$y,$args[2]);";
162           }
163         else
164           {
165           $try .= "\$x >> \$y;";
166           }
167       }elsif ($f eq "band"){
168         $try .= "\$x & \$y;";
169       }elsif ($f eq "bior"){
170         $try .= "\$x | \$y;";
171       }elsif ($f eq "bxor"){
172         $try .= "\$x ^ \$y;";
173       }elsif ($f eq "bpow"){
174         $try .= "\$x ** \$y;";
175       }elsif ($f eq "digit"){
176         $try = "\$x = $class->new('$args[0]'); \$x->digit($args[1]);";
177       } else { warn "Unknown op '$f'"; }
178     } # end else all other ops
179
180   $ans1 = eval $try;
181   # convert hex/binary targets to decimal       
182   if ($ans =~ /^(0x0x|0b0b)/)
183     {
184     $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
185     }
186   if ($ans eq "")
187     {
188     ok_undef ($ans1); 
189     }
190   else
191     {
192     # print "try: $try ans: $ans1 $ans\n";
193     print "# Tried: '$try'\n" if !ok ($ans1, $ans);
194     if ($expected_class ne $class)
195       {
196       ok (ref($ans1),$expected_class);  # also checks that it really is ref!
197       ok ($Math::BigInt::upgrade,'Math::BigFloat');     # still okay?
198       }
199     }
200   # check internal state of number objects
201   is_valid($ans1,$f) if ref $ans1; 
202   } # endwhile data tests
203 close DATA;
204
205 # all tests done
206
207 1;
208
209 ###############################################################################
210 ###############################################################################
211 # Perl 5.005 does not like ok ($x,undef)
212
213 sub ok_undef
214   {
215   my $x = shift;
216
217   ok (1,1) and return if !defined $x;
218   ok ($x,'undef');
219   }
220
221 ###############################################################################
222 # sub to check validity of a BigInt internally, to ensure that no op leaves a
223 # number object in an invalid state (f.i. "-0")
224
225 sub is_valid
226   {
227   my ($x,$f,$c) = @_;
228
229   # The checks here are loosened a bit to allow BigInt or BigFloats to pass
230
231   my $e = 0;                    # error?
232   # ok as reference? 
233   # $e = "Not a reference to $c" if (ref($x) || '') ne $c;
234
235   # has ok sign?
236   $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
237    if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
238
239   $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
240   #$e = $CALC->_check($x->{value}) if $e eq '0';
241
242   # test done, see if error did crop up
243   ok (1,1), return if ($e eq '0');
244
245   ok (1,$e." after op '$f'");
246   }
247
248 __DATA__
249 &.=
250 1234:-345:1234-345
251 &+=
252 1:2:3
253 -1:-2:-3
254 &-=
255 1:2:-1
256 -1:-2:1
257 &*=
258 2:3:6
259 -1:5:-5
260 &%=
261 100:3:1
262 8:9:8
263 &/=
264 100:3:33
265 -8:2:-4
266 &|=
267 2:1:3
268 &&=
269 5:7:5
270 &^=
271 5:7:2
272 &is_negative
273 0:0
274 -1:1
275 1:0
276 +inf:0
277 -inf:1
278 NaNneg:0
279 &is_positive
280 0:1
281 -1:0
282 1:1
283 +inf:1
284 -inf:0
285 NaNneg:0
286 &is_odd
287 abc:0
288 0:0
289 1:1
290 3:1
291 -1:1
292 -3:1
293 10000001:1
294 10000002:0
295 2:0
296 120:0
297 121:1
298 &is_int
299 NaN:0
300 inf:0
301 -inf:0
302 1:1
303 12:1
304 123e12:1
305 &is_even
306 abc:0
307 0:1
308 1:0
309 3:0
310 -1:0
311 -3:0
312 10000001:0
313 10000002:1
314 2:1
315 120:1
316 121:0
317 &bacmp
318 +0:-0:0
319 +0:+1:-1
320 -1:+1:0
321 +1:-1:0
322 -1:+2:-1
323 +2:-1:1
324 -123456789:+987654321:-1
325 +123456789:-987654321:-1
326 +987654321:+123456789:1
327 -987654321:+123456789:1
328 -123:+4567889:-1
329 # NaNs
330 acmpNaN:123:
331 123:acmpNaN:
332 acmpNaN:acmpNaN:
333 # infinity
334 +inf:+inf:0
335 -inf:-inf:0
336 +inf:-inf:0
337 -inf:+inf:0
338 +inf:123:1
339 -inf:123:1
340 +inf:-123:1
341 -inf:-123:1
342 # return undef
343 +inf:NaN:
344 NaN:inf:
345 -inf:NaN:
346 NaN:-inf:
347 &bnorm
348 123:123
349 12.3:12.3^
350 # binary input
351 0babc:NaN
352 0b123:NaN
353 0b0:0
354 -0b0:0
355 -0b1:-1
356 0b0001:1
357 0b001:1
358 0b011:3
359 0b101:5
360 0b1001:9
361 0b10001:17
362 0b100001:33
363 0b1000001:65
364 0b10000001:129
365 0b100000001:257
366 0b1000000001:513
367 0b10000000001:1025
368 0b100000000001:2049
369 0b1000000000001:4097
370 0b10000000000001:8193
371 0b100000000000001:16385
372 0b1000000000000001:32769
373 0b10000000000000001:65537
374 0b100000000000000001:131073
375 0b1000000000000000001:262145
376 0b10000000000000000001:524289
377 0b100000000000000000001:1048577
378 0b1000000000000000000001:2097153
379 0b10000000000000000000001:4194305
380 0b100000000000000000000001:8388609
381 0b1000000000000000000000001:16777217
382 0b10000000000000000000000001:33554433
383 0b100000000000000000000000001:67108865
384 0b1000000000000000000000000001:134217729
385 0b10000000000000000000000000001:268435457
386 0b100000000000000000000000000001:536870913
387 0b1000000000000000000000000000001:1073741825
388 0b10000000000000000000000000000001:2147483649
389 0b100000000000000000000000000000001:4294967297
390 0b1000000000000000000000000000000001:8589934593
391 0b10000000000000000000000000000000001:17179869185
392 0b_101:NaN
393 0b1_0_1:5
394 0b0_0_0_1:1
395 # hex input
396 -0x0:0
397 0xabcdefgh:NaN
398 0x1234:4660
399 0xabcdef:11259375
400 -0xABCDEF:-11259375
401 -0x1234:-4660
402 0x12345678:305419896
403 0x1_2_3_4_56_78:305419896
404 0xa_b_c_d_e_f:11259375
405 0x_123:NaN
406 0x9:9
407 0x11:17
408 0x21:33
409 0x41:65
410 0x81:129
411 0x101:257
412 0x201:513
413 0x401:1025
414 0x801:2049
415 0x1001:4097
416 0x2001:8193
417 0x4001:16385
418 0x8001:32769
419 0x10001:65537
420 0x20001:131073
421 0x40001:262145
422 0x80001:524289
423 0x100001:1048577
424 0x200001:2097153
425 0x400001:4194305
426 0x800001:8388609
427 0x1000001:16777217
428 0x2000001:33554433
429 0x4000001:67108865
430 0x8000001:134217729
431 0x10000001:268435457
432 0x20000001:536870913
433 0x40000001:1073741825
434 0x80000001:2147483649
435 0x100000001:4294967297
436 0x200000001:8589934593
437 0x400000001:17179869185
438 0x800000001:34359738369
439 # inf input
440 inf:inf
441 +inf:inf
442 -inf:-inf
443 0inf:NaN
444 # abnormal input
445 :NaN
446 abc:NaN
447    1 a:NaN
448 1bcd2:NaN
449 11111b:NaN
450 +1z:NaN
451 -1z:NaN
452 # only one underscore between two digits
453 _123:NaN
454 _123_:NaN
455 123_:NaN
456 1__23:NaN
457 1E1__2:NaN
458 1_E12:NaN
459 1E_12:NaN
460 1_E_12:NaN
461 +_1E12:NaN
462 +0_1E2:100
463 +0_0_1E2:100
464 -0_0_1E2:-100
465 -0_0_1E+0_0_2:-100
466 E1:NaN
467 E23:NaN
468 1.23E1:12.3^
469 1.23E-1:0.123^
470 # bug with two E's in number beeing valid
471 1e2e3:NaN
472 1e2r:NaN
473 1e2.0:NaN
474 # leading zeros
475 012:12
476 0123:123
477 01234:1234
478 012345:12345
479 0123456:123456
480 01234567:1234567
481 012345678:12345678
482 0123456789:123456789
483 01234567891:1234567891
484 012345678912:12345678912
485 0123456789123:123456789123
486 01234567891234:1234567891234
487 # normal input
488 0:0
489 +0:0
490 +00:0
491 +000:0
492 000000000000000000:0
493 -0:0
494 -0000:0
495 +1:1
496 +01:1
497 +001:1
498 +00000100000:100000
499 123456789:123456789
500 -1:-1
501 -01:-1
502 -001:-1
503 -123456789:-123456789
504 -00000100000:-100000
505 1_2_3:123
506 10000000000E-1_0:1
507 1E2:100
508 1E1:10
509 1E0:1
510 1.23E2:123
511 100E-1:10
512 # floating point input
513 # .2e2:20
514 1.E3:1000
515 1.01E2:101
516 1010E-1:101
517 -1010E0:-1010
518 -1010E1:-10100
519 1234.00:1234
520 # non-integer numbers
521 -1010E-2:-10.1^
522 -1.01E+1:-10.1^
523 -1.01E-1:-0.101^
524 &bnan
525 1:NaN
526 2:NaN
527 abc:NaN
528 &bone
529 2:+:1
530 2:-:-1
531 boneNaN:-:-1
532 boneNaN:+:1
533 2:abc:1
534 3::1
535 &binf
536 1:+:inf
537 2:-:-inf
538 3:abc:inf
539 &is_nan
540 123:0
541 abc:1
542 NaN:1
543 -123:0
544 &is_inf
545 +inf::1
546 -inf::1
547 abc::0
548 1::0
549 NaN::0
550 -1::0
551 +inf:-:0
552 +inf:+:1
553 -inf:-:1
554 -inf:+:0
555 # it must be exactly /^[+-]inf$/
556 +infinity::0
557 -infinity::0
558 &blsft
559 abc:abc:NaN
560 +2:+2:8
561 +1:+32:4294967296
562 +1:+48:281474976710656
563 +8:-2:NaN
564 # excercise base 10
565 +12345:4:10:123450000
566 -1234:0:10:-1234
567 +1234:0:10:1234
568 +2:2:10:200
569 +12:2:10:1200
570 +1234:-3:10:NaN
571 1234567890123:12:10:1234567890123000000000000
572 &brsft
573 abc:abc:NaN
574 +8:+2:2
575 +4294967296:+32:1
576 +281474976710656:+48:1
577 +2:-2:NaN
578 # excercise base 10
579 -1234:0:10:-1234
580 +1234:0:10:1234
581 +200:2:10:2
582 +1234:3:10:1
583 +1234:2:10:12
584 +1234:-3:10:NaN
585 310000:4:10:31
586 12300000:5:10:123
587 1230000000000:10:10:123
588 09876123456789067890:12:10:9876123
589 1234561234567890123:13:10:123456
590 &bsstr
591 1e+34:1e+34
592 123.456E3:123456e+0
593 100:1e+2
594 abc:NaN
595 &bneg
596 bnegNaN:NaN
597 +inf:-inf
598 -inf:inf
599 abd:NaN
600 0:0
601 1:-1
602 -1:1
603 +123456789:-123456789
604 -123456789:123456789
605 &babs
606 babsNaN:NaN
607 +inf:inf
608 -inf:inf
609 0:0
610 1:1
611 -1:1
612 +123456789:123456789
613 -123456789:123456789
614 &bcmp
615 bcmpNaN:bcmpNaN:
616 bcmpNaN:0:
617 0:bcmpNaN:
618 0:0:0
619 -1:0:-1
620 0:-1:1
621 1:0:1
622 0:1:-1
623 -1:1:-1
624 1:-1:1
625 -1:-1:0
626 1:1:0
627 123:123:0
628 123:12:1
629 12:123:-1
630 -123:-123:0
631 -123:-12:-1
632 -12:-123:1
633 123:124:-1
634 124:123:1
635 -123:-124:1
636 -124:-123:-1
637 100:5:1
638 -123456789:987654321:-1
639 +123456789:-987654321:1
640 -987654321:123456789:-1
641 -inf:5432112345:-1
642 +inf:5432112345:1
643 -inf:-5432112345:-1
644 +inf:-5432112345:1
645 +inf:+inf:0
646 -inf:-inf:0
647 +inf:-inf:1
648 -inf:+inf:-1
649 5:inf:-1
650 5:inf:-1
651 -5:-inf:1
652 -5:-inf:1
653 # return undef
654 +inf:NaN:
655 NaN:inf:
656 -inf:NaN:
657 NaN:-inf:
658 &binc
659 abc:NaN
660 +inf:inf
661 -inf:-inf
662 +0:1
663 +1:2
664 -1:0
665 &bdec
666 abc:NaN
667 +inf:inf
668 -inf:-inf
669 +0:-1
670 +1:0
671 -1:-2
672 &badd
673 abc:abc:NaN
674 abc:0:NaN
675 +0:abc:NaN
676 +inf:-inf:NaN
677 -inf:+inf:NaN
678 +inf:+inf:inf
679 -inf:-inf:-inf
680 baddNaN:+inf:NaN
681 baddNaN:+inf:NaN
682 +inf:baddNaN:NaN
683 -inf:baddNaN:NaN
684 0:0:0
685 1:0:1
686 0:1:1
687 1:1:2
688 -1:0:-1
689 0:-1:-1
690 -1:-1:-2
691 -1:+1:0
692 +1:-1:0
693 +9:+1:10
694 +99:+1:100
695 +999:+1:1000
696 +9999:+1:10000
697 +99999:+1:100000
698 +999999:+1:1000000
699 +9999999:+1:10000000
700 +99999999:+1:100000000
701 +999999999:+1:1000000000
702 +9999999999:+1:10000000000
703 +99999999999:+1:100000000000
704 +10:-1:9
705 +100:-1:99
706 +1000:-1:999
707 +10000:-1:9999
708 +100000:-1:99999
709 +1000000:-1:999999
710 +10000000:-1:9999999
711 +100000000:-1:99999999
712 +1000000000:-1:999999999
713 +10000000000:-1:9999999999
714 +123456789:987654321:1111111110
715 -123456789:987654321:864197532
716 -123456789:-987654321:-1111111110
717 +123456789:-987654321:-864197532
718 #2:2.5:4.5^
719 #-123:-1.5:-124.5^
720 #-1.2:1:-0.2^
721 &bsub
722 abc:abc:NaN
723 abc:+0:NaN
724 +0:abc:NaN
725 +inf:-inf:inf
726 -inf:+inf:-inf
727 +inf:+inf:NaN
728 -inf:-inf:NaN
729 +0:+0:0
730 +1:+0:1
731 +0:+1:-1
732 +1:+1:0
733 -1:+0:-1
734 +0:-1:1
735 -1:-1:0
736 -1:+1:-2
737 +1:-1:2
738 +9:+1:8
739 +99:+1:98
740 +999:+1:998
741 +9999:+1:9998
742 +99999:+1:99998
743 +999999:+1:999998
744 +9999999:+1:9999998
745 +99999999:+1:99999998
746 +999999999:+1:999999998
747 +9999999999:+1:9999999998
748 +99999999999:+1:99999999998
749 +10:-1:11
750 +100:-1:101
751 +1000:-1:1001
752 +10000:-1:10001
753 +100000:-1:100001
754 +1000000:-1:1000001
755 +10000000:-1:10000001
756 +100000000:-1:100000001
757 +1000000000:-1:1000000001
758 +10000000000:-1:10000000001
759 +123456789:+987654321:-864197532
760 -123456789:+987654321:-1111111110
761 -123456789:-987654321:864197532
762 +123456789:-987654321:1111111110
763 &bmul
764 abc:abc:NaN
765 abc:+0:NaN
766 +0:abc:NaN
767 NaNmul:+inf:NaN
768 NaNmul:-inf:NaN
769 -inf:NaNmul:NaN
770 +inf:NaNmul:NaN
771 +inf:+inf:inf
772 +inf:-inf:-inf
773 -inf:+inf:-inf
774 -inf:-inf:inf
775 +0:+0:0
776 +0:+1:0
777 +1:+0:0
778 +0:-1:0
779 -1:+0:0
780 123456789123456789:0:0
781 0:123456789123456789:0
782 -1:-1:1
783 -1:+1:-1
784 +1:-1:-1
785 +1:+1:1
786 +2:+3:6
787 -2:+3:-6
788 +2:-3:-6
789 -2:-3:6
790 111:111:12321
791 10101:10101:102030201
792 1001001:1001001:1002003002001
793 100010001:100010001:10002000300020001
794 10000100001:10000100001:100002000030000200001
795 11111111111:9:99999999999
796 22222222222:9:199999999998
797 33333333333:9:299999999997
798 44444444444:9:399999999996
799 55555555555:9:499999999995
800 66666666666:9:599999999994
801 77777777777:9:699999999993
802 88888888888:9:799999999992
803 99999999999:9:899999999991
804 +25:+25:625
805 +12345:+12345:152399025
806 +99999:+11111:1111088889
807 9999:10000:99990000
808 99999:100000:9999900000
809 999999:1000000:999999000000
810 9999999:10000000:99999990000000
811 99999999:100000000:9999999900000000
812 999999999:1000000000:999999999000000000
813 9999999999:10000000000:99999999990000000000
814 99999999999:100000000000:9999999999900000000000
815 999999999999:1000000000000:999999999999000000000000
816 9999999999999:10000000000000:99999999999990000000000000
817 99999999999999:100000000000000:9999999999999900000000000000
818 999999999999999:1000000000000000:999999999999999000000000000000
819 9999999999999999:10000000000000000:99999999999999990000000000000000
820 99999999999999999:100000000000000000:9999999999999999900000000000000000
821 999999999999999999:1000000000000000000:999999999999999999000000000000000000
822 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000
823 &bdiv-list
824 100:20:5,0
825 4095:4095:1,0
826 -4095:-4095:1,0
827 4095:-4095:-1,0
828 -4095:4095:-1,0
829 123:2:61,1
830 9:5:1,4
831 9:4:2,1
832 # inf handling and general remainder
833 5:8:0.625,5
834 0:8:0,0
835 11:2:5,1
836 11:-2:-5,-1
837 -11:2:-5,1
838 # see table in documentation in MBI
839 0:inf:0,0
840 0:-inf:0,0
841 5:inf:0,5
842 5:-inf:0,5
843 -5:inf:0,-5
844 -5:-inf:0,-5
845 inf:5:inf,0
846 -inf:5:-inf,0
847 inf:-5:-inf,0
848 -inf:-5:inf,0
849 5:5:1,0
850 -5:-5:1,0
851 inf:inf:NaN,NaN
852 -inf:-inf:NaN,NaN
853 -inf:inf:NaN,NaN
854 inf:-inf:NaN,NaN
855 8:0:inf,8
856 inf:0:inf,inf
857 # exceptions to reminder rule
858 -8:0:-inf,-8
859 -inf:0:-inf,-inf
860 0:0:NaN,NaN
861 &bdiv
862 abc:abc:NaN
863 abc:1:NaN
864 1:abc:NaN
865 0:0:NaN
866 # inf handling (see table in doc)
867 0:inf:0
868 0:-inf:0
869 5:inf:0
870 5:-inf:0
871 -5:inf:0
872 -5:-inf:0
873 inf:5:inf
874 -inf:5:-inf
875 inf:-5:-inf
876 -inf:-5:inf
877 5:5:1
878 -5:-5:1
879 inf:inf:NaN
880 -inf:-inf:NaN
881 -inf:inf:NaN
882 inf:-inf:NaN
883 8:0:inf
884 inf:0:inf
885 -8:0:-inf
886 -inf:0:-inf
887 0:0:NaN
888 11:2:5
889 -11:-2:5
890 -11:2:-5
891 11:-2:-5
892 0:1:0
893 0:-1:0
894 1:1:1
895 -1:-1:1
896 1:-1:-1
897 -1:1:-1
898 1:2:0.5^
899 2:1:2
900 1000000000:9:111111111
901 2000000000:9:222222222
902 3000000000:9:333333333
903 4000000000:9:444444444
904 5000000000:9:555555555
905 6000000000:9:666666666
906 7000000000:9:777777777
907 8000000000:9:888888888
908 9000000000:9:1000000000
909 35500000:113:314159
910 71000000:226:314159
911 106500000:339:314159
912 1000000000:3:333333333
913 +10:+5:2
914 +100:+4:25
915 +1000:+8:125
916 +10000:+16:625
917 999999999999:9:111111111111
918 999999999999:99:10101010101
919 999999999999:999:1001001001
920 999999999999:9999:100010001
921 999999999999999:99999:10000100001
922 +1111088889:99999:11111
923 -5:-3:1
924 -5:3:-1
925 4:3:1
926 4:-3:-1
927 1:3:0.3333333333333333333333333333333333333333
928 1:-3:-0.3333333333333333333333333333333333333333
929 -2:-3:0.6666666666666666666666666666666666666667
930 -2:3:-0.6666666666666666666666666666666666666667
931 #8:5:1.6^
932 #-8:5:-1.6^
933 8:5:1
934 -8:5:-1
935 14:-3:-4
936 -14:3:-4
937 -14:-3:4
938 14:3:4
939 # bug in Calc with '99999' vs $BASE-1
940 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
941 12:24:0.5^
942 &bmod
943 # inf handling, see table in doc
944 0:inf:0
945 0:-inf:0
946 5:inf:5
947 5:-inf:5
948 -5:inf:-5
949 -5:-inf:-5
950 inf:5:0
951 -inf:5:0
952 inf:-5:0
953 -inf:-5:0
954 5:5:0
955 -5:-5:0
956 inf:inf:NaN
957 -inf:-inf:NaN
958 -inf:inf:NaN
959 inf:-inf:NaN
960 8:0:8
961 inf:0:inf
962 # exceptions to reminder rule
963 -inf:0:-inf
964 -8:0:-8
965 0:0:NaN
966 abc:abc:NaN
967 abc:1:abc:NaN
968 1:abc:NaN
969 0:0:NaN
970 0:1:0
971 1:0:1
972 0:-1:0
973 -1:0:-1
974 1:1:0
975 -1:-1:0
976 1:-1:0
977 -1:1:0
978 1:2:1
979 2:1:0
980 1000000000:9:1
981 2000000000:9:2
982 3000000000:9:3
983 4000000000:9:4
984 5000000000:9:5
985 6000000000:9:6
986 7000000000:9:7
987 8000000000:9:8
988 9000000000:9:0
989 35500000:113:33
990 71000000:226:66
991 106500000:339:99
992 1000000000:3:1
993 10:5:0
994 100:4:0
995 1000:8:0
996 10000:16:0
997 999999999999:9:0
998 999999999999:99:0
999 999999999999:999:0
1000 999999999999:9999:0
1001 999999999999999:99999:0
1002 -9:+5:1
1003 +9:-5:-1
1004 -9:-5:-4
1005 -5:3:1
1006 -2:3:1
1007 4:3:1
1008 1:3:1
1009 -5:-3:-2
1010 -2:-3:-2
1011 4:-3:-2
1012 1:-3:-2
1013 4095:4095:0
1014 100041000510123:3:0
1015 152403346:12345:4321
1016 9:5:4
1017 &bgcd
1018 abc:abc:NaN
1019 abc:+0:NaN
1020 +0:abc:NaN
1021 +0:+0:0
1022 +0:+1:1
1023 +1:+0:1
1024 +1:+1:1
1025 +2:+3:1
1026 +3:+2:1
1027 -3:+2:1
1028 100:625:25
1029 4096:81:1
1030 1034:804:2
1031 27:90:56:1
1032 27:90:54:9
1033 &blcm
1034 abc:abc:NaN
1035 abc:+0:NaN
1036 +0:abc:NaN
1037 +0:+0:NaN
1038 +1:+0:0
1039 +0:+1:0
1040 +27:+90:270
1041 +1034:+804:415668
1042 &band
1043 abc:abc:NaN
1044 abc:0:NaN
1045 0:abc:NaN
1046 1:2:0
1047 3:2:2
1048 +8:+2:0
1049 +281474976710656:0:0
1050 +281474976710656:1:0
1051 +281474976710656:+281474976710656:281474976710656
1052 -2:-3:-4
1053 -1:-1:-1
1054 -6:-6:-6
1055 -7:-4:-8
1056 -7:4:0
1057 -4:7:4
1058 # equal arguments are treated special, so also do some test with unequal ones
1059 0xFFFF:0xFFFF:0x0xFFFF
1060 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1061 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1062 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1063 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1064 0xF0F0:0xF0F0:0x0xF0F0
1065 0x0F0F:0x0F0F:0x0x0F0F
1066 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1067 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1068 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1069 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1070 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1071 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1072 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1073 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1074 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
1075 &bior
1076 abc:abc:NaN
1077 abc:0:NaN
1078 0:abc:NaN
1079 1:2:3
1080 +8:+2:10
1081 +281474976710656:0:281474976710656
1082 +281474976710656:1:281474976710657
1083 +281474976710656:281474976710656:281474976710656
1084 -2:-3:-1
1085 -1:-1:-1
1086 -6:-6:-6
1087 -7:4:-3
1088 -4:7:-1
1089 # equal arguments are treated special, so also do some test with unequal ones
1090 0xFFFF:0xFFFF:0x0xFFFF
1091 0xFFFFFF:0xFFFFFF:0x0xFFFFFF
1092 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
1093 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1094 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1095 0:0xFFFF:0x0xFFFF
1096 0:0xFFFFFF:0x0xFFFFFF
1097 0:0xFFFFFFFF:0x0xFFFFFFFF
1098 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1099 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1100 0xFFFF:0:0x0xFFFF
1101 0xFFFFFF:0:0x0xFFFFFF
1102 0xFFFFFFFF:0:0x0xFFFFFFFF
1103 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1104 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1105 0xF0F0:0xF0F0:0x0xF0F0
1106 0x0F0F:0x0F0F:0x0x0F0F
1107 0xF0F0:0x0F0F:0x0xFFFF
1108 0xF0F0F0:0xF0F0F0:0x0xF0F0F0
1109 0x0F0F0F:0x0F0F0F:0x0x0F0F0F
1110 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1111 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
1112 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
1113 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1114 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
1115 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
1116 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1117 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
1118 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
1119 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1120 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1121 &bxor
1122 abc:abc:NaN
1123 abc:0:NaN
1124 0:abc:NaN
1125 1:2:3
1126 +8:+2:10
1127 +281474976710656:0:281474976710656
1128 +281474976710656:1:281474976710657
1129 +281474976710656:281474976710656:0
1130 -2:-3:3
1131 -1:-1:0
1132 -6:-6:0
1133 -7:4:-3
1134 -4:7:-5
1135 4:-7:-3
1136 -4:-7:5
1137 # equal arguments are treated special, so also do some test with unequal ones
1138 0xFFFF:0xFFFF:0
1139 0xFFFFFF:0xFFFFFF:0
1140 0xFFFFFFFF:0xFFFFFFFF:0
1141 0xFFFFFFFFFF:0xFFFFFFFFFF:0
1142 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
1143 0:0xFFFF:0x0xFFFF
1144 0:0xFFFFFF:0x0xFFFFFF
1145 0:0xFFFFFFFF:0x0xFFFFFFFF
1146 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF
1147 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
1148 0xFFFF:0:0x0xFFFF
1149 0xFFFFFF:0:0x0xFFFFFF
1150 0xFFFFFFFF:0:0x0xFFFFFFFF
1151 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF
1152 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
1153 0xF0F0:0xF0F0:0
1154 0x0F0F:0x0F0F:0
1155 0xF0F0:0x0F0F:0x0xFFFF
1156 0xF0F0F0:0xF0F0F0:0
1157 0x0F0F0F:0x0F0F0F:0
1158 0x0F0F0F:0xF0F0F0:0x0xFFFFFF
1159 0xF0F0F0F0:0xF0F0F0F0:0
1160 0x0F0F0F0F:0x0F0F0F0F:0
1161 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
1162 0xF0F0F0F0F0:0xF0F0F0F0F0:0
1163 0x0F0F0F0F0F:0x0F0F0F0F0F:0
1164 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
1165 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
1166 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
1167 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
1168 &bnot
1169 abc:NaN
1170 +0:-1
1171 +8:-9
1172 +281474976710656:-281474976710657
1173 -1:0
1174 -2:1
1175 -12:11
1176 &digit
1177 0:0:0
1178 12:0:2
1179 12:1:1
1180 123:0:3
1181 123:1:2
1182 123:2:1
1183 123:-1:1
1184 123:-2:2
1185 123:-3:3
1186 123456:0:6
1187 123456:1:5
1188 123456:2:4
1189 123456:3:3
1190 123456:4:2
1191 123456:5:1
1192 123456:-1:1
1193 123456:-2:2
1194 123456:-3:3
1195 100000:-3:0
1196 100000:0:0
1197 100000:1:0
1198 &mantissa
1199 abc:NaN
1200 1e4:1
1201 2e0:2
1202 123:123
1203 -1:-1
1204 -2:-2
1205 +inf:inf
1206 -inf:-inf
1207 &exponent
1208 abc:NaN
1209 1e4:4
1210 2e0:0
1211 123:0
1212 -1:0
1213 -2:0
1214 0:1
1215 +inf:inf
1216 -inf:inf
1217 &parts
1218 abc:NaN,NaN
1219 1e4:1,4
1220 2e0:2,0
1221 123:123,0
1222 -1:-1,0
1223 -2:-2,0
1224 0:0,1
1225 +inf:inf,inf
1226 -inf:-inf,inf
1227 &bfac
1228 -1:NaN
1229 NaNfac:NaN
1230 +inf:NaN
1231 -inf:NaN
1232 0:1
1233 1:1
1234 2:2
1235 3:6
1236 4:24
1237 5:120
1238 6:720
1239 10:3628800
1240 11:39916800
1241 12:479001600
1242 &bpow
1243 abc:12:NaN
1244 12:abc:NaN
1245 0:0:1
1246 0:1:0
1247 0:2:0
1248 0:-1:NaN
1249 0:-2:NaN
1250 1:0:1
1251 1:1:1
1252 1:2:1
1253 1:3:1
1254 1:-1:1
1255 1:-2:1
1256 1:-3:1
1257 2:0:1
1258 2:1:2
1259 2:2:4
1260 2:3:8
1261 3:3:27
1262 2:-1:NaN
1263 -2:-1:NaN
1264 2:-2:NaN
1265 -2:-2:NaN
1266 +inf:1234500012:inf
1267 -inf:1234500012:-inf
1268 +inf:-12345000123:inf
1269 -inf:-12345000123:-inf
1270 # 1 ** -x => 1 / (1 ** x)
1271 -1:0:1
1272 -2:0:1
1273 -1:1:-1
1274 -1:2:1
1275 -1:3:-1
1276 -1:4:1
1277 -1:5:-1
1278 -1:-1:-1
1279 -1:-2:1
1280 -1:-3:-1
1281 -1:-4:1
1282 10:2:100
1283 10:3:1000
1284 10:4:10000
1285 10:5:100000
1286 10:6:1000000
1287 10:7:10000000
1288 10:8:100000000
1289 10:9:1000000000
1290 10:20:100000000000000000000
1291 123456:2:15241383936
1292 &length
1293 100:3
1294 10:2
1295 1:1
1296 0:1
1297 12345:5
1298 10000000000000000:17
1299 -123:3
1300 215960156869840440586892398248:30
1301 &bsqrt
1302 145:12.04159457879229548012824103037860805243^
1303 144:12^
1304 143:11.95826074310139802112984075619561661399^
1305 16:4
1306 170:13.03840481040529742916594311485836883306^
1307 169:13
1308 168:12.96148139681572046193193487217599331541^
1309 4:2
1310 3:1.732050807568877293527446341505872366943^
1311 2:1.41421356237309504880168872420969807857^
1312 9:3
1313 12:3.464101615137754587054892683011744733886^
1314 256:16
1315 100000000:10000
1316 4000000000000:2000000
1317 152399026:12345.00004050222755607815159966235881398^
1318 152399025:12345
1319 152399024:12344.99995949777231103967404745303741942^
1320 1:1
1321 0:0
1322 -2:NaN
1323 -123:NaN
1324 Nan:NaN
1325 +inf:NaN
1326 &bround
1327 $round_mode('trunc')
1328 0:12:0
1329 NaNbround:12:NaN
1330 +inf:12:inf
1331 -inf:12:-inf
1332 1234:0:1234
1333 1234:2:1200
1334 123456:4:123400
1335 123456:5:123450
1336 123456:6:123456
1337 +10123456789:5:10123000000
1338 -10123456789:5:-10123000000
1339 +10123456789:9:10123456700
1340 -10123456789:9:-10123456700
1341 +101234500:6:101234000
1342 -101234500:6:-101234000
1343 #+101234500:-4:101234000
1344 #-101234500:-4:-101234000
1345 $round_mode('zero')
1346 +20123456789:5:20123000000
1347 -20123456789:5:-20123000000
1348 +20123456789:9:20123456800
1349 -20123456789:9:-20123456800
1350 +201234500:6:201234000
1351 -201234500:6:-201234000
1352 #+201234500:-4:201234000
1353 #-201234500:-4:-201234000
1354 +12345000:4:12340000
1355 -12345000:4:-12340000
1356 $round_mode('+inf')
1357 +30123456789:5:30123000000
1358 -30123456789:5:-30123000000
1359 +30123456789:9:30123456800
1360 -30123456789:9:-30123456800
1361 +301234500:6:301235000
1362 -301234500:6:-301234000
1363 #+301234500:-4:301235000
1364 #-301234500:-4:-301234000
1365 +12345000:4:12350000
1366 -12345000:4:-12340000
1367 $round_mode('-inf')
1368 +40123456789:5:40123000000
1369 -40123456789:5:-40123000000
1370 +40123456789:9:40123456800
1371 -40123456789:9:-40123456800
1372 +401234500:6:401234000
1373 +401234500:6:401234000
1374 #-401234500:-4:-401235000
1375 #-401234500:-4:-401235000
1376 +12345000:4:12340000
1377 -12345000:4:-12350000
1378 $round_mode('odd')
1379 +50123456789:5:50123000000
1380 -50123456789:5:-50123000000
1381 +50123456789:9:50123456800
1382 -50123456789:9:-50123456800
1383 +501234500:6:501235000
1384 -501234500:6:-501235000
1385 #+501234500:-4:501235000
1386 #-501234500:-4:-501235000
1387 +12345000:4:12350000
1388 -12345000:4:-12350000
1389 $round_mode('even')
1390 +60123456789:5:60123000000
1391 -60123456789:5:-60123000000
1392 +60123456789:9:60123456800
1393 -60123456789:9:-60123456800
1394 +601234500:6:601234000
1395 -601234500:6:-601234000
1396 #+601234500:-4:601234000
1397 #-601234500:-4:-601234000
1398 #-601234500:-9:0
1399 #-501234500:-9:0
1400 #-601234500:-8:0
1401 #-501234500:-8:0
1402 +1234567:7:1234567
1403 +1234567:6:1234570
1404 +12345000:4:12340000
1405 -12345000:4:-12340000
1406 &is_zero
1407 0:1
1408 NaNzero:0
1409 +inf:0
1410 -inf:0
1411 123:0
1412 -1:0
1413 1:0
1414 &is_one
1415 0:0
1416 NaNone:0
1417 +inf:0
1418 -inf:0
1419 1:1
1420 2:0
1421 -1:0
1422 -2:0
1423 # floor and ceil tests are pretty pointless in integer space...but play safe
1424 &bfloor
1425 0:0
1426 NaNfloor:NaN
1427 +inf:inf
1428 -inf:-inf
1429 -1:-1
1430 -2:-2
1431 2:2
1432 3:3
1433 abc:NaN
1434 &bceil
1435 NaNceil:NaN
1436 +inf:inf
1437 -inf:-inf
1438 0:0
1439 -1:-1
1440 -2:-2
1441 2:2
1442 3:3
1443 abc:NaN
1444 &as_hex
1445 128:0x80
1446 -128:-0x80
1447 0:0x0
1448 -0:0x0
1449 1:0x1
1450 0x123456789123456789:0x123456789123456789
1451 +inf:inf
1452 -inf:-inf
1453 NaNas_hex:NaN
1454 &as_bin
1455 128:0b10000000
1456 -128:-0b10000000
1457 0:0b0
1458 -0:0b0
1459 1:0b1
1460 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1461 +inf:inf
1462 -inf:-inf
1463 NaNas_bin:NaN