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)$/) { 81 $try .= " \$x->$f();"; 82 } elsif ($f =~ /^b[dt]?fac$/) { 83 $try .= " \$x->$f();"; 84 } elsif ($f =~ /^(numify|length|stringify)$/) { 85 $try .= " \$x->$f();"; 86 } elsif ($f =~ /^(to|as)_(hex|oct|bin)$/) { 87 $try .= " \$x->$f();"; 88 # overloaded functions 89 } elsif ($f =~ /^(log|exp|sin|cos|atan2|int|neg|abs|sqrt)$/) { 90 $try .= " \$x = $f(\$x);"; 91 } elsif ($f eq "parts") { 92 $try .= ' ($m, $e) = $x->parts();'; 93 # ->bstr() to see if an object is returned 94 $try .= ' $m = $m->bstr(); $m = "NaN" if !defined $m;'; 95 $try .= ' $e = $e->bstr(); $e = "NaN" if !defined $e;'; 96 $try .= ' "$m,$e";'; 97 } elsif ($f eq "exponent") { 98 # ->bstr() to see if an object is returned 99 $try .= ' $x = $x->exponent()->bstr();'; 100 } elsif ($f eq "mantissa") { 101 # ->bstr() to see if an object is returned 102 $try .= ' $x = $x->mantissa()->bstr();'; 103 } elsif ($f eq "bpi") { 104 $try .= " $CLASS\->bpi(\$x);"; 105 } else { 106 # binary operators 107 $try .= qq| \$y = $CLASS->new("$args[1]");|; 108 if ($f eq "bcmp") { 109 $try .= ' $x->bcmp($y);'; 110 } elsif ($f eq "bround") { 111 $try .= " $round_mode; \$x->bround(\$y);"; 112 } elsif ($f eq "bacmp") { 113 $try .= ' $x->bacmp($y);'; 114 } elsif ($f eq "badd") { 115 $try .= ' $x->badd($y);'; 116 } elsif ($f eq "bsub") { 117 $try .= ' $x->bsub($y);'; 118 } elsif ($f eq "bmul") { 119 $try .= ' $x->bmul($y);'; 120 } elsif ($f eq "bdiv") { 121 $try .= ' $x->bdiv($y);'; 122 } elsif ($f eq "bdiv-list") { 123 $try .= ' join(",", $x->bdiv($y));'; 124 } elsif ($f eq "btdiv") { 125 $try .= ' $x->btdiv($y);'; 126 } elsif ($f eq "btdiv-list") { 127 $try .= ' join (",", $x->btdiv($y));'; 128 # overload via x= 129 } elsif ($f =~ /^.=$/) { 130 $try .= " \$x $f \$y;"; 131 # overload via x 132 } elsif ($f =~ /^.$/) { 133 $try .= " \$x $f \$y;"; 134 } elsif ($f eq "bmod") { 135 $try .= ' $x % $y;'; 136 } elsif ($f eq "bgcd") { 137 if (defined $args[2]) { 138 $try .= qq| \$z = $CLASS->new("$args[2]");|; 139 } 140 $try .= " $CLASS->bgcd(\$x, \$y"; 141 $try .= ", \$z" if defined $args[2]; 142 $try .= ");"; 143 } elsif ($f eq "blcm") { 144 if (defined $args[2]) { 145 $try .= qq| \$z = $CLASS->new("$args[2]");|; 146 } 147 $try .= " $CLASS->blcm(\$x, \$y"; 148 $try .= ", \$z" if defined $args[2]; 149 $try .= ");"; 150 } elsif ($f eq "blsft") { 151 if (defined $args[2]) { 152 $try .= " \$x->blsft(\$y, $args[2]);"; 153 } else { 154 $try .= " \$x << \$y;"; 155 } 156 } elsif ($f eq "brsft") { 157 if (defined $args[2]) { 158 $try .= " \$x->brsft(\$y, $args[2]);"; 159 } else { 160 $try .= " \$x >> \$y;"; 161 } 162 } elsif ($f eq "bnok") { 163 $try .= " \$x->bnok(\$y);"; 164 } elsif ($f eq "bmfac") { 165 $try .= " \$x->bmfac(\$y);"; 166 } elsif ($f eq "broot") { 167 $try .= " \$x->broot(\$y);"; 168 } elsif ($f eq "blog") { 169 $try .= " \$x->blog(\$y);"; 170 } elsif ($f eq "band") { 171 $try .= " \$x & \$y;"; 172 } elsif ($f eq "bior") { 173 $try .= " \$x | \$y;"; 174 } elsif ($f eq "bxor") { 175 $try .= " \$x ^ \$y;"; 176 } elsif ($f eq "bpow") { 177 $try .= " \$x ** \$y;"; 178 } elsif ( $f eq "bmodinv") { 179 $try .= " \$x->bmodinv(\$y);"; 180 } elsif ($f eq "digit") { 181 $try .= " \$x->digit(\$y);"; 182 } elsif ($f eq "batan2") { 183 $try .= " \$x->batan2(\$y);"; 184 } else { 185 # Functions with three arguments 186 $try .= qq| \$z = $CLASS->new("$args[2]");|; 187 188 if ( $f eq "bmodpow") { 189 $try .= " \$x->bmodpow(\$y, \$z);"; 190 } elsif ($f eq "bmuladd") { 191 $try .= " \$x->bmuladd(\$y, \$z);"; 192 } else { 193 warn "Unknown op '$f'"; 194 } 195 } 196 } # end else all other ops 197 198 $got = eval $try; 199 print "# Error: $@\n" if $@; 200 201 # convert hex/binary targets to decimal 202 if ($want =~ /^(0x0x|0b0b)/) { 203 $want =~ s/^0[xb]//; 204 $want = Math::BigInt->new($want)->bstr(); 205 } 206 if ($want eq "") { 207 is($got, undef, $try); 208 } else { 209 # print "try: $try ans: $got $want\n"; 210 is($got, $want, $try); 211 is(ref($got), $expected_class, 212 qq|output is a "$expected_class" object|) 213 if $expected_class ne $CLASS; 214 } 215 # check internal state of number objects 216 is_valid($got, $f) if ref $got; 217} # end while data tests 218close DATA; 219 220# test whether self-multiplication works correctly (result is 2**64) 221$try = qq|\$x = $CLASS->new("4294967296");|; 222$try .= ' $a = $x->bmul($x);'; 223$got = eval $try; 224is($got, $CLASS->new(2) ** 64, $try); 225 226# test self-pow 227$try = qq|\$x = $CLASS->new(10);|; 228$try .= ' $a = $x->bpow($x);'; 229$got = eval $try; 230is($got, $CLASS->new(10) ** 10, $try); 231 232############################################################################### 233# test whether op destroys args or not (should better not) 234 235$x = $CLASS->new(3); 236$y = $CLASS->new(4); 237$z = $x & $y; 238is($x, 3, '$z = $x & $y; $x'); 239is($y, 4, '$z = $x & $y; $y'); 240is($z, 0, '$z = $x & $y; $z'); 241 242$z = $x | $y; 243is($x, 3, '$z = $x | $y; $x'); 244is($y, 4, '$z = $x | $y; $y'); 245is($z, 7, '$z = $x | $y; $z'); 246 247$x = $CLASS->new(1); 248$y = $CLASS->new(2); 249$z = $x | $y; 250is($x, 1, '$z = $x | $y; $x'); 251is($y, 2, '$z = $x | $y; $y'); 252is($z, 3, '$z = $x | $y; $z'); 253 254$x = $CLASS->new(5); 255$y = $CLASS->new(4); 256$z = $x ^ $y; 257is($x, 5, '$z = $x ^ $y; $x'); 258is($y, 4, '$z = $x ^ $y; $y'); 259is($z, 1, '$z = $x ^ $y; $z'); 260 261$x = $CLASS->new(-5); 262$y = -$x; 263is($x, -5, '$y = -$x; $x'); 264 265$x = $CLASS->new(-5); 266$y = abs($x); 267is($x, -5, '$y = abs($x); $x'); 268 269$x = $CLASS->new(8); 270$y = $CLASS->new(-1); 271$z = $CLASS->new(5033); 272my $u = $x->copy()->bmodpow($y, $z); 273is($u, 4404, '$x->copy()->bmodpow($y, $z); $u'); 274is($y, -1, '$x->copy()->bmodpow($y, $z); $y'); 275is($z, 5033, '$x->copy()->bmodpow($y, $z); $z'); 276 277$x = $CLASS->new(-5); 278$y = -$x; 279is($x, -5, '$y = -$x; $x'); 280is($y, 5, '$y = -$x; $y'); 281 282$x = $CLASS->new(-5); 283$y = $x->copy()->bneg(); 284is($x, -5, '$y = $x->copy()->bneg(); $x'); 285is($y, 5, '$y = $x->copy()->bneg(); $y'); 286 287$x = $CLASS->new(-5); 288$y = $CLASS->new(3); 289$x->bmul($y); 290is($x, -15, '$x->bmul($y); $x'); 291is($y, 3, '$x->bmul($y); $y'); 292 293$x = $CLASS->new(-5); 294$y = $CLASS->new(3); 295$x->badd($y); 296is($x, -2, '$x->badd($y); $x'); 297is($y, 3, '$x->badd($y); $y'); 298 299$x = $CLASS->new(-5); 300$y = $CLASS->new(3); 301$x->bsub($y); 302is($x, -8, '$x->bsub($y); $x'); 303is($y, 3, '$x->bsub($y); $y'); 304 305$x = $CLASS->new(-15); 306$y = $CLASS->new(3); 307$x->bdiv($y); 308is($x, -5, '$x->bdiv($y); $x'); 309is($y, 3, '$x->bdiv($y); $y'); 310 311$x = $CLASS->new(-5); 312$y = $CLASS->new(3); 313$x->bmod($y); 314is($x, 1, '$x->bmod($y); $x'); 315is($y, 3, '$x->bmod($y); $y'); 316 317$x = $CLASS->new(5); 318$y = $CLASS->new(3); 319$x->bmul($y); 320is($x, 15, '$x->bmul($y); $x'); 321is($y, 3, '$x->bmul($y); $y'); 322 323$x = $CLASS->new(5); 324$y = $CLASS->new(3); 325$x->badd($y); 326is($x, 8, '$x->badd($y); $x'); 327is($y, 3, '$x->badd($y); $y'); 328 329$x = $CLASS->new(5); 330$y = $CLASS->new(3); 331$x->bsub($y); 332is($x, 2, '$x->bsub($y); $x'); 333is($y, 3, '$x->bsub($y); $y'); 334 335$x = $CLASS->new(15); 336$y = $CLASS->new(3); 337$x->bdiv($y); 338is($x, 5, '$x->bdiv($y); $x'); 339is($y, 3, '$x->bdiv($y); $y'); 340 341$x = $CLASS->new(5); 342$y = $CLASS->new(3); 343$x->bmod($y); 344is($x, 2, '$x->bmod($y); $x'); 345is($y, 3, '$x->bmod($y); $y'); 346 347$x = $CLASS->new(5); 348$y = $CLASS->new(-3); 349$x->bmul($y); 350is($x, -15, '$x->bmul($y); $x'); 351is($y, -3, '$x->bmul($y); $y'); 352 353$x = $CLASS->new(5); 354$y = $CLASS->new(-3); 355$x->badd($y); 356is($x, 2, '$x->badd($y); $x'); 357is($y, -3, '$x->badd($y); $y'); 358 359$x = $CLASS->new(5); 360$y = $CLASS->new(-3); 361$x->bsub($y); 362is($x, 8, '$x->bsub($y); $x'); 363is($y, -3, '$x->bsub($y); $y'); 364 365$x = $CLASS->new(15); 366$y = $CLASS->new(-3); 367$x->bdiv($y); 368is($x, -5, '$x->bdiv($y); $x'); 369is($y, -3, '$x->bdiv($y); $y'); 370 371$x = $CLASS->new(5); 372$y = $CLASS->new(-3); 373$x->bmod($y); 374is($x, -1, '$x->bmod($y); $x'); 375is($y, -3, '$x->bmod($y); $y'); 376 377############################################################################### 378# check whether overloading cmp works 379$try = '$x = $CLASS->new(0);'; 380$try .= ' $y = 10;'; 381$try .= ' $x ne $y;'; 382$want = eval $try; 383ok($want, "overloading cmp works"); 384 385# We can't test for working cmpt with other objects here, we would need a dummy 386# object with stringify overload for this. See Math::String tests as example. 387 388############################################################################### 389# check reversed order of arguments 390 391$try = "\$x = $CLASS->new(10); \$x = 2 ** \$x; \$x == 1024;"; 392$want = eval $try; 393ok($want, $try); 394 395$try = "\$x = $CLASS->new(10); \$x = 2 * \$x; \$x == 20;"; 396$want = eval $try; 397ok($want, $try); 398 399$try = "\$x = $CLASS->new(10); \$x = 2 + \$x; \$x == 12;"; 400$want = eval $try; 401ok($want, $try); 402 403$try = "\$x = $CLASS\->new(10); \$x = 2 - \$x; \$x == -8;"; 404$want = eval $try; 405ok($want, $try); 406 407$try = "\$x = $CLASS\->new(10); \$x = 20 / \$x; \$x == 2;"; 408$want = eval $try; 409ok($want, $try); 410 411$try = "\$x = $CLASS\->new(3); \$x = 20 % \$x; \$x == 2;"; 412$want = eval $try; 413ok($want, $try); 414 415$try = "\$x = $CLASS\->new(7); \$x = 20 & \$x; \$x == 4;"; 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$try = "\$x = $CLASS\->new(7); \$x = 0x20 ^ \$x; \$x == 0x27;"; 424$want = eval $try; 425ok($want, $try); 426 427############################################################################### 428# check badd(4, 5) form 429 430$try = "\$x = $CLASS\->badd(4, 5); \$x == 9;"; 431$want = eval $try; 432ok($want, $try); 433 434############################################################################### 435# check undefs: NOT DONE YET 436 437############################################################################### 438# bool 439 440$x = $CLASS->new(1); 441if ($x) { 442 pass("\$x = $CLASS->new(1); \$x is true"); 443} else { 444 fail("\$x = $CLASS->new(1); \$x is true"); 445} 446 447$x = $CLASS->new(0); 448if (!$x) { 449 pass("\$x = $CLASS->new(0); !\$x is false"); 450} else { 451 fail("\$x = $CLASS->new(0); !\$x is false"); 452} 453 454############################################################################### 455# objectify() 456 457@args = Math::BigInt::objectify(2, 4, 5); 458is(scalar(@args), 3, "objectify(2, 4, 5) gives $CLASS, 4, 5"); 459like($args[0], qr/^Math::BigInt/, "first arg matches /^Math::BigInt/"); 460is($args[1], 4, "second arg is 4"); 461is($args[2], 5, "third arg is 5"); 462 463@args = Math::BigInt::objectify(0, 4, 5); 464is(scalar(@args), 3, "objectify(0, 4, 5) gives $CLASS, 4, 5"); 465like($args[0], qr/^Math::BigInt/, "first arg matches /^Math::BigInt/"); 466is($args[1], 4, "second arg is 4"); 467is($args[2], 5, "third arg is 5"); 468 469@args = Math::BigInt::objectify(2, 4, 5); 470is(scalar(@args), 3, "objectify(2, 4, 5) gives $CLASS, 4, 5"); 471like($args[0], qr/^Math::BigInt/, "first arg matches /^Math::BigInt/"); 472is($args[1], 4, "second arg is 4"); 473is($args[2], 5, "third arg is 5"); 474 475@args = Math::BigInt::objectify(2, 4, 5, 6, 7); 476is(scalar(@args), 5, 477 "objectify(2, 4, 5, 6, 7) gives $CLASS, 4, 5, 6, 7"); 478like($args[0], qr/^Math::BigInt/, "first arg matches /^Math::BigInt/"); 479is($args[1], 4, "second arg is 4"); 480is(ref($args[1]), $args[0], "second arg is a $args[0] object"); 481is($args[2], 5, "third arg is 5"); 482is(ref($args[2]), $args[0], "third arg is a $args[0] object"); 483is($args[3], 6, "fourth arg is 6"); 484is(ref($args[3]), '', "fourth arg is a scalar"); 485is($args[4], 7, "fifth arg is 7"); 486is(ref($args[4]), '', "fifth arg is a scalar"); 487 488@args = Math::BigInt::objectify(2, $CLASS, 4, 5, 6, 7); 489is(scalar(@args), 5, 490 "objectify(2, $CLASS, 4, 5, 6, 7) gives $CLASS, 4, 5, 6, 7"); 491is($args[0], $CLASS, "first arg is $CLASS"); 492is($args[1], 4, "second arg is 4"); 493is(ref($args[1]), $args[0], "second arg is a $args[0] object"); 494is($args[2], 5, "third arg is 5"); 495is(ref($args[2]), $args[0], "third arg is a $args[0] object"); 496is($args[3], 6, "fourth arg is 6"); 497is(ref($args[3]), '', "fourth arg is a scalar"); 498is($args[4], 7, "fifth arg is 7"); 499is(ref($args[4]), '', "fifth arg is a scalar"); 500 501############################################################################### 502# test whether an opp calls objectify properly or not (or at least does what 503# it should do given non-objects, w/ or w/o objectify()) 504 505is($CLASS->new(123)->badd(123), 246, 506 qq|$CLASS->new(123)->badd(123) = 246|);; 507is($CLASS->badd(123, 321), 444, 508 qq|$CLASS->badd(123, 321) = 444|);; 509is($CLASS->badd(123, $CLASS->new(321)), 444, 510 qq|$CLASS->badd(123, $CLASS->new(321)) = 444|);; 511 512is($CLASS->new(123)->bsub(122), 1, 513 qq|$CLASS->new(123)->bsub(122) = 1|);; 514is($CLASS->bsub(321, 123), 198, 515 qq|$CLASS->bsub(321, 123) = 198|);; 516is($CLASS->bsub(321, $CLASS->new(123)), 198, 517 qq|$CLASS->bsub(321, $CLASS->new(123)) = 198|);; 518 519is($CLASS->new(123)->bmul(123), 15129, 520 qq|$CLASS->new(123)->bmul(123) = 15129|);; 521is($CLASS->bmul(123, 123), 15129, 522 qq|$CLASS->bmul(123, 123) = 15129|);; 523is($CLASS->bmul(123, $CLASS->new(123)), 15129, 524 qq|$CLASS->bmul(123, $CLASS->new(123)) = 15129|);; 525 526is($CLASS->new(15129)->bdiv(123), 123, 527 qq|$CLASS->new(15129)->bdiv(123) = 123|);; 528is($CLASS->bdiv(15129, 123), 123, 529 qq|$CLASS->bdiv(15129, 123) = 123|);; 530is($CLASS->bdiv(15129, $CLASS->new(123)), 123, 531 qq|$CLASS->bdiv(15129, $CLASS->new(123)) = 123|);; 532 533is($CLASS->new(15131)->bmod(123), 2, 534 qq|$CLASS->new(15131)->bmod(123) = 2|);; 535is($CLASS->bmod(15131, 123), 2, 536 qq|$CLASS->bmod(15131, 123) = 2|);; 537is($CLASS->bmod(15131, $CLASS->new(123)), 2, 538 qq|$CLASS->bmod(15131, $CLASS->new(123)) = 2|);; 539 540is($CLASS->new(2)->bpow(16), 65536, 541 qq|$CLASS->new(2)->bpow(16) = 65536|);; 542is($CLASS->bpow(2, 16), 65536, 543 qq|$CLASS->bpow(2, 16) = 65536|);; 544is($CLASS->bpow(2, $CLASS->new(16)), 65536, 545 qq|$CLASS->bpow(2, $CLASS->new(16)) = 65536|);; 546 547is($CLASS->new(2**15)->brsft(1), 2**14, 548 qq|$CLASS->new(2**15)->brsft(1) = 2**14|);; 549is($CLASS->brsft(2**15, 1), 2**14, 550 qq|$CLASS->brsft(2**15, 1) = 2**14|);; 551is($CLASS->brsft(2**15, $CLASS->new(1)), 2**14, 552 qq|$CLASS->brsft(2**15, $CLASS->new(1)) = 2**14|);; 553 554is($CLASS->new(2**13)->blsft(1), 2**14, 555 qq|$CLASS->new(2**13)->blsft(1) = 2**14|);; 556is($CLASS->blsft(2**13, 1), 2**14, 557 qq|$CLASS->blsft(2**13, 1) = 2**14|);; 558is($CLASS->blsft(2**13, $CLASS->new(1)), 2**14, 559 qq|$CLASS->blsft(2**13, $CLASS->new(1)) = 2**14|);; 560 561############################################################################### 562# test for floating-point input (other tests in bnorm() below) 563 564$z = 1050000000000000; # may be int on systems with 64bit? 565$x = $CLASS->new($z); 566is($x->bsstr(), '105e+13', # not 1.05e+15 567 qq|\$x = $CLASS->new($z); \$x->bsstr() = "105e+13"|); 568$z = 1e+129; # definitely a float (may fail on UTS) 569# don't compare to $z, since some Perl versions stringify $z into something 570# like '1.e+129' or something equally ugly 571SKIP:{ 572 my $vax_float = (pack("d", 1) =~ /^[\x80\x10]\x40/); 573 skip("vax float range smaller", 1) if $vax_float; 574 $x = $CLASS->new($z); 575 is($x -> bsstr(), '1e+129', 576 qq|\$x = $CLASS->new($z); \$x->bsstr() = "1e+129"|); 577} 578 579############################################################################### 580# test for whitespace including newlines to be handled correctly 581 582# is($Math::BigInt::strict, 1); # the default 583 584foreach my $c (qw/1 12 123 1234 12345 123456 1234567 585 12345678 123456789 1234567890/) 586{ 587 my $m = $CLASS->new($c); 588 is($CLASS->new("$c"), $m, qq|$CLASS->new("$c") = $m|); 589 is($CLASS->new(" $c"), $m, qq|$CLASS->new(" $c") = $m|); 590 is($CLASS->new("$c "), $m, qq|$CLASS->new("$c ") = $m|); 591 is($CLASS->new(" $c "), $m, qq|$CLASS->new(" $c ") = $m|); 592 is($CLASS->new("\n$c"), $m, qq|$CLASS->new("\\n$c") = $m|); 593 is($CLASS->new("$c\n"), $m, qq|$CLASS->new("$c\\n") = $m|); 594 is($CLASS->new("\n$c\n"), $m, qq|$CLASS->new("\\n$c\\n") = $m|); 595 is($CLASS->new(" \n$c\n"), $m, qq|$CLASS->new(" \\n$c\\n") = $m|); 596 is($CLASS->new(" \n$c \n"), $m, qq|$CLASS->new(" \\n$c \\n") = $m|); 597 is($CLASS->new(" \n$c\n "), $m, qq|$CLASS->new(" \\n$c\\n ") = $m|); 598 is($CLASS->new(" \n$c\n1"), 'NaN', qq|$CLASS->new(" \\n$c\\n1") = 'NaN'|); 599 is($CLASS->new("1 \n$c\n1"), 'NaN', qq|$CLASS->new("1 \\n$c\\n1") = 'NaN'|); 600} 601 602############################################################################### 603# prime number tests, also test for **= and length() 604# found on: http://www.utm.edu/research/primes/notes/by_year.html 605 606# ((2^148)+1)/17 607$x = $CLASS->new(2); 608$x **= 148; 609$x++; 610$x = $x / 17; 611is($x, "20988936657440586486151264256610222593863921", 612 "value of ((2^148)+1)/17"); 613is($x->length(), length("20988936657440586486151264256610222593863921"), 614 "number of digits in ((2^148)+1)/17"); 615 616# MM7 = 2^127-1 617$x = $CLASS->new(2); 618$x **= 127; 619$x--; 620is($x, "170141183460469231731687303715884105727", "value of 2^127-1"); 621 622$x = $CLASS->new('215960156869840440586892398248'); 623($x, $y) = $x->length(); 624is($x, 30, "number of digits in 2^127-1"); 625is($y, 0, "number of digits in fraction part of 2^127-1"); 626 627$x = $CLASS->new('1_000_000_000_000'); 628($x, $y) = $x->length(); 629is($x, 13, "number of digits in 1_000_000_000_000"); 630is($y, 0, "number of digits in fraction part of 1_000_000_000_000"); 631 632# test <<=, >>= 633$x = $CLASS->new('2'); 634$y = $CLASS->new('18'); 635is($x <<= $y, 2 << 18, "2 <<= 18 with $CLASS objects"); 636is($x, 2 << 18, "2 <<= 18 with $CLASS objects"); 637is($x >>= $y, 2, "2 >>= 18 with $CLASS objects"); 638is($x, 2, "2 >>= 18 with $CLASS objects"); 639 640# I am afraid the following is not yet possible due to slowness 641# Also, testing for 2 meg output is a bit hard ;) 642#$x = $CLASS->new(2); 643#$x **= 6972593; 644#$x--; 645 646# 593573509*2^332162+1 has exactly 1,000,000 digits 647# takes about 24 mins on 300 Mhz, so cannot be done yet ;) 648#$x = $CLASS->new(2); 649#$x **= 332162; 650#$x *= "593573509"; 651#$x++; 652#is($x->length(), 1_000_000); 653 654############################################################################### 655# inheritance and overriding of _swap 656 657$x = Math::Foo->new(5); 658$x = $x - 8; # 8 - 5 instead of 5-8 659is($x, 3, '$x = Math::Foo->new(5); $x = $x - 8; $x = 3'); 660is(ref($x), 'Math::Foo', '$x is an object of class "Math::Foo"'); 661 662$x = Math::Foo->new(5); 663$x = 8 - $x; # 5 - 8 instead of 8 - 5 664is($x, -3, '$x = Math::Foo->new(5); $x = 8 - $x; $x = -3'); 665is(ref($x), 'Math::Foo', '$x is an object of class "Math::Foo"'); 666 667############################################################################### 668# Test whether +inf eq inf 669# 670# This tried to test whether Math::BigInt inf equals Perl inf. Unfortunately, 671# Perl hasn't (before 5.7.3 at least) a consistent way to say inf, and some 672# things like 1e100000 crash on some platforms. So simple test for the string 673# 'inf'. 674 675$x = $CLASS->new('+inf'); 676is($x, 'inf', qq|$CLASS->new("+inf") = "inf"|); 677 678############################################################################### 679# numify() and 64 bit integer support 680 681require Config; 682SKIP: { 683 skip("no 64 bit integer support", 4) 684 if ! $Config::Config{use64bitint} || ! $Config::Config{use64bitall} 685 || "$]" < 5.007001; 686 687 # The following should not give "1.84467440737096e+19". 688 689 $x = $CLASS -> new(2) -> bpow(64) -> bdec(); 690 is($x -> bstr(), "18446744073709551615", "bigint 2**64-1 as string"); 691 is($x -> numify(), "18446744073709551615", "bigint 2**64-1 as number"); 692 693 # The following should not give "-9.22337203685478e+18". 694 695 $x = $CLASS -> new(2) -> bpow(63) -> bneg(); 696 is($x -> bstr(), "-9223372036854775808", "bigint -2**63 as string"); 697 is($x -> numify(), "-9223372036854775808", "bigint -2**63 as number"); 698}; 699 700############################################################################### 701############################################################################### 702# the following tests only make sense with Math::BigInt::Calc or BareCalc or 703# FastCalc 704 705SKIP: { 706 # skip GMP, Pari et al. 707 skip("skipping tests not intended for the backend $LIB", 50) 708 unless $LIB =~ /^Math::BigInt::(Bare|Fast)?Calc$/; 709 710 ########################################################################### 711 # check proper length of internal arrays 712 713 my $bl = $LIB->_base_len(); 714 my $BASE = '9' x $bl; 715 my $MAX = $BASE; 716 $BASE++; 717 718 # f.i. 9999 719 $x = $CLASS->new($MAX); 720 is_valid($x); 721 722 # 10000 723 $x += 1; 724 is($x, $BASE, "\$x == $BASE"); 725 is_valid($x); 726 727 # 9999 again 728 $x -= 1; 729 is($x, $MAX, "\$x == $MAX"); 730 is_valid($x); 731 732 ########################################################################### 733 # check numify 734 735 $x = $CLASS->new($BASE-1); 736 is($x->numify(), $BASE-1, q|$x->numify() = $BASE-1|); 737 738 $x = $CLASS->new(-($BASE-1)); 739 is($x->numify(), -($BASE-1), q|$x->numify() = -($BASE-1)|); 740 741 # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaarglburbll...) 742 $x = $CLASS->new($BASE); 743 is($x->numify()+0, $BASE+0, q|$x->numify()+0 = $BASE+0|); 744 745 $x = $CLASS->new(-$BASE); 746 is($x->numify(), -$BASE, q|$x->numify() = -$BASE|); 747 748 $x = $CLASS->new(-($BASE*$BASE*1+$BASE*1+1)); 749 is($x->numify(), -($BASE*$BASE*1+$BASE*1+1), 750 q|$x->numify() = -($BASE*$BASE*1+$BASE*1+1))|); 751 752 ########################################################################### 753 # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead 754 # of 1 755 756 $x = $CLASS->new($BASE - 2); 757 $x++; 758 $x++; 759 $x++; 760 $x++; 761 ok($x > $BASE, '$x > $BASE'); 762 763 $x = $CLASS->new($BASE + 3); 764 $x++; 765 ok($x > $BASE, '$x > $BASE'); 766 767 # test for +0 instead of int(): 768 $x = $CLASS->new($MAX); 769 is($x->length(), length($MAX), q|$x->length() = length($MAX)|); 770 771 ########################################################################### 772 # test bug that $CLASS->digit($string) did not work 773 774 is($CLASS->digit(123, 2), 1, qq|$CLASS->digit(123, 2) = 1|); 775 776 ########################################################################### 777 # bug in sub where number with at least 6 trailing zeros after any op failed 778 779 $x = $CLASS->new(123456); 780 $z = $CLASS->new(10000); 781 $z *= 10; 782 $x -= $z; 783 is($z, 100000, "testing bug in sub"); 784 is($x, 23456, "testing bug in sub"); 785 786 ########################################################################### 787 # bug in shortcut in mul() 788 789 # construct a number with a zero-hole of BASE_LEN_SMALL 790 { 791 my @bl = $LIB->_base_len(); 792 my $bl = $bl[5]; 793 794 # Compute the value. 795 $x = ('1' x $bl) . ('0' x $bl) . ('1' x $bl) . ('0' x $bl); 796 $y = '1' x (2 * $bl); 797 $x = $CLASS->new($x)->bmul($y); 798 799 # Build the expected output. 800 $y = ''; 801 if ($bl >= 2) { 802 $y .= '123456790' x int(($bl - 2) / 9); 803 $y .= substr '123456790', 0, ($bl - 2) % 9; 804 $y .= ($bl - 1) % 9; 805 } 806 $y .= ((($bl - 1) % 9) + 1) x ($bl * 3); 807 if ($bl >= 2) { 808 $y .= substr '098765432', -(($bl - 1) % 9); 809 $y .= '098765432' x int(($bl - 2) / 9); 810 } 811 $y .= '1'; 812 $y .= '0' x $bl; 813 814 is($x, $y, "testing number with a zero-hole of BASE_LEN_SMALL"); 815 816 ######################################################################### 817 # see if mul shortcut for small numbers works 818 819 $x = '9' x $bl; 820 $x = $CLASS->new($x); 821 # 999 * 999 => 998 . 001 822 # 9999 * 9999 => 9998 . 0001 823 $y = '9' x ($bl - 1) . '8' . '0' x ($bl - 1) . '1'; 824 is($x * $x, $y, 825 "see if mul shortcut for small numbers works ($x * $x = $y)"); 826 } 827 828 ########################################################################### 829 # bug with rest "-0" in div, causing further div()s to fail 830 831 $x = $CLASS->new('-322056000'); 832 ($x, $y) = $x->bdiv('-12882240'); 833 834 is($y, '0', '-322056000 / -12882240 has remainder 0'); 835 is_valid($y); # $y not '-0' 836 837 ########################################################################### 838 # bug in $x->bmod($y) 839 840 # if $x < 0 and $y > 0 841 $x = $CLASS->new('-629'); 842 is($x->bmod(5033), 4404, q|$x->bmod(5033) = 4404|); 843 844 ########################################################################### 845 # bone/binf etc as plain calls (Lite failed them) 846 847 is($CLASS->bzero(), 0, qq|$CLASS->bzero() = 0|); 848 is($CLASS->bone(), 1, qq|$CLASS->bone() = 1|); 849 is($CLASS->bone("+"), 1, qq|$CLASS->bone("+") = 1|); 850 is($CLASS->bone("-"), -1, qq|$CLASS->bone("-") = -1|); 851 is($CLASS->bnan(), "NaN", qq|$CLASS->bnan() = "NaN"|); 852 is($CLASS->binf(), "inf", qq|$CLASS->binf() = "inf"|); 853 is($CLASS->binf("+"), "inf", qq|$CLASS->binf("+") = "inf"|); 854 is($CLASS->binf("-"), "-inf", qq|$CLASS->binf("-") = "-inf"|); 855 is($CLASS->binf("-inf"), "-inf", qq|$CLASS->binf("-inf") = "-inf"|); 856 857 ########################################################################### 858 # is_one("-") 859 860 is($CLASS->new(1)->is_one("-"), 0, qq|$CLASS->new(1)->is_one("-") = 0|); 861 is($CLASS->new(-1)->is_one("-"), 1, qq|$CLASS->new(-1)->is_one("-") = 1|); 862 is($CLASS->new(1)->is_one(), 1, qq|$CLASS->new(1)->is_one() = 1|); 863 is($CLASS->new(-1)->is_one(), 0, qq|$CLASS->new(-1)->is_one() = 0|); 864 865 ########################################################################### 866 # [perl #30609] bug with $x -= $x not being 0, but 2*$x 867 868 $x = $CLASS->new(3); 869 $x -= $x; 870 is($x, 0, qq|\$x = $CLASS->new(3); \$x -= \$x; = 0|); 871 872 $x = $CLASS->new(-3); 873 $x -= $x; 874 is($x, 0, qq|\$x = $CLASS->new(-3); \$x -= \$x; = 0|); 875 876 $x = $CLASS->new("NaN"); 877 $x -= $x; 878 is($x->is_nan(), 1, 879 qq|\$x = $CLASS->new("NaN"); \$x -= \$x; \$x->is_nan() = 1|); 880 881 $x = $CLASS->new("inf"); 882 $x -= $x; 883 is($x->is_nan(), 1, 884 qq|\$x = $CLASS->new("inf"); \$x -= \$x; \$x->is_nan() = 1|); 885 886 $x = $CLASS->new("-inf"); 887 $x -= $x; 888 is($x->is_nan(), 1, 889 qq|\$x = $CLASS->new("-inf"); \$x -= \$x; \$x->is_nan() = 1|); 890 891 $x = $CLASS->new("NaN"); 892 $x += $x; 893 is($x->is_nan(), 1, 894 qq|\$x = $CLASS->new("NaN"); \$x += \$x; \$x->is_nan() = 1|); 895 896 $x = $CLASS->new("inf"); 897 $x += $x; 898 is($x->is_inf(), 1, 899 qq|\$x = $CLASS->new("inf"); \$x += \$x; \$x->is_inf() = 1|); 900 901 $x = $CLASS->new("-inf"); 902 $x += $x; 903 is($x->is_inf("-"), 1, 904 qq|\$x = $CLASS->new("-inf"); \$x += \$x; \$x->is_inf("-") = 1|); 905 906 $x = $CLASS->new(3); 907 $x += $x; 908 is($x, 6, qq|\$x = $CLASS->new(3); \$x += \$x; \$x = 6|); 909 910 $x = $CLASS->new(-3); 911 $x += $x; 912 is($x, -6, qq|\$x = $CLASS->new(-3); \$x += \$x; \$x = -6|); 913 914 $x = $CLASS->new(3); 915 $x *= $x; 916 is($x, 9, qq|\$x = $CLASS->new(3); \$x *= \$x; \$x = 9|); 917 918 $x = $CLASS->new(-3); 919 $x *= $x; 920 is($x, 9, qq|\$x = $CLASS->new(-3); \$x *= \$x; \$x = 9|); 921 922 $x = $CLASS->new(3); 923 $x /= $x; 924 is($x, 1, qq|\$x = $CLASS->new(3); \$x /= \$x; \$x = 1|); 925 926 $x = $CLASS->new(-3); 927 $x /= $x; 928 is($x, 1, qq|\$x = $CLASS->new(-3); \$x /= \$x; \$x = 1|); 929 930 $x = $CLASS->new(3); 931 $x %= $x; 932 is($x, 0, qq|\$x = $CLASS->new(3); \$x %= \$x; \$x = 0|); 933 934 $x = $CLASS->new(-3); 935 $x %= $x; 936 is($x, 0, qq|\$x = $CLASS->new(-3); \$x %= \$x; \$x = 0|); 937} 938 939############################################################################### 940# all tests done 941 9421; 943 944############################################################################### 945# sub to check validity of a Math::BigInt internally, to ensure that no op 946# leaves a number object in an invalid state (f.i. "-0") 947 948sub is_valid { 949 my ($x, $f) = @_; 950 951 my $e = 0; # error? 952 953 # allow the check to pass for all Lite, and all MBI and subclasses 954 # ok as reference? 955 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/; 956 957 if (ref($x) ne 'Math::BigInt::Lite') { 958 # has ok sign? 959 $e = qq|Illegal sign $x->{sign}| 960 . qq| (expected: "+", "-", "-inf", "+inf" or "NaN"| 961 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/; 962 963 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0; 964 $e = $LIB->_check($x->{value}) if $e eq '0'; 965 } 966 967 # test done, see if error did crop up 968 if ($e eq '0') { 969 pass('is a valid object'); 970 return; 971 } 972 973 fail($e . " after op '$f'"); 974} 975 976__DATA__ 977 978&.= 9791234:-345:1234-345 980 981&+= 9821:2:3 983-1:-2:-3 984 985&-= 9861:2:-1 987-1:-2:1 988 989&*= 9902:3:6 991-1:5:-5 992 993&%= 994100:3:1 9958:9:8 996-629:5033:4404 997 998&/= 999100:3:33 1000-8:2:-4 1001 1002&|= 10032:1:3 1004 1005&&= 10065:7:5 1007 1008&^= 10095:7:2 1010 1011&blog 1012# 1013invalid:2:NaN 1014122:invalid:NaN 1015invalid:invalid:NaN 1016# 1017122:inf:0 1018inf:122:inf 1019122:-inf:0 1020-inf:122:inf 1021-inf:-inf:NaN 10220:4:-inf 1023-21:4:NaN 102421:-21:NaN 1025# 10260:-inf:NaN 10270:-1:NaN 10280:0:NaN 10290:1:NaN 10300:inf:NaN 1031# 10321:-inf:0 10331:-1:0 10341:0:0 10351:1:NaN 10361:4:0 10371:inf:0 1038# 1039inf:-inf:NaN 1040inf:-1:NaN 1041inf:0:NaN 1042inf:1:NaN 1043inf:4:inf 1044inf:inf:NaN 1045# 1046# normal results 10471024:2:10 104881:3:4 1049# 3.01.. truncate 105082:3:4 1051# 3.9... truncate 105280:3:3 10534096:2:12 105415625:5:6 105515626:5:6 105615624:5:5 10571000:10:3 105810000:10:4 1059100000:10:5 10601000000:10:6 106110000000:10:7 1062100000000:10:8 10638916100448256:12:12 10648916100448257:12:12 10658916100448255:12:11 10662251799813685248:8:17 106772057594037927936:2:56 1068144115188075855872:2:57 1069288230376151711744:2:58 1070576460752303423488:2:59 10711329227995784915872903807060280344576:2:120 1072# $x == $base => result 1 10733:3:1 1074# $x < $base => result 0 ($base ** 0 <= $x) 10753:4:0 1076# $x == 1 => result 0 10771:5:0 1078 1079&is_negative 10800:0 1081-1:1 10821:0 1083+inf:0 1084-inf:1 1085invalid:0 1086 1087&is_positive 10880:0 1089-1:0 10901:1 1091+inf:1 1092-inf:0 1093invalid:0 1094 1095&is_non_negative 10960:1 1097-1:0 10981:1 1099+inf:1 1100-inf:0 1101NaN:0 1102 1103&is_non_positive 11040:1 1105-1:1 11061:0 1107+inf:0 1108-inf:1 1109NaN:0 1110 1111&is_int 1112-inf:0 1113+inf:0 1114invalid:0 11151:1 11160:1 1117123e12:1 1118 1119&is_odd 1120abc:0 11210:0 11221:1 11233:1 1124-1:1 1125-3:1 112610000001:1 112710000002:0 11282:0 1129120:0 1130121:1 1131 1132&is_even 1133abc:0 11340:1 11351:0 11363:0 1137-1:0 1138-3:0 113910000001:0 114010000002:1 11412:1 1142120:1 1143121:0 1144 1145&bacmp 1146+0:-0:0 1147+0:+1:-1 1148-1:+1:0 1149+1:-1:0 1150-1:+2:-1 1151+2:-1:1 1152-123456789:+987654321:-1 1153+123456789:-987654321:-1 1154+987654321:+123456789:1 1155-987654321:+123456789:1 1156-123:+4567889:-1 1157# NaNs 1158invalid:123: 1159123:invalid: 1160invalid:invalid: 1161# infinity 1162+inf:+inf:0 1163-inf:-inf:0 1164+inf:-inf:0 1165-inf:+inf:0 1166+inf:123:1 1167-inf:123:1 1168+inf:-123:1 1169-inf:-123:1 1170123:-inf:-1 1171-123:inf:-1 1172-123:-inf:-1 1173123:inf:-1 1174# return undef 1175+inf:NaN: 1176NaN:inf: 1177-inf:NaN: 1178NaN:-inf: 1179 1180&bnorm 11810e999:0 11820e-999:0 1183-0e999:0 1184-0e-999:0 1185123:123 1186123.000:123 1187123e0:123 1188123e+0:123 1189123e-0:123 1190123.000e0:123 1191123.000e+0:123 1192123.000e-0:123 1193# binary input 11940babc:NaN 11950b123:NaN 11960b0:0 1197-0b0:0 1198-0b1:-1 11990b0001:1 12000b001:1 12010b011:3 12020b101:5 12030b1001:9 12040b10001:17 12050b100001:33 12060b1000001:65 12070b10000001:129 12080b100000001:257 12090b1000000001:513 12100b10000000001:1025 12110b100000000001:2049 12120b1000000000001:4097 12130b10000000000001:8193 12140b100000000000001:16385 12150b1000000000000001:32769 12160b10000000000000001:65537 12170b100000000000000001:131073 12180b1000000000000000001:262145 12190b10000000000000000001:524289 12200b100000000000000000001:1048577 12210b1000000000000000000001:2097153 12220b10000000000000000000001:4194305 12230b100000000000000000000001:8388609 12240b1000000000000000000000001:16777217 12250b10000000000000000000000001:33554433 12260b100000000000000000000000001:67108865 12270b1000000000000000000000000001:134217729 12280b10000000000000000000000000001:268435457 12290b100000000000000000000000000001:536870913 12300b1000000000000000000000000000001:1073741825 12310b10000000000000000000000000000001:2147483649 12320b100000000000000000000000000000001:4294967297 12330b1000000000000000000000000000000001:8589934593 12340b10000000000000000000000000000000001:17179869185 12350b1_0_1:5 12360b0_0_0_1:1 1237# hex input 1238-0x0:0 12390xabcdefgh:NaN 12400x1234:4660 12410xabcdef:11259375 1242-0xABCDEF:-11259375 1243-0x1234:-4660 12440x12345678:305419896 12450x1_2_3_4_56_78:305419896 12460xa_b_c_d_e_f:11259375 12470x9:9 12480x11:17 12490x21:33 12500x41:65 12510x81:129 12520x101:257 12530x201:513 12540x401:1025 12550x801:2049 12560x1001:4097 12570x2001:8193 12580x4001:16385 12590x8001:32769 12600x10001:65537 12610x20001:131073 12620x40001:262145 12630x80001:524289 12640x100001:1048577 12650x200001:2097153 12660x400001:4194305 12670x800001:8388609 12680x1000001:16777217 12690x2000001:33554433 12700x4000001:67108865 12710x8000001:134217729 12720x10000001:268435457 12730x20000001:536870913 12740x40000001:1073741825 12750x80000001:2147483649 12760x100000001:4294967297 12770x200000001:8589934593 12780x400000001:17179869185 12790x800000001:34359738369 1280# bug found by Mark Lakata in Calc.pm creating too big one-element numbers 1281# in _from_hex() 12820x2dd59e18a125dbed30a6ab1d93e9c855569f44f75806f0645dc9a2e98b808c3:1295719234436071846486578237372801883390756472611551858964079371952886122691 1283# inf input 1284inf:inf 1285+inf:inf 1286-inf:-inf 12870inf:NaN 1288# abnormal input 1289:NaN 1290abc:NaN 1291 1 a:NaN 12921bcd2:NaN 129311111b:NaN 1294+1z:NaN 1295-1z:NaN 1296# only one underscore between two digits 1297_123:NaN 1298_123_: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 14183::1 1419 1420&binf 14211:+:inf 14222:-:-inf 14233:+inf:inf 1424 1425&is_nan 1426123:0 1427abc:1 1428NaN:1 1429-123:0 1430 1431&is_inf 1432+inf::1 1433-inf::1 1434abc::0 14351::0 1436NaN::0 1437-1::0 1438+inf:-:0 1439+inf:+:1 1440-inf:-:1 1441-inf:+:0 1442-inf:-inf:1 1443-inf:+inf:0 1444+inf:-inf:0 1445+inf:+inf:1 1446+iNfInItY::1 1447-InFiNiTy::1 1448 1449&blsft 1450abc:abc:NaN 1451+2:+2:8 1452+1:+32:4294967296 1453+1:+48:281474976710656 1454+8:-2:2 1455# exercise base 10 1456+12345:4:10:123450000 1457-1234:0:10:-1234 1458+1234:0:10:1234 1459+2:2:10:200 1460+12:2:10:1200 1461+1234:-3:10:1 14621234567890123:12:10:1234567890123000000000000 1463-3:1:2:-6 1464-5:1:2:-10 1465-2:1:2:-4 1466-102533203:1:2:-205066406 1467 1468&brsft 1469abc:abc:NaN 1470+8:+2:2 1471+4294967296:+32:1 1472+281474976710656:+48:1 1473+2:-2:8 1474# exercise base 10 1475-1234:0:10:-1234 1476+1234:0:10:1234 1477+200:2:10:2 1478+1234:3:10:1 1479+1234:2:10:12 1480+1234:-3:10:1234000 1481310000:4:10:31 148212300000:5:10:123 14831230000000000:10:10:123 148409876123456789067890:12:10:9876123 14851234561234567890123:13:10:123456 1486820265627:1:2:410132813 1487# test shifting negative numbers in base 2 1488-15:1:2:-8 1489-14:1:2:-7 1490-13:1:2:-7 1491-12:1:2:-6 1492-11:1:2:-6 1493-10:1:2:-5 1494-9:1:2:-5 1495-8:1:2:-4 1496-7:1:2:-4 1497-6:1:2:-3 1498-5:1:2:-3 1499-4:1:2:-2 1500-3:1:2:-2 1501-2:1:2:-1 1502-1:1:2:-1 1503-1640531254:2:2:-410132814 1504-1640531254:1:2:-820265627 1505-820265627:1:2:-410132814 1506-205066405:1:2:-102533203 1507 1508&bsstr 1509+inf:inf 1510-inf:-inf 15111e+34:1e+34 1512123.456E3:123456e+0 1513100:1e+2 1514bsstrabc:NaN 1515-5:-5e+0 1516-100:-1e+2 1517 1518&numify 15195:5 1520-5:-5 1521100:100 1522-100:-100 1523 1524&bneg 1525invalid:NaN 1526+inf:-inf 1527-inf:inf 1528abd:NaN 15290:0 15301:-1 1531-1:1 1532+123456789:-123456789 1533-123456789:123456789 1534 1535&babs 1536invalid:NaN 1537+inf:inf 1538-inf:inf 15390:0 15401:1 1541-1:1 1542+123456789:123456789 1543-123456789:123456789 1544 1545&bsgn 1546NaN:NaN 1547+inf:1 1548-inf:-1 15490:0 1550+123456789:1 1551-123456789:-1 1552 1553&bcmp 1554invalid:invalid: 1555invalid:0: 15560:invalid: 15570:0:0 1558-1:0:-1 15590:-1:1 15601:0:1 15610:1:-1 1562-1:1:-1 15631:-1:1 1564-1:-1:0 15651:1:0 1566123:123:0 1567123:12:1 156812:123:-1 1569-123:-123:0 1570-123:-12:-1 1571-12:-123:1 1572123:124:-1 1573124:123:1 1574-123:-124:1 1575-124:-123:-1 1576100:5:1 1577-123456789:987654321:-1 1578+123456789:-987654321:1 1579-987654321:123456789:-1 1580-inf:5432112345:-1 1581+inf:5432112345:1 1582-inf:-5432112345:-1 1583+inf:-5432112345:1 1584+inf:+inf:0 1585-inf:-inf:0 1586+inf:-inf:1 1587-inf:+inf:-1 15885:inf:-1 15895:inf:-1 1590-5:-inf:1 1591-5:-inf:1 1592# return undef 1593+inf:NaN: 1594NaN:inf: 1595-inf:NaN: 1596NaN:-inf: 1597 1598&binc 1599abc:NaN 1600+inf:inf 1601-inf:-inf 1602+0:1 1603+1:2 1604-1:0 1605 1606&bdec 1607abc:NaN 1608+inf:inf 1609-inf:-inf 1610+0:-1 1611+1:0 1612-1:-2 1613 1614&badd 1615abc:abc:NaN 1616abc:0:NaN 1617+0:abc:NaN 1618+inf:-inf:NaN 1619-inf:+inf:NaN 1620+inf:+inf:inf 1621-inf:-inf:-inf 1622invalid:+inf:NaN 1623invalid:+inf:NaN 1624+inf:invalid:NaN 1625-inf:invalid:NaN 16260:0:0 16271:0:1 16280:1:1 16291:1:2 1630-1:0:-1 16310:-1:-1 1632-1:-1:-2 1633-1:+1:0 1634+1:-1:0 1635+9:+1:10 1636+99:+1:100 1637+999:+1:1000 1638+9999:+1:10000 1639+99999:+1:100000 1640+999999:+1:1000000 1641+9999999:+1:10000000 1642+99999999:+1:100000000 1643+999999999:+1:1000000000 1644+9999999999:+1:10000000000 1645+99999999999:+1:100000000000 1646+10:-1:9 1647+100:-1:99 1648+1000:-1:999 1649+10000:-1:9999 1650+100000:-1:99999 1651+1000000:-1:999999 1652+10000000:-1:9999999 1653+100000000:-1:99999999 1654+1000000000:-1:999999999 1655+10000000000:-1:9999999999 1656+123456789:987654321:1111111110 1657-123456789:987654321:864197532 1658-123456789:-987654321:-1111111110 1659+123456789:-987654321:-864197532 1660-1:10001:10000 1661-1:100001:100000 1662-1:1000001:1000000 1663-1:10000001:10000000 1664-1:100000001:100000000 1665-1:1000000001:1000000000 1666-1:10000000001:10000000000 1667-1:100000000001:100000000000 1668-1:1000000000001:1000000000000 1669-1:10000000000001:10000000000000 1670-1:-10001:-10002 1671-1:-100001:-100002 1672-1:-1000001:-1000002 1673-1:-10000001:-10000002 1674-1:-100000001:-100000002 1675-1:-1000000001:-1000000002 1676-1:-10000000001:-10000000002 1677-1:-100000000001:-100000000002 1678-1:-1000000000001:-1000000000002 1679-1:-10000000000001:-10000000000002 1680 1681&bsub 1682abc:abc:NaN 1683abc:+0:NaN 1684+0:abc:NaN 1685+inf:-inf:inf 1686-inf:+inf:-inf 1687+inf:+inf:NaN 1688-inf:-inf:NaN 1689+0:+0:0 1690+1:+0:1 1691+0:+1:-1 1692+1:+1:0 1693-1:+0:-1 1694+0:-1:1 1695-1:-1:0 1696-1:+1:-2 1697+1:-1:2 1698+9:+1:8 1699+99:+1:98 1700+999:+1:998 1701+9999:+1:9998 1702+99999:+1:99998 1703+999999:+1:999998 1704+9999999:+1:9999998 1705+99999999:+1:99999998 1706+999999999:+1:999999998 1707+9999999999:+1:9999999998 1708+99999999999:+1:99999999998 1709+10:-1:11 1710+100:-1:101 1711+1000:-1:1001 1712+10000:-1:10001 1713+100000:-1:100001 1714+1000000:-1:1000001 1715+10000000:-1:10000001 1716+100000000:-1:100000001 1717+1000000000:-1:1000000001 1718+10000000000:-1:10000000001 1719+123456789:+987654321:-864197532 1720-123456789:+987654321:-1111111110 1721-123456789:-987654321:864197532 1722+123456789:-987654321:1111111110 172310001:1:10000 1724100001:1:100000 17251000001:1:1000000 172610000001:1:10000000 1727100000001:1:100000000 17281000000001:1:1000000000 172910000000001:1:10000000000 1730100000000001:1:100000000000 17311000000000001:1:1000000000000 173210000000000001:1:10000000000000 173310001:-1:10002 1734100001:-1:100002 17351000001:-1:1000002 173610000001:-1:10000002 1737100000001:-1:100000002 17381000000001:-1:1000000002 173910000000001:-1:10000000002 1740100000000001:-1:100000000002 17411000000000001:-1:1000000000002 174210000000000001:-1:10000000000002 1743 1744&bmuladd 1745abc:abc:0:NaN 1746abc:+0:0:NaN 1747+0:abc:0:NaN 1748+0:0:abc:NaN 1749invalid:+inf:0:NaN 1750invalid:-inf:0:NaN 1751-inf:invalid:0:NaN 1752+inf:invalid:0:NaN 1753+inf:+inf:0:inf 1754+inf:-inf:0:-inf 1755-inf:+inf:0:-inf 1756-inf:-inf:0:inf 1757+0:+0:0:0 1758+0:+1:0:0 1759+1:+0:0:0 1760+0:-1:0:0 1761-1:+0:0:0 1762123456789123456789:0:0:0 17630:123456789123456789:0:0 1764-1:-1:0:1 1765-1:-1:0:1 1766-1:+1:0:-1 1767+1:-1:0:-1 1768+1:+1:0:1 1769+2:+3:0:6 1770-2:+3:0:-6 1771+2:-3:0:-6 1772-2:-3:0:6 1773111:111:0:12321 177410101:10101:0:102030201 17751001001:1001001:0:1002003002001 1776100010001:100010001:0:10002000300020001 177710000100001:10000100001:0:100002000030000200001 177811111111111:9:0:99999999999 177922222222222:9:0:199999999998 178033333333333:9:0:299999999997 178144444444444:9:0:399999999996 178255555555555:9:0:499999999995 178366666666666:9:0:599999999994 178477777777777:9:0:699999999993 178588888888888:9:0:799999999992 178699999999999:9:0:899999999991 178711111111111:9:1:100000000000 178822222222222:9:1:199999999999 178933333333333:9:1:299999999998 179044444444444:9:1:399999999997 179155555555555:9:1:499999999996 179266666666666:9:1:599999999995 179377777777777:9:1:699999999994 179488888888888:9:1:799999999993 179599999999999:9:1:899999999992 1796-3:-4:-5:7 17973:-4:-5:-17 1798-3:4:-5:-17 17993:4:-5:7 1800-3:4:5:-7 18013:-4:5:-7 18029999999999999999999:10000000000000000000:1234567890:99999999999999999990000000001234567890 18032:3:12345678901234567890:12345678901234567896 1804 1805&bmul 1806abc:abc:NaN 1807abc:+0:NaN 1808+0:abc:NaN 1809invalid:+inf:NaN 1810invalid:-inf:NaN 1811-inf:invalid:NaN 1812+inf:invalid:NaN 1813+inf:+inf:inf 1814+inf:-inf:-inf 1815-inf:+inf:-inf 1816-inf:-inf:inf 1817+0:+0:0 1818+0:+1:0 1819+1:+0:0 1820+0:-1:0 1821-1:+0:0 1822123456789123456789:0:0 18230:123456789123456789:0 1824-1:-1:1 1825-1:+1:-1 1826+1:-1:-1 1827+1:+1:1 1828+2:+3:6 1829-2:+3:-6 1830+2:-3:-6 1831-2:-3:6 1832111:111:12321 183310101:10101:102030201 18341001001:1001001:1002003002001 1835100010001:100010001:10002000300020001 183610000100001:10000100001:100002000030000200001 183711111111111:9:99999999999 183822222222222:9:199999999998 183933333333333:9:299999999997 184044444444444:9:399999999996 184155555555555:9:499999999995 184266666666666:9:599999999994 184377777777777:9:699999999993 184488888888888:9:799999999992 184599999999999:9:899999999991 1846+25:+25:625 1847+12345:+12345:152399025 1848+99999:+11111:1111088889 18499999:10000:99990000 185099999:100000:9999900000 1851999999:1000000:999999000000 18529999999:10000000:99999990000000 185399999999:100000000:9999999900000000 1854999999999:1000000000:999999999000000000 18559999999999:10000000000:99999999990000000000 185699999999999:100000000000:9999999999900000000000 1857999999999999:1000000000000:999999999999000000000000 18589999999999999:10000000000000:99999999999990000000000000 185999999999999999:100000000000000:9999999999999900000000000000 1860999999999999999:1000000000000000:999999999999999000000000000000 18619999999999999999:10000000000000000:99999999999999990000000000000000 186299999999999999999:100000000000000000:9999999999999999900000000000000000 1863999999999999999999:1000000000000000000:999999999999999999000000000000000000 18649999999999999999999:10000000000000000000:99999999999999999990000000000000000000 1865 1866&bdiv-list 1867 1868# Divide by zero and modulo zero. 1869 1870inf:0:inf,inf 18715:0:inf,5 18720:0:NaN,0 1873-5:0:-inf,-5 1874-inf:0:-inf,-inf 1875 1876# Numerator (dividend) is +/-inf, and denominator is finite and non-zero. 1877 1878inf:-inf:NaN,NaN 1879inf:-5:-inf,NaN 1880inf:5:inf,NaN 1881inf:inf:NaN,NaN 1882 1883-inf:-inf:NaN,NaN 1884-inf:-5:inf,NaN 1885-inf:5:-inf,NaN 1886-inf:inf:NaN,NaN 1887 1888# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf 1889# are covered above. 1890 1891-5:inf:-1,inf 18920:inf:0,0 18935:inf:0,5 1894 1895-5:-inf:0,-5 18960:-inf:0,0 18975:-inf:-1,-inf 1898 1899# Numerator is finite, and denominator is finite and non-zero. 1900 1901-5:-5:1,0 1902-5:-2:2,-1 1903-5:-1:5,0 1904-5:1:-5,0 1905-5:2:-3,1 1906-5:5:-1,0 1907-2:-5:0,-2 1908-2:-2:1,0 1909-2:-1:2,0 1910-2:1:-2,0 1911-2:2:-1,0 1912-2:5:-1,3 1913-1:-5:0,-1 1914-1:-2:0,-1 1915-1:-1:1,0 1916-1:1:-1,0 1917-1:2:-1,1 1918-1:5:-1,4 19190:-5:0,0 19200:-2:0,0 19210:-1:0,0 19220:1:0,0 19230:2:0,0 19240:5:0,0 19251:-5:-1,-4 19261:-2:-1,-1 19271:-1:-1,0 19281:1:1,0 19291:2:0,1 19301:5:0,1 19312:-5:-1,-3 19322:-2:-1,0 19332:-1:-2,0 19342:1:2,0 19352:2:1,0 19362:5:0,2 19375:-5:-1,0 19385:-2:-3,-1 19395:-1:-5,0 19405:1:5,0 19415:2:2,1 19425:5:1,0 1943 1944# test the shortcut in Calc if @$x == @$yorg 19451234567812345678:123456712345678:10,688888898 194612345671234567:1234561234567:10,58888897 1947123456123456:12345123456:10,4888896 19481234512345:123412345:10,388895 19491234567890999999999:1234567890:1000000000,999999999 19501234567890000000000:1234567890:1000000000,0 19511234567890999999999:9876543210:124999998,9503086419 19521234567890000000000:9876543210:124999998,8503086420 195396969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451 1954# bug in v1.76 19551267650600228229401496703205375:1267650600228229401496703205376:0,1267650600228229401496703205375 1956# exercise shortcut for numbers of the same length in div 1957999999999999999999999999999999999:999999999999999999999999999999999:1,0 1958999999999999999999999999999999999:888888888888888888888888888888888:1,111111111111111111111111111111111 1959999999999999999999999999999999999:777777777777777777777777777777777:1,222222222222222222222222222222222 1960999999999999999999999999999999999:666666666666666666666666666666666:1,333333333333333333333333333333333 1961999999999999999999999999999999999:555555555555555555555555555555555:1,444444444444444444444444444444444 1962999999999999999999999999999999999:444444444444444444444444444444444:2,111111111111111111111111111111111 1963999999999999999999999999999999999:333333333333333333333333333333333:3,0 1964999999999999999999999999999999999:222222222222222222222222222222222:4,111111111111111111111111111111111 1965999999999999999999999999999999999:111111111111111111111111111111111:9,0 19669999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3,0 19679999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3,999999999999999999999 19689999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3,999999999999999999999999999 19699999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4,1999999999999999999999999999 19709999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9,999999999999999999999999999 19719999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99,99999999999999999999999999 19729999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999,9999999999999999999999999 19739999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999,999999999999999999999999 19749999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999,99999999999999999999999 19759999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999,9999999999999999999999 19769999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999,999999999999999999999 1977 1978&bdiv 1979 1980# Divide by zero and modulo zero. 1981 1982inf:0:inf 19835:0:inf 19840:0:NaN 1985-5:0:-inf 1986-inf:0:-inf 1987 1988# Numerator (dividend) is +/-inf, and denominator is finite and non-zero. 1989 1990inf:-inf:NaN 1991inf:-5:-inf 1992inf:5:inf 1993inf:inf:NaN 1994 1995-inf:-inf:NaN 1996-inf:-5:inf 1997-inf:5:-inf 1998-inf:inf:NaN 1999 2000# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf 2001# are covered above. 2002 2003-5:inf:-1 20040:inf:0 20055:inf:0 2006 2007-5:-inf:0 20080:-inf:0 20095:-inf:-1 2010 2011# Numerator is finite, and denominator is finite and non-zero. 2012 20135:5:1 2014-5:-5:1 201511:2:5 2016-11:-2:5 2017-11:2:-6 201811:-2:-6 20190:1:0 20200:-1:0 20211:1:1 2022-1:-1:1 20231:-1:-1 2024-1:1:-1 20251:2:0 20262:1:2 20271:26:0 20281000000000:9:111111111 20292000000000:9:222222222 20303000000000:9:333333333 20314000000000:9:444444444 20325000000000:9:555555555 20336000000000:9:666666666 20347000000000:9:777777777 20358000000000:9:888888888 20369000000000:9:1000000000 203735500000:113:314159 203871000000:226:314159 2039106500000:339:314159 20401000000000:3:333333333 2041+10:+5:2 2042+100:+4:25 2043+1000:+8:125 2044+10000:+16:625 2045999999999999:9:111111111111 2046999999999999:99:10101010101 2047999999999999:999:1001001001 2048999999999999:9999:100010001 2049999999999999999:99999:10000100001 2050+1111088889:99999:11111 2051-5:-3:1 2052-5:3:-2 20534:3:1 20544:-3:-2 20551:3:0 20561:-3:-1 2057-2:-3:0 2058-2:3:-1 20598:3:2 2060-8:3:-3 206114:-3:-5 2062-14:3:-5 2063-14:-3:4 206414:3:4 2065# bug in Calc with '99999' vs $BASE-1 206610000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576 2067# test the shortcut in Calc if @$x == @$yorg 20681234567812345678:123456712345678:10 206912345671234567:1234561234567:10 2070123456123456:12345123456:10 20711234512345:123412345:10 20721234567890999999999:1234567890:1000000000 20731234567890000000000:1234567890:1000000000 20741234567890999999999:9876543210:124999998 20751234567890000000000:9876543210:124999998 207696969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199 2077# bug up to v0.35 in Calc (--$q one too many) 207884696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999 207984696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998 208084696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000 208184696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997 2082# exercise shortcut for numbers of the same length in div 2083999999999999999999999999999999999:999999999999999999999999999999999:1 2084999999999999999999999999999999999:888888888888888888888888888888888:1 2085999999999999999999999999999999999:777777777777777777777777777777777:1 2086999999999999999999999999999999999:666666666666666666666666666666666:1 2087999999999999999999999999999999999:555555555555555555555555555555555:1 2088999999999999999999999999999999999:444444444444444444444444444444444:2 2089999999999999999999999999999999999:333333333333333333333333333333333:3 2090999999999999999999999999999999999:222222222222222222222222222222222:4 2091999999999999999999999999999999999:111111111111111111111111111111111:9 20929999999_9999999_9999999_9999999:3333333_3333333_3333333_3333333:3 20939999999_9999999_9999999_9999999:3333333_0000000_0000000_0000000:3 20949999999_9999999_9999999_9999999:3000000_0000000_0000000_0000000:3 20959999999_9999999_9999999_9999999:2000000_0000000_0000000_0000000:4 20969999999_9999999_9999999_9999999:1000000_0000000_0000000_0000000:9 20979999999_9999999_9999999_9999999:100000_0000000_0000000_0000000:99 20989999999_9999999_9999999_9999999:10000_0000000_0000000_0000000:999 20999999999_9999999_9999999_9999999:1000_0000000_0000000_0000000:9999 21009999999_9999999_9999999_9999999:100_0000000_0000000_0000000:99999 21019999999_9999999_9999999_9999999:10_0000000_0000000_0000000:999999 21029999999_9999999_9999999_9999999:1_0000000_0000000_0000000:9999999 2103# bug with shortcut in Calc 0.44 2104949418181818187070707070707070707070:181818181853535353535353535353535353:5 2105 2106&btdiv-list 2107 2108# Divide by zero and modulo zero. 2109 2110inf:0:inf,inf 21115:0:inf,5 21120:0:NaN,0 2113-5:0:-inf,-5 2114-inf:0:-inf,-inf 2115 2116# Numerator (dividend) is +/-inf, and denominator is finite and non-zero. 2117 2118inf:-inf:NaN,NaN 2119inf:-5:-inf,NaN 2120inf:5:inf,NaN 2121inf:inf:NaN,NaN 2122 2123-inf:-inf:NaN,NaN 2124-inf:-5:inf,NaN 2125-inf:5:-inf,NaN 2126-inf:inf:NaN,NaN 2127 2128# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf 2129# are covered above. 2130 2131-5:inf:0,-5 21320:inf:0,0 21335:inf:0,5 2134 2135-5:-inf:0,-5 21360:-inf:0,0 21375:-inf:0,5 2138 2139# Numerator is finite, and denominator is finite and non-zero. 2140 2141-5:-5:1,0 2142-5:-2:2,-1 2143-5:-1:5,0 2144-5:1:-5,0 2145-5:2:-2,-1 2146-5:5:-1,0 2147-2:-5:0,-2 2148-2:-2:1,0 2149-2:-1:2,0 2150-2:1:-2,0 2151-2:2:-1,0 2152-2:5:0,-2 2153-1:-5:0,-1 2154-1:-2:0,-1 2155-1:-1:1,0 2156-1:1:-1,0 2157-1:2:0,-1 2158-1:5:0,-1 21590:-5:0,0 21600:-2:0,0 21610:-1:0,0 21620:1:0,0 21630:2:0,0 21640:5:0,0 21651:-5:0,1 21661:-2:0,1 21671:-1:-1,0 21681:1:1,0 21691:2:0,1 21701:5:0,1 21712:-5:0,2 21722:-2:-1,0 21732:-1:-2,0 21742:1:2,0 21752:2:1,0 21762:5:0,2 21775:-5:-1,0 21785:-2:-2,1 21795:-1:-5,0 21805:1:5,0 21815:2:2,1 21825:5:1,0 2183 2184&btdiv 2185 2186# Divide by zero and modulo zero. 2187 2188inf:0:inf 21895:0:inf 21900:0:NaN 2191-5:0:-inf 2192-inf:0:-inf 2193 2194# Numerator (dividend) is +/-inf, and denominator is finite and non-zero. 2195 2196inf:-inf:NaN 2197inf:-5:-inf 2198inf:5:inf 2199inf:inf:NaN 2200 2201-inf:-inf:NaN 2202-inf:-5:inf 2203-inf:5:-inf 2204-inf:inf:NaN 2205 2206# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf 2207# are covered above. 2208 2209-5:inf:0 22100:inf:0 22115:inf:0 2212 2213-5:-inf:0 22140:-inf:0 22155:-inf:0 2216 2217# Numerator is finite, and denominator is finite and non-zero. 2218 2219-5:-5:1 2220-5:-2:2 2221-5:-1:5 2222-5:1:-5 2223-5:2:-2 2224-5:5:-1 2225-2:-5:0 2226-2:-2:1 2227-2:-1:2 2228-2:1:-2 2229-2:2:-1 2230-2:5:0 2231-1:-5:0 2232-1:-2:0 2233-1:-1:1 2234-1:1:-1 2235-1:2:0 2236-1:5:0 22370:-5:0 22380:-2:0 22390:-1:0 22400:1:0 22410:2:0 22420:5:0 22431:-5:0 22441:-2:0 22451:-1:-1 22461:1:1 22471:2:0 22481:5:0 22492:-5:0 22502:-2:-1 22512:-1:-2 22522:1:2 22532:2:1 22542:5:0 22555:-5:-1 22565:-2:-2 22575:-1:-5 22585:1:5 22595:2:2 22605:5:1 2261 2262############################################################################### 2263 2264&bmodinv 2265# format: number:modulus:result 2266# bmodinv Data errors 2267abc:abc:NaN 2268abc:5:NaN 22695:abc:NaN 2270# bmodinv Expected Results from normal use 22711:5:1 22723:5:2 22733:-5:-3 2274-2:5:2 22758:5033:4404 22761234567891:13:6 2277-1234567891:13:7 2278324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902 2279-2:1:0 2280-1:1:0 22810:1:0 22821:1:0 22832:1:0 22843:1:0 22854:1:0 2286-2:3:1 2287-1:3:2 22880:3:NaN 22891:3:1 22902:3:2 22913:3:NaN 22924:3:1 2293-2:4:NaN 2294-1:4:3 22950:4:NaN 22961:4:1 22972:4:NaN 22983:4:3 22994:4:NaN 2300## bmodinv Error cases / useless use of function 2301inf:5:NaN 23025:inf:NaN 2303-inf:5:NaN 23045:-inf:NaN 2305 2306&bmodpow 2307# format: number:exponent:modulus:result 2308# bmodpow Data errors 2309abc:abc:abc:NaN 23105:abc:abc:NaN 2311abc:5:abc:NaN 2312abc:abc:5:NaN 23135:5:abc:NaN 23145:abc:5:NaN 2315abc:5:5:NaN 23163:5:0:3 2317# bmodpow Expected results 23180:0:2:1 23191:0:2:1 23200:3:5:0 2321-2:-2:1:0 2322-1:-2:1:0 23230:-2:1:0 23241:-2:1:0 23252:-2:1:0 23263:-2:1:0 23274:-2:1:0 2328-2:-1:1:0 2329-1:-1:1:0 23300:-1:1:0 23311:-1:1:0 23322:-1:1:0 23333:-1:1:0 23344:-1:1:0 2335-2:0:1:0 2336-1:0:1:0 23370:0:1:0 23381:0:1:0 23392:0:1:0 23403:0:1:0 23414:0:1:0 2342-2:1:1:0 2343-1:1:1:0 23440:1:1:0 23451:1:1:0 23462:1:1:0 23473:1:1:0 23484:1:1:0 2349-2:2:1:0 2350-1:2:1:0 23510:2:1:0 23521:2:1:0 23532:2:1:0 23543:2:1:0 23554:2:1:0 2356-2:3:1:0 2357-1:3:1:0 23580:3:1:0 23591:3:1:0 23602:3:1:0 23613:3:1:0 23624:3:1:0 2363-2:4:1:0 2364-1:4:1:0 23650:4:1:0 23661:4:1:0 23672:4:1:0 23683:4:1:0 23694:4:1:0 2370-2:-2:3:1 2371-1:-2:3:1 23720:-2:3:NaN 23731:-2:3:1 23742:-2:3:1 23753:-2:3:NaN 23764:-2:3:1 2377-2:-1:3:1 2378-1:-1:3:2 23790:-1:3:NaN 23801:-1:3:1 23812:-1:3:2 23823:-1:3:NaN 23834:-1:3:1 2384-2:0:3:1 2385-1:0:3:1 23860:0:3:1 23871:0:3:1 23882:0:3:1 23893:0:3:1 23904:0:3:1 2391-2:1:3:1 2392-1:1:3:2 23930:1:3:0 23941:1:3:1 23952:1:3:2 23963:1:3:0 23974:1:3:1 2398-2:2:3:1 2399-1:2:3:1 24000:2:3:0 24011:2:3:1 24022:2:3:1 24033:2:3:0 24044:2:3:1 2405-2:3:3:1 2406-1:3:3:2 24070:3:3:0 24081:3:3:1 24092:3:3:2 24103:3:3:0 24114:3:3:1 2412-2:4:3:1 2413-1:4:3:1 24140:4:3:0 24151:4:3:1 24162:4:3:1 24173:4:3:0 24184:4:3:1 2419-2:-2:4:NaN 2420-1:-2:4:1 24210:-2:4:NaN 24221:-2:4:1 24232:-2:4:NaN 24243:-2:4:1 24254:-2:4:NaN 2426-2:-1:4:NaN 2427-1:-1:4:3 24280:-1:4:NaN 24291:-1:4:1 24302:-1:4:NaN 24313:-1:4:3 24324:-1:4:NaN 2433-2:0:4:1 2434-1:0:4:1 24350:0:4:1 24361:0:4:1 24372:0:4:1 24383:0:4:1 24394:0:4:1 2440-2:1:4:2 2441-1:1:4:3 24420:1:4:0 24431:1:4:1 24442:1:4:2 24453:1:4:3 24464:1:4:0 2447-2:2:4:0 2448-1:2:4:1 24490:2:4:0 24501:2:4:1 24512:2:4:0 24523:2:4:1 24534:2:4:0 2454-2:3:4:0 2455-1:3:4:3 24560:3:4:0 24571:3:4:1 24582:3:4:0 24593:3:4:3 24604:3:4:0 2461-2:4:4:0 2462-1:4:4:1 24630:4:4:0 24641:4:4:1 24652:4:4:0 24663:4:4:1 24674:4:4:0 24688:-1:16:NaN 24698:-1:5033:4404 24708:7:5032:3840 24718:8:-5:-4 24721e50:1:1:0 247398436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518 2474# bmodpow Error cases 2475inf:5:13:NaN 24765:inf:13:NaN 2477 2478&bmod 2479 2480# Divide by zero and modulo zero. 2481 2482inf:0:inf 24835:0:5 24840:0:0 2485-5:0:-5 2486-inf:0:-inf 2487 2488# Numerator (dividend) is +/-inf, and denominator is finite and non-zero. 2489 2490inf:-inf:NaN 2491inf:-5:NaN 2492inf:5:NaN 2493inf:inf:NaN 2494 2495-inf:-inf:NaN 2496-inf:-5:NaN 2497-inf:5:NaN 2498-inf:inf:NaN 2499 2500# Denominator (divisor) is +/-inf. The cases when the numerator is +/-inf 2501# are covered above. 2502 2503-5:inf:inf 25040:inf:0 25055:inf:5 2506 2507-5:-inf:-5 25080:-inf:0 25095:-inf:-inf 2510 2511# Numerator is finite, and denominator is finite and non-zero. 2512 25135:5:0 2514-5:-5:0 25150:1:0 25160:-1:0 25171:1:0 2518-1:-1:0 25191:-1:0 2520-1:1:0 25211:2:1 25222:1:0 25231000000000:9:1 25242000000000:9:2 25253000000000:9:3 25264000000000:9:4 25275000000000:9:5 25286000000000:9:6 25297000000000:9:7 25308000000000:9:8 25319000000000:9:0 253235500000:113:33 253371000000:226:66 2534106500000:339:99 25351000000000:3:1 253610:5:0 2537100:4:0 25381000:8:0 253910000:16:0 2540999999999999:9:0 2541999999999999:99:0 2542999999999999:999:0 2543999999999999:9999:0 2544999999999999999:99999:0 2545-9:+5:1 2546+9:-5:-1 2547-9:-5:-4 2548-5:3:1 2549-2:3:1 25504:3:1 25511:3:1 2552-5:-3:-2 2553-2:-3:-2 25544:-3:-2 25551:-3:-2 25564095:4095:0 2557100041000510123:3:0 2558152403346:12345:4321 25599:5:4 2560# test shortcuts in Calc 2561# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0 25621234:9:1 2563123456:9:3 256412345678:9:0 25651234567891:9:1 2566123456789123:9:6 256712345678912345:9:6 25681234567891234567:9:1 2569123456789123456789:9:0 25701234:10:4 2571123456:10:6 257212345678:10:8 25731234567891:10:1 2574123456789123:10:3 257512345678912345:10:5 25761234567891234567:10:7 2577123456789123456789:10:9 25781234:113:104 2579123456:113:60 258012345678:113:89 25811234567891:113:64 2582123456789123:113:95 258312345678912345:113:53 25841234567891234567:113:56 2585123456789123456789:113:39 2586# bug in bmod() not modifying the variable in place 2587-629:5033:4404 2588# bug in bmod() in Calc in the _div_use_div() shortcut code path, 2589# when X == X and X was big 2590111111111111111111111111111111:111111111111111111111111111111:0 259112345678901234567890:12345678901234567890:0 2592 2593&bgcd 2594inf:12:NaN 2595-inf:12:NaN 259612:inf:NaN 259712:-inf:NaN 2598inf:inf:NaN 2599inf:-inf:NaN 2600-inf:-inf:NaN 2601abc:abc:NaN 2602abc:+0:NaN 2603+0:abc:NaN 2604+0:+0:0 2605+0:+1:1 2606+1:+0:1 2607+1:+1:1 2608+2:+3:1 2609+3:+2:1 2610-3:+2:1 2611-3:-2:1 2612-144:-60:12 2613144:-60:12 2614144:60:12 2615100:625:25 26164096:81:1 26171034:804:2 261827:90:56:1 261927:90:54:9 2620 2621&blcm 2622abc:abc:NaN 2623abc:+0:NaN 2624+0:abc:NaN 2625+0:+0:0 2626+1:+0:0 2627+0:+1:0 2628+27:+90:270 2629+1034:+804:415668 2630 2631&band 2632abc:abc:NaN 2633abc:0:NaN 26340:abc:NaN 26351:2:0 26363:2:2 2637+8:+2:0 2638+281474976710656:0:0 2639+281474976710656:1:0 2640+281474976710656:+281474976710656:281474976710656 2641281474976710656:-1:281474976710656 2642-2:-3:-4 2643-1:-1:-1 2644-6:-6:-6 2645-7:-4:-8 2646-7:4:0 2647-4:7:4 2648# negative argument is bitwise shorter than positive [perl #26559] 264930:-3:28 2650123:-1:123 2651# equal arguments are treated special, so also do some test with unequal ones 26520xFFFF:0xFFFF:0x0xFFFF 26530xFFFFFF:0xFFFFFF:0x0xFFFFFF 26540xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF 26550xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF 26560xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF 26570xF0F0:0xF0F0:0x0xF0F0 26580x0F0F:0x0F0F:0x0x0F0F 26590xF0F0F0:0xF0F0F0:0x0xF0F0F0 26600x0F0F0F:0x0F0F0F:0x0x0F0F0F 26610xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 26620x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F 26630xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 26640x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F 26650xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 26660x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F 26670x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F 2668 2669&bior 2670abc:abc:NaN 2671abc:0:NaN 26720:abc:NaN 26731:2:3 2674+8:+2:10 2675+281474976710656:0:281474976710656 2676+281474976710656:1:281474976710657 2677+281474976710656:281474976710656:281474976710656 2678-2:-3:-1 2679-1:-1:-1 2680-6:-6:-6 2681-7:4:-3 2682-4:7:-1 2683+281474976710656:-1:-1 268430:-3:-1 268530:-4:-2 2686300:-76:-68 2687-76:300:-68 2688# equal arguments are treated special, so also do some test with unequal ones 26890xFFFF:0xFFFF:0x0xFFFF 26900xFFFFFF:0xFFFFFF:0x0xFFFFFF 26910xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF 26920xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF 26930xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF 26940:0xFFFF:0x0xFFFF 26950:0xFFFFFF:0x0xFFFFFF 26960:0xFFFFFFFF:0x0xFFFFFFFF 26970:0xFFFFFFFFFF:0x0xFFFFFFFFFF 26980:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF 26990xFFFF:0:0x0xFFFF 27000xFFFFFF:0:0x0xFFFFFF 27010xFFFFFFFF:0:0x0xFFFFFFFF 27020xFFFFFFFFFF:0:0x0xFFFFFFFFFF 27030xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF 27040xF0F0:0xF0F0:0x0xF0F0 27050x0F0F:0x0F0F:0x0x0F0F 27060xF0F0:0x0F0F:0x0xFFFF 27070xF0F0F0:0xF0F0F0:0x0xF0F0F0 27080x0F0F0F:0x0F0F0F:0x0x0F0F0F 27090x0F0F0F:0xF0F0F0:0x0xFFFFFF 27100xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 27110x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F 27120x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF 27130xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 27140x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F 27150x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF 27160xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 27170x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F 27180x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF 27190x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF 2720 2721&bxor 2722abc:abc:NaN 2723abc:0:NaN 27240:abc:NaN 27251:2:3 2726+8:+2:10 2727+281474976710656:0:281474976710656 2728+281474976710656:1:281474976710657 2729+281474976710656:281474976710656:0 2730-2:-3:3 2731-1:-1:0 2732-6:-6:0 2733-7:4:-3 2734-4:7:-5 27354:-7:-3 2736-4:-7:5 273730:-3:-29 273830:-4:-30 2739300:-76:-360 2740-76:300:-360 2741# equal arguments are treated special, so also do some test with unequal ones 27420xFFFF:0xFFFF:0 27430xFFFFFF:0xFFFFFF:0 27440xFFFFFFFF:0xFFFFFFFF:0 27450xFFFFFFFFFF:0xFFFFFFFFFF:0 27460xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0 27470:0xFFFF:0x0xFFFF 27480:0xFFFFFF:0x0xFFFFFF 27490:0xFFFFFFFF:0x0xFFFFFFFF 27500:0xFFFFFFFFFF:0x0xFFFFFFFFFF 27510:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF 27520xFFFF:0:0x0xFFFF 27530xFFFFFF:0:0x0xFFFFFF 27540xFFFFFFFF:0:0x0xFFFFFFFF 27550xFFFFFFFFFF:0:0x0xFFFFFFFFFF 27560xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF 27570xF0F0:0xF0F0:0 27580x0F0F:0x0F0F:0 27590xF0F0:0x0F0F:0x0xFFFF 27600xF0F0F0:0xF0F0F0:0 27610x0F0F0F:0x0F0F0F:0 27620x0F0F0F:0xF0F0F0:0x0xFFFFFF 27630xF0F0F0F0:0xF0F0F0F0:0 27640x0F0F0F0F:0x0F0F0F0F:0 27650x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF 27660xF0F0F0F0F0:0xF0F0F0F0F0:0 27670x0F0F0F0F0F:0x0F0F0F0F0F:0 27680x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF 27690xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0 27700x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0 27710x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF 2772 2773&bnot 2774abc:NaN 2775+0:-1 2776+8:-9 2777+281474976710656:-281474976710657 2778-1:0 2779-2:1 2780-12:11 2781 2782&digit 27830:0:0 278412:0:2 278512:1:1 2786123:0:3 2787123:1:2 2788123:2:1 2789123:-1:1 2790123:-2:2 2791123:-3:3 2792123456:0:6 2793123456:1:5 2794123456:2:4 2795123456:3:3 2796123456:4:2 2797123456:5:1 2798123456:-1:1 2799123456:-2:2 2800123456:-3:3 2801100000:-3:0 2802100000:0:0 2803100000:1:0 2804 2805&mantissa 2806abc:NaN 28071e4:1 28082e0:2 2809123:123 2810-1:-1 2811-2:-2 2812+inf:inf 2813-inf:-inf 2814 2815&exponent 2816abc:NaN 28171e4:4 28182e0:0 2819123:0 2820-1:0 2821-2:0 28220:0 2823+inf:inf 2824-inf:inf 2825 2826&parts 2827abc:NaN,NaN 28281e4:1,4 28292e0:2,0 2830123:123,0 2831-1:-1,0 2832-2:-2,0 28330:0,0 2834+inf:inf,inf 2835-inf:-inf,inf 2836 2837&bfac 2838NaN:NaN 2839+inf:inf 2840-inf:NaN 2841-1:NaN 28420:1 28431:1 28442:2 28453:6 28464:24 28475:120 28486:720 28497:5040 28508:40320 28519:362880 285210:3628800 285311:39916800 285412:479001600 285520:2432902008176640000 285622:1124000727777607680000 285769:171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000 2858 2859&bdfac 2860NaN:NaN 2861+inf:inf 2862-inf:NaN 2863-2:NaN 2864-1:1 28650:1 28661:1 28672:2 28683:3 28694:8 28705:15 28716:48 28727:105 28738:384 28749:945 287510:3840 287611:10395 287712:46080 2878 2879&btfac 2880NaN:NaN 2881+inf:inf 2882-inf:NaN 2883-3:NaN 2884-2:1 2885-1:1 28860:1 28871:1 28882:2 28893:3 28904:4 28915:10 28926:18 28937:28 28948:80 28959:162 289610:280 289711:880 289812:1944 2899 2900&bmfac 2901 29027:-inf:NaN 29037:-1:NaN 29047:0:NaN 29057:inf:7 29067:NaN:NaN 2907 2908NaN:1:NaN 2909+inf:1:inf 2910-inf:1:NaN 2911-1:1:NaN 29120:1:1 29131:1:1 29142:1:2 29153:1:6 29164:1:24 29175:1:120 29186:1:720 29197:1:5040 29208:1:40320 29219:1:362880 292210:1:3628800 2923 2924NaN:2:NaN 2925+inf:2:inf 2926-inf:2:NaN 2927-2:2:NaN 2928-1:2:1 29290:2:1 29301:2:1 29312:2:2 29323:2:3 29334:2:8 29345:2:15 29356:2:48 29367:2:105 29378:2:384 29389:2:945 293910:2:3840 2940 2941NaN:3:NaN 2942+inf:3:inf 2943-inf:3:NaN 2944-3:3:NaN 2945-2:3:1 2946-1:3:1 29470:3:1 29481:3:1 29492:3:2 29503:3:3 29514:3:4 29525:3:10 29536:3:18 29547:3:28 29558:3:80 29569:3:162 295710:3:280 2958 2959NaN:4:NaN 2960+inf:4:inf 2961-inf:4:NaN 2962-4:4:NaN 2963-3:4:1 2964-2:4:1 2965-1:4:1 29660:4:1 29671:4:1 29682:4:2 29693:4:3 29704:4:4 29715:4:5 29726:4:12 29737:4:21 29748:4:32 29759:4:45 297610:4:120 2977 2978NaN:5:NaN 2979+inf:5:inf 2980-inf:5:NaN 2981-5:5:NaN 2982-4:5:1 2983-3:5:1 2984-2:5:1 2985-1:5:1 29860:5:1 29871:5:1 29882:5:2 29893:5:3 29904:5:4 29915:5:5 29926:5:6 29937:5:14 29948:5:24 29959:5:36 299610:5:50 2997 2998&bpow 2999# 3000abc:12:NaN 300112:abc:NaN 3002# 3003# 3004-inf:-inf:0 3005-inf:-3:0 3006-inf:-2:0 3007-inf:-1:0 3008-inf:0:NaN 3009-inf:1:-inf 3010-inf:2:inf 3011-inf:3:-inf 3012-inf:inf:inf # complex infinity 3013-inf:NaN:NaN 3014# 3015-3:-inf:0 3016-3:-3:0 3017-3:-2:0 3018-3:-1:0 3019-3:0:1 3020-3:1:-3 3021-3:2:9 3022-3:3:-27 3023-3:inf:inf # complex infinity 3024-3:NaN:NaN 3025# 3026-2:-inf:0 3027-2:-3:0 3028-2:-2:0 3029-2:-1:0 3030-2:0:1 3031-2:1:-2 3032-2:2:4 3033-2:3:-8 3034-2:inf:inf # complex infinity 3035-2:NaN:NaN 3036# 3037-1:-inf:NaN 3038-1:-3:-1 3039-1:-2:1 3040-1:-1:-1 3041-1:0:1 3042-1:1:-1 3043-1:2:1 3044-1:3:-1 3045-1:inf:NaN 3046-1:NaN:NaN 3047# 30480:-inf:inf # complex infinity 30490:-3:inf # complex infinity 30500:-2:inf # complex infinity 30510:-1:inf # complex infinity 30520:0:1 30530:1:0 30540:2:0 30550:3:0 30560:inf:0 30570:NaN:NaN 3058# 30591:-inf:1 30601:-3:1 30611:-2:1 30621:-1:1 30631:0:1 30641:1:1 30651:2:1 30661:3:1 30671:inf:1 30681:NaN:NaN 3069# 30702:-inf:0 30712:-3:0 30722:-2:0 30732:-1:0 30742:0:1 30752:1:2 30762:2:4 30772:3:8 30782:inf:inf 30792:NaN:NaN 3080# 30813:-inf:0 30823:-3:0 30833:-2:0 30843:-1:0 30853:0:1 30863:1:3 30873:2:9 30883:3:27 30893:inf:inf 30903:NaN:NaN 3091# 3092inf:-inf:0 3093inf:-3:0 3094inf:-2:0 3095inf:-1:0 3096inf:0:NaN 3097inf:1:inf 3098inf:2:inf 3099inf:3:inf 3100inf:inf:inf 3101inf:NaN:NaN 3102# 3103NaN:-inf:NaN 3104NaN:-3:NaN 3105NaN:-2:NaN 3106NaN:-1:NaN 3107NaN:0:NaN 3108NaN:1:NaN 3109NaN:2:NaN 3110NaN:3:NaN 3111NaN:inf:NaN 3112NaN:NaN:NaN 3113# 3114+inf:1234500012:inf 3115-inf:1234500012:inf 3116-inf:1234500013:-inf 3117+inf:-12345000123:0 3118-inf:-12345000123:0 3119# 312010:2:100 312110:3:1000 312210:4:10000 312310:5:100000 312410:6:1000000 312510:7:10000000 312610:8:100000000 312710:9:1000000000 312810:20:100000000000000000000 3129123456:2:15241383936 3130-2:4:16 3131-2:5:-32 3132-3:3:-27 3133-3:4:81 3134-3:5:-243 3135 3136&length 3137100:3 313810:2 31391:1 31400:1 314112345:5 314210000000000000000:17 3143-123:3 3144215960156869840440586892398248:30 3145 3146&broot 3147# sqrt() 3148+0:2:0 3149+1:2:1 3150-1:2:NaN 3151# -$x ** (1/2) => -$y, but not in broot() 3152-123:2:NaN 3153+inf:2:inf 3154-inf:2:NaN 31552:2:1 3156-2:2:NaN 31574:2:2 31589:2:3 315916:2:4 3160100:2:10 3161123:2:11 316215241:2:123 3163144:2:12 316412:2:3 3165# invalid ones 31661:NaN:NaN 3167-1:NaN:NaN 31680:NaN:NaN 3169-inf:NaN:NaN 3170+inf:NaN:NaN 3171NaN:0:NaN 3172NaN:2:NaN 3173NaN:inf:NaN 3174NaN:inf:NaN 317512:-inf:NaN 317612:inf:NaN 3177+0:0:NaN 3178+1:0:NaN 3179-1:0:NaN 3180-2:0:NaN 3181-123.45:0:NaN 3182+inf:0:NaN 318312:1:12 3184-12:1:NaN 31858:-1:NaN 3186-8:-1:NaN 3187# cubic root 31888:3:2 3189-8:3:NaN 3190# fourths root 319116:4:2 319281:4:3 3193# 2 ** 64 319418446744073709551616:4:65536 319518446744073709551616:8:256 319618446744073709551616:16:16 319718446744073709551616:32:4 319818446744073709551616:64:2 319918446744073709551616:128:1 3200# 213 ** 15 320184274086103068221283760416414557757:15:213 3202 3203# see t/bigroot.t for more tests 3204&bsqrt 3205145:12 3206144:12 3207143:11 320816:4 3209170:13 3210169:13 3211168:12 32124:2 32133:1 32142:1 32159:3 321612:3 3217256:16 3218100000000:10000 32194000000000000:2000000 3220152399026:12345 3221152399025:12345 3222152399024:12344 3223# 2 ** 64 => 2 ** 32 322418446744073709551616:4294967296 322584274086103068221283760416414557757:290299993288095377 32261:1 32270:0 3228-2:NaN 3229-123:NaN 3230Nan:NaN 3231+inf:inf 3232-inf:NaN 3233 3234# see t/biglog.t for more tests 3235&bexp 3236NaN:NaN 3237inf:inf 32381:2 32392:7 3240 3241&batan2 3242NaN:1:10:NaN 3243NaN:NaN:10:NaN 32441:NaN:10:NaN 3245inf:1:14:1 3246-inf:1:14:-1 32470:-inf:14:3 3248-1:-inf:14:-3 32491:-inf:14:3 32500:inf:14:0 3251inf:-inf:14:2 3252-inf:-inf:14:-2 3253# +- 0.78.... 3254inf:+inf:14:0 3255-inf:+inf:14:0 32561:5:13:0 32571:5:14:0 32580:0:10:0 32590:1:14:0 32600:2:14:0 32611:0:14:1 32625:0:14:1 3263-1:0:11:-1 3264-2:0:77:-1 32652:0:77:1 3266-1:5:14:0 32671:5:14:0 3268-1:8:14:0 32691:8:14:0 3270-1:1:14:0 3271 3272&bpi 327377:3 3274+0:3 327511:3 3276 3277# see t/bignok.t for more tests 3278&bnok 3279+inf:10:inf 3280NaN:NaN:NaN 3281NaN:1:NaN 32821:NaN:NaN 32831:1:1 3284# k > n 32851:2:0 32862:3:0 3287# k < 0 32881:-2:0 3289# 7 over 3 = 35 32907:3:35 32917:6:7 3292100:90:17310309456440 3293100:95:75287520 32942:0:1 32957:0:1 32962:1:2 3297 3298&bround 3299$round_mode("trunc") 33000:12:0 3301invalid:12:NaN 3302+inf:12:inf 3303-inf:12:-inf 33041234:0:1234 33051234:2:1200 3306123456:4:123400 3307123456:5:123450 3308123456:6:123456 3309+10123456789:5:10123000000 3310-10123456789:5:-10123000000 3311+10123456789:9:10123456700 3312-10123456789:9:-10123456700 3313+101234500:6:101234000 3314-101234500:6:-101234000 3315#+101234500:-4:101234000 3316#-101234500:-4:-101234000 3317$round_mode("zero") 3318+20123456789:5:20123000000 3319-20123456789:5:-20123000000 3320+20123456789:9:20123456800 3321-20123456789:9:-20123456800 3322+201234500:6:201234000 3323-201234500:6:-201234000 3324#+201234500:-4:201234000 3325#-201234500:-4:-201234000 3326+12345000:4:12340000 3327-12345000:4:-12340000 3328$round_mode("+inf") 3329+30123456789:5:30123000000 3330-30123456789:5:-30123000000 3331+30123456789:9:30123456800 3332-30123456789:9:-30123456800 3333+301234500:6:301235000 3334-301234500:6:-301234000 3335#+301234500:-4:301235000 3336#-301234500:-4:-301234000 3337+12345000:4:12350000 3338-12345000:4:-12340000 3339$round_mode("-inf") 3340+40123456789:5:40123000000 3341-40123456789:5:-40123000000 3342+40123456789:9:40123456800 3343-40123456789:9:-40123456800 3344+401234500:6:401234000 3345+401234500:6:401234000 3346#-401234500:-4:-401235000 3347#-401234500:-4:-401235000 3348+12345000:4:12340000 3349-12345000:4:-12350000 3350$round_mode("odd") 3351+50123456789:5:50123000000 3352-50123456789:5:-50123000000 3353+50123456789:9:50123456800 3354-50123456789:9:-50123456800 3355+501234500:6:501235000 3356-501234500:6:-501235000 3357#+501234500:-4:501235000 3358#-501234500:-4:-501235000 3359+12345000:4:12350000 3360-12345000:4:-12350000 3361$round_mode("common") 3362+60123456789:5:60123000000 3363+60123199999:5:60123000000 3364+60123299999:5:60123000000 3365+60123399999:5:60123000000 3366+60123499999:5:60123000000 3367+60123500000:5:60124000000 3368+60123600000:5:60124000000 3369+60123700000:5:60124000000 3370+60123800000:5:60124000000 3371+60123900000:5:60124000000 3372-60123456789:5:-60123000000 3373-60123199999:5:-60123000000 3374-60123299999:5:-60123000000 3375-60123399999:5:-60123000000 3376-60123499999:5:-60123000000 3377-60123500000:5:-60124000000 3378-60123600000:5:-60124000000 3379-60123700000:5:-60124000000 3380-60123800000:5:-60124000000 3381-60123900000:5:-60124000000 3382$round_mode("even") 3383+60123456789:5:60123000000 3384-60123456789:5:-60123000000 3385+60123456789:9:60123456800 3386-60123456789:9:-60123456800 3387+601234500:6:601234000 3388-601234500:6:-601234000 3389#+601234500:-4:601234000 3390#-601234500:-4:-601234000 3391#-601234500:-9:0 3392#-501234500:-9:0 3393#-601234500:-8:0 3394#-501234500:-8:0 3395+1234567:7:1234567 3396+1234567:6:1234570 3397+12345000:4:12340000 3398-12345000:4:-12340000 3399 3400&is_zero 34010:1 3402invalid:0 3403+inf:0 3404-inf:0 3405123:0 3406-1:0 34071:0 3408 3409&is_one 34100:0 3411invalid:0 3412+inf:0 3413-inf:0 34141:1 34152:0 3416-1:0 3417-2:0 3418 3419# floor, ceil, and int are pretty pointless in integer space, but play safe 3420&bfloor 34210:0 3422invalid:NaN 3423+inf:inf 3424-inf:-inf 3425-1:-1 3426-2:-2 34272:2 34283:3 3429abc:NaN 3430 3431&bceil 3432invalid:NaN 3433+inf:inf 3434-inf:-inf 34350:0 3436-1:-1 3437-2:-2 34382:2 34393:3 3440abc:NaN 3441 3442&bint 3443NaN:NaN 3444+inf:inf 3445-inf:-inf 34460:0 3447-1:-1 3448-2:-2 34492:2 34503:3 3451 3452&as_hex 3453128:0x80 3454-128:-0x80 34550:0x0 3456-0:0x0 34571:0x1 34580x123456789123456789:0x123456789123456789 3459+inf:inf 3460-inf:-inf 3461invalid:NaN 3462 3463&as_bin 3464128:0b10000000 3465-128:-0b10000000 34660:0b0 3467-0:0b0 34681:0b1 34690b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101 34700x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001 3471+inf:inf 3472-inf:-inf 3473invalid:NaN 3474 3475&as_oct 3476128:0200 3477-128:-0200 34780:00 3479-0:00 34801:01 34810b1010111101010101010110110110110110101:01275252666665 34820x123456789123456789:044321263611044321263611 3483+inf:inf 3484-inf:-inf 3485invalid:NaN 3486 3487&to_hex 3488128:80 3489-128:-80 34900:0 3491-0:0 34921:1 34930x123456789123456789:123456789123456789 3494+inf:inf 3495-inf:-inf 3496invalid:NaN 3497 3498&to_bin 3499128:10000000 3500-128:-10000000 35010:0 3502-0:0 35031:1 35040b1010111101010101010110110110110110101:1010111101010101010110110110110110101 35050x123456789123456789:100100011010001010110011110001001000100100011010001010110011110001001 3506+inf:inf 3507-inf:-inf 3508invalid:NaN 3509 3510&to_oct 3511128:200 3512-128:-200 35130:0 3514-0:0 35151:1 35160b1010111101010101010110110110110110101:1275252666665 35170x123456789123456789:44321263611044321263611 3518+inf:inf 3519-inf:-inf 3520invalid:NaN 3521 3522# overloaded functions 3523&log 3524-1:NaN 35250:-inf 35261:0 35272:0 35283:1 3529123456789:18 35301234567890987654321:41 3531-inf:inf 3532inf:inf 3533NaN:NaN 3534 3535&exp 3536 3537&sin 3538 3539&cos 3540 3541&atan2 3542 3543&int 3544 3545&neg 3546 3547&abs 3548 3549&sqrt 3550