1#include this file into another for subclass testing
2
3use strict;
4use warnings;
5
6our ($CLASS, $LIB);
7
8##############################################################################
9# for testing inheritance of _swap
10
11package Math::Foo;
12
13use Math::BigInt lib => $main::LIB;
14our @ISA = qw/Math::BigInt/;
15
16use 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
22sub _swap {
23    # a fake _swap, which reverses the params
24    my $self = shift;           # for override in subclass
25    if ($_[2]) {
26        my $c = ref($_[0]) || 'Math::Foo';
27        return( $_[0]->copy(), $_[1] );
28    } else {
29        return( Math::Foo->new($_[1]), $_[0] );
30    }
31}
32
33##############################################################################
34package main;
35
36is($CLASS->config('lib'), $LIB, "$CLASS->config('lib')");
37
38my ($x, $y, $z, @args, $try, $got, $want);
39my ($f, $round_mode, $expected_class);
40
41while (<DATA>) {
42    s/#.*$//;                   # remove comments
43    s/\s+$//;                   # remove trailing whitespace
44    next unless length;         # skip empty lines
45
46    my ($m, $e);
47
48    if (s/^&//) {
49        $f = $_;
50        next;
51    }
52
53    if (/^\$/) {
54        $round_mode = $_;
55        $round_mode =~ s/^\$/$CLASS\->/;
56        next;
57    }
58
59    @args = split(/:/, $_, 99);
60    $want = pop(@args);
61    $expected_class = $CLASS;
62
63    if ($want =~ /(.*?)=(.*)/) {
64        $expected_class = $2;
65        $want = $1;
66    }
67
68    $try = qq|\$x = $CLASS->new("$args[0]");|;
69    if ($f eq "bnorm") {
70        $try = qq|\$x = $CLASS->bnorm("$args[0]");|;
71    } elsif ($f =~ /^is_(zero|one|odd|even|(non_)?(negative|positive)|nan|int)$/) {
72        $try .= " \$x->$f() || 0;";
73    } elsif ($f eq "is_inf") {
74        $try .= qq| \$x->is_inf("$args[1]");|;
75    } elsif ($f eq "binf") {
76        $try .= qq| \$x->binf("$args[1]");|;
77    } elsif ($f eq "bone") {
78        $try .= qq| \$x->bone("$args[1]");|;
79    # some unary ops
80    } elsif ($f =~ /^b(nan|floor|ceil|int|sstr|neg|abs|sgn|inc|dec|not|sqrt|exp|fac)$/) {
81        $try .= " \$x->$f();";
82    } elsif ($f =~ /^(numify|length|stringify)$/) {
83        $try .= " \$x->$f();";
84    } elsif ($f =~ /^(to|as)_(hex|oct|bin)$/) {
85        $try .= " \$x->$f();";
86    # overloaded functions
87    } elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) {
88        $try .= " \$x = $f(\$x);";
89    } elsif ($f eq "parts") {
90        $try .= ' ($m, $e) = $x->parts();';
91        # ->bstr() to see if an object is returned
92        $try .= ' $m = $m->bstr(); $m = "NaN" if !defined $m;';
93        $try .= ' $e = $e->bstr(); $e = "NaN" if !defined $e;';
94        $try .= ' "$m,$e";';
95    } elsif ($f eq "exponent") {
96        # ->bstr() to see if an object is returned
97        $try .= ' $x = $x->exponent()->bstr();';
98    } elsif ($f eq "mantissa") {
99        # ->bstr() to see if an object is returned
100        $try .= ' $x = $x->mantissa()->bstr();';
101    } elsif ($f eq "bpi") {
102        $try .= " $CLASS\->bpi(\$x);";
103    } else {
104        # binary operators
105        $try .= qq| \$y = $CLASS->new("$args[1]");|;
106        if ($f eq "bcmp") {
107            $try .= ' $x->bcmp($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->badd($y);';
114        } elsif ($f eq "bsub") {
115            $try .= ' $x->bsub($y);';
116        } elsif ($f eq "bmul") {
117            $try .= ' $x->bmul($y);';
118        } elsif ($f eq "bdiv") {
119            $try .= ' $x->bdiv($y);';
120        } elsif ($f eq "bdiv-list") {
121            $try .= ' join(",", $x->bdiv($y));';
122        } elsif ($f eq "btdiv") {
123            $try .= ' $x->btdiv($y);';
124        } elsif ($f eq "btdiv-list") {
125            $try .= ' join (",", $x->btdiv($y));';
126        # overload via x=
127        } elsif ($f =~ /^.=$/) {
128            $try .= " \$x $f \$y;";
129            # overload via x
130        } elsif ($f =~ /^.$/) {
131            $try .= " \$x $f \$y;";
132        } elsif ($f eq "bmod") {
133            $try .= ' $x % $y;';
134        } elsif ($f eq "bgcd") {
135            if (defined $args[2]) {
136                $try .= qq| \$z = $CLASS->new("$args[2]");|;
137            }
138            $try .= " $CLASS\::bgcd(\$x, \$y";
139            $try .= ", \$z" if defined $args[2];
140            $try .= ");";
141        } elsif ($f eq "blcm") {
142            if (defined $args[2]) {
143                $try .= qq| \$z = $CLASS->new("$args[2]");|;
144            }
145            $try .= " $CLASS\::blcm(\$x, \$y";
146            $try .= ", \$z" if defined $args[2];
147            $try .= ");";
148        } elsif ($f eq "blsft") {
149            if (defined $args[2]) {
150                $try .= " \$x->blsft(\$y, $args[2]);";
151            } else {
152                $try .= " \$x << \$y;";
153            }
154        } elsif ($f eq "brsft") {
155            if (defined $args[2]) {
156                $try .= " \$x->brsft(\$y, $args[2]);";
157            } else {
158                $try .= " \$x >> \$y;";
159            }
160        } elsif ($f eq "bnok") {
161            $try .= " \$x->bnok(\$y);";
162        } elsif ($f eq "broot") {
163            $try .= " \$x->broot(\$y);";
164        } elsif ($f eq "blog") {
165            $try .= " \$x->blog(\$y);";
166        } elsif ($f eq "band") {
167            $try .= " \$x & \$y;";
168        } elsif ($f eq "bior") {
169            $try .= " \$x | \$y;";
170        } elsif ($f eq "bxor") {
171            $try .= " \$x ^ \$y;";
172        } elsif ($f eq "bpow") {
173            $try .= " \$x ** \$y;";
174        } elsif ( $f eq "bmodinv") {
175            $try .= " \$x->bmodinv(\$y);";
176        } elsif ($f eq "digit") {
177            $try .= " \$x->digit(\$y);";
178        } elsif ($f eq "batan2") {
179            $try .= " \$x->batan2(\$y);";
180        } else {
181            # Functions with three arguments
182            $try .= qq| \$z = $CLASS->new("$args[2]");|;
183
184            if ( $f eq "bmodpow") {
185                $try .= " \$x->bmodpow(\$y, \$z);";
186            } elsif ($f eq "bmuladd") {
187                $try .= " \$x->bmuladd(\$y, \$z);";
188            } else {
189                warn "Unknown op '$f'";
190            }
191        }
192    }                           # end else all other ops
193
194    $got = eval $try;
195    print "# Error: $@\n" if $@;
196
197    # convert hex/binary targets to decimal
198    if ($want =~ /^(0x0x|0b0b)/) {
199        $want =~ s/^0[xb]//;
200        $want = Math::BigInt->new($want)->bstr();
201    }
202    if ($want eq "") {
203        is($got, undef, $try);
204    } else {
205        # print "try: $try ans: $got $want\n";
206        is($got, $want, $try);
207        is(ref($got), $expected_class,
208           qq|output is a "$expected_class" object|)
209          if $expected_class ne $CLASS;
210    }
211    # check internal state of number objects
212    is_valid($got, $f) if ref $got;
213}                               # end while data tests
214close DATA;
215
216# test whether self-multiplication works correctly (result is 2**64)
217$try = qq|\$x = $CLASS->new("4294967296");|;
218$try .= ' $a = $x->bmul($x);';
219$got = eval $try;
220is($got, $CLASS->new(2) ** 64, $try);
221
222# test self-pow
223$try = qq|\$x = $CLASS->new(10);|;
224$try .= ' $a = $x->bpow($x);';
225$got = eval $try;
226is($got, $CLASS->new(10) ** 10, $try);
227
228###############################################################################
229# test whether op destroys args or not (should better not)
230
231$x = $CLASS->new(3);
232$y = $CLASS->new(4);
233$z = $x & $y;
234is($x, 3, '$z = $x & $y; $x');
235is($y, 4, '$z = $x & $y; $y');
236is($z, 0, '$z = $x & $y; $z');
237
238$z = $x | $y;
239is($x, 3, '$z = $x | $y; $x');
240is($y, 4, '$z = $x | $y; $y');
241is($z, 7, '$z = $x | $y; $z');
242
243$x = $CLASS->new(1);
244$y = $CLASS->new(2);
245$z = $x | $y;
246is($x, 1, '$z = $x | $y; $x');
247is($y, 2, '$z = $x | $y; $y');
248is($z, 3, '$z = $x | $y; $z');
249
250$x = $CLASS->new(5);
251$y = $CLASS->new(4);
252$z = $x ^ $y;
253is($x, 5, '$z = $x ^ $y; $x');
254is($y, 4, '$z = $x ^ $y; $y');
255is($z, 1, '$z = $x ^ $y; $z');
256
257$x = $CLASS->new(-5);
258$y = -$x;
259is($x, -5, '$y = -$x; $x');
260
261$x = $CLASS->new(-5);
262$y = abs($x);
263is($x, -5, '$y = abs($x); $x');
264
265$x = $CLASS->new(8);
266$y = $CLASS->new(-1);
267$z = $CLASS->new(5033);
268my $u = $x->copy()->bmodpow($y, $z);
269is($u, 4404, '$x->copy()->bmodpow($y, $z); $u');
270is($y, -1,   '$x->copy()->bmodpow($y, $z); $y');
271is($z, 5033, '$x->copy()->bmodpow($y, $z); $z');
272
273$x = $CLASS->new(-5);
274$y = -$x;
275is($x, -5, '$y = -$x; $x');
276is($y, 5,  '$y = -$x; $y');
277
278$x = $CLASS->new(-5);
279$y = $x->copy()->bneg();
280is($x, -5, '$y = $x->copy()->bneg(); $x');
281is($y, 5,  '$y = $x->copy()->bneg(); $y');
282
283$x = $CLASS->new(-5);
284$y = $CLASS->new(3);
285$x->bmul($y);
286is($x, -15, '$x->bmul($y); $x');
287is($y, 3,   '$x->bmul($y); $y');
288
289$x = $CLASS->new(-5);
290$y = $CLASS->new(3);
291$x->badd($y);
292is($x, -2, '$x->badd($y); $x');
293is($y, 3,  '$x->badd($y); $y');
294
295$x = $CLASS->new(-5);
296$y = $CLASS->new(3);
297$x->bsub($y);
298is($x, -8, '$x->bsub($y); $x');
299is($y, 3,  '$x->bsub($y); $y');
300
301$x = $CLASS->new(-15);
302$y = $CLASS->new(3);
303$x->bdiv($y);
304is($x, -5, '$x->bdiv($y); $x');
305is($y, 3,  '$x->bdiv($y); $y');
306
307$x = $CLASS->new(-5);
308$y = $CLASS->new(3);
309$x->bmod($y);
310is($x, 1, '$x->bmod($y); $x');
311is($y, 3, '$x->bmod($y); $y');
312
313$x = $CLASS->new(5);
314$y = $CLASS->new(3);
315$x->bmul($y);
316is($x, 15, '$x->bmul($y); $x');
317is($y, 3,  '$x->bmul($y); $y');
318
319$x = $CLASS->new(5);
320$y = $CLASS->new(3);
321$x->badd($y);
322is($x, 8, '$x->badd($y); $x');
323is($y, 3, '$x->badd($y); $y');
324
325$x = $CLASS->new(5);
326$y = $CLASS->new(3);
327$x->bsub($y);
328is($x, 2, '$x->bsub($y); $x');
329is($y, 3, '$x->bsub($y); $y');
330
331$x = $CLASS->new(15);
332$y = $CLASS->new(3);
333$x->bdiv($y);
334is($x, 5, '$x->bdiv($y); $x');
335is($y, 3, '$x->bdiv($y); $y');
336
337$x = $CLASS->new(5);
338$y = $CLASS->new(3);
339$x->bmod($y);
340is($x, 2, '$x->bmod($y); $x');
341is($y, 3, '$x->bmod($y); $y');
342
343$x = $CLASS->new(5);
344$y = $CLASS->new(-3);
345$x->bmul($y);
346is($x, -15, '$x->bmul($y); $x');
347is($y, -3,  '$x->bmul($y); $y');
348
349$x = $CLASS->new(5);
350$y = $CLASS->new(-3);
351$x->badd($y);
352is($x, 2,  '$x->badd($y); $x');
353is($y, -3, '$x->badd($y); $y');
354
355$x = $CLASS->new(5);
356$y = $CLASS->new(-3);
357$x->bsub($y);
358is($x, 8,  '$x->bsub($y); $x');
359is($y, -3, '$x->bsub($y); $y');
360
361$x = $CLASS->new(15);
362$y = $CLASS->new(-3);
363$x->bdiv($y);
364is($x, -5, '$x->bdiv($y); $x');
365is($y, -3, '$x->bdiv($y); $y');
366
367$x = $CLASS->new(5);
368$y = $CLASS->new(-3);
369$x->bmod($y);
370is($x, -1, '$x->bmod($y); $x');
371is($y, -3, '$x->bmod($y); $y');
372
373###############################################################################
374# check whether overloading cmp works
375$try = '$x = $CLASS->new(0);';
376$try .= ' $y = 10;';
377$try .= ' $x ne $y;';
378$want = eval $try;
379ok($want, "overloading cmp works");
380
381# We can't test for working cmpt with other objects here, we would need a dummy
382# object with stringify overload for this. See Math::String tests as example.
383
384###############################################################################
385# check reversed order of arguments
386
387$try = "\$x = $CLASS->new(10); \$x = 2 ** \$x; \$x == 1024;";
388$want = eval $try;
389ok($want, $try);
390
391$try = "\$x = $CLASS->new(10); \$x = 2 * \$x; \$x == 20;";
392$want = eval $try;
393ok($want, $try);
394
395$try = "\$x = $CLASS->new(10); \$x = 2 + \$x; \$x == 12;";
396$want = eval $try;
397ok($want, $try);
398
399$try = "\$x = $CLASS\->new(10); \$x = 2 - \$x; \$x == -8;";
400$want = eval $try;
401ok($want, $try);
402
403$try = "\$x = $CLASS\->new(10); \$x = 20 / \$x; \$x == 2;";
404$want = eval $try;
405ok($want, $try);
406
407$try = "\$x = $CLASS\->new(3); \$x = 20 % \$x; \$x == 2;";
408$want = eval $try;
409ok($want, $try);
410
411$try = "\$x = $CLASS\->new(7); \$x = 20 & \$x; \$x == 4;";
412$want = eval $try;
413ok($want, $try);
414
415$try = "\$x = $CLASS\->new(7); \$x = 0x20 | \$x; \$x == 0x27;";
416$want = eval $try;
417ok($want, $try);
418
419$try = "\$x = $CLASS\->new(7); \$x = 0x20 ^ \$x; \$x == 0x27;";
420$want = eval $try;
421ok($want, $try);
422
423###############################################################################
424# check badd(4, 5) form
425
426$try = "\$x = $CLASS\->badd(4, 5); \$x == 9;";
427$want = eval $try;
428ok($want, $try);
429
430###############################################################################
431# check undefs: NOT DONE YET
432
433###############################################################################
434# bool
435
436$x = $CLASS->new(1);
437if ($x) {
438    pass("\$x = $CLASS->new(1); \$x is true");
439} else {
440    fail("\$x = $CLASS->new(1); \$x is true");
441}
442
443$x = $CLASS->new(0);
444if (!$x) {
445    pass("\$x = $CLASS->new(0); !\$x is false");
446} else {
447    fail("\$x = $CLASS->new(0); !\$x is false");
448}
449
450###############################################################################
451# objectify()
452
453@args = Math::BigInt::objectify(2, 4, 5);
454is(scalar(@args), 3,                 "objectify(2, 4, 5) gives $CLASS, 4, 5");
455like($args[0],    qr/^Math::BigInt/, "first arg matches /^Math::BigInt/");
456is($args[1],      4,                 "second arg is 4");
457is($args[2],      5,                 "third arg is 5");
458
459@args = Math::BigInt::objectify(0, 4, 5);
460is(scalar(@args), 3,                 "objectify(0, 4, 5) gives $CLASS, 4, 5");
461like($args[0],    qr/^Math::BigInt/, "first arg matches /^Math::BigInt/");
462is($args[1],      4,                 "second arg is 4");
463is($args[2],      5,                 "third arg is 5");
464
465@args = Math::BigInt::objectify(2, 4, 5);
466is(scalar(@args), 3,                 "objectify(2, 4, 5) gives $CLASS, 4, 5");
467like($args[0],    qr/^Math::BigInt/, "first arg matches /^Math::BigInt/");
468is($args[1],      4,                 "second arg is 4");
469is($args[2],      5,                 "third arg is 5");
470
471@args = Math::BigInt::objectify(2, 4, 5, 6, 7);
472is(scalar(@args), 5,
473   "objectify(2, 4, 5, 6, 7) gives $CLASS, 4, 5, 6, 7");
474like($args[0],    qr/^Math::BigInt/, "first arg matches /^Math::BigInt/");
475is($args[1],      4,                 "second arg is 4");
476is(ref($args[1]), $args[0],          "second arg is a $args[0] object");
477is($args[2],      5,                 "third arg is 5");
478is(ref($args[2]), $args[0],          "third arg is a $args[0] object");
479is($args[3],      6,                 "fourth arg is 6");
480is(ref($args[3]), '',                "fourth arg is a scalar");
481is($args[4],      7,                 "fifth arg is 7");
482is(ref($args[4]), '',                "fifth arg is a scalar");
483
484@args = Math::BigInt::objectify(2, $CLASS, 4, 5, 6, 7);
485is(scalar(@args), 5,
486   "objectify(2, $CLASS, 4, 5, 6, 7) gives $CLASS, 4, 5, 6, 7");
487is($args[0],      $CLASS,            "first arg is $CLASS");
488is($args[1],      4,                 "second arg is 4");
489is(ref($args[1]), $args[0],          "second arg is a $args[0] object");
490is($args[2],      5,                 "third arg is 5");
491is(ref($args[2]), $args[0],          "third arg is a $args[0] object");
492is($args[3],      6,                 "fourth arg is 6");
493is(ref($args[3]), '',                "fourth arg is a scalar");
494is($args[4],      7,                 "fifth arg is 7");
495is(ref($args[4]), '',                "fifth arg is a scalar");
496
497###############################################################################
498# test whether an opp calls objectify properly or not (or at least does what
499# it should do given non-objects, w/ or w/o objectify())
500
501is($CLASS->new(123)->badd(123), 246,
502   qq|$CLASS->new(123)->badd(123) = 246|);;
503is($CLASS->badd(123, 321), 444,
504   qq|$CLASS->badd(123, 321) = 444|);;
505is($CLASS->badd(123, $CLASS->new(321)), 444,
506   qq|$CLASS->badd(123, $CLASS->new(321)) = 444|);;
507
508is($CLASS->new(123)->bsub(122), 1,
509   qq|$CLASS->new(123)->bsub(122) = 1|);;
510is($CLASS->bsub(321, 123), 198,
511   qq|$CLASS->bsub(321, 123) = 198|);;
512is($CLASS->bsub(321, $CLASS->new(123)), 198,
513   qq|$CLASS->bsub(321, $CLASS->new(123)) = 198|);;
514
515is($CLASS->new(123)->bmul(123), 15129,
516   qq|$CLASS->new(123)->bmul(123) = 15129|);;
517is($CLASS->bmul(123, 123), 15129,
518   qq|$CLASS->bmul(123, 123) = 15129|);;
519is($CLASS->bmul(123, $CLASS->new(123)), 15129,
520   qq|$CLASS->bmul(123, $CLASS->new(123)) = 15129|);;
521
522is($CLASS->new(15129)->bdiv(123), 123,
523   qq|$CLASS->new(15129)->bdiv(123) = 123|);;
524is($CLASS->bdiv(15129, 123), 123,
525   qq|$CLASS->bdiv(15129, 123) = 123|);;
526is($CLASS->bdiv(15129, $CLASS->new(123)), 123,
527   qq|$CLASS->bdiv(15129, $CLASS->new(123)) = 123|);;
528
529is($CLASS->new(15131)->bmod(123), 2,
530   qq|$CLASS->new(15131)->bmod(123) = 2|);;
531is($CLASS->bmod(15131, 123), 2,
532   qq|$CLASS->bmod(15131, 123) = 2|);;
533is($CLASS->bmod(15131, $CLASS->new(123)), 2,
534   qq|$CLASS->bmod(15131, $CLASS->new(123)) = 2|);;
535
536is($CLASS->new(2)->bpow(16), 65536,
537   qq|$CLASS->new(2)->bpow(16) = 65536|);;
538is($CLASS->bpow(2, 16), 65536,
539   qq|$CLASS->bpow(2, 16) = 65536|);;
540is($CLASS->bpow(2, $CLASS->new(16)), 65536,
541   qq|$CLASS->bpow(2, $CLASS->new(16)) = 65536|);;
542
543is($CLASS->new(2**15)->brsft(1), 2**14,
544   qq|$CLASS->new(2**15)->brsft(1) = 2**14|);;
545is($CLASS->brsft(2**15, 1), 2**14,
546   qq|$CLASS->brsft(2**15, 1) = 2**14|);;
547is($CLASS->brsft(2**15, $CLASS->new(1)), 2**14,
548   qq|$CLASS->brsft(2**15, $CLASS->new(1)) = 2**14|);;
549
550is($CLASS->new(2**13)->blsft(1), 2**14,
551   qq|$CLASS->new(2**13)->blsft(1) = 2**14|);;
552is($CLASS->blsft(2**13, 1), 2**14,
553   qq|$CLASS->blsft(2**13, 1) = 2**14|);;
554is($CLASS->blsft(2**13, $CLASS->new(1)), 2**14,
555   qq|$CLASS->blsft(2**13, $CLASS->new(1)) = 2**14|);;
556
557###############################################################################
558# test for floating-point input (other tests in bnorm() below)
559
560$z = 1050000000000000;          # may be int on systems with 64bit?
561$x = $CLASS->new($z);
562is($x->bsstr(), '105e+13',      # not 1.05e+15
563   qq|\$x = $CLASS->new($z); \$x->bsstr() = "105e+13"|);
564$z = 1e+129;                    # definitely a float (may fail on UTS)
565# don't compare to $z, since some Perl versions stringify $z into something
566# like '1.e+129' or something equally ugly
567SKIP:{
568    my $vax_float = (pack("d", 1) =~ /^[\x80\x10]\x40/);
569    skip("vax float range smaller", 1) if $vax_float;
570    $x = $CLASS->new($z);
571    is($x -> bsstr(), '1e+129',
572       qq|\$x = $CLASS->new($z); \$x->bsstr() = "1e+129"|);
573}
574
575###############################################################################
576# test for whitespace including newlines to be handled correctly
577
578# is($Math::BigInt::strict, 1);         # the default
579
580foreach my $c (qw/1 12 123 1234 12345 123456 1234567
581                  12345678 123456789 1234567890/)
582{
583    my $m = $CLASS->new($c);
584    is($CLASS->new("$c"),        $m,    qq|$CLASS->new("$c") = $m|);
585    is($CLASS->new(" $c"),       $m,    qq|$CLASS->new(" $c") = $m|);
586    is($CLASS->new("$c "),       $m,    qq|$CLASS->new("$c ") = $m|);
587    is($CLASS->new(" $c "),      $m,    qq|$CLASS->new(" $c ") = $m|);
588    is($CLASS->new("\n$c"),      $m,    qq|$CLASS->new("\\n$c") = $m|);
589    is($CLASS->new("$c\n"),      $m,    qq|$CLASS->new("$c\\n") = $m|);
590    is($CLASS->new("\n$c\n"),    $m,    qq|$CLASS->new("\\n$c\\n") = $m|);
591    is($CLASS->new(" \n$c\n"),   $m,    qq|$CLASS->new(" \\n$c\\n") = $m|);
592    is($CLASS->new(" \n$c \n"),  $m,    qq|$CLASS->new(" \\n$c \\n") = $m|);
593    is($CLASS->new(" \n$c\n "),  $m,    qq|$CLASS->new(" \\n$c\\n ") = $m|);
594    is($CLASS->new(" \n$c\n1"),  'NaN', qq|$CLASS->new(" \\n$c\\n1") = 'NaN'|);
595    is($CLASS->new("1 \n$c\n1"), 'NaN', qq|$CLASS->new("1 \\n$c\\n1") = 'NaN'|);
596}
597
598###############################################################################
599# prime number tests, also test for **= and length()
600# found on: http://www.utm.edu/research/primes/notes/by_year.html
601
602# ((2^148)+1)/17
603$x = $CLASS->new(2);
604$x **= 148;
605$x++;
606$x = $x / 17;
607is($x, "20988936657440586486151264256610222593863921",
608   "value of ((2^148)+1)/17");
609is($x->length(), length("20988936657440586486151264256610222593863921"),
610   "number of digits in ((2^148)+1)/17");
611
612# MM7 = 2^127-1
613$x = $CLASS->new(2);
614$x **= 127;
615$x--;
616is($x, "170141183460469231731687303715884105727", "value of 2^127-1");
617
618$x = $CLASS->new('215960156869840440586892398248');
619($x, $y) = $x->length();
620is($x, 30, "number of digits in 2^127-1");
621is($y, 0, "number of digits in fraction part of 2^127-1");
622
623$x = $CLASS->new('1_000_000_000_000');
624($x, $y) = $x->length();
625is($x, 13, "number of digits in 1_000_000_000_000");
626is($y, 0, "number of digits in fraction part of 1_000_000_000_000");
627
628# test <<=, >>=
629$x = $CLASS->new('2');
630$y = $CLASS->new('18');
631is($x <<= $y, 2 << 18, "2 <<= 18 with $CLASS objects");
632is($x,        2 << 18, "2 <<= 18 with $CLASS objects");
633is($x >>= $y, 2,       "2 >>= 18 with $CLASS objects");
634is($x,        2,       "2 >>= 18 with $CLASS objects");
635
636# I am afraid the following is not yet possible due to slowness
637# Also, testing for 2 meg output is a bit hard ;)
638#$x = $CLASS->new(2);
639#$x **= 6972593;
640#$x--;
641
642# 593573509*2^332162+1 has exactly 1,000,000 digits
643# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
644#$x = $CLASS->new(2);
645#$x **= 332162;
646#$x *= "593573509";
647#$x++;
648#is($x->length(), 1_000_000);
649
650###############################################################################
651# inheritance and overriding of _swap
652
653$x = Math::Foo->new(5);
654$x = $x - 8;            # 8 - 5 instead of 5-8
655is($x, 3, '$x = Math::Foo->new(5); $x = $x - 8; $x = 3');
656is(ref($x), 'Math::Foo', '$x is an object of class "Math::Foo"');
657
658$x = Math::Foo->new(5);
659$x = 8 - $x;            # 5 - 8 instead of 8 - 5
660is($x, -3, '$x = Math::Foo->new(5); $x = 8 - $x; $x = -3');
661is(ref($x), 'Math::Foo', '$x is an object of class "Math::Foo"');
662
663###############################################################################
664# Test whether +inf eq inf
665#
666# This tried to test whether Math::BigInt inf equals Perl inf. Unfortunately,
667# Perl hasn't (before 5.7.3 at least) a consistent way to say inf, and some
668# things like 1e100000 crash on some platforms. So simple test for the string
669# 'inf'.
670
671$x = $CLASS->new('+inf');
672is($x, 'inf', qq|$CLASS->new("+inf") = "inf"|);
673
674###############################################################################
675# numify() and 64 bit integer support
676
677require Config;
678SKIP: {
679    skip("no 64 bit integer support", 4)
680      if ! $Config::Config{use64bitint} || ! $Config::Config{use64bitall}
681          || "$]" < 5.007001;
682
683    # The following should not give "1.84467440737096e+19".
684
685    $x = $CLASS -> new(2) -> bpow(64) -> bdec();
686    is($x -> bstr(),   "18446744073709551615", "bigint 2**64-1 as string");
687    is($x -> numify(), "18446744073709551615", "bigint 2**64-1 as number");
688
689    # The following should not give "-9.22337203685478e+18".
690
691    $x = $CLASS -> new(2) -> bpow(63) -> bneg();
692    is($x -> bstr(),   "-9223372036854775808", "bigint -2**63 as string");
693    is($x -> numify(), "-9223372036854775808", "bigint -2**63 as number");
694};
695
696###############################################################################
697###############################################################################
698# the following tests only make sense with Math::BigInt::Calc or BareCalc or
699# FastCalc
700
701SKIP: {
702    # skip GMP, Pari et al.
703    skip("skipping tests not intended for the backend $LIB", 50)
704      unless $LIB =~ /^Math::BigInt::(Bare|Fast)?Calc$/;
705
706    ###########################################################################
707    # check proper length of internal arrays
708
709    my $bl = $LIB->_base_len();
710    my $BASE = '9' x $bl;
711    my $MAX = $BASE;
712    $BASE++;
713
714    # f.i. 9999
715    $x = $CLASS->new($MAX);
716    is_valid($x);
717
718    # 10000
719    $x += 1;
720    is($x, $BASE, "\$x == $BASE");
721    is_valid($x);
722
723    # 9999 again
724    $x -= 1;
725    is($x, $MAX, "\$x == $MAX");
726    is_valid($x);
727
728    ###########################################################################
729    # check numify
730
731    $x = $CLASS->new($BASE-1);
732    is($x->numify(), $BASE-1, q|$x->numify() = $BASE-1|);
733
734    $x = $CLASS->new(-($BASE-1));
735    is($x->numify(), -($BASE-1), q|$x->numify() = -($BASE-1)|);
736
737    # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaarglburbll...)
738    $x = $CLASS->new($BASE);
739    is($x->numify()+0, $BASE+0, q|$x->numify()+0 = $BASE+0|);
740
741    $x = $CLASS->new(-$BASE);
742    is($x->numify(), -$BASE, q|$x->numify() = -$BASE|);
743
744    $x = $CLASS->new(-($BASE*$BASE*1+$BASE*1+1));
745    is($x->numify(), -($BASE*$BASE*1+$BASE*1+1),
746       q|$x->numify() = -($BASE*$BASE*1+$BASE*1+1))|);
747
748    ###########################################################################
749    # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead
750    # of 1
751
752    $x = $CLASS->new($BASE - 2);
753    $x++;
754    $x++;
755    $x++;
756    $x++;
757    ok($x > $BASE, '$x > $BASE');
758
759    $x = $CLASS->new($BASE + 3);
760    $x++;
761    ok($x > $BASE, '$x > $BASE');
762
763    # test for +0 instead of int():
764    $x = $CLASS->new($MAX);
765    is($x->length(), length($MAX), q|$x->length() = length($MAX)|);
766
767    ###########################################################################
768    # test bug that $CLASS->digit($string) did not work
769
770    is($CLASS->digit(123, 2), 1, qq|$CLASS->digit(123, 2) = 1|);
771
772    ###########################################################################
773    # bug in sub where number with at least 6 trailing zeros after any op failed
774
775    $x = $CLASS->new(123456);
776    $z = $CLASS->new(10000);
777    $z *= 10;
778    $x -= $z;
779    is($z, 100000, "testing bug in sub");
780    is($x, 23456, "testing bug in sub");
781
782    ###########################################################################
783    # bug in shortcut in mul()
784
785    # construct a number with a zero-hole of BASE_LEN_SMALL
786    {
787        my @bl = $LIB->_base_len();
788        my $bl = $bl[5];
789
790        # Compute the value.
791        $x = ('1' x $bl) . ('0' x $bl) . ('1' x $bl) . ('0' x $bl);
792        $y = '1' x (2 * $bl);
793        $x = $CLASS->new($x)->bmul($y);
794
795        # Build the expected output.
796        $y = '';
797        if ($bl >= 2) {
798            $y .= '123456790' x int(($bl - 2) / 9);
799            $y .= substr '123456790', 0, ($bl - 2) % 9;
800            $y .= ($bl - 1) % 9;
801        }
802        $y .= ((($bl - 1) % 9) + 1) x ($bl * 3);
803        if ($bl >= 2) {
804            $y .= substr '098765432', -(($bl - 1) % 9);
805            $y .= '098765432' x int(($bl - 2) / 9);
806        }
807        $y .= '1';
808        $y .= '0' x $bl;
809
810        is($x, $y, "testing number with a zero-hole of BASE_LEN_SMALL");
811
812        #########################################################################
813        # see if mul shortcut for small numbers works
814
815        $x = '9' x $bl;
816        $x = $CLASS->new($x);
817        # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
818        is($x * $x, '9' x ($bl - 1) . '8' . '0' x ($bl - 1) . '1',
819           "see if mul shortcut for small numbers works");
820    }
821
822    ###########################################################################
823    # bug with rest "-0" in div, causing further div()s to fail
824
825    $x = $CLASS->new('-322056000');
826    ($x, $y) = $x->bdiv('-12882240');
827
828    is($y, '0', '-322056000 / -12882240 has remainder 0');
829    is_valid($y);               # $y not '-0'
830
831    ###########################################################################
832    # bug in $x->bmod($y)
833
834    # if $x < 0 and $y > 0
835    $x = $CLASS->new('-629');
836    is($x->bmod(5033), 4404, q|$x->bmod(5033) = 4404|);
837
838    ###########################################################################
839    # bone/binf etc as plain calls (Lite failed them)
840
841    is($CLASS->bzero(),      0,      qq|$CLASS->bzero() = 0|);
842    is($CLASS->bone(),       1,      qq|$CLASS->bone() = 1|);
843    is($CLASS->bone("+"),    1,      qq|$CLASS->bone("+") = 1|);
844    is($CLASS->bone("-"),    -1,     qq|$CLASS->bone("-") = -1|);
845    is($CLASS->bnan(),       "NaN",  qq|$CLASS->bnan() = "NaN"|);
846    is($CLASS->binf(),       "inf",  qq|$CLASS->binf() = "inf"|);
847    is($CLASS->binf("+"),    "inf",  qq|$CLASS->binf("+") = "inf"|);
848    is($CLASS->binf("-"),    "-inf", qq|$CLASS->binf("-") = "-inf"|);
849    is($CLASS->binf("-inf"), "-inf", qq|$CLASS->binf("-inf") = "-inf"|);
850
851    ###########################################################################
852    # is_one("-")
853
854    is($CLASS->new(1)->is_one("-"),  0, qq|$CLASS->new(1)->is_one("-") = 0|);
855    is($CLASS->new(-1)->is_one("-"), 1, qq|$CLASS->new(-1)->is_one("-") = 1|);
856    is($CLASS->new(1)->is_one(),     1, qq|$CLASS->new(1)->is_one() = 1|);
857    is($CLASS->new(-1)->is_one(),    0, qq|$CLASS->new(-1)->is_one() = 0|);
858
859    ###########################################################################
860    # [perl #30609] bug with $x -= $x not being 0, but 2*$x
861
862    $x = $CLASS->new(3);
863    $x -= $x;
864    is($x, 0, qq|\$x = $CLASS->new(3); \$x -= \$x; = 0|);
865
866    $x = $CLASS->new(-3);
867    $x -= $x;
868    is($x, 0, qq|\$x = $CLASS->new(-3); \$x -= \$x; = 0|);
869
870    $x = $CLASS->new("NaN");
871    $x -= $x;
872    is($x->is_nan(), 1,
873       qq|\$x = $CLASS->new("NaN"); \$x -= \$x; \$x->is_nan() = 1|);
874
875    $x = $CLASS->new("inf");
876    $x -= $x;
877    is($x->is_nan(), 1,
878       qq|\$x = $CLASS->new("inf"); \$x -= \$x; \$x->is_nan() = 1|);
879
880    $x = $CLASS->new("-inf");
881    $x -= $x;
882    is($x->is_nan(), 1,
883       qq|\$x = $CLASS->new("-inf"); \$x -= \$x; \$x->is_nan() = 1|);
884
885    $x = $CLASS->new("NaN");
886    $x += $x;
887    is($x->is_nan(), 1,
888       qq|\$x = $CLASS->new("NaN"); \$x += \$x; \$x->is_nan() = 1|);
889
890    $x = $CLASS->new("inf");
891    $x += $x;
892    is($x->is_inf(), 1,
893       qq|\$x = $CLASS->new("inf"); \$x += \$x; \$x->is_inf() = 1|);
894
895    $x = $CLASS->new("-inf");
896    $x += $x;
897    is($x->is_inf("-"), 1,
898       qq|\$x = $CLASS->new("-inf"); \$x += \$x; \$x->is_inf("-") = 1|);
899
900    $x = $CLASS->new(3);
901    $x += $x;
902    is($x, 6, qq|\$x = $CLASS->new(3); \$x += \$x; \$x = 6|);
903
904    $x = $CLASS->new(-3);
905    $x += $x;
906    is($x, -6, qq|\$x = $CLASS->new(-3); \$x += \$x; \$x = -6|);
907
908    $x = $CLASS->new(3);
909    $x *= $x;
910    is($x, 9, qq|\$x = $CLASS->new(3); \$x *= \$x; \$x = 9|);
911
912    $x = $CLASS->new(-3);
913    $x *= $x;
914    is($x, 9, qq|\$x = $CLASS->new(-3); \$x *= \$x; \$x = 9|);
915
916    $x = $CLASS->new(3);
917    $x /= $x;
918    is($x, 1, qq|\$x = $CLASS->new(3); \$x /= \$x; \$x = 1|);
919
920    $x = $CLASS->new(-3);
921    $x /= $x;
922    is($x, 1, qq|\$x = $CLASS->new(-3); \$x /= \$x; \$x = 1|);
923
924    $x = $CLASS->new(3);
925    $x %= $x;
926    is($x, 0, qq|\$x = $CLASS->new(3); \$x %= \$x; \$x = 0|);
927
928    $x = $CLASS->new(-3);
929    $x %= $x;
930    is($x, 0, qq|\$x = $CLASS->new(-3); \$x %= \$x; \$x = 0|);
931}
932
933###############################################################################
934# all tests done
935
9361;
937
938###############################################################################
939# sub to check validity of a Math::BigInt internally, to ensure that no op
940# leaves a number object in an invalid state (f.i. "-0")
941
942sub is_valid {
943    my ($x, $f) = @_;
944
945    my $e = 0;                  # error?
946
947    # allow the check to pass for all Lite, and all MBI and subclasses
948    # ok as reference?
949    $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
950
951    if (ref($x) ne 'Math::BigInt::Lite') {
952        # has ok sign?
953        $e = qq|Illegal sign $x->{sign}|
954          . qq| (expected: "+", "-", "-inf", "+inf" or "NaN"|
955            if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
956
957        $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
958        $e = $LIB->_check($x->{value}) if $e eq '0';
959    }
960
961    # test done, see if error did crop up
962    if ($e eq '0') {
963        pass('is a valid object');
964        return;
965    }
966
967    fail($e . " after op '$f'");
968}
969
970__DATA__
971
972&.=
9731234:-345:1234-345
974
975&+=
9761:2:3
977-1:-2:-3
978
979&-=
9801:2:-1
981-1:-2:1
982
983&*=
9842:3:6
985-1:5:-5
986
987&%=
988100:3:1
9898:9:8
990-629:5033:4404
991
992&/=
993100:3:33
994-8:2:-4
995
996&|=
9972:1:3
998
999&&=
10005:7:5
1001
1002&^=
10035:7:2
1004
1005&blog
1006#
1007invalid:2:NaN
1008122:invalid:NaN
1009invalid:invalid:NaN
1010#
1011122:inf:0
1012inf:122:inf
1013122:-inf:0
1014-inf:122:inf
1015-inf:-inf:NaN
10160:4:-inf
1017-21:4:NaN
101821:-21:NaN
1019#
10200:-inf:NaN
10210:-1:NaN
10220:0:NaN
10230:1:NaN
10240:inf:NaN
1025#
10261:-inf:0
10271:-1:0
10281:0:0
10291:1:NaN
10301:4:0
10311:inf:0
1032#
1033inf:-inf:NaN
1034inf:-1:NaN
1035inf:0:NaN
1036inf:1:NaN
1037inf:4:inf
1038inf:inf:NaN
1039#
1040# normal results
10411024:2:10
104281:3:4
1043# 3.01.. truncate
104482:3:4
1045# 3.9... truncate
104680:3:3
10474096:2:12
104815625:5:6
104915626:5:6
105015624:5:5
10511000:10:3
105210000:10:4
1053100000:10:5
10541000000:10:6
105510000000:10:7
1056100000000:10:8
10578916100448256:12:12
10588916100448257:12:12
10598916100448255:12:11
10602251799813685248:8:17
106172057594037927936:2:56
1062144115188075855872:2:57
1063288230376151711744:2:58
1064576460752303423488:2:59
10651329227995784915872903807060280344576:2:120
1066# $x == $base => result 1
10673:3:1
1068# $x < $base => result 0 ($base ** 0 <= $x)
10693:4:0
1070# $x == 1 => result 0
10711:5:0
1072
1073&is_negative
10740:0
1075-1:1
10761:0
1077+inf:0
1078-inf:1
1079invalid:0
1080
1081&is_positive
10820:0
1083-1:0
10841:1
1085+inf:1
1086-inf:0
1087invalid:0
1088
1089&is_non_negative
10900:1
1091-1:0
10921:1
1093+inf:1
1094-inf:0
1095NaN:0
1096
1097&is_non_positive
10980:1
1099-1:1
11001:0
1101+inf:0
1102-inf:1
1103NaN:0
1104
1105&is_int
1106-inf:0
1107+inf:0
1108invalid:0
11091:1
11100:1
1111123e12:1
1112
1113&is_odd
1114abc:0
11150:0
11161:1
11173:1
1118-1:1
1119-3:1
112010000001:1
112110000002:0
11222:0
1123120:0
1124121:1
1125
1126&is_even
1127abc:0
11280:1
11291:0
11303:0
1131-1:0
1132-3:0
113310000001:0
113410000002:1
11352:1
1136120:1
1137121:0
1138
1139&bacmp
1140+0:-0:0
1141+0:+1:-1
1142-1:+1:0
1143+1:-1:0
1144-1:+2:-1
1145+2:-1:1
1146-123456789:+987654321:-1
1147+123456789:-987654321:-1
1148+987654321:+123456789:1
1149-987654321:+123456789:1
1150-123:+4567889:-1
1151# NaNs
1152invalid:123:
1153123:invalid:
1154invalid:invalid:
1155# infinity
1156+inf:+inf:0
1157-inf:-inf:0
1158+inf:-inf:0
1159-inf:+inf:0
1160+inf:123:1
1161-inf:123:1
1162+inf:-123:1
1163-inf:-123:1
1164123:-inf:-1
1165-123:inf:-1
1166-123:-inf:-1
1167123:inf:-1
1168# return undef
1169+inf:NaN:
1170NaN:inf:
1171-inf:NaN:
1172NaN:-inf:
1173
1174&bnorm
11750e999:0
11760e-999:0
1177-0e999:0
1178-0e-999:0
1179123:123
1180123.000:123
1181123e0:123
1182123e+0:123
1183123e-0:123
1184123.000e0:123
1185123.000e+0:123
1186123.000e-0:123
1187# binary input
11880babc:NaN
11890b123:NaN
11900b0:0
1191-0b0:0
1192-0b1:-1
11930b0001:1
11940b001:1
11950b011:3
11960b101:5
11970b1001:9
11980b10001:17
11990b100001:33
12000b1000001:65
12010b10000001:129
12020b100000001:257
12030b1000000001:513
12040b10000000001:1025
12050b100000000001:2049
12060b1000000000001:4097
12070b10000000000001:8193
12080b100000000000001:16385
12090b1000000000000001:32769
12100b10000000000000001:65537
12110b100000000000000001:131073
12120b1000000000000000001:262145
12130b10000000000000000001:524289
12140b100000000000000000001:1048577
12150b1000000000000000000001:2097153
12160b10000000000000000000001:4194305
12170b100000000000000000000001:8388609
12180b1000000000000000000000001:16777217
12190b10000000000000000000000001:33554433
12200b100000000000000000000000001:67108865
12210b1000000000000000000000000001:134217729
12220b10000000000000000000000000001:268435457
12230b100000000000000000000000000001:536870913
12240b1000000000000000000000000000001:1073741825
12250b10000000000000000000000000000001:2147483649
12260b100000000000000000000000000000001:4294967297
12270b1000000000000000000000000000000001:8589934593
12280b10000000000000000000000000000000001:17179869185
12290b__101:NaN
12300b1_0_1:5
12310b0_0_0_1:1
1232# hex input
1233-0x0:0
12340xabcdefgh:NaN
12350x1234:4660
12360xabcdef:11259375
1237-0xABCDEF:-11259375
1238-0x1234:-4660
12390x12345678:305419896
12400x1_2_3_4_56_78:305419896
12410xa_b_c_d_e_f:11259375
12420x__123:NaN
12430x9:9
12440x11:17
12450x21:33
12460x41:65
12470x81:129
12480x101:257
12490x201:513
12500x401:1025
12510x801:2049
12520x1001:4097
12530x2001:8193
12540x4001:16385
12550x8001:32769
12560x10001:65537
12570x20001:131073
12580x40001:262145
12590x80001:524289
12600x100001:1048577
12610x200001:2097153
12620x400001:4194305
12630x800001:8388609
12640x1000001:16777217
12650x2000001:33554433
12660x4000001:67108865
12670x8000001:134217729
12680x10000001:268435457
12690x20000001:536870913
12700x40000001:1073741825
12710x80000001:2147483649
12720x100000001:4294967297
12730x200000001:8589934593
12740x400000001:17179869185
12750x800000001:34359738369
1276# bug found by Mark Lakata in Calc.pm creating too big one-element numbers
1277# in _from_hex()
12780x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691
1279# inf input
1280inf:inf
1281+inf:inf
1282-inf:-inf
12830inf:NaN
1284# abnormal input
1285:NaN
1286abc:NaN
1287   1 a:NaN
12881bcd2:NaN
128911111b:NaN
1290+1z:NaN
1291-1z:NaN
1292# only one underscore between two digits
1293_123:NaN
1294_123_:NaN
1295123_:NaN
12961__23:NaN
12971E1__2:NaN
12981_E12:NaN
12991E_12:NaN
13001_E_12:NaN
1301+_1E12:NaN
1302+0_1E2:100
1303+0_0_1E2:100
1304-0_0_1E2:-100
1305-0_0_1E+0_0_2:-100
1306E1:NaN
1307E23:NaN
13081.23E1:NaN
13091.23E-1:NaN
1310# bug with two E's in number being valid
13111e2e3:NaN
13121e2r:NaN
13131e2.0:NaN
1314# bug with two '.' in number being valid
13151.2.2:NaN
13161.2.3e1:NaN
1317-1.2.3:NaN
1318-1.2.3e-4:NaN
13191.2e3.4:NaN
13201.2e-3.4:NaN
13211.2.3.4:NaN
13221.2.t:NaN
13231..2:NaN
13241..2e1:NaN
13251..2e1..1:NaN
132612e1..1:NaN
1327..2:NaN
1328.-2:NaN
1329# leading zeros
1330012:12
13310123:123
133201234:1234
1333012345:12345
13340123456:123456
133501234567:1234567
1336012345678:12345678
13370123456789:123456789
133801234567891:1234567891
1339012345678912:12345678912
13400123456789123:123456789123
134101234567891234:1234567891234
1342# some inputs that result in zero
13430e0:0
1344+0e0:0
1345+0e+0:0
1346-0e+0:0
13470e-0:0
1348-0e-0:0
1349+0e-0:0
1350000:0
135100e2:0
135200e02:0
1353000e002:0
1354000e1230:0
135500e-3:0
135600e+3:0
135700e-03:0
135800e+03:0
1359-000:0
1360-00e2:0
1361-00e02:0
1362-000e002:0
1363-000e1230:0
1364-00e-3:0
1365-00e+3:0
1366-00e-03:0
1367-00e+03:0
1368# normal input
13690:0
1370+0:0
1371+00:0
1372+000:0
1373000000000000000000:0
1374-0:0
1375-0000:0
1376+1:1
1377+01:1
1378+001:1
1379+00000100000:100000
1380123456789:123456789
1381-1:-1
1382-01:-1
1383-001:-1
1384-123456789:-123456789
1385-00000100000:-100000
13861_2_3:123
138710000000000E-1_0:1
13881E2:100
13891E1:10
13901E0:1
13911.23E2:123
1392100E-1:10
1393# floating point input
1394# .2e2:20
13951.E3:1000
13961.01E2:101
13971010E-1:101
1398-1010E0:-1010
1399-1010E1:-10100
14001234.00:1234
1401# non-integer numbers
1402-1010E-2:NaN
1403-1.01E+1:NaN
1404-1.01E-1:NaN
14051E-999999:NaN
14060.5:NaN
1407
1408&bnan
14091:NaN
14102:NaN
1411abc:NaN
1412
1413&bone
14142:+:1
14152:-:-1
1416invalid:-:-1
1417invalid:+:1
14182:abc:1
14193::1
1420
1421&binf
14221:+:inf
14232:-:-inf
14243:abc:inf
1425
1426&is_nan
1427123:0
1428abc:1
1429NaN:1
1430-123:0
1431
1432&is_inf
1433+inf::1
1434-inf::1
1435abc::0
14361::0
1437NaN::0
1438-1::0
1439+inf:-:0
1440+inf:+:1
1441-inf:-:1
1442-inf:+:0
1443-inf:-inf:1
1444-inf:+inf:0
1445+inf:-inf:0
1446+inf:+inf:1
1447+iNfInItY::1
1448-InFiNiTy::1
1449
1450&blsft
1451abc:abc:NaN
1452+2:+2:8
1453+1:+32:4294967296
1454+1:+48:281474976710656
1455+8:-2:NaN
1456# exercise base 10
1457+12345:4:10:123450000
1458-1234:0:10:-1234
1459+1234:0:10:1234
1460+2:2:10:200
1461+12:2:10:1200
1462+1234:-3:10:NaN
14631234567890123:12:10:1234567890123000000000000
1464-3:1:2:-6
1465-5:1:2:-10
1466-2:1:2:-4
1467-102533203:1:2:-205066406
1468
1469&brsft
1470abc:abc:NaN
1471+8:+2:2
1472+4294967296:+32:1
1473+281474976710656:+48:1
1474+2:-2:NaN
1475# exercise base 10
1476-1234:0:10:-1234
1477+1234:0:10:1234
1478+200:2:10:2
1479+1234:3:10:1
1480+1234:2:10:12
1481+1234:-3:10:NaN
1482310000:4:10:31
148312300000:5:10:123
14841230000000000:10:10:123
148509876123456789067890:12:10:9876123
14861234561234567890123:13:10:123456
1487820265627:1:2:410132813
1488# test shifting negative numbers in base 2
1489-15:1:2:-8
1490-14:1:2:-7
1491-13:1:2:-7
1492-12:1:2:-6
1493-11:1:2:-6
1494-10:1:2:-5
1495-9:1:2:-5
1496-8:1:2:-4
1497-7:1:2:-4
1498-6:1:2:-3
1499-5:1:2:-3
1500-4:1:2:-2
1501-3:1:2:-2
1502-2:1:2:-1
1503-1:1:2:-1
1504-1640531254:2:2:-410132814
1505-1640531254:1:2:-820265627
1506-820265627:1:2:-410132814
1507-205066405:1:2:-102533203
1508
1509&bsstr
1510+inf:inf
1511-inf:-inf
15121e+34:1e+34
1513123.456E3:123456e+0
1514100:1e+2
1515bsstrabc:NaN
1516-5:-5e+0
1517-100:-1e+2
1518
1519&numify
15205:5
1521-5:-5
1522100:100
1523-100:-100
1524
1525&bneg
1526invalid:NaN
1527+inf:-inf
1528-inf:inf
1529abd:NaN
15300:0
15311:-1
1532-1:1
1533+123456789:-123456789
1534-123456789:123456789
1535
1536&babs
1537invalid:NaN
1538+inf:inf
1539-inf:inf
15400:0
15411:1
1542-1:1
1543+123456789:123456789
1544-123456789:123456789
1545
1546&bsgn
1547NaN:NaN
1548+inf:1
1549-inf:-1
15500:0
1551+123456789:1
1552-123456789:-1
1553
1554&bcmp
1555invalid:invalid:
1556invalid:0:
15570:invalid:
15580:0:0
1559-1:0:-1
15600:-1:1
15611:0:1
15620:1:-1
1563-1:1:-1
15641:-1:1
1565-1:-1:0
15661:1:0
1567123:123:0
1568123:12:1
156912:123:-1
1570-123:-123:0
1571-123:-12:-1
1572-12:-123:1
1573123:124:-1
1574124:123:1
1575-123:-124:1
1576-124:-123:-1
1577100:5:1
1578-123456789:987654321:-1
1579+123456789:-987654321:1
1580-987654321:123456789:-1
1581-inf:5432112345:-1
1582+inf:5432112345:1
1583-inf:-5432112345:-1
1584+inf:-5432112345:1
1585+inf:+inf:0
1586-inf:-inf:0
1587+inf:-inf:1
1588-inf:+inf:-1
15895:inf:-1
15905:inf:-1
1591-5:-inf:1
1592-5:-inf:1
1593# return undef
1594+inf:NaN:
1595NaN:inf:
1596-inf:NaN:
1597NaN:-inf:
1598
1599&binc
1600abc:NaN
1601+inf:inf
1602-inf:-inf
1603+0:1
1604+1:2
1605-1:0
1606
1607&bdec
1608abc:NaN
1609+inf:inf
1610-inf:-inf
1611+0:-1
1612+1:0
1613-1:-2
1614
1615&badd
1616abc:abc:NaN
1617abc:0:NaN
1618+0:abc:NaN
1619+inf:-inf:NaN
1620-inf:+inf:NaN
1621+inf:+inf:inf
1622-inf:-inf:-inf
1623invalid:+inf:NaN
1624invalid:+inf:NaN
1625+inf:invalid:NaN
1626-inf:invalid:NaN
16270:0:0
16281:0:1
16290:1:1
16301:1:2
1631-1:0:-1
16320:-1:-1
1633-1:-1:-2
1634-1:+1:0
1635+1:-1:0
1636+9:+1:10
1637+99:+1:100
1638+999:+1:1000
1639+9999:+1:10000
1640+99999:+1:100000
1641+999999:+1:1000000
1642+9999999:+1:10000000
1643+99999999:+1:100000000
1644+999999999:+1:1000000000
1645+9999999999:+1:10000000000
1646+99999999999:+1:100000000000
1647+10:-1:9
1648+100:-1:99
1649+1000:-1:999
1650+10000:-1:9999
1651+100000:-1:99999
1652+1000000:-1:999999
1653+10000000:-1:9999999
1654+100000000:-1:99999999
1655+1000000000:-1:999999999
1656+10000000000:-1:9999999999
1657+123456789:987654321:1111111110
1658-123456789:987654321:864197532
1659-123456789:-987654321:-1111111110
1660+123456789:-987654321:-864197532
1661-1:10001:10000
1662-1:100001:100000
1663-1:1000001:1000000
1664-1:10000001:10000000
1665-1:100000001:100000000
1666-1:1000000001:1000000000
1667-1:10000000001:10000000000
1668-1:100000000001:100000000000
1669-1:1000000000001:1000000000000
1670-1:10000000000001:10000000000000
1671-1:-10001:-10002
1672-1:-100001:-100002
1673-1:-1000001:-1000002
1674-1:-10000001:-10000002
1675-1:-100000001:-100000002
1676-1:-1000000001:-1000000002
1677-1:-10000000001:-10000000002
1678-1:-100000000001:-100000000002
1679-1:-1000000000001:-1000000000002
1680-1:-10000000000001:-10000000000002
1681
1682&bsub
1683abc:abc:NaN
1684abc:+0:NaN
1685+0:abc:NaN
1686+inf:-inf:inf
1687-inf:+inf:-inf
1688+inf:+inf:NaN
1689-inf:-inf:NaN
1690+0:+0:0
1691+1:+0:1
1692+0:+1:-1
1693+1:+1:0
1694-1:+0:-1
1695+0:-1:1
1696-1:-1:0
1697-1:+1:-2
1698+1:-1:2
1699+9:+1:8
1700+99:+1:98
1701+999:+1:998
1702+9999:+1:9998
1703+99999:+1:99998
1704+999999:+1:999998
1705+9999999:+1:9999998
1706+99999999:+1:99999998
1707+999999999:+1:999999998
1708+9999999999:+1:9999999998
1709+99999999999:+1:99999999998
1710+10:-1:11
1711+100:-1:101
1712+1000:-1:1001
1713+10000:-1:10001
1714+100000:-1:100001
1715+1000000:-1:1000001
1716+10000000:-1:10000001
1717+100000000:-1:100000001
1718+1000000000:-1:1000000001
1719+10000000000:-1:10000000001
1720+123456789:+987654321:-864197532
1721-123456789:+987654321:-1111111110
1722-123456789:-987654321:864197532
1723+123456789:-987654321:1111111110
172410001:1:10000
1725100001:1:100000
17261000001:1:1000000
172710000001:1:10000000
1728100000001:1:100000000
17291000000001:1:1000000000
173010000000001:1:10000000000
1731100000000001:1:100000000000
17321000000000001:1:1000000000000
173310000000000001:1:10000000000000
173410001:-1:10002
1735100001:-1:100002
17361000001:-1:1000002
173710000001:-1:10000002
1738100000001:-1:100000002
17391000000001:-1:1000000002
174010000000001:-1:10000000002
1741100000000001:-1:100000000002
17421000000000001:-1:1000000000002
174310000000000001:-1:10000000000002
1744
1745&bmuladd
1746abc:abc:0:NaN
1747abc:+0:0:NaN
1748+0:abc:0:NaN
1749+0:0:abc:NaN
1750invalid:+inf:0:NaN
1751invalid:-inf:0:NaN
1752-inf:invalid:0:NaN
1753+inf:invalid:0:NaN
1754+inf:+inf:0:inf
1755+inf:-inf:0:-inf
1756-inf:+inf:0:-inf
1757-inf:-inf:0:inf
1758+0:+0:0:0
1759+0:+1:0:0
1760+1:+0:0:0
1761+0:-1:0:0
1762-1:+0:0:0
1763123456789123456789:0:0:0
17640:123456789123456789:0:0
1765-1:-1:0:1
1766-1:-1:0:1
1767-1:+1:0:-1
1768+1:-1:0:-1
1769+1:+1:0:1
1770+2:+3:0:6
1771-2:+3:0:-6
1772+2:-3:0:-6
1773-2:-3:0:6
1774111:111:0:12321
177510101:10101:0:102030201
17761001001:1001001:0:1002003002001
1777100010001:100010001:0:10002000300020001
177810000100001:10000100001:0:100002000030000200001
177911111111111:9:0:99999999999
178022222222222:9:0:199999999998
178133333333333:9:0:299999999997
178244444444444:9:0:399999999996
178355555555555:9:0:499999999995
178466666666666:9:0:599999999994
178577777777777:9:0:699999999993
178688888888888:9:0:799999999992
178799999999999:9:0:899999999991
178811111111111:9:1:100000000000
178922222222222:9:1:199999999999
179033333333333:9:1:299999999998
179144444444444:9:1:399999999997
179255555555555:9:1:499999999996
179366666666666:9:1:599999999995
179477777777777:9:1:699999999994
179588888888888:9:1:799999999993
179699999999999:9:1:899999999992
1797-3:-4:-5:7
17983:-4:-5:-17
1799-3:4:-5:-17
18003:4:-5:7
1801-3:4:5:-7
18023:-4:5:-7
18039999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890
18042:3:12345678901234567890:12345678901234567896
1805
1806&bmul
1807abc:abc:NaN
1808abc:+0:NaN
1809+0:abc:NaN
1810invalid:+inf:NaN
1811invalid:-inf:NaN
1812-inf:invalid:NaN
1813+inf:invalid:NaN
1814+inf:+inf:inf
1815+inf:-inf:-inf
1816-inf:+inf:-inf
1817-inf:-inf:inf
1818+0:+0:0
1819+0:+1:0
1820+1:+0:0
1821+0:-1:0
1822-1:+0:0
1823123456789123456789:0:0
18240:123456789123456789:0
1825-1:-1:1
1826-1:+1:-1
1827+1:-1:-1
1828+1:+1:1
1829+2:+3:6
1830-2:+3:-6
1831+2:-3:-6
1832-2:-3:6
1833111:111:12321
183410101:10101:102030201
18351001001:1001001:1002003002001
1836100010001:100010001:10002000300020001
183710000100001:10000100001:100002000030000200001
183811111111111:9:99999999999
183922222222222:9:199999999998
184033333333333:9:299999999997
184144444444444:9:399999999996
184255555555555:9:499999999995
184366666666666:9:599999999994
184477777777777:9:699999999993
184588888888888:9:799999999992
184699999999999:9:899999999991
1847+25:+25:625
1848+12345:+12345:152399025
1849+99999:+11111:1111088889
18509999:10000:99990000
185199999:100000:9999900000
1852999999:1000000:999999000000
18539999999:10000000:99999990000000
185499999999:100000000:9999999900000000
1855999999999:1000000000:999999999000000000
18569999999999:10000000000:99999999990000000000
185799999999999:100000000000:9999999999900000000000
1858999999999999:1000000000000:999999999999000000000000
18599999999999999:10000000000000:99999999999990000000000000
186099999999999999:100000000000000:9999999999999900000000000000
1861999999999999999:1000000000000000:999999999999999000000000000000
18629999999999999999:10000000000000000:99999999999999990000000000000000
186399999999999999999:100000000000000000:9999999999999999900000000000000000
1864999999999999999999:1000000000000000000:999999999999999999000000000000000000
18659999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1866
1867&bdiv-list
1868
1869# Divide by zero and modulo zero.
1870
1871inf:0:inf,inf
18725:0:inf,5
18730:0:NaN,0
1874-5:0:-inf,-5
1875-inf:0:-inf,-inf
1876
1877# Numerator (dividend) is +/-inf, and denominator is finite and non-zero.
1878
1879inf:-inf:NaN,NaN
1880inf:-5:-inf,NaN
1881inf:5:inf,NaN
1882inf:inf:NaN,NaN
1883
1884-inf:-inf:NaN,NaN
1885-inf:-5:inf,NaN
1886-inf:5:-inf,NaN
1887-inf:inf:NaN,NaN
1888
1889# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf
1890# are covered above.
1891
1892-5:inf:-1,inf
18930:inf:0,0
18945:inf:0,5
1895
1896-5:-inf:0,-5
18970:-inf:0,0
18985:-inf:-1,-inf
1899
1900# Numerator is finite, and denominator is finite and non-zero.
1901
1902-5:-5:1,0
1903-5:-2:2,-1
1904-5:-1:5,0
1905-5:1:-5,0
1906-5:2:-3,1
1907-5:5:-1,0
1908-2:-5:0,-2
1909-2:-2:1,0
1910-2:-1:2,0
1911-2:1:-2,0
1912-2:2:-1,0
1913-2:5:-1,3
1914-1:-5:0,-1
1915-1:-2:0,-1
1916-1:-1:1,0
1917-1:1:-1,0
1918-1:2:-1,1
1919-1:5:-1,4
19200:-5:0,0
19210:-2:0,0
19220:-1:0,0
19230:1:0,0
19240:2:0,0
19250:5:0,0
19261:-5:-1,-4
19271:-2:-1,-1
19281:-1:-1,0
19291:1:1,0
19301:2:0,1
19311:5:0,1
19322:-5:-1,-3
19332:-2:-1,0
19342:-1:-2,0
19352:1:2,0
19362:2:1,0
19372:5:0,2
19385:-5:-1,0
19395:-2:-3,-1
19405:-1:-5,0
19415:1:5,0
19425:2:2,1
19435:5:1,0
1944
1945# test the shortcut in Calc if @$x == @$yorg
19461234567812345678:123456712345678:10,688888898
194712345671234567:1234561234567:10,58888897
1948123456123456:12345123456:10,4888896
19491234512345:123412345:10,388895
19501234567890999999999:1234567890:1000000000,999999999
19511234567890000000000:1234567890:1000000000,0
19521234567890999999999:9876543210:124999998,9503086419
19531234567890000000000:9876543210:124999998,8503086420
195496969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
1955# bug in v1.76
19561267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375
1957# exercise shortcut for numbers of the same length in div
1958999999999999999999999999999999999:999999999999999999999999999999999:1,0
1959999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111
1960999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222
1961999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333
1962999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444
1963999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111
1964999999999999999999999999999999999:333333333333333333333333333333333:3,0
1965999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111
1966999999999999999999999999999999999:111111111111111111111111111111111:9,0
19679999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0
19689999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999
19699999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999
19709999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999
19719999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999
19729999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999
19739999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999
19749999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999
19759999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999
19769999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999
19779999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999
1978
1979&bdiv
1980
1981# Divide by zero and modulo zero.
1982
1983inf:0:inf
19845:0:inf
19850:0:NaN
1986-5:0:-inf
1987-inf:0:-inf
1988
1989# Numerator (dividend) is +/-inf, and denominator is finite and non-zero.
1990
1991inf:-inf:NaN
1992inf:-5:-inf
1993inf:5:inf
1994inf:inf:NaN
1995
1996-inf:-inf:NaN
1997-inf:-5:inf
1998-inf:5:-inf
1999-inf:inf:NaN
2000
2001# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf
2002# are covered above.
2003
2004-5:inf:-1
20050:inf:0
20065:inf:0
2007
2008-5:-inf:0
20090:-inf:0
20105:-inf:-1
2011
2012# Numerator is finite, and denominator is finite and non-zero.
2013
20145:5:1
2015-5:-5:1
201611:2:5
2017-11:-2:5
2018-11:2:-6
201911:-2:-6
20200:1:0
20210:-1:0
20221:1:1
2023-1:-1:1
20241:-1:-1
2025-1:1:-1
20261:2:0
20272:1:2
20281:26:0
20291000000000:9:111111111
20302000000000:9:222222222
20313000000000:9:333333333
20324000000000:9:444444444
20335000000000:9:555555555
20346000000000:9:666666666
20357000000000:9:777777777
20368000000000:9:888888888
20379000000000:9:1000000000
203835500000:113:314159
203971000000:226:314159
2040106500000:339:314159
20411000000000:3:333333333
2042+10:+5:2
2043+100:+4:25
2044+1000:+8:125
2045+10000:+16:625
2046999999999999:9:111111111111
2047999999999999:99:10101010101
2048999999999999:999:1001001001
2049999999999999:9999:100010001
2050999999999999999:99999:10000100001
2051+1111088889:99999:11111
2052-5:-3:1
2053-5:3:-2
20544:3:1
20554:-3:-2
20561:3:0
20571:-3:-1
2058-2:-3:0
2059-2:3:-1
20608:3:2
2061-8:3:-3
206214:-3:-5
2063-14:3:-5
2064-14:-3:4
206514:3:4
2066# bug in Calc with '99999' vs $BASE-1
206710000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
2068# test the shortcut in Calc if @$x == @$yorg
20691234567812345678:123456712345678:10
207012345671234567:1234561234567:10
2071123456123456:12345123456:10
20721234512345:123412345:10
20731234567890999999999:1234567890:1000000000
20741234567890000000000:1234567890:1000000000
20751234567890999999999:9876543210:124999998
20761234567890000000000:9876543210:124999998
207796969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
2078# bug up to v0.35 in Calc (--$q one too many)
207984696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
208084696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
208184696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
208284696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
2083# exercise shortcut for numbers of the same length in div
2084999999999999999999999999999999999:999999999999999999999999999999999:1
2085999999999999999999999999999999999:888888888888888888888888888888888:1
2086999999999999999999999999999999999:777777777777777777777777777777777:1
2087999999999999999999999999999999999:666666666666666666666666666666666:1
2088999999999999999999999999999999999:555555555555555555555555555555555:1
2089999999999999999999999999999999999:444444444444444444444444444444444:2
2090999999999999999999999999999999999:333333333333333333333333333333333:3
2091999999999999999999999999999999999:222222222222222222222222222222222:4
2092999999999999999999999999999999999:111111111111111111111111111111111:9
20939999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3
20949999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3
20959999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3
20969999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4
20979999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9
20989999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99
20999999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999
21009999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999
21019999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999
21029999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999
21039999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999
2104# bug with shortcut in Calc 0.44
2105949418181818187070707070707070707070:181818181853535353535353535353535353:5
2106
2107&btdiv-list
2108
2109# Divide by zero and modulo zero.
2110
2111inf:0:inf,inf
21125:0:inf,5
21130:0:NaN,0
2114-5:0:-inf,-5
2115-inf:0:-inf,-inf
2116
2117# Numerator (dividend) is +/-inf, and denominator is finite and non-zero.
2118
2119inf:-inf:NaN,NaN
2120inf:-5:-inf,NaN
2121inf:5:inf,NaN
2122inf:inf:NaN,NaN
2123
2124-inf:-inf:NaN,NaN
2125-inf:-5:inf,NaN
2126-inf:5:-inf,NaN
2127-inf:inf:NaN,NaN
2128
2129# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf
2130# are covered above.
2131
2132-5:inf:0,-5
21330:inf:0,0
21345:inf:0,5
2135
2136-5:-inf:0,-5
21370:-inf:0,0
21385:-inf:0,5
2139
2140# Numerator is finite, and denominator is finite and non-zero.
2141
2142-5:-5:1,0
2143-5:-2:2,-1
2144-5:-1:5,0
2145-5:1:-5,0
2146-5:2:-2,-1
2147-5:5:-1,0
2148-2:-5:0,-2
2149-2:-2:1,0
2150-2:-1:2,0
2151-2:1:-2,0
2152-2:2:-1,0
2153-2:5:0,-2
2154-1:-5:0,-1
2155-1:-2:0,-1
2156-1:-1:1,0
2157-1:1:-1,0
2158-1:2:0,-1
2159-1:5:0,-1
21600:-5:0,0
21610:-2:0,0
21620:-1:0,0
21630:1:0,0
21640:2:0,0
21650:5:0,0
21661:-5:0,1
21671:-2:0,1
21681:-1:-1,0
21691:1:1,0
21701:2:0,1
21711:5:0,1
21722:-5:0,2
21732:-2:-1,0
21742:-1:-2,0
21752:1:2,0
21762:2:1,0
21772:5:0,2
21785:-5:-1,0
21795:-2:-2,1
21805:-1:-5,0
21815:1:5,0
21825:2:2,1
21835:5:1,0
2184
2185&btdiv
2186
2187# Divide by zero and modulo zero.
2188
2189inf:0:inf
21905:0:inf
21910:0:NaN
2192-5:0:-inf
2193-inf:0:-inf
2194
2195# Numerator (dividend) is +/-inf, and denominator is finite and non-zero.
2196
2197inf:-inf:NaN
2198inf:-5:-inf
2199inf:5:inf
2200inf:inf:NaN
2201
2202-inf:-inf:NaN
2203-inf:-5:inf
2204-inf:5:-inf
2205-inf:inf:NaN
2206
2207# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf
2208# are covered above.
2209
2210-5:inf:0
22110:inf:0
22125:inf:0
2213
2214-5:-inf:0
22150:-inf:0
22165:-inf:0
2217
2218# Numerator is finite, and denominator is finite and non-zero.
2219
2220-5:-5:1
2221-5:-2:2
2222-5:-1:5
2223-5:1:-5
2224-5:2:-2
2225-5:5:-1
2226-2:-5:0
2227-2:-2:1
2228-2:-1:2
2229-2:1:-2
2230-2:2:-1
2231-2:5:0
2232-1:-5:0
2233-1:-2:0
2234-1:-1:1
2235-1:1:-1
2236-1:2:0
2237-1:5:0
22380:-5:0
22390:-2:0
22400:-1:0
22410:1:0
22420:2:0
22430:5:0
22441:-5:0
22451:-2:0
22461:-1:-1
22471:1:1
22481:2:0
22491:5:0
22502:-5:0
22512:-2:-1
22522:-1:-2
22532:1:2
22542:2:1
22552:5:0
22565:-5:-1
22575:-2:-2
22585:-1:-5
22595:1:5
22605:2:2
22615:5:1
2262
2263###############################################################################
2264
2265&bmodinv
2266# format: number:modulus:result
2267# bmodinv Data errors
2268abc:abc:NaN
2269abc:5:NaN
22705:abc:NaN
2271# bmodinv Expected Results from normal use
22721:5:1
22733:5:2
22743:-5:-3
2275-2:5:2
22768:5033:4404
22771234567891:13:6
2278-1234567891:13:7
2279324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
2280-2:1:0
2281-1:1:0
22820:1:0
22831:1:0
22842:1:0
22853:1:0
22864:1:0
2287-2:3:1
2288-1:3:2
22890:3:NaN
22901:3:1
22912:3:2
22923:3:NaN
22934:3:1
2294-2:4:NaN
2295-1:4:3
22960:4:NaN
22971:4:1
22982:4:NaN
22993:4:3
23004:4:NaN
2301## bmodinv Error cases / useless use of function
2302inf:5:NaN
23035:inf:NaN
2304-inf:5:NaN
23055:-inf:NaN
2306
2307&bmodpow
2308# format: number:exponent:modulus:result
2309# bmodpow Data errors
2310abc:abc:abc:NaN
23115:abc:abc:NaN
2312abc:5:abc:NaN
2313abc:abc:5:NaN
23145:5:abc:NaN
23155:abc:5:NaN
2316abc:5:5:NaN
23173:5:0:3
2318# bmodpow Expected results
23190:0:2:1
23201:0:2:1
23210:3:5:0
2322-2:-2:1:0
2323-1:-2:1:0
23240:-2:1:0
23251:-2:1:0
23262:-2:1:0
23273:-2:1:0
23284:-2:1:0
2329-2:-1:1:0
2330-1:-1:1:0
23310:-1:1:0
23321:-1:1:0
23332:-1:1:0
23343:-1:1:0
23354:-1:1:0
2336-2:0:1:0
2337-1:0:1:0
23380:0:1:0
23391:0:1:0
23402:0:1:0
23413:0:1:0
23424:0:1:0
2343-2:1:1:0
2344-1:1:1:0
23450:1:1:0
23461:1:1:0
23472:1:1:0
23483:1:1:0
23494:1:1:0
2350-2:2:1:0
2351-1:2:1:0
23520:2:1:0
23531:2:1:0
23542:2:1:0
23553:2:1:0
23564:2:1:0
2357-2:3:1:0
2358-1:3:1:0
23590:3:1:0
23601:3:1:0
23612:3:1:0
23623:3:1:0
23634:3:1:0
2364-2:4:1:0
2365-1:4:1:0
23660:4:1:0
23671:4:1:0
23682:4:1:0
23693:4:1:0
23704:4:1:0
2371-2:-2:3:1
2372-1:-2:3:1
23730:-2:3:NaN
23741:-2:3:1
23752:-2:3:1
23763:-2:3:NaN
23774:-2:3:1
2378-2:-1:3:1
2379-1:-1:3:2
23800:-1:3:NaN
23811:-1:3:1
23822:-1:3:2
23833:-1:3:NaN
23844:-1:3:1
2385-2:0:3:1
2386-1:0:3:1
23870:0:3:1
23881:0:3:1
23892:0:3:1
23903:0:3:1
23914:0:3:1
2392-2:1:3:1
2393-1:1:3:2
23940:1:3:0
23951:1:3:1
23962:1:3:2
23973:1:3:0
23984:1:3:1
2399-2:2:3:1
2400-1:2:3:1
24010:2:3:0
24021:2:3:1
24032:2:3:1
24043:2:3:0
24054:2:3:1
2406-2:3:3:1
2407-1:3:3:2
24080:3:3:0
24091:3:3:1
24102:3:3:2
24113:3:3:0
24124:3:3:1
2413-2:4:3:1
2414-1:4:3:1
24150:4:3:0
24161:4:3:1
24172:4:3:1
24183:4:3:0
24194:4:3:1
2420-2:-2:4:NaN
2421-1:-2:4:1
24220:-2:4:NaN
24231:-2:4:1
24242:-2:4:NaN
24253:-2:4:1
24264:-2:4:NaN
2427-2:-1:4:NaN
2428-1:-1:4:3
24290:-1:4:NaN
24301:-1:4:1
24312:-1:4:NaN
24323:-1:4:3
24334:-1:4:NaN
2434-2:0:4:1
2435-1:0:4:1
24360:0:4:1
24371:0:4:1
24382:0:4:1
24393:0:4:1
24404:0:4:1
2441-2:1:4:2
2442-1:1:4:3
24430:1:4:0
24441:1:4:1
24452:1:4:2
24463:1:4:3
24474:1:4:0
2448-2:2:4:0
2449-1:2:4:1
24500:2:4:0
24511:2:4:1
24522:2:4:0
24533:2:4:1
24544:2:4:0
2455-2:3:4:0
2456-1:3:4:3
24570:3:4:0
24581:3:4:1
24592:3:4:0
24603:3:4:3
24614:3:4:0
2462-2:4:4:0
2463-1:4:4:1
24640:4:4:0
24651:4:4:1
24662:4:4:0
24673:4:4:1
24684:4:4:0
24698:-1:16:NaN
24708:-1:5033:4404
24718:7:5032:3840
24728:8:-5:-4
24731e50:1:1:0
247498436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
2475# bmodpow Error cases
2476inf:5:13:NaN
24775:inf:13:NaN
2478
2479&bmod
2480
2481# Divide by zero and modulo zero.
2482
2483inf:0:inf
24845:0:5
24850:0:0
2486-5:0:-5
2487-inf:0:-inf
2488
2489# Numerator (dividend) is +/-inf, and denominator is finite and non-zero.
2490
2491inf:-inf:NaN
2492inf:-5:NaN
2493inf:5:NaN
2494inf:inf:NaN
2495
2496-inf:-inf:NaN
2497-inf:-5:NaN
2498-inf:5:NaN
2499-inf:inf:NaN
2500
2501# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf
2502# are covered above.
2503
2504-5:inf:inf
25050:inf:0
25065:inf:5
2507
2508-5:-inf:-5
25090:-inf:0
25105:-inf:-inf
2511
2512# Numerator is finite, and denominator is finite and non-zero.
2513
25145:5:0
2515-5:-5:0
25160:1:0
25170:-1:0
25181:1:0
2519-1:-1:0
25201:-1:0
2521-1:1:0
25221:2:1
25232:1:0
25241000000000:9:1
25252000000000:9:2
25263000000000:9:3
25274000000000:9:4
25285000000000:9:5
25296000000000:9:6
25307000000000:9:7
25318000000000:9:8
25329000000000:9:0
253335500000:113:33
253471000000:226:66
2535106500000:339:99
25361000000000:3:1
253710:5:0
2538100:4:0
25391000:8:0
254010000:16:0
2541999999999999:9:0
2542999999999999:99:0
2543999999999999:999:0
2544999999999999:9999:0
2545999999999999999:99999:0
2546-9:+5:1
2547+9:-5:-1
2548-9:-5:-4
2549-5:3:1
2550-2:3:1
25514:3:1
25521:3:1
2553-5:-3:-2
2554-2:-3:-2
25554:-3:-2
25561:-3:-2
25574095:4095:0
2558100041000510123:3:0
2559152403346:12345:4321
25609:5:4
2561# test shortcuts in Calc
2562# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
25631234:9:1
2564123456:9:3
256512345678:9:0
25661234567891:9:1
2567123456789123:9:6
256812345678912345:9:6
25691234567891234567:9:1
2570123456789123456789:9:0
25711234:10:4
2572123456:10:6
257312345678:10:8
25741234567891:10:1
2575123456789123:10:3
257612345678912345:10:5
25771234567891234567:10:7
2578123456789123456789:10:9
25791234:113:104
2580123456:113:60
258112345678:113:89
25821234567891:113:64
2583123456789123:113:95
258412345678912345:113:53
25851234567891234567:113:56
2586123456789123456789:113:39
2587# bug in bmod() not modifying the variable in place
2588-629:5033:4404
2589# bug in bmod() in Calc in the _div_use_div() shortcut code path,
2590# when X == X and X was big
2591111111111111111111111111111111:111111111111111111111111111111:0
259212345678901234567890:12345678901234567890:0
2593
2594&bgcd
2595inf:12:NaN
2596-inf:12:NaN
259712:inf:NaN
259812:-inf:NaN
2599inf:inf:NaN
2600inf:-inf:NaN
2601-inf:-inf:NaN
2602abc:abc:NaN
2603abc:+0:NaN
2604+0:abc:NaN
2605+0:+0:0
2606+0:+1:1
2607+1:+0:1
2608+1:+1:1
2609+2:+3:1
2610+3:+2:1
2611-3:+2:1
2612-3:-2:1
2613-144:-60:12
2614144:-60:12
2615144:60:12
2616100:625:25
26174096:81:1
26181034:804:2
261927:90:56:1
262027:90:54:9
2621
2622&blcm
2623abc:abc:NaN
2624abc:+0:NaN
2625+0:abc:NaN
2626+0:+0:0
2627+1:+0:0
2628+0:+1:0
2629+27:+90:270
2630+1034:+804:415668
2631
2632&band
2633abc:abc:NaN
2634abc:0:NaN
26350:abc:NaN
26361:2:0
26373:2:2
2638+8:+2:0
2639+281474976710656:0:0
2640+281474976710656:1:0
2641+281474976710656:+281474976710656:281474976710656
2642281474976710656:-1:281474976710656
2643-2:-3:-4
2644-1:-1:-1
2645-6:-6:-6
2646-7:-4:-8
2647-7:4:0
2648-4:7:4
2649# negative argument is bitwise shorter than positive [perl #26559]
265030:-3:28
2651123:-1:123
2652# equal arguments are treated special, so also do some test with unequal ones
26530xFFFF:0xFFFF:0x0xFFFF
26540xFFFFFF:0xFFFFFF:0x0xFFFFFF
26550xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
26560xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
26570xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
26580xF0F0:0xF0F0:0x0xF0F0
26590x0F0F:0x0F0F:0x0x0F0F
26600xF0F0F0:0xF0F0F0:0x0xF0F0F0
26610x0F0F0F:0x0F0F0F:0x0x0F0F0F
26620xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
26630x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
26640xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
26650x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
26660xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
26670x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
26680x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
2669
2670&bior
2671abc:abc:NaN
2672abc:0:NaN
26730:abc:NaN
26741:2:3
2675+8:+2:10
2676+281474976710656:0:281474976710656
2677+281474976710656:1:281474976710657
2678+281474976710656:281474976710656:281474976710656
2679-2:-3:-1
2680-1:-1:-1
2681-6:-6:-6
2682-7:4:-3
2683-4:7:-1
2684+281474976710656:-1:-1
268530:-3:-1
268630:-4:-2
2687300:-76:-68
2688-76:300:-68
2689# equal arguments are treated special, so also do some test with unequal ones
26900xFFFF:0xFFFF:0x0xFFFF
26910xFFFFFF:0xFFFFFF:0x0xFFFFFF
26920xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
26930xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
26940xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
26950:0xFFFF:0x0xFFFF
26960:0xFFFFFF:0x0xFFFFFF
26970:0xFFFFFFFF:0x0xFFFFFFFF
26980:0xFFFFFFFFFF:0x0xFFFFFFFFFF
26990:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
27000xFFFF:0:0x0xFFFF
27010xFFFFFF:0:0x0xFFFFFF
27020xFFFFFFFF:0:0x0xFFFFFFFF
27030xFFFFFFFFFF:0:0x0xFFFFFFFFFF
27040xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
27050xF0F0:0xF0F0:0x0xF0F0
27060x0F0F:0x0F0F:0x0x0F0F
27070xF0F0:0x0F0F:0x0xFFFF
27080xF0F0F0:0xF0F0F0:0x0xF0F0F0
27090x0F0F0F:0x0F0F0F:0x0x0F0F0F
27100x0F0F0F:0xF0F0F0:0x0xFFFFFF
27110xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
27120x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
27130x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
27140xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
27150x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
27160x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
27170xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
27180x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
27190x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
27200x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
2721
2722&bxor
2723abc:abc:NaN
2724abc:0:NaN
27250:abc:NaN
27261:2:3
2727+8:+2:10
2728+281474976710656:0:281474976710656
2729+281474976710656:1:281474976710657
2730+281474976710656:281474976710656:0
2731-2:-3:3
2732-1:-1:0
2733-6:-6:0
2734-7:4:-3
2735-4:7:-5
27364:-7:-3
2737-4:-7:5
273830:-3:-29
273930:-4:-30
2740300:-76:-360
2741-76:300:-360
2742# equal arguments are treated special, so also do some test with unequal ones
27430xFFFF:0xFFFF:0
27440xFFFFFF:0xFFFFFF:0
27450xFFFFFFFF:0xFFFFFFFF:0
27460xFFFFFFFFFF:0xFFFFFFFFFF:0
27470xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
27480:0xFFFF:0x0xFFFF
27490:0xFFFFFF:0x0xFFFFFF
27500:0xFFFFFFFF:0x0xFFFFFFFF
27510:0xFFFFFFFFFF:0x0xFFFFFFFFFF
27520:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
27530xFFFF:0:0x0xFFFF
27540xFFFFFF:0:0x0xFFFFFF
27550xFFFFFFFF:0:0x0xFFFFFFFF
27560xFFFFFFFFFF:0:0x0xFFFFFFFFFF
27570xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
27580xF0F0:0xF0F0:0
27590x0F0F:0x0F0F:0
27600xF0F0:0x0F0F:0x0xFFFF
27610xF0F0F0:0xF0F0F0:0
27620x0F0F0F:0x0F0F0F:0
27630x0F0F0F:0xF0F0F0:0x0xFFFFFF
27640xF0F0F0F0:0xF0F0F0F0:0
27650x0F0F0F0F:0x0F0F0F0F:0
27660x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
27670xF0F0F0F0F0:0xF0F0F0F0F0:0
27680x0F0F0F0F0F:0x0F0F0F0F0F:0
27690x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
27700xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
27710x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
27720x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
2773
2774&bnot
2775abc:NaN
2776+0:-1
2777+8:-9
2778+281474976710656:-281474976710657
2779-1:0
2780-2:1
2781-12:11
2782
2783&digit
27840:0:0
278512:0:2
278612:1:1
2787123:0:3
2788123:1:2
2789123:2:1
2790123:-1:1
2791123:-2:2
2792123:-3:3
2793123456:0:6
2794123456:1:5
2795123456:2:4
2796123456:3:3
2797123456:4:2
2798123456:5:1
2799123456:-1:1
2800123456:-2:2
2801123456:-3:3
2802100000:-3:0
2803100000:0:0
2804100000:1:0
2805
2806&mantissa
2807abc:NaN
28081e4:1
28092e0:2
2810123:123
2811-1:-1
2812-2:-2
2813+inf:inf
2814-inf:-inf
2815
2816&exponent
2817abc:NaN
28181e4:4
28192e0:0
2820123:0
2821-1:0
2822-2:0
28230:0
2824+inf:inf
2825-inf:inf
2826
2827&parts
2828abc:NaN,NaN
28291e4:1,4
28302e0:2,0
2831123:123,0
2832-1:-1,0
2833-2:-2,0
28340:0,0
2835+inf:inf,inf
2836-inf:-inf,inf
2837
2838&bfac
2839-1:NaN
2840invalid:NaN
2841+inf:inf
2842-inf:NaN
28430:1
28441:1
28452:2
28463:6
28474:24
28485:120
28496:720
28507:5040
28518:40320
28529:362880
285310:3628800
285411:39916800
285512:479001600
285620:2432902008176640000
285722:1124000727777607680000
285869:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
2859
2860&bpow
2861#
2862abc:12:NaN
286312:abc:NaN
2864#
2865#
2866-inf:-inf:0
2867-inf:-3:0
2868-inf:-2:0
2869-inf:-1:0
2870-inf:0:NaN
2871-inf:1:-inf
2872-inf:2:inf
2873-inf:3:-inf
2874-inf:inf:inf    # complex infinity
2875-inf:NaN:NaN
2876#
2877-3:-inf:0
2878-3:-3:0
2879-3:-2:0
2880-3:-1:0
2881-3:0:1
2882-3:1:-3
2883-3:2:9
2884-3:3:-27
2885-3:inf:inf      # complex infinity
2886-3:NaN:NaN
2887#
2888-2:-inf:0
2889-2:-3:0
2890-2:-2:0
2891-2:-1:0
2892-2:0:1
2893-2:1:-2
2894-2:2:4
2895-2:3:-8
2896-2:inf:inf      # complex infinity
2897-2:NaN:NaN
2898#
2899-1:-inf:NaN
2900-1:-3:-1
2901-1:-2:1
2902-1:-1:-1
2903-1:0:1
2904-1:1:-1
2905-1:2:1
2906-1:3:-1
2907-1:inf:NaN
2908-1:NaN:NaN
2909#
29100:-inf:inf      # complex infinity
29110:-3:inf        # complex infinity
29120:-2:inf        # complex infinity
29130:-1:inf        # complex infinity
29140:0:1
29150:1:0
29160:2:0
29170:3:0
29180:inf:0
29190:NaN:NaN
2920#
29211:-inf:1
29221:-3:1
29231:-2:1
29241:-1:1
29251:0:1
29261:1:1
29271:2:1
29281:3:1
29291:inf:1
29301:NaN:NaN
2931#
29322:-inf:0
29332:-3:0
29342:-2:0
29352:-1:0
29362:0:1
29372:1:2
29382:2:4
29392:3:8
29402:inf:inf
29412:NaN:NaN
2942#
29433:-inf:0
29443:-3:0
29453:-2:0
29463:-1:0
29473:0:1
29483:1:3
29493:2:9
29503:3:27
29513:inf:inf
29523:NaN:NaN
2953#
2954inf:-inf:0
2955inf:-3:0
2956inf:-2:0
2957inf:-1:0
2958inf:0:NaN
2959inf:1:inf
2960inf:2:inf
2961inf:3:inf
2962inf:inf:inf
2963inf:NaN:NaN
2964#
2965NaN:-inf:NaN
2966NaN:-3:NaN
2967NaN:-2:NaN
2968NaN:-1:NaN
2969NaN:0:NaN
2970NaN:1:NaN
2971NaN:2:NaN
2972NaN:3:NaN
2973NaN:inf:NaN
2974NaN:NaN:NaN
2975#
2976+inf:1234500012:inf
2977-inf:1234500012:inf
2978-inf:1234500013:-inf
2979+inf:-12345000123:0
2980-inf:-12345000123:0
2981#
298210:2:100
298310:3:1000
298410:4:10000
298510:5:100000
298610:6:1000000
298710:7:10000000
298810:8:100000000
298910:9:1000000000
299010:20:100000000000000000000
2991123456:2:15241383936
2992-2:4:16
2993-2:5:-32
2994-3:3:-27
2995-3:4:81
2996-3:5:-243
2997
2998&length
2999100:3
300010:2
30011:1
30020:1
300312345:5
300410000000000000000:17
3005-123:3
3006215960156869840440586892398248:30
3007
3008&broot
3009# sqrt()
3010+0:2:0
3011+1:2:1
3012-1:2:NaN
3013# -$x ** (1/2) => -$y, but not in broot()
3014-123:2:NaN
3015+inf:2:inf
3016-inf:2:NaN
30172:2:1
3018-2:2:NaN
30194:2:2
30209:2:3
302116:2:4
3022100:2:10
3023123:2:11
302415241:2:123
3025144:2:12
302612:2:3
3027# invalid ones
30281:NaN:NaN
3029-1:NaN:NaN
30300:NaN:NaN
3031-inf:NaN:NaN
3032+inf:NaN:NaN
3033NaN:0:NaN
3034NaN:2:NaN
3035NaN:inf:NaN
3036NaN:inf:NaN
303712:-inf:NaN
303812:inf:NaN
3039+0:0:NaN
3040+1:0:NaN
3041-1:0:NaN
3042-2:0:NaN
3043-123.45:0:NaN
3044+inf:0:NaN
304512:1:12
3046-12:1:NaN
30478:-1:NaN
3048-8:-1:NaN
3049# cubic root
30508:3:2
3051-8:3:NaN
3052# fourths root
305316:4:2
305481:4:3
3055# 2 ** 64
305618446744073709551616:4:65536
305718446744073709551616:8:256
305818446744073709551616:16:16
305918446744073709551616:32:4
306018446744073709551616:64:2
306118446744073709551616:128:1
3062# 213 ** 15
306384274086103068221283760416414557757:15:213
3064
3065# see t/bigroot.t for more tests
3066&bsqrt
3067145:12
3068144:12
3069143:11
307016:4
3071170:13
3072169:13
3073168:12
30744:2
30753:1
30762:1
30779:3
307812:3
3079256:16
3080100000000:10000
30814000000000000:2000000
3082152399026:12345
3083152399025:12345
3084152399024:12344
3085# 2 ** 64 => 2 ** 32
308618446744073709551616:4294967296
308784274086103068221283760416414557757:290299993288095377
30881:1
30890:0
3090-2:NaN
3091-123:NaN
3092Nan:NaN
3093+inf:inf
3094-inf:NaN
3095
3096# see t/biglog.t for more tests
3097&bexp
3098NaN:NaN
3099inf:inf
31001:2
31012:7
3102
3103&batan2
3104NaN:1:10:NaN
3105NaN:NaN:10:NaN
31061:NaN:10:NaN
3107inf:1:14:1
3108-inf:1:14:-1
31090:-inf:14:3
3110-1:-inf:14:-3
31111:-inf:14:3
31120:inf:14:0
3113inf:-inf:14:2
3114-inf:-inf:14:-2
3115# +- 0.78....
3116inf:+inf:14:0
3117-inf:+inf:14:0
31181:5:13:0
31191:5:14:0
31200:0:10:0
31210:1:14:0
31220:2:14:0
31231:0:14:1
31245:0:14:1
3125-1:0:11:-1
3126-2:0:77:-1
31272:0:77:1
3128-1:5:14:0
31291:5:14:0
3130-1:8:14:0
31311:8:14:0
3132-1:1:14:0
3133
3134&bpi
313577:3
3136+0:3
313711:3
3138
3139# see t/bignok.t for more tests
3140&bnok
3141+inf:10:inf
3142NaN:NaN:NaN
3143NaN:1:NaN
31441:NaN:NaN
31451:1:1
3146# k > n
31471:2:0
31482:3:0
3149# k < 0
31501:-2:0
3151# 7 over 3 = 35
31527:3:35
31537:6:7
3154100:90:17310309456440
3155100:95:75287520
31562:0:1
31577:0:1
31582:1:2
3159
3160&bround
3161$round_mode("trunc")
31620:12:0
3163invalid:12:NaN
3164+inf:12:inf
3165-inf:12:-inf
31661234:0:1234
31671234:2:1200
3168123456:4:123400
3169123456:5:123450
3170123456:6:123456
3171+10123456789:5:10123000000
3172-10123456789:5:-10123000000
3173+10123456789:9:10123456700
3174-10123456789:9:-10123456700
3175+101234500:6:101234000
3176-101234500:6:-101234000
3177#+101234500:-4:101234000
3178#-101234500:-4:-101234000
3179$round_mode("zero")
3180+20123456789:5:20123000000
3181-20123456789:5:-20123000000
3182+20123456789:9:20123456800
3183-20123456789:9:-20123456800
3184+201234500:6:201234000
3185-201234500:6:-201234000
3186#+201234500:-4:201234000
3187#-201234500:-4:-201234000
3188+12345000:4:12340000
3189-12345000:4:-12340000
3190$round_mode("+inf")
3191+30123456789:5:30123000000
3192-30123456789:5:-30123000000
3193+30123456789:9:30123456800
3194-30123456789:9:-30123456800
3195+301234500:6:301235000
3196-301234500:6:-301234000
3197#+301234500:-4:301235000
3198#-301234500:-4:-301234000
3199+12345000:4:12350000
3200-12345000:4:-12340000
3201$round_mode("-inf")
3202+40123456789:5:40123000000
3203-40123456789:5:-40123000000
3204+40123456789:9:40123456800
3205-40123456789:9:-40123456800
3206+401234500:6:401234000
3207+401234500:6:401234000
3208#-401234500:-4:-401235000
3209#-401234500:-4:-401235000
3210+12345000:4:12340000
3211-12345000:4:-12350000
3212$round_mode("odd")
3213+50123456789:5:50123000000
3214-50123456789:5:-50123000000
3215+50123456789:9:50123456800
3216-50123456789:9:-50123456800
3217+501234500:6:501235000
3218-501234500:6:-501235000
3219#+501234500:-4:501235000
3220#-501234500:-4:-501235000
3221+12345000:4:12350000
3222-12345000:4:-12350000
3223$round_mode("even")
3224+60123456789:5:60123000000
3225-60123456789:5:-60123000000
3226+60123456789:9:60123456800
3227-60123456789:9:-60123456800
3228+601234500:6:601234000
3229-601234500:6:-601234000
3230#+601234500:-4:601234000
3231#-601234500:-4:-601234000
3232#-601234500:-9:0
3233#-501234500:-9:0
3234#-601234500:-8:0
3235#-501234500:-8:0
3236+1234567:7:1234567
3237+1234567:6:1234570
3238+12345000:4:12340000
3239-12345000:4:-12340000
3240$round_mode("common")
3241+60123456789:5:60123000000
3242+60123199999:5:60123000000
3243+60123299999:5:60123000000
3244+60123399999:5:60123000000
3245+60123499999:5:60123000000
3246+60123500000:5:60124000000
3247+60123600000:5:60124000000
3248+60123700000:5:60124000000
3249+60123800000:5:60124000000
3250+60123900000:5:60124000000
3251-60123456789:5:-60123000000
3252-60123199999:5:-60123000000
3253-60123299999:5:-60123000000
3254-60123399999:5:-60123000000
3255-60123499999:5:-60123000000
3256-60123500000:5:-60124000000
3257-60123600000:5:-60124000000
3258-60123700000:5:-60124000000
3259-60123800000:5:-60124000000
3260-60123900000:5:-60124000000
3261
3262&is_zero
32630:1
3264invalid:0
3265+inf:0
3266-inf:0
3267123:0
3268-1:0
32691:0
3270
3271&is_one
32720:0
3273invalid:0
3274+inf:0
3275-inf:0
32761:1
32772:0
3278-1:0
3279-2:0
3280
3281# floor, ceil, and int are pretty pointless in integer space, but play safe
3282&bfloor
32830:0
3284invalid:NaN
3285+inf:inf
3286-inf:-inf
3287-1:-1
3288-2:-2
32892:2
32903:3
3291abc:NaN
3292
3293&bceil
3294invalid:NaN
3295+inf:inf
3296-inf:-inf
32970:0
3298-1:-1
3299-2:-2
33002:2
33013:3
3302abc:NaN
3303
3304&bint
3305NaN:NaN
3306+inf:inf
3307-inf:-inf
33080:0
3309-1:-1
3310-2:-2
33112:2
33123:3
3313
3314&as_hex
3315128:0x80
3316-128:-0x80
33170:0x0
3318-0:0x0
33191:0x1
33200x123456789123456789:0x123456789123456789
3321+inf:inf
3322-inf:-inf
3323invalid:NaN
3324
3325&as_bin
3326128:0b10000000
3327-128:-0b10000000
33280:0b0
3329-0:0b0
33301:0b1
33310b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
33320x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
3333+inf:inf
3334-inf:-inf
3335invalid:NaN
3336
3337&as_oct
3338128:0200
3339-128:-0200
33400:00
3341-0:00
33421:01
33430b1010111101010101010110110110110110101:01275252666665
33440x123456789123456789:044321263611044321263611
3345+inf:inf
3346-inf:-inf
3347invalid:NaN
3348
3349&to_hex
3350128:80
3351-128:-80
33520:0
3353-0:0
33541:1
33550x123456789123456789:123456789123456789
3356+inf:inf
3357-inf:-inf
3358invalid:NaN
3359
3360&to_bin
3361128:10000000
3362-128:-10000000
33630:0
3364-0:0
33651:1
33660b1010111101010101010110110110110110101:1010111101010101010110110110110110101
33670x123456789123456789:100100011010001010110011110001001000100100011010001010110011110001001
3368+inf:inf
3369-inf:-inf
3370invalid:NaN
3371
3372&to_oct
3373128:200
3374-128:-200
33750:0
3376-0:0
33771:1
33780b1010111101010101010110110110110110101:1275252666665
33790x123456789123456789:44321263611044321263611
3380+inf:inf
3381-inf:-inf
3382invalid:NaN
3383
3384# overloaded functions
3385&log
3386-1:NaN
33870:-inf
33881:0
33892:0
33903:1
3391123456789:18
33921234567890987654321:41
3393-inf:inf
3394inf:inf
3395NaN:NaN
3396
3397&exp
3398
3399&sin
3400
3401&cos
3402
3403&atan2
3404
3405&int
3406
3407&neg
3408
3409&abs
3410
3411&sqrt
3412