add the 'test_harness' target to vms "makefile"
[p5sagit/p5-mst-13.2.git] / lib / Math / BigInt / t / bigintpm.inc
CommitLineData
6854fd01 1#include this file into another for subclass testing
2
3my $version = ${"$class\::VERSION"};
4
56d9de68 5use strict;
6
6854fd01 7##############################################################################
8# for testing inheritance of _swap
9
10package Math::Foo;
11
61f5c3f5 12use Math::BigInt lib => $main::CL;
6854fd01 13use vars qw/@ISA/;
14@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
21sub _swap
22 {
23 # a fake _swap, which reverses the params
24 my $self = shift; # for override in subclass
25 if ($_[2])
26 {
27 my $c = ref ($_[0] ) || 'Math::Foo';
28 return ( $_[0]->copy(), $_[1] );
29 }
30 else
31 {
32 return ( Math::Foo->new($_[1]), $_[0] );
33 }
34 }
35
36##############################################################################
37package main;
38
b3abae2a 39my $CALC = $class->config()->{lib}; ok ($CALC,$CL);
6854fd01 40
b3abae2a 41my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class);
6854fd01 42
43while (<DATA>)
44 {
d614cd8b 45 chomp;
6854fd01 46 next if /^#/; # skip comments
47 if (s/^&//)
48 {
61f5c3f5 49 $f = $_; next;
6854fd01 50 }
51 elsif (/^\$/)
52 {
61f5c3f5 53 $round_mode = $_; $round_mode =~ s/^\$/$class\->/; next;
6854fd01 54 }
61f5c3f5 55
56 @args = split(/:/,$_,99); $ans = pop(@args);
b3abae2a 57 $expected_class = $class;
58 if ($ans =~ /(.*?)=(.*)/)
59 {
60 $expected_class = $2; $ans = $1;
61 }
61f5c3f5 62 $try = "\$x = $class->new(\"$args[0]\");";
63 if ($f eq "bnorm")
6854fd01 64 {
61f5c3f5 65 $try = "\$x = $class->bnorm(\"$args[0]\");";
66 # some is_xxx tests
b3abae2a 67 } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan|int)$/) {
56d9de68 68 $try .= "\$x->$f() || 0;";
61f5c3f5 69 } elsif ($f eq "is_inf") {
70 $try .= "\$x->is_inf('$args[1]');";
71 } elsif ($f eq "binf") {
72 $try .= "\$x->binf('$args[1]');";
73 } elsif ($f eq "bone") {
74 $try .= "\$x->bone('$args[1]');";
56d9de68 75 # some unary ops
b3abae2a 76 } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt|fac)$/) {
61f5c3f5 77 $try .= "\$x->$f();";
56d9de68 78 } elsif ($f =~ /^(numify|length|stringify|as_hex|as_bin)$/) {
79 $try .= "\$x->$f();";
61f5c3f5 80 } elsif ($f eq "exponent"){
81 # ->bstr() to see if an object is returned
82 $try .= '$x = $x->exponent()->bstr();';
83 } elsif ($f eq "mantissa"){
84 # ->bstr() to see if an object is returned
85 $try .= '$x = $x->mantissa()->bstr();';
86 } elsif ($f eq "parts"){
87 $try .= '($m,$e) = $x->parts();';
88 # ->bstr() to see if an object is returned
89 $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;';
90 $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;';
91 $try .= '"$m,$e";';
92 } else {
56d9de68 93 # binary ops
61f5c3f5 94 $try .= "\$y = $class->new('$args[1]');";
95 if ($f eq "bcmp")
96 {
97 $try .= '$x <=> $y;';
98 } elsif ($f eq "bround") {
6854fd01 99 $try .= "$round_mode; \$x->bround(\$y);";
61f5c3f5 100 } elsif ($f eq "bacmp"){
101 $try .= '$x->bacmp($y);';
102 } elsif ($f eq "badd"){
103 $try .= '$x + $y;';
104 } elsif ($f eq "bsub"){
105 $try .= '$x - $y;';
106 } elsif ($f eq "bmul"){
107 $try .= '$x * $y;';
108 } elsif ($f eq "bdiv"){
109 $try .= '$x / $y;';
110 } elsif ($f eq "bdiv-list"){
111 $try .= 'join (",",$x->bdiv($y));';
027dc388 112 # overload via x=
61f5c3f5 113 } elsif ($f =~ /^.=$/){
114 $try .= "\$x $f \$y;";
027dc388 115 # overload via x
61f5c3f5 116 } elsif ($f =~ /^.$/){
117 $try .= "\$x $f \$y;";
118 } elsif ($f eq "bmod"){
119 $try .= '$x % $y;';
120 } elsif ($f eq "bgcd")
6854fd01 121 {
122 if (defined $args[2])
123 {
61f5c3f5 124 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 125 }
126 $try .= "$class\::bgcd(\$x, \$y";
127 $try .= ", \$z" if (defined $args[2]);
128 $try .= " );";
129 }
130 elsif ($f eq "blcm")
131 {
132 if (defined $args[2])
133 {
61f5c3f5 134 $try .= " \$z = $class->new('$args[2]'); ";
6854fd01 135 }
136 $try .= "$class\::blcm(\$x, \$y";
137 $try .= ", \$z" if (defined $args[2]);
138 $try .= " );";
139 }elsif ($f eq "blsft"){
140 if (defined $args[2])
141 {
142 $try .= "\$x->blsft(\$y,$args[2]);";
143 }
144 else
145 {
146 $try .= "\$x << \$y;";
147 }
148 }elsif ($f eq "brsft"){
149 if (defined $args[2])
150 {
151 $try .= "\$x->brsft(\$y,$args[2]);";
152 }
153 else
154 {
155 $try .= "\$x >> \$y;";
156 }
990fb837 157 }elsif ($f eq "broot"){
158 $try .= "\$x->broot(\$y);";
091c87b1 159 }elsif ($f eq "blog"){
160 $try .= "\$x->blog(\$y);";
6854fd01 161 }elsif ($f eq "band"){
162 $try .= "\$x & \$y;";
163 }elsif ($f eq "bior"){
164 $try .= "\$x | \$y;";
165 }elsif ($f eq "bxor"){
166 $try .= "\$x ^ \$y;";
167 }elsif ($f eq "bpow"){
168 $try .= "\$x ** \$y;";
d614cd8b 169 } elsif( $f eq "bmodinv") {
170 $try .= "\$x->bmodinv(\$y);";
6854fd01 171 }elsif ($f eq "digit"){
56b9c951 172 $try .= "\$x->digit(\$y);";
d614cd8b 173 } else {
174 $try .= "\$z = $class->new(\"$args[2]\");";
175
176 # Functions with three arguments
177 if( $f eq "bmodpow") {
178 $try .= "\$x->bmodpow(\$y,\$z);";
179 } else { warn "Unknown op '$f'"; }
180 }
61f5c3f5 181 } # end else all other ops
182
183 $ans1 = eval $try;
184 # convert hex/binary targets to decimal
185 if ($ans =~ /^(0x0x|0b0b)/)
186 {
187 $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr();
6854fd01 188 }
61f5c3f5 189 if ($ans eq "")
190 {
191 ok_undef ($ans1);
192 }
193 else
194 {
195 # print "try: $try ans: $ans1 $ans\n";
196 print "# Tried: '$try'\n" if !ok ($ans1, $ans);
b3abae2a 197 ok (ref($ans),$expected_class) if $expected_class ne $class;
6854fd01 198 }
61f5c3f5 199 # check internal state of number objects
200 is_valid($ans1,$f) if ref $ans1;
6854fd01 201 } # endwhile data tests
202close DATA;
203
204# test some more
205@a = ();
206for (my $i = 1; $i < 10; $i++)
207 {
208 push @a, $i;
209 }
210ok "@a", "1 2 3 4 5 6 7 8 9";
211
212# test whether self-multiplication works correctly (result is 2**64)
213$try = "\$x = $class->new('4294967296');";
214$try .= '$a = $x->bmul($x);';
215$ans1 = eval $try;
216print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64);
217# test self-pow
218$try = "\$x = $class->new(10);";
219$try .= '$a = $x->bpow($x);';
220$ans1 = eval $try;
221print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10);
222
07d34614 223###############################################################################
6854fd01 224# test whether op destroys args or not (should better not)
225
226$x = $class->new(3);
227$y = $class->new(4);
228$z = $x & $y;
229ok ($x,3);
230ok ($y,4);
231ok ($z,0);
232$z = $x | $y;
233ok ($x,3);
234ok ($y,4);
235ok ($z,7);
236$x = $class->new(1);
237$y = $class->new(2);
238$z = $x | $y;
239ok ($x,1);
240ok ($y,2);
241ok ($z,3);
242
243$x = $class->new(5);
244$y = $class->new(4);
245$z = $x ^ $y;
246ok ($x,5);
247ok ($y,4);
248ok ($z,1);
249
250$x = $class->new(-5); $y = -$x;
251ok ($x, -5);
252
253$x = $class->new(-5); $y = abs($x);
254ok ($x, -5);
255
07d34614 256$x = $class->new(8);
257$y = $class->new(-1);
258$z = $class->new(5033);
259my $u = $x->copy()->bmodpow($y,$z);
260ok ($u,4404);
261ok ($y,-1);
262ok ($z,5033);
263
264$x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5);
265$x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5);
266
267$x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3);
268$x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3);
269$x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3);
270$x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3);
271$x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3);
272
273$x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3);
274$x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3);
275$x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3);
276$x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3);
277$x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3);
278
279$x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3);
280$x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3);
281$x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3);
282$x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3);
283$x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3);
284
285###############################################################################
6854fd01 286# check whether overloading cmp works
287$try = "\$x = $class->new(0);";
288$try .= "\$y = 10;";
289$try .= "'false' if \$x ne \$y;";
290$ans = eval $try;
291print "# For '$try'\n" if (!ok "$ans" , "false" );
292
293# we cant test for working cmpt with other objects here, we would need a dummy
294# object with stringify overload for this. see Math::String tests as example
295
296###############################################################################
6854fd01 297# check reversed order of arguments
027dc388 298
6854fd01 299$try = "\$x = $class->new(10); \$x = 2 ** \$x;";
300$try .= "'ok' if \$x == 1024;"; $ans = eval $try;
301print "# For '$try'\n" if (!ok "$ans" , "ok" );
302
303$try = "\$x = $class->new(10); \$x = 2 * \$x;";
304$try .= "'ok' if \$x == 20;"; $ans = eval $try;
305print "# For '$try'\n" if (!ok "$ans" , "ok" );
306
307$try = "\$x = $class->new(10); \$x = 2 + \$x;";
308$try .= "'ok' if \$x == 12;"; $ans = eval $try;
309print "# For '$try'\n" if (!ok "$ans" , "ok" );
310
311$try = "\$x = $class\->new(10); \$x = 2 - \$x;";
312$try .= "'ok' if \$x == -8;"; $ans = eval $try;
313print "# For '$try'\n" if (!ok "$ans" , "ok" );
314
315$try = "\$x = $class\->new(10); \$x = 20 / \$x;";
316$try .= "'ok' if \$x == 2;"; $ans = eval $try;
317print "# For '$try'\n" if (!ok "$ans" , "ok" );
318
027dc388 319$try = "\$x = $class\->new(3); \$x = 20 % \$x;";
320$try .= "'ok' if \$x == 2;"; $ans = eval $try;
321print "# For '$try'\n" if (!ok "$ans" , "ok" );
322
323$try = "\$x = $class\->new(7); \$x = 20 & \$x;";
324$try .= "'ok' if \$x == 4;"; $ans = eval $try;
325print "# For '$try'\n" if (!ok "$ans" , "ok" );
326
327$try = "\$x = $class\->new(7); \$x = 0x20 | \$x;";
328$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
329print "# For '$try'\n" if (!ok "$ans" , "ok" );
330
331$try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;";
332$try .= "'ok' if \$x == 0x27;"; $ans = eval $try;
333print "# For '$try'\n" if (!ok "$ans" , "ok" );
334
6854fd01 335###############################################################################
336# check badd(4,5) form
337
338$try = "\$x = $class\->badd(4,5);";
339$try .= "'ok' if \$x == 9;";
340$ans = eval $try;
341print "# For '$try'\n" if (!ok "$ans" , "ok" );
342
343###############################################################################
344# check undefs: NOT DONE YET
345
346###############################################################################
347# bool
348
f9a08e12 349$x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') }
350$x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') }
6854fd01 351
352###############################################################################
353# objectify()
354
355@args = Math::BigInt::objectify(2,4,5);
356ok (scalar @args,3); # $class, 4, 5
56b9c951 357ok ($args[0] =~ /^Math::BigInt/);
6854fd01 358ok ($args[1],4);
359ok ($args[2],5);
360
361@args = Math::BigInt::objectify(0,4,5);
362ok (scalar @args,3); # $class, 4, 5
56b9c951 363ok ($args[0] =~ /^Math::BigInt/);
6854fd01 364ok ($args[1],4);
365ok ($args[2],5);
366
367@args = Math::BigInt::objectify(2,4,5);
368ok (scalar @args,3); # $class, 4, 5
56b9c951 369ok ($args[0] =~ /^Math::BigInt/);
6854fd01 370ok ($args[1],4);
371ok ($args[2],5);
372
373@args = Math::BigInt::objectify(2,4,5,6,7);
374ok (scalar @args,5); # $class, 4, 5, 6, 7
56b9c951 375ok ($args[0] =~ /^Math::BigInt/);
6854fd01 376ok ($args[1],4); ok (ref($args[1]),$args[0]);
377ok ($args[2],5); ok (ref($args[2]),$args[0]);
378ok ($args[3],6); ok (ref($args[3]),'');
379ok ($args[4],7); ok (ref($args[4]),'');
380
381@args = Math::BigInt::objectify(2,$class,4,5,6,7);
382ok (scalar @args,5); # $class, 4, 5, 6, 7
383ok ($args[0],$class);
384ok ($args[1],4); ok (ref($args[1]),$args[0]);
385ok ($args[2],5); ok (ref($args[2]),$args[0]);
386ok ($args[3],6); ok (ref($args[3]),'');
387ok ($args[4],7); ok (ref($args[4]),'');
388
389###############################################################################
f9a08e12 390# test whether an opp calls objectify properly or not (or at least does what
391# it should do given non-objects, w/ or w/o objectify())
392
393ok ($class->new(123)->badd(123),246);
394ok ($class->badd(123,321),444);
395ok ($class->badd(123,$class->new(321)),444);
396
397ok ($class->new(123)->bsub(122),1);
398ok ($class->bsub(321,123),198);
399ok ($class->bsub(321,$class->new(123)),198);
400
401ok ($class->new(123)->bmul(123),15129);
402ok ($class->bmul(123,123),15129);
403ok ($class->bmul(123,$class->new(123)),15129);
404
405ok ($class->new(15129)->bdiv(123),123);
406ok ($class->bdiv(15129,123),123);
407ok ($class->bdiv(15129,$class->new(123)),123);
408
409ok ($class->new(15131)->bmod(123),2);
410ok ($class->bmod(15131,123),2);
411ok ($class->bmod(15131,$class->new(123)),2);
412
413ok ($class->new(2)->bpow(16),65536);
414ok ($class->bpow(2,16),65536);
415ok ($class->bpow(2,$class->new(16)),65536);
416
417ok ($class->new(2**15)->brsft(1),2**14);
418ok ($class->brsft(2**15,1),2**14);
419ok ($class->brsft(2**15,$class->new(1)),2**14);
420
421ok ($class->new(2**13)->blsft(1),2**14);
422ok ($class->blsft(2**13,1),2**14);
423ok ($class->blsft(2**13,$class->new(1)),2**14);
424
425###############################################################################
6854fd01 426# test for floating-point input (other tests in bnorm() below)
427
428$z = 1050000000000000; # may be int on systems with 64bit?
429$x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15
430$z = 1e+129; # definitely a float (may fail on UTS)
431# don't compare to $z, since some Perl versions stringify $z into something
432# like '1.e+129' or something equally ugly
433$x = $class->new($z); ok ($x->bsstr(),'1e+129');
434
435###############################################################################
56d9de68 436# test for whitespace inlcuding newlines to be handled correctly
437
438# ok ($Math::BigInt::strict,1); # the default
439
440foreach my $c (
441 qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/)
442 {
443 my $m = $class->new($c);
444 ok ($class->new("$c"),$m);
445 ok ($class->new(" $c"),$m);
446 ok ($class->new("$c "),$m);
447 ok ($class->new(" $c "),$m);
448 ok ($class->new("\n$c"),$m);
449 ok ($class->new("$c\n"),$m);
450 ok ($class->new("\n$c\n"),$m);
451 ok ($class->new(" \n$c\n"),$m);
452 ok ($class->new(" \n$c \n"),$m);
453 ok ($class->new(" \n$c\n "),$m);
454 ok ($class->new(" \n$c\n1"),'NaN');
455 ok ($class->new("1 \n$c\n1"),'NaN');
456 }
457
458###############################################################################
6854fd01 459# prime number tests, also test for **= and length()
460# found on: http://www.utm.edu/research/primes/notes/by_year.html
461
462# ((2^148)-1)/17
463$x = $class->new(2); $x **= 148; $x++; $x = $x / 17;
464ok ($x,"20988936657440586486151264256610222593863921");
465ok ($x->length(),length "20988936657440586486151264256610222593863921");
466
467# MM7 = 2^127-1
468$x = $class->new(2); $x **= 127; $x--;
469ok ($x,"170141183460469231731687303715884105727");
470
471$x = $class->new('215960156869840440586892398248');
472($x,$y) = $x->length();
473ok ($x,30); ok ($y,0);
474
475$x = $class->new('1_000_000_000_000');
476($x,$y) = $x->length();
477ok ($x,13); ok ($y,0);
478
479# I am afraid the following is not yet possible due to slowness
480# Also, testing for 2 meg output is a bit hard ;)
481#$x = $class->new(2); $x **= 6972593; $x--;
482
483# 593573509*2^332162+1 has exactly 1,000,000 digits
484# takes about 24 mins on 300 Mhz, so cannot be done yet ;)
485#$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++;
486#ok ($x->length(),1_000_000);
487
488###############################################################################
489# inheritance and overriding of _swap
490
491$x = Math::Foo->new(5);
492$x = $x - 8; # 8 - 5 instead of 5-8
493ok ($x,3);
494ok (ref($x),'Math::Foo');
495
496$x = Math::Foo->new(5);
497$x = 8 - $x; # 5 - 8 instead of 8 - 5
498ok ($x,-3);
499ok (ref($x),'Math::Foo');
500
501###############################################################################
502# Test whether +inf eq inf
503# This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl
504# hasn't (before 5.7.3 at least) a consistent way to say inf, and some things
505# like 1e100000 crash on some platforms. So simple test for the string 'inf'
506$x = $class->new('+inf'); ok ($x,'inf');
507
508###############################################################################
509###############################################################################
56d9de68 510# the followin tests only make sense with Math::BigInt::Calc or BareCalc or
511# FastCalc
6854fd01 512
56d9de68 513exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al.
6854fd01 514
515###############################################################################
516# check proper length of internal arrays
517
394e6ffb 518my $bl = $CL->_base_len();
6854fd01 519my $BASE = '9' x $bl;
520my $MAX = $BASE;
521$BASE++;
522
523$x = $class->new($MAX); is_valid($x); # f.i. 9999
524$x += 1; ok ($x,$BASE); is_valid($x); # 10000
525$x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again
526
527###############################################################################
528# check numify
529
530$x = $class->new($BASE-1); ok ($x->numify(),$BASE-1);
531$x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1));
61f5c3f5 532
533# +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...)
534$x = $class->new($BASE); ok ($x->numify()+0,$BASE+0);
6854fd01 535$x = $class->new(-$BASE); ok ($x->numify(),-$BASE);
536$x = $class->new( -($BASE*$BASE*1+$BASE*1+1) );
537ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1));
538
539###############################################################################
540# test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1
541
394e6ffb 542$x = $class->new($BASE-2); $x++; $x++; $x++; $x++;
543if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); }
544
545$x = $class->new($BASE+3); $x++;
546if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); }
6854fd01 547
394e6ffb 548# test for +0 instead of int():
549$x = $class->new($MAX); ok ($x->length(), length($MAX));
6854fd01 550
551###############################################################################
56b9c951 552# test bug that $class->digit($string) did not work
553
554ok ($class->digit(123,2),1);
555
556###############################################################################
6854fd01 557# bug in sub where number with at least 6 trailing zeros after any op failed
558
394e6ffb 559$x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z;
6854fd01 560ok ($z, 100000);
561ok ($x, 23456);
562
563###############################################################################
564# bug in shortcut in mul()
565
61f5c3f5 566# construct a number with a zero-hole of BASE_LEN_SMALL
567{
568 my @bl = $CL->_base_len(); my $bl = $bl[4];
569
570 $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl;
571 $y = '1' x (2*$bl);
572 $x = $class->new($x)->bmul($y);
573 # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl
574 $y = ''; my $d = '';
575 for (my $i = 1; $i <= $bl; $i++)
576 {
577 $y .= $i; $d = $i.$d;
578 }
579 $y .= $bl x (3*$bl-1) . $d . '0' x $bl;
580 ok ($x,$y);
581
6854fd01 582
f9a08e12 583 #############################################################################
584 # see if mul shortcut for small numbers works
394e6ffb 585
f9a08e12 586 $x = '9' x $bl;
587 $x = $class->new($x);
588 # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001
589 ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1');
590}
61f5c3f5 591
394e6ffb 592###############################################################################
6854fd01 593# bug with rest "-0" in div, causing further div()s to fail
594
394e6ffb 595$x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240');
6854fd01 596
61f5c3f5 597ok ($y,'0'); is_valid($y); # $y not '-0'
394e6ffb 598
79c55733 599###############################################################################
f9a08e12 600# bug in $x->bmod($y)
07d34614 601
f9a08e12 602# if $x < 0 and $y > 0
07d34614 603$x = $class->new('-629'); ok ($x->bmod(5033),4404);
604
605###############################################################################
56b9c951 606# bone/binf etc as plain calls (Lite failed them)
607
608ok ($class->bzero(),0);
609ok ($class->bone(),1);
610ok ($class->bone('+'),1);
611ok ($class->bone('-'),-1);
612ok ($class->bnan(),'NaN');
613ok ($class->binf(),'inf');
614ok ($class->binf('+'),'inf');
615ok ($class->binf('-'),'-inf');
616ok ($class->binf('-inf'),'-inf');
617
618###############################################################################
990fb837 619# is_one('-')
620
621ok ($class->new(1)->is_one('-'),0);
622ok ($class->new(-1)->is_one('-'),1);
623ok ($class->new(1)->is_one(),1);
624ok ($class->new(-1)->is_one(),0);
625
626###############################################################################
03874afe 627# [perl #30609] bug with $x -= $x not beeing 0, but 2*$x
628
629$x = $class->new(3); $x -= $x; ok ($x, 0);
630$x = $class->new(-3); $x -= $x; ok ($x, 0);
631$x = $class->new('NaN'); $x -= $x; ok ($x->is_nan(), 1);
632$x = $class->new('inf'); $x -= $x; ok ($x->is_nan(), 1);
633$x = $class->new('-inf'); $x -= $x; ok ($x->is_nan(), 1);
634
635$x = $class->new('NaN'); $x += $x; ok ($x->is_nan(), 1);
636$x = $class->new('inf'); $x += $x; ok ($x->is_inf(), 1);
637$x = $class->new('-inf'); $x += $x; ok ($x->is_inf('-'), 1);
638$x = $class->new(3); $x += $x; ok ($x, 6);
639$x = $class->new(-3); $x += $x; ok ($x, -6);
640
641$x = $class->new(3); $x *= $x; ok ($x, 9);
642$x = $class->new(-3); $x *= $x; ok ($x, 9);
643$x = $class->new(3); $x /= $x; ok ($x, 1);
644$x = $class->new(-3); $x /= $x; ok ($x, 1);
645$x = $class->new(3); $x %= $x; ok ($x, 0);
646$x = $class->new(-3); $x %= $x; ok ($x, 0);
647
648###############################################################################
61f5c3f5 649# all tests done
6854fd01 650
6511;
652
653###############################################################################
61f5c3f5 654###############################################################################
6854fd01 655# Perl 5.005 does not like ok ($x,undef)
656
657sub ok_undef
658 {
659 my $x = shift;
660
661 ok (1,1) and return if !defined $x;
662 ok ($x,'undef');
663 }
664
665###############################################################################
666# sub to check validity of a BigInt internally, to ensure that no op leaves a
667# number object in an invalid state (f.i. "-0")
668
669sub is_valid
670 {
671 my ($x,$f) = @_;
672
673 my $e = 0; # error?
6854fd01 674
56b9c951 675 # allow the check to pass for all Lite, and all MBI and subclasses
676 # ok as reference?
677 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 678
56b9c951 679 if (ref($x) ne 'Math::BigInt::Lite')
680 {
681 # has ok sign?
682 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
683 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
684
685 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
686 $e = $CALC->_check($x->{value}) if $e eq '0';
687 }
6854fd01 688
689 # test done, see if error did crop up
690 ok (1,1), return if ($e eq '0');
691
027dc388 692 ok (1,$e." after op '$f'");
6854fd01 693 }
694
695__DATA__
027dc388 696&.=
6971234:-345:1234-345
698&+=
6991:2:3
700-1:-2:-3
701&-=
7021:2:-1
703-1:-2:1
704&*=
7052:3:6
706-1:5:-5
707&%=
708100:3:1
7098:9:8
07d34614 710-629:5033:4404
027dc388 711&/=
712100:3:33
713-8:2:-4
714&|=
7152:1:3
716&&=
7175:7:5
718&^=
7195:7:2
091c87b1 720&blog
721NaNlog:2:NaN
722122:NaNlog:NaN
723NaNlog1:NaNlog:NaN
724122:inf:NaN
725inf:122:NaN
726122:-inf:NaN
727-inf:122:NaN
728-inf:-inf:NaN
729inf:inf:NaN
7300:4:NaN
731-21:4:NaN
73221:-21:NaN
733# normal results
7341024:2:10
73581:3:4
736# 3.01.. truncate
73782:3:4
738# 3.9... truncate
73980:3:3
74015625:5:6
74115626:5:6
74215624:5:5
8df1e0a2 7431000:10:3
74410000:10:4
745100000:10:5
7461000000:10:6
74710000000:10:7
748100000000:10:8
7498916100448256:12:12
7508916100448257:12:12
7518916100448255:12:11
7522251799813685248:8:17
75372057594037927936:2:56
754144115188075855872:2:57
755288230376151711744:2:58
756576460752303423488:2:59
7574096:2:12
7581329227995784915872903807060280344576:2:120
091c87b1 759# $x == $base => result 1
7603:3:1
761# $x < $base => result 0 ($base ** 0 <= $x)
7623:4:0
763# $x == 1 => result 0
7641:5:0
6854fd01 765&is_negative
7660:0
767-1:1
7681:0
769+inf:0
770-inf:1
771NaNneg:0
772&is_positive
7730:1
774-1:0
7751:1
776+inf:1
777-inf:0
778NaNneg:0
b3abae2a 779&is_int
780-inf:0
781+inf:0
782NaNis_int:0
7831:1
7840:1
785123e12:1
6854fd01 786&is_odd
787abc:0
7880:0
7891:1
7903:1
791-1:1
792-3:1
79310000001:1
79410000002:0
7952:0
b3abae2a 796120:0
797121:1
6854fd01 798&is_even
799abc:0
8000:1
8011:0
8023:0
803-1:0
804-3:0
80510000001:0
80610000002:1
8072:1
b3abae2a 808120:1
809121:0
6854fd01 810&bacmp
811+0:-0:0
812+0:+1:-1
813-1:+1:0
814+1:-1:0
815-1:+2:-1
816+2:-1:1
817-123456789:+987654321:-1
818+123456789:-987654321:-1
819+987654321:+123456789:1
820-987654321:+123456789:1
821-123:+4567889:-1
822# NaNs
823acmpNaN:123:
824123:acmpNaN:
825acmpNaN:acmpNaN:
826# infinity
827+inf:+inf:0
828-inf:-inf:0
829+inf:-inf:0
830-inf:+inf:0
831+inf:123:1
832-inf:123:1
833+inf:-123:1
834-inf:-123:1
ef9466ea 835123:-inf:-1
836-123:inf:-1
837-123:-inf:-1
838123:inf:-1
6854fd01 839# return undef
840+inf:NaN:
841NaN:inf:
842-inf:NaN:
843NaN:-inf:
844&bnorm
aef458a0 8450e999:0
8460e-999:0
847-0e999:0
848-0e-999:0
6854fd01 849123:123
850# binary input
8510babc:NaN
8520b123:NaN
8530b0:0
854-0b0:0
855-0b1:-1
8560b0001:1
8570b001:1
8580b011:3
8590b101:5
61f5c3f5 8600b1001:9
8610b10001:17
8620b100001:33
8630b1000001:65
8640b10000001:129
8650b100000001:257
8660b1000000001:513
8670b10000000001:1025
8680b100000000001:2049
8690b1000000000001:4097
8700b10000000000001:8193
8710b100000000000001:16385
8720b1000000000000001:32769
8730b10000000000000001:65537
8740b100000000000000001:131073
8750b1000000000000000001:262145
8760b10000000000000000001:524289
8770b100000000000000000001:1048577
8780b1000000000000000000001:2097153
8790b10000000000000000000001:4194305
8800b100000000000000000000001:8388609
8810b1000000000000000000000001:16777217
8820b10000000000000000000000001:33554433
8830b100000000000000000000000001:67108865
8840b1000000000000000000000000001:134217729
8850b10000000000000000000000000001:268435457
8860b100000000000000000000000000001:536870913
8870b1000000000000000000000000000001:1073741825
8880b10000000000000000000000000000001:2147483649
8890b100000000000000000000000000000001:4294967297
8900b1000000000000000000000000000000001:8589934593
8910b10000000000000000000000000000000001:17179869185
6854fd01 8920b_101:NaN
8930b1_0_1:5
394e6ffb 8940b0_0_0_1:1
6854fd01 895# hex input
896-0x0:0
8970xabcdefgh:NaN
8980x1234:4660
8990xabcdef:11259375
900-0xABCDEF:-11259375
901-0x1234:-4660
9020x12345678:305419896
9030x1_2_3_4_56_78:305419896
394e6ffb 9040xa_b_c_d_e_f:11259375
6854fd01 9050x_123:NaN
61f5c3f5 9060x9:9
9070x11:17
9080x21:33
9090x41:65
9100x81:129
9110x101:257
9120x201:513
9130x401:1025
9140x801:2049
9150x1001:4097
9160x2001:8193
9170x4001:16385
9180x8001:32769
9190x10001:65537
9200x20001:131073
9210x40001:262145
9220x80001:524289
9230x100001:1048577
9240x200001:2097153
9250x400001:4194305
9260x800001:8388609
9270x1000001:16777217
9280x2000001:33554433
9290x4000001:67108865
9300x8000001:134217729
9310x10000001:268435457
9320x20000001:536870913
9330x40000001:1073741825
9340x80000001:2147483649
9350x100000001:4294967297
9360x200000001:8589934593
9370x400000001:17179869185
9380x800000001:34359738369
6854fd01 939# inf input
940inf:inf
941+inf:inf
942-inf:-inf
9430inf:NaN
027dc388 944# abnormal input
6854fd01 945:NaN
946abc:NaN
947 1 a:NaN
9481bcd2:NaN
94911111b:NaN
950+1z:NaN
951-1z:NaN
027dc388 952# only one underscore between two digits
953_123:NaN
954_123_:NaN
955123_:NaN
9561__23:NaN
9571E1__2:NaN
9581_E12:NaN
9591E_12:NaN
9601_E_12:NaN
961+_1E12:NaN
962+0_1E2:100
963+0_0_1E2:100
964-0_0_1E2:-100
965-0_0_1E+0_0_2:-100
966E1:NaN
967E23:NaN
9681.23E1:NaN
9691.23E-1:NaN
970# bug with two E's in number beeing valid
9711e2e3:NaN
9721e2r:NaN
9731e2.0:NaN
07d34614 974# bug with two '.' in number beeing valid
9751.2.2:NaN
9761.2.3e1:NaN
977-1.2.3:NaN
978-1.2.3e-4:NaN
9791.2e3.4:NaN
9801.2e-3.4:NaN
9811.2.3.4:NaN
9821.2.t:NaN
9831..2:NaN
9841..2e1:NaN
9851..2e1..1:NaN
98612e1..1:NaN
987..2:NaN
988.-2:NaN
61f5c3f5 989# leading zeros
990012:12
9910123:123
99201234:1234
993012345:12345
9940123456:123456
99501234567:1234567
996012345678:12345678
9970123456789:123456789
99801234567891:1234567891
999012345678912:12345678912
10000123456789123:123456789123
100101234567891234:1234567891234
027dc388 1002# normal input
6854fd01 10030:0
1004+0:0
1005+00:0
1006+000:0
1007000000000000000000:0
1008-0:0
1009-0000:0
1010+1:1
1011+01:1
1012+001:1
1013+00000100000:100000
1014123456789:123456789
1015-1:-1
1016-01:-1
1017-001:-1
1018-123456789:-123456789
1019-00000100000:-100000
10201_2_3:123
6854fd01 102110000000000E-1_0:1
10221E2:100
10231E1:10
10241E0:1
6854fd01 10251.23E2:123
6854fd01 1026100E-1:10
1027# floating point input
027dc388 1028# .2e2:20
10291.E3:1000
6854fd01 10301.01E2:101
10311010E-1:101
1032-1010E0:-1010
1033-1010E1:-10100
027dc388 10341234.00:1234
1035# non-integer numbers
6854fd01 1036-1010E-2:NaN
1037-1.01E+1:NaN
1038-1.01E-1:NaN
6854fd01 1039&bnan
10401:NaN
10412:NaN
1042abc:NaN
1043&bone
61f5c3f5 10442:+:1
6854fd01 10452:-:-1
1046boneNaN:-:-1
61f5c3f5 1047boneNaN:+:1
10482:abc:1
10493::1
6854fd01 1050&binf
10511:+:inf
10522:-:-inf
10533:abc:inf
027dc388 1054&is_nan
1055123:0
1056abc:1
1057NaN:1
1058-123:0
6854fd01 1059&is_inf
1060+inf::1
1061-inf::1
1062abc::0
10631::0
1064NaN::0
1065-1::0
1066+inf:-:0
1067+inf:+:1
1068-inf:-:1
1069-inf:+:0
79c55733 1070-inf:-inf:1
1071-inf:+inf:0
1072+inf:-inf:0
1073+inf:+inf:1
6854fd01 1074# it must be exactly /^[+-]inf$/
1075+infinity::0
1076-infinity::0
1077&blsft
1078abc:abc:NaN
61f5c3f5 1079+2:+2:8
1080+1:+32:4294967296
1081+1:+48:281474976710656
6854fd01 1082+8:-2:NaN
1083# excercise base 10
1084+12345:4:10:123450000
1085-1234:0:10:-1234
61f5c3f5 1086+1234:0:10:1234
6854fd01 1087+2:2:10:200
1088+12:2:10:1200
1089+1234:-3:10:NaN
10901234567890123:12:10:1234567890123000000000000
b3abae2a 1091-3:1:2:-6
1092-5:1:2:-10
1093-2:1:2:-4
1094-102533203:1:2:-205066406
6854fd01 1095&brsft
1096abc:abc:NaN
61f5c3f5 1097+8:+2:2
1098+4294967296:+32:1
1099+281474976710656:+48:1
6854fd01 1100+2:-2:NaN
1101# excercise base 10
1102-1234:0:10:-1234
61f5c3f5 1103+1234:0:10:1234
6854fd01 1104+200:2:10:2
1105+1234:3:10:1
1106+1234:2:10:12
1107+1234:-3:10:NaN
1108310000:4:10:31
110912300000:5:10:123
11101230000000000:10:10:123
111109876123456789067890:12:10:9876123
11121234561234567890123:13:10:123456
b3abae2a 1113820265627:1:2:410132813
1114# test shifting negative numbers in base 2
1115-15:1:2:-8
1116-14:1:2:-7
1117-13:1:2:-7
1118-12:1:2:-6
1119-11:1:2:-6
1120-10:1:2:-5
1121-9:1:2:-5
1122-8:1:2:-4
1123-7:1:2:-4
1124-6:1:2:-3
1125-5:1:2:-3
1126-4:1:2:-2
1127-3:1:2:-2
1128-2:1:2:-1
1129-1:1:2:-1
1130-1640531254:2:2:-410132814
1131-1640531254:1:2:-820265627
1132-820265627:1:2:-410132814
1133-205066405:1:2:-102533203
6854fd01 1134&bsstr
56d9de68 1135+inf:inf
1136-inf:-inf
6854fd01 11371e+34:1e+34
1138123.456E3:123456e+0
1139100:1e+2
56d9de68 1140bsstrabc:NaN
1141-5:-5e+0
1142-100:-1e+2
1143&numify
1144numifyabc:NaN
1145+inf:inf
1146-inf:-inf
11475:5
1148-5:-5
1149100:100
1150-100:-100
6854fd01 1151&bneg
1152bnegNaN:NaN
1153+inf:-inf
1154-inf:inf
1155abd:NaN
61f5c3f5 11560:0
11571:-1
1158-1:1
6854fd01 1159+123456789:-123456789
61f5c3f5 1160-123456789:123456789
6854fd01 1161&babs
1162babsNaN:NaN
1163+inf:inf
1164-inf:inf
61f5c3f5 11650:0
11661:1
1167-1:1
1168+123456789:123456789
1169-123456789:123456789
6854fd01 1170&bcmp
1171bcmpNaN:bcmpNaN:
61f5c3f5 1172bcmpNaN:0:
11730:bcmpNaN:
11740:0:0
1175-1:0:-1
11760:-1:1
11771:0:1
11780:1:-1
1179-1:1:-1
11801:-1:1
6854fd01 1181-1:-1:0
61f5c3f5 11821:1:0
1183123:123:0
1184123:12:1
118512:123:-1
6854fd01 1186-123:-123:0
1187-123:-12:-1
1188-12:-123:1
61f5c3f5 1189123:124:-1
1190124:123:1
6854fd01 1191-123:-124:1
1192-124:-123:-1
61f5c3f5 1193100:5:1
1194-123456789:987654321:-1
6854fd01 1195+123456789:-987654321:1
61f5c3f5 1196-987654321:123456789:-1
6854fd01 1197-inf:5432112345:-1
1198+inf:5432112345:1
1199-inf:-5432112345:-1
1200+inf:-5432112345:1
1201+inf:+inf:0
1202-inf:-inf:0
1203+inf:-inf:1
1204-inf:+inf:-1
12055:inf:-1
12065:inf:-1
1207-5:-inf:1
1208-5:-inf:1
1209# return undef
1210+inf:NaN:
1211NaN:inf:
1212-inf:NaN:
1213NaN:-inf:
1214&binc
1215abc:NaN
1216+inf:inf
1217-inf:-inf
61f5c3f5 1218+0:1
1219+1:2
1220-1:0
6854fd01 1221&bdec
1222abc:NaN
1223+inf:inf
1224-inf:-inf
1225+0:-1
61f5c3f5 1226+1:0
6854fd01 1227-1:-2
1228&badd
1229abc:abc:NaN
61f5c3f5 1230abc:0:NaN
6854fd01 1231+0:abc:NaN
b3abae2a 1232+inf:-inf:NaN
1233-inf:+inf:NaN
6854fd01 1234+inf:+inf:inf
1235-inf:-inf:-inf
1236baddNaN:+inf:NaN
1237baddNaN:+inf:NaN
1238+inf:baddNaN:NaN
1239-inf:baddNaN:NaN
61f5c3f5 12400:0:0
12411:0:1
12420:1:1
12431:1:2
1244-1:0:-1
12450:-1:-1
6854fd01 1246-1:-1:-2
61f5c3f5 1247-1:+1:0
1248+1:-1:0
1249+9:+1:10
1250+99:+1:100
1251+999:+1:1000
1252+9999:+1:10000
1253+99999:+1:100000
1254+999999:+1:1000000
1255+9999999:+1:10000000
1256+99999999:+1:100000000
1257+999999999:+1:1000000000
1258+9999999999:+1:10000000000
1259+99999999999:+1:100000000000
1260+10:-1:9
1261+100:-1:99
1262+1000:-1:999
1263+10000:-1:9999
1264+100000:-1:99999
1265+1000000:-1:999999
1266+10000000:-1:9999999
1267+100000000:-1:99999999
1268+1000000000:-1:999999999
1269+10000000000:-1:9999999999
1270+123456789:987654321:1111111110
1271-123456789:987654321:864197532
6854fd01 1272-123456789:-987654321:-1111111110
1273+123456789:-987654321:-864197532
56b9c951 1274-1:10001:10000
1275-1:100001:100000
1276-1:1000001:1000000
1277-1:10000001:10000000
1278-1:100000001:100000000
1279-1:1000000001:1000000000
1280-1:10000000001:10000000000
1281-1:100000000001:100000000000
1282-1:1000000000001:1000000000000
1283-1:10000000000001:10000000000000
1284-1:-10001:-10002
1285-1:-100001:-100002
1286-1:-1000001:-1000002
1287-1:-10000001:-10000002
1288-1:-100000001:-100000002
1289-1:-1000000001:-1000000002
1290-1:-10000000001:-10000000002
1291-1:-100000000001:-100000000002
1292-1:-1000000000001:-1000000000002
1293-1:-10000000000001:-10000000000002
6854fd01 1294&bsub
1295abc:abc:NaN
1296abc:+0:NaN
1297+0:abc:NaN
1298+inf:-inf:inf
1299-inf:+inf:-inf
b3abae2a 1300+inf:+inf:NaN
1301-inf:-inf:NaN
61f5c3f5 1302+0:+0:0
1303+1:+0:1
6854fd01 1304+0:+1:-1
61f5c3f5 1305+1:+1:0
6854fd01 1306-1:+0:-1
61f5c3f5 1307+0:-1:1
1308-1:-1:0
6854fd01 1309-1:+1:-2
61f5c3f5 1310+1:-1:2
1311+9:+1:8
1312+99:+1:98
1313+999:+1:998
1314+9999:+1:9998
1315+99999:+1:99998
1316+999999:+1:999998
1317+9999999:+1:9999998
1318+99999999:+1:99999998
1319+999999999:+1:999999998
1320+9999999999:+1:9999999998
1321+99999999999:+1:99999999998
1322+10:-1:11
1323+100:-1:101
1324+1000:-1:1001
1325+10000:-1:10001
1326+100000:-1:100001
1327+1000000:-1:1000001
1328+10000000:-1:10000001
1329+100000000:-1:100000001
1330+1000000000:-1:1000000001
1331+10000000000:-1:10000000001
6854fd01 1332+123456789:+987654321:-864197532
1333-123456789:+987654321:-1111111110
61f5c3f5 1334-123456789:-987654321:864197532
1335+123456789:-987654321:1111111110
56b9c951 133610001:1:10000
1337100001:1:100000
13381000001:1:1000000
133910000001:1:10000000
1340100000001:1:100000000
13411000000001:1:1000000000
134210000000001:1:10000000000
1343100000000001:1:100000000000
13441000000000001:1:1000000000000
134510000000000001:1:10000000000000
134610001:-1:10002
1347100001:-1:100002
13481000001:-1:1000002
134910000001:-1:10000002
1350100000001:-1:100000002
13511000000001:-1:1000000002
135210000000001:-1:10000000002
1353100000000001:-1:100000000002
13541000000000001:-1:1000000000002
135510000000000001:-1:10000000000002
6854fd01 1356&bmul
1357abc:abc:NaN
1358abc:+0:NaN
1359+0:abc:NaN
1360NaNmul:+inf:NaN
1361NaNmul:-inf:NaN
1362-inf:NaNmul:NaN
1363+inf:NaNmul:NaN
1364+inf:+inf:inf
1365+inf:-inf:-inf
1366-inf:+inf:-inf
1367-inf:-inf:inf
61f5c3f5 1368+0:+0:0
1369+0:+1:0
1370+1:+0:0
1371+0:-1:0
1372-1:+0:0
1373123456789123456789:0:0
13740:123456789123456789:0
1375-1:-1:1
6854fd01 1376-1:+1:-1
1377+1:-1:-1
61f5c3f5 1378+1:+1:1
1379+2:+3:6
6854fd01 1380-2:+3:-6
1381+2:-3:-6
61f5c3f5 1382-2:-3:6
1383111:111:12321
138410101:10101:102030201
13851001001:1001001:1002003002001
1386100010001:100010001:10002000300020001
138710000100001:10000100001:100002000030000200001
138811111111111:9:99999999999
138922222222222:9:199999999998
139033333333333:9:299999999997
139144444444444:9:399999999996
139255555555555:9:499999999995
139366666666666:9:599999999994
139477777777777:9:699999999993
139588888888888:9:799999999992
139699999999999:9:899999999991
1397+25:+25:625
1398+12345:+12345:152399025
1399+99999:+11111:1111088889
6854fd01 14009999:10000:99990000
140199999:100000:9999900000
1402999999:1000000:999999000000
14039999999:10000000:99999990000000
140499999999:100000000:9999999900000000
1405999999999:1000000000:999999999000000000
14069999999999:10000000000:99999999990000000000
140799999999999:100000000000:9999999999900000000000
1408999999999999:1000000000000:999999999999000000000000
14099999999999999:10000000000000:99999999999990000000000000
141099999999999999:100000000000000:9999999999999900000000000000
1411999999999999999:1000000000000000:999999999999999000000000000000
14129999999999999999:10000000000000000:99999999999999990000000000000000
141399999999999999999:100000000000000000:9999999999999999900000000000000000
1414999999999999999999:1000000000000000000:999999999999999999000000000000000000
14159999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1416&bdiv-list
1417100:20:5,0
14184095:4095:1,0
1419-4095:-4095:1,0
14204095:-4095:-1,0
1421-4095:4095:-1,0
1422123:2:61,1
b3abae2a 14239:5:1,4
14249:4:2,1
6854fd01 1425# inf handling and general remainder
14265:8:0,5
14270:8:0,0
142811:2:5,1
142911:-2:-5,-1
1430-11:2:-5,1
1431# see table in documentation in MBI
14320:inf:0,0
14330:-inf:0,0
14345:inf:0,5
14355:-inf:0,5
1436-5:inf:0,-5
1437-5:-inf:0,-5
1438inf:5:inf,0
1439-inf:5:-inf,0
1440inf:-5:-inf,0
1441-inf:-5:inf,0
14425:5:1,0
1443-5:-5:1,0
b3abae2a 1444inf:inf:NaN,NaN
1445-inf:-inf:NaN,NaN
1446-inf:inf:NaN,NaN
1447inf:-inf:NaN,NaN
6854fd01 14488:0:inf,8
1449inf:0:inf,inf
1450# exceptions to reminder rule
1451-8:0:-inf,-8
1452-inf:0:-inf,-inf
14530:0:NaN,NaN
990fb837 1454# test the shortcut in Calc if @$x == @$yorg
14551234567812345678:123456712345678:10,688888898
145612345671234567:1234561234567:10,58888897
1457123456123456:12345123456:10,4888896
14581234512345:123412345:10,388895
14591234567890999999999:1234567890:1000000000,999999999
14601234567890000000000:1234567890:1000000000,0
14611234567890999999999:9876543210:124999998,9503086419
14621234567890000000000:9876543210:124999998,8503086420
146396969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
6854fd01 1464&bdiv
1465abc:abc:NaN
61f5c3f5 1466abc:1:NaN
14671:abc:NaN
14680:0:NaN
6854fd01 1469# inf handling (see table in doc)
14700:inf:0
14710:-inf:0
14725:inf:0
14735:-inf:0
1474-5:inf:0
1475-5:-inf:0
1476inf:5:inf
1477-inf:5:-inf
1478inf:-5:-inf
1479-inf:-5:inf
14805:5:1
1481-5:-5:1
b3abae2a 1482inf:inf:NaN
1483-inf:-inf:NaN
1484-inf:inf:NaN
1485inf:-inf:NaN
6854fd01 14868:0:inf
1487inf:0:inf
1488-8:0:-inf
1489-inf:0:-inf
14900:0:NaN
149111:2:5
1492-11:-2:5
1493-11:2:-5
149411:-2:-5
61f5c3f5 14950:1:0
14960:-1:0
14971:1:1
1498-1:-1:1
14991:-1:-1
1500-1:1:-1
15011:2:0
15022:1:2
15031:26:0
15041000000000:9:111111111
15052000000000:9:222222222
15063000000000:9:333333333
15074000000000:9:444444444
15085000000000:9:555555555
15096000000000:9:666666666
15107000000000:9:777777777
15118000000000:9:888888888
15129000000000:9:1000000000
151335500000:113:314159
151471000000:226:314159
1515106500000:339:314159
15161000000000:3:333333333
1517+10:+5:2
1518+100:+4:25
1519+1000:+8:125
1520+10000:+16:625
1521999999999999:9:111111111111
1522999999999999:99:10101010101
1523999999999999:999:1001001001
1524999999999999:9999:100010001
1525999999999999999:99999:10000100001
1526+1111088889:99999:11111
6854fd01 1527-5:-3:1
1528-5:3:-1
15294:3:1
15304:-3:-1
15311:3:0
15321:-3:0
1533-2:-3:0
1534-2:3:0
15358:3:2
1536-8:3:-2
153714:-3:-4
1538-14:3:-4
1539-14:-3:4
154014:3:4
1541# bug in Calc with '99999' vs $BASE-1
154210000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1543# test the shortcut in Calc if @$x == @$yorg
15441234567812345678:123456712345678:10
154512345671234567:1234561234567:10
1546123456123456:12345123456:10
15471234512345:123412345:10
15481234567890999999999:1234567890:1000000000
15491234567890000000000:1234567890:1000000000
15501234567890999999999:9876543210:124999998
15511234567890000000000:9876543210:124999998
155296969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1553# bug up to v0.35 in Calc (--$q one too many)
155484696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
155584696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
155684696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
155784696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
07d34614 1558&bmodinv
1559# format: number:modulus:result
1560# bmodinv Data errors
1561abc:abc:NaN
1562abc:5:NaN
15635:abc:NaN
1564# bmodinv Expected Results from normal use
15651:5:1
15663:5:2
1567-2:5:2
15688:5033:4404
56d9de68 15691234567891:13:6
1570-1234567891:13:7
07d34614 1571324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1572## bmodinv Error cases / useless use of function
07d34614 15733:-5:NaN
1574inf:5:NaN
1ddff52a 15755:inf:NaN
1576-inf:5:NaN
15775:-inf:NaN
07d34614 1578&bmodpow
1579# format: number:exponent:modulus:result
1580# bmodpow Data errors
1581abc:abc:abc:NaN
15825:abc:abc:NaN
1583abc:5:abc:NaN
1584abc:abc:5:NaN
15855:5:abc:NaN
15865:abc:5:NaN
1587abc:5:5:NaN
1588# bmodpow Expected results
15890:0:2:1
15901:0:2:1
15910:0:1:0
15928:7:5032:3840
15938:-1:5033:4404
159498436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1595# bmodpow Error cases
15968:8:-5:NaN
15978:-1:16:NaN
1598inf:5:13:NaN
15995:inf:13:NaN
6854fd01 1600&bmod
1601# inf handling, see table in doc
16020:inf:0
16030:-inf:0
16045:inf:5
16055:-inf:5
1606-5:inf:-5
1607-5:-inf:-5
1608inf:5:0
1609-inf:5:0
1610inf:-5:0
1611-inf:-5:0
16125:5:0
1613-5:-5:0
b3abae2a 1614inf:inf:NaN
1615-inf:-inf:NaN
1616-inf:inf:NaN
1617inf:-inf:NaN
6854fd01 16188:0:8
1619inf:0:inf
1620# exceptions to reminder rule
1621-inf:0:-inf
1622-8:0:-8
16230:0:NaN
1624abc:abc:NaN
61f5c3f5 1625abc:1:abc:NaN
16261:abc:NaN
16270:0:NaN
16280:1:0
16291:0:1
16300:-1:0
1631-1:0:-1
16321:1:0
1633-1:-1:0
16341:-1:0
1635-1:1:0
16361:2:1
16372:1:0
16381000000000:9:1
16392000000000:9:2
16403000000000:9:3
16414000000000:9:4
16425000000000:9:5
16436000000000:9:6
16447000000000:9:7
16458000000000:9:8
16469000000000:9:0
164735500000:113:33
164871000000:226:66
1649106500000:339:99
16501000000000:3:1
165110:5:0
1652100:4:0
16531000:8:0
165410000:16:0
1655999999999999:9:0
1656999999999999:99:0
1657999999999999:999:0
1658999999999999:9999:0
1659999999999999999:99999:0
1660-9:+5:1
6854fd01 1661+9:-5:-1
1662-9:-5:-4
1663-5:3:1
1664-2:3:1
16654:3:1
16661:3:1
1667-5:-3:-2
1668-2:-3:-2
16694:-3:-2
16701:-3:-2
16714095:4095:0
027dc388 1672100041000510123:3:0
1673152403346:12345:4321
b3abae2a 16749:5:4
28df3e88 1675# test shortcuts in Calc
1676# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
16771234:9:1
1678123456:9:3
167912345678:9:0
16801234567891:9:1
1681123456789123:9:6
168212345678912345:9:6
16831234567891234567:9:1
1684123456789123456789:9:0
16851234:10:4
1686123456:10:6
168712345678:10:8
16881234567891:10:1
1689123456789123:10:3
169012345678912345:10:5
16911234567891234567:10:7
1692123456789123456789:10:9
16931234:113:104
1694123456:113:60
169512345678:113:89
16961234567891:113:64
1697123456789123:113:95
169812345678912345:113:53
16991234567891234567:113:56
1700123456789123456789:113:39
07d34614 1701# bug in bmod() not modifying the variable in place
1702-629:5033:4404
aef458a0 1703# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1704# when X == X and X was big
1705111111111111111111111111111111:111111111111111111111111111111:0
170612345678901234567890:12345678901234567890:0
6854fd01 1707&bgcd
9b924220 1708inf:12:NaN
1709-inf:12:NaN
171012:inf:NaN
171112:-inf:NaN
1712inf:inf:NaN
1713inf:-inf:NaN
1714-inf:-inf:NaN
6854fd01 1715abc:abc:NaN
1716abc:+0:NaN
1717+0:abc:NaN
61f5c3f5 1718+0:+0:0
1719+0:+1:1
1720+1:+0:1
1721+1:+1:1
1722+2:+3:1
1723+3:+2:1
1724-3:+2:1
9b924220 1725-3:-2:1
1726-144:-60:12
1727144:-60:12
1728144:60:12
61f5c3f5 1729100:625:25
17304096:81:1
17311034:804:2
173227:90:56:1
173327:90:54:9
6854fd01 1734&blcm
1735abc:abc:NaN
1736abc:+0:NaN
1737+0:abc:NaN
1738+0:+0:NaN
61f5c3f5 1739+1:+0:0
1740+0:+1:0
1741+27:+90:270
1742+1034:+804:415668
6854fd01 1743&band
1744abc:abc:NaN
1745abc:0:NaN
17460:abc:NaN
17471:2:0
17483:2:2
61f5c3f5 1749+8:+2:0
1750+281474976710656:0:0
1751+281474976710656:1:0
1752+281474976710656:+281474976710656:281474976710656
9b924220 1753281474976710656:-1:281474976710656
6854fd01 1754-2:-3:-4
1755-1:-1:-1
1756-6:-6:-6
1757-7:-4:-8
1758-7:4:0
1759-4:7:4
9b924220 1760# negative argument is bitwise shorter than positive [perl #26559]
176130:-3:28
1762123:-1:123
394e6ffb 1763# equal arguments are treated special, so also do some test with unequal ones
17640xFFFF:0xFFFF:0x0xFFFF
17650xFFFFFF:0xFFFFFF:0x0xFFFFFF
17660xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
17670xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17680xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17690xF0F0:0xF0F0:0x0xF0F0
17700x0F0F:0x0F0F:0x0x0F0F
17710xF0F0F0:0xF0F0F0:0x0xF0F0F0
17720x0F0F0F:0x0F0F0F:0x0x0F0F0F
17730xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
17740x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
17750xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
17760x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
17770xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
17780x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
17790x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1780&bior
1781abc:abc:NaN
1782abc:0:NaN
17830:abc:NaN
17841:2:3
61f5c3f5 1785+8:+2:10
1786+281474976710656:0:281474976710656
1787+281474976710656:1:281474976710657
1788+281474976710656:281474976710656:281474976710656
6854fd01 1789-2:-3:-1
1790-1:-1:-1
1791-6:-6:-6
1792-7:4:-3
1793-4:7:-1
9b924220 1794+281474976710656:-1:-1
179530:-3:-1
179630:-4:-2
1797300:-76:-68
1798-76:300:-68
394e6ffb 1799# equal arguments are treated special, so also do some test with unequal ones
18000xFFFF:0xFFFF:0x0xFFFF
18010xFFFFFF:0xFFFFFF:0x0xFFFFFF
18020xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
18030xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18040xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18050:0xFFFF:0x0xFFFF
18060:0xFFFFFF:0x0xFFFFFF
18070:0xFFFFFFFF:0x0xFFFFFFFF
18080:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18090:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18100xFFFF:0:0x0xFFFF
18110xFFFFFF:0:0x0xFFFFFF
18120xFFFFFFFF:0:0x0xFFFFFFFF
18130xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18140xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18150xF0F0:0xF0F0:0x0xF0F0
18160x0F0F:0x0F0F:0x0x0F0F
18170xF0F0:0x0F0F:0x0xFFFF
18180xF0F0F0:0xF0F0F0:0x0xF0F0F0
18190x0F0F0F:0x0F0F0F:0x0x0F0F0F
18200x0F0F0F:0xF0F0F0:0x0xFFFFFF
18210xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18220x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18230x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
18240xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18250x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18260x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
18270xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18280x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18290x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
18300x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1831&bxor
1832abc:abc:NaN
1833abc:0:NaN
18340:abc:NaN
18351:2:3
61f5c3f5 1836+8:+2:10
1837+281474976710656:0:281474976710656
1838+281474976710656:1:281474976710657
1839+281474976710656:281474976710656:0
6854fd01 1840-2:-3:3
1841-1:-1:0
1842-6:-6:0
1843-7:4:-3
1844-4:7:-5
18454:-7:-3
1846-4:-7:5
9b924220 184730:-3:-29
184830:-4:-30
1849300:-76:-360
1850-76:300:-360
394e6ffb 1851# equal arguments are treated special, so also do some test with unequal ones
18520xFFFF:0xFFFF:0
18530xFFFFFF:0xFFFFFF:0
18540xFFFFFFFF:0xFFFFFFFF:0
18550xFFFFFFFFFF:0xFFFFFFFFFF:0
18560xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
18570:0xFFFF:0x0xFFFF
18580:0xFFFFFF:0x0xFFFFFF
18590:0xFFFFFFFF:0x0xFFFFFFFF
18600:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18610:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18620xFFFF:0:0x0xFFFF
18630xFFFFFF:0:0x0xFFFFFF
18640xFFFFFFFF:0:0x0xFFFFFFFF
18650xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18660xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18670xF0F0:0xF0F0:0
18680x0F0F:0x0F0F:0
18690xF0F0:0x0F0F:0x0xFFFF
18700xF0F0F0:0xF0F0F0:0
18710x0F0F0F:0x0F0F0F:0
18720x0F0F0F:0xF0F0F0:0x0xFFFFFF
18730xF0F0F0F0:0xF0F0F0F0:0
18740x0F0F0F0F:0x0F0F0F0F:0
18750x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
18760xF0F0F0F0F0:0xF0F0F0F0F0:0
18770x0F0F0F0F0F:0x0F0F0F0F0F:0
18780x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
18790xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
18800x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
18810x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1882&bnot
1883abc:NaN
1884+0:-1
1885+8:-9
1886+281474976710656:-281474976710657
1887-1:0
1888-2:1
1889-12:11
1890&digit
18910:0:0
189212:0:2
189312:1:1
1894123:0:3
1895123:1:2
1896123:2:1
1897123:-1:1
1898123:-2:2
1899123:-3:3
1900123456:0:6
1901123456:1:5
1902123456:2:4
1903123456:3:3
1904123456:4:2
1905123456:5:1
1906123456:-1:1
1907123456:-2:2
1908123456:-3:3
1909100000:-3:0
1910100000:0:0
1911100000:1:0
1912&mantissa
1913abc:NaN
19141e4:1
19152e0:2
1916123:123
1917-1:-1
1918-2:-2
1919+inf:inf
1920-inf:-inf
1921&exponent
1922abc:NaN
19231e4:4
19242e0:0
1925123:0
1926-1:0
1927-2:0
19280:1
1929+inf:inf
1930-inf:inf
1931&parts
1932abc:NaN,NaN
19331e4:1,4
19342e0:2,0
1935123:123,0
1936-1:-1,0
1937-2:-2,0
19380:0,1
1939+inf:inf,inf
1940-inf:-inf,inf
b3abae2a 1941&bfac
1942-1:NaN
1943NaNfac:NaN
b282a552 1944+inf:inf
b3abae2a 1945-inf:NaN
19460:1
19471:1
19482:2
19493:6
19504:24
19515:120
19526:720
990fb837 19537:5040
19548:40320
19559:362880
b3abae2a 195610:3628800
195711:39916800
195812:479001600
6854fd01 1959&bpow
1960abc:12:NaN
196112:abc:NaN
19620:0:1
19630:1:0
19640:2:0
9b924220 19650:-1:inf
19660:-2:inf
6854fd01 19671:0:1
19681:1:1
19691:2:1
19701:3:1
19711:-1:1
19721:-2:1
19731:-3:1
19742:0:1
19752:1:2
19762:2:4
19772:3:8
19783:3:27
19792:-1:NaN
1980-2:-1:NaN
19812:-2:NaN
1982-2:-2:NaN
1983+inf:1234500012:inf
1984-inf:1234500012:-inf
1985+inf:-12345000123:inf
1986-inf:-12345000123:-inf
1987# 1 ** -x => 1 / (1 ** x)
1988-1:0:1
1989-2:0:1
1990-1:1:-1
1991-1:2:1
1992-1:3:-1
1993-1:4:1
1994-1:5:-1
1995-1:-1:-1
1996-1:-2:1
1997-1:-3:-1
1998-1:-4:1
199910:2:100
200010:3:1000
200110:4:10000
200210:5:100000
200310:6:1000000
200410:7:10000000
200510:8:100000000
200610:9:1000000000
200710:20:100000000000000000000
2008123456:2:15241383936
9b924220 2009-2:2:4
2010-2:3:-8
2011-2:4:16
2012-2:5:-32
2013-3:2:9
2014-3:3:-27
2015-3:4:81
2016-3:5:-243
6854fd01 2017&length
2018100:3
201910:2
20201:1
20210:1
202212345:5
202310000000000000000:17
2024-123:3
2025215960156869840440586892398248:30
990fb837 2026&broot
2027# sqrt()
2028+0:2:0
2029+1:2:1
2030-1:2:NaN
2031# -$x ** (1/2) => -$y, but not in froot()
2032-123:2:NaN
2033+inf:2:inf
2034-inf:2:NaN
20352:2:1
2036-2:2:NaN
20374:2:2
20389:2:3
203916:2:4
2040100:2:10
2041123:2:11
204215241:2:123
2043144:2:12
204412:2:3
20450.49:2:0
20460.0049:2:0
2047# invalid ones
20481:NaN:NaN
2049-1:NaN:NaN
20500:NaN:NaN
2051-inf:NaN:NaN
2052+inf:NaN:NaN
2053NaN:0:NaN
2054NaN:2:NaN
2055NaN:inf:NaN
2056NaN:inf:NaN
205712:-inf:NaN
205812:inf:NaN
2059+0:0:NaN
2060+1:0:NaN
2061-1:0:NaN
2062-2:0:NaN
2063-123.45:0:NaN
2064+inf:0:NaN
206512:1:12
2066-12:1:NaN
20678:-1:NaN
2068-8:-1:NaN
2069# cubic root
20708:3:2
2071-8:3:NaN
2072# fourths root
c38b2de2 207316:4:2
207481:4:3
3a427a11 2075# 2 ** 64
c38b2de2 207618446744073709551616:4:65536
207718446744073709551616:8:256
207818446744073709551616:16:16
207918446744073709551616:32:4
208018446744073709551616:64:2
208118446744073709551616:128:1
3a427a11 2082# 213 ** 15
208384274086103068221283760416414557757:15:213
2084# see t/bigroot for more tests
6854fd01 2085&bsqrt
394e6ffb 2086145:12
6854fd01 2087144:12
394e6ffb 2088143:11
6854fd01 208916:4
394e6ffb 2090170:13
2091169:13
2092168:12
6854fd01 20934:2
394e6ffb 20943:1
6854fd01 20952:1
394e6ffb 20969:3
6854fd01 209712:3
2098256:16
2099100000000:10000
21004000000000000:2000000
394e6ffb 2101152399026:12345
2102152399025:12345
2103152399024:12344
3a427a11 2104# 2 ** 64 => 2 ** 32
210518446744073709551616:4294967296
210684274086103068221283760416414557757:290299993288095377
6854fd01 21071:1
21080:0
2109-2:NaN
394e6ffb 2110-123:NaN
6854fd01 2111Nan:NaN
990fb837 2112+inf:inf
2113-inf:NaN
6854fd01 2114&bround
2115$round_mode('trunc')
21160:12:0
2117NaNbround:12:NaN
2118+inf:12:inf
2119-inf:12:-inf
21201234:0:1234
21211234:2:1200
2122123456:4:123400
2123123456:5:123450
2124123456:6:123456
61f5c3f5 2125+10123456789:5:10123000000
6854fd01 2126-10123456789:5:-10123000000
61f5c3f5 2127+10123456789:9:10123456700
6854fd01 2128-10123456789:9:-10123456700
61f5c3f5 2129+101234500:6:101234000
6854fd01 2130-101234500:6:-101234000
61f5c3f5 2131#+101234500:-4:101234000
6854fd01 2132#-101234500:-4:-101234000
2133$round_mode('zero')
61f5c3f5 2134+20123456789:5:20123000000
6854fd01 2135-20123456789:5:-20123000000
61f5c3f5 2136+20123456789:9:20123456800
6854fd01 2137-20123456789:9:-20123456800
61f5c3f5 2138+201234500:6:201234000
6854fd01 2139-201234500:6:-201234000
61f5c3f5 2140#+201234500:-4:201234000
6854fd01 2141#-201234500:-4:-201234000
2142+12345000:4:12340000
2143-12345000:4:-12340000
2144$round_mode('+inf')
61f5c3f5 2145+30123456789:5:30123000000
6854fd01 2146-30123456789:5:-30123000000
61f5c3f5 2147+30123456789:9:30123456800
6854fd01 2148-30123456789:9:-30123456800
61f5c3f5 2149+301234500:6:301235000
6854fd01 2150-301234500:6:-301234000
61f5c3f5 2151#+301234500:-4:301235000
6854fd01 2152#-301234500:-4:-301234000
2153+12345000:4:12350000
2154-12345000:4:-12340000
2155$round_mode('-inf')
61f5c3f5 2156+40123456789:5:40123000000
6854fd01 2157-40123456789:5:-40123000000
61f5c3f5 2158+40123456789:9:40123456800
6854fd01 2159-40123456789:9:-40123456800
61f5c3f5 2160+401234500:6:401234000
2161+401234500:6:401234000
6854fd01 2162#-401234500:-4:-401235000
2163#-401234500:-4:-401235000
2164+12345000:4:12340000
2165-12345000:4:-12350000
2166$round_mode('odd')
61f5c3f5 2167+50123456789:5:50123000000
6854fd01 2168-50123456789:5:-50123000000
61f5c3f5 2169+50123456789:9:50123456800
6854fd01 2170-50123456789:9:-50123456800
61f5c3f5 2171+501234500:6:501235000
6854fd01 2172-501234500:6:-501235000
61f5c3f5 2173#+501234500:-4:501235000
6854fd01 2174#-501234500:-4:-501235000
2175+12345000:4:12350000
2176-12345000:4:-12350000
2177$round_mode('even')
61f5c3f5 2178+60123456789:5:60123000000
6854fd01 2179-60123456789:5:-60123000000
61f5c3f5 2180+60123456789:9:60123456800
6854fd01 2181-60123456789:9:-60123456800
61f5c3f5 2182+601234500:6:601234000
6854fd01 2183-601234500:6:-601234000
61f5c3f5 2184#+601234500:-4:601234000
6854fd01 2185#-601234500:-4:-601234000
2186#-601234500:-9:0
2187#-501234500:-9:0
2188#-601234500:-8:0
2189#-501234500:-8:0
2190+1234567:7:1234567
2191+1234567:6:1234570
2192+12345000:4:12340000
2193-12345000:4:-12340000
2194&is_zero
21950:1
2196NaNzero:0
2197+inf:0
2198-inf:0
2199123:0
2200-1:0
22011:0
2202&is_one
22030:0
2204NaNone:0
2205+inf:0
2206-inf:0
22071:1
22082:0
2209-1:0
2210-2:0
2211# floor and ceil tests are pretty pointless in integer space...but play safe
2212&bfloor
22130:0
2214NaNfloor:NaN
2215+inf:inf
2216-inf:-inf
2217-1:-1
2218-2:-2
22192:2
22203:3
2221abc:NaN
2222&bceil
2223NaNceil:NaN
2224+inf:inf
2225-inf:-inf
22260:0
2227-1:-1
2228-2:-2
22292:2
22303:3
2231abc:NaN
2232&as_hex
2233128:0x80
2234-128:-0x80
22350:0x0
2236-0:0x0
22371:0x1
22380x123456789123456789:0x123456789123456789
2239+inf:inf
2240-inf:-inf
2241NaNas_hex:NaN
2242&as_bin
2243128:0b10000000
2244-128:-0b10000000
22450:0b0
2246-0:0b0
22471:0b1
22480b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 22490x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2250+inf:inf
2251-inf:-inf
2252NaNas_bin:NaN