Turn 2 strcpy()s into memcpy() because we know the length.
[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###############################################################################
61f5c3f5 627# all tests done
6854fd01 628
6291;
630
631###############################################################################
61f5c3f5 632###############################################################################
6854fd01 633# Perl 5.005 does not like ok ($x,undef)
634
635sub ok_undef
636 {
637 my $x = shift;
638
639 ok (1,1) and return if !defined $x;
640 ok ($x,'undef');
641 }
642
643###############################################################################
644# sub to check validity of a BigInt internally, to ensure that no op leaves a
645# number object in an invalid state (f.i. "-0")
646
647sub is_valid
648 {
649 my ($x,$f) = @_;
650
651 my $e = 0; # error?
6854fd01 652
56b9c951 653 # allow the check to pass for all Lite, and all MBI and subclasses
654 # ok as reference?
655 $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/;
6854fd01 656
56b9c951 657 if (ref($x) ne 'Math::BigInt::Lite')
658 {
659 # has ok sign?
660 $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'"
661 if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/;
662
663 $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0;
664 $e = $CALC->_check($x->{value}) if $e eq '0';
665 }
6854fd01 666
667 # test done, see if error did crop up
668 ok (1,1), return if ($e eq '0');
669
027dc388 670 ok (1,$e." after op '$f'");
6854fd01 671 }
672
673__DATA__
027dc388 674&.=
6751234:-345:1234-345
676&+=
6771:2:3
678-1:-2:-3
679&-=
6801:2:-1
681-1:-2:1
682&*=
6832:3:6
684-1:5:-5
685&%=
686100:3:1
6878:9:8
07d34614 688-629:5033:4404
027dc388 689&/=
690100:3:33
691-8:2:-4
692&|=
6932:1:3
694&&=
6955:7:5
696&^=
6975:7:2
091c87b1 698&blog
699NaNlog:2:NaN
700122:NaNlog:NaN
701NaNlog1:NaNlog:NaN
702122:inf:NaN
703inf:122:NaN
704122:-inf:NaN
705-inf:122:NaN
706-inf:-inf:NaN
707inf:inf:NaN
7080:4:NaN
709-21:4:NaN
71021:-21:NaN
711# normal results
7121024:2:10
71381:3:4
714# 3.01.. truncate
71582:3:4
716# 3.9... truncate
71780:3:3
71815625:5:6
71915626:5:6
72015624:5:5
8df1e0a2 7211000:10:3
72210000:10:4
723100000:10:5
7241000000:10:6
72510000000:10:7
726100000000:10:8
7278916100448256:12:12
7288916100448257:12:12
7298916100448255:12:11
7302251799813685248:8:17
73172057594037927936:2:56
732144115188075855872:2:57
733288230376151711744:2:58
734576460752303423488:2:59
7354096:2:12
7361329227995784915872903807060280344576:2:120
091c87b1 737# $x == $base => result 1
7383:3:1
739# $x < $base => result 0 ($base ** 0 <= $x)
7403:4:0
741# $x == 1 => result 0
7421:5:0
6854fd01 743&is_negative
7440:0
745-1:1
7461:0
747+inf:0
748-inf:1
749NaNneg:0
750&is_positive
7510:1
752-1:0
7531:1
754+inf:1
755-inf:0
756NaNneg:0
b3abae2a 757&is_int
758-inf:0
759+inf:0
760NaNis_int:0
7611:1
7620:1
763123e12:1
6854fd01 764&is_odd
765abc:0
7660:0
7671:1
7683:1
769-1:1
770-3:1
77110000001:1
77210000002:0
7732:0
b3abae2a 774120:0
775121:1
6854fd01 776&is_even
777abc:0
7780:1
7791:0
7803:0
781-1:0
782-3:0
78310000001:0
78410000002:1
7852:1
b3abae2a 786120:1
787121:0
6854fd01 788&bacmp
789+0:-0:0
790+0:+1:-1
791-1:+1:0
792+1:-1:0
793-1:+2:-1
794+2:-1:1
795-123456789:+987654321:-1
796+123456789:-987654321:-1
797+987654321:+123456789:1
798-987654321:+123456789:1
799-123:+4567889:-1
800# NaNs
801acmpNaN:123:
802123:acmpNaN:
803acmpNaN:acmpNaN:
804# infinity
805+inf:+inf:0
806-inf:-inf:0
807+inf:-inf:0
808-inf:+inf:0
809+inf:123:1
810-inf:123:1
811+inf:-123:1
812-inf:-123:1
ef9466ea 813123:-inf:-1
814-123:inf:-1
815-123:-inf:-1
816123:inf:-1
6854fd01 817# return undef
818+inf:NaN:
819NaN:inf:
820-inf:NaN:
821NaN:-inf:
822&bnorm
aef458a0 8230e999:0
8240e-999:0
825-0e999:0
826-0e-999:0
6854fd01 827123:123
828# binary input
8290babc:NaN
8300b123:NaN
8310b0:0
832-0b0:0
833-0b1:-1
8340b0001:1
8350b001:1
8360b011:3
8370b101:5
61f5c3f5 8380b1001:9
8390b10001:17
8400b100001:33
8410b1000001:65
8420b10000001:129
8430b100000001:257
8440b1000000001:513
8450b10000000001:1025
8460b100000000001:2049
8470b1000000000001:4097
8480b10000000000001:8193
8490b100000000000001:16385
8500b1000000000000001:32769
8510b10000000000000001:65537
8520b100000000000000001:131073
8530b1000000000000000001:262145
8540b10000000000000000001:524289
8550b100000000000000000001:1048577
8560b1000000000000000000001:2097153
8570b10000000000000000000001:4194305
8580b100000000000000000000001:8388609
8590b1000000000000000000000001:16777217
8600b10000000000000000000000001:33554433
8610b100000000000000000000000001:67108865
8620b1000000000000000000000000001:134217729
8630b10000000000000000000000000001:268435457
8640b100000000000000000000000000001:536870913
8650b1000000000000000000000000000001:1073741825
8660b10000000000000000000000000000001:2147483649
8670b100000000000000000000000000000001:4294967297
8680b1000000000000000000000000000000001:8589934593
8690b10000000000000000000000000000000001:17179869185
6854fd01 8700b_101:NaN
8710b1_0_1:5
394e6ffb 8720b0_0_0_1:1
6854fd01 873# hex input
874-0x0:0
8750xabcdefgh:NaN
8760x1234:4660
8770xabcdef:11259375
878-0xABCDEF:-11259375
879-0x1234:-4660
8800x12345678:305419896
8810x1_2_3_4_56_78:305419896
394e6ffb 8820xa_b_c_d_e_f:11259375
6854fd01 8830x_123:NaN
61f5c3f5 8840x9:9
8850x11:17
8860x21:33
8870x41:65
8880x81:129
8890x101:257
8900x201:513
8910x401:1025
8920x801:2049
8930x1001:4097
8940x2001:8193
8950x4001:16385
8960x8001:32769
8970x10001:65537
8980x20001:131073
8990x40001:262145
9000x80001:524289
9010x100001:1048577
9020x200001:2097153
9030x400001:4194305
9040x800001:8388609
9050x1000001:16777217
9060x2000001:33554433
9070x4000001:67108865
9080x8000001:134217729
9090x10000001:268435457
9100x20000001:536870913
9110x40000001:1073741825
9120x80000001:2147483649
9130x100000001:4294967297
9140x200000001:8589934593
9150x400000001:17179869185
9160x800000001:34359738369
6854fd01 917# inf input
918inf:inf
919+inf:inf
920-inf:-inf
9210inf:NaN
027dc388 922# abnormal input
6854fd01 923:NaN
924abc:NaN
925 1 a:NaN
9261bcd2:NaN
92711111b:NaN
928+1z:NaN
929-1z:NaN
027dc388 930# only one underscore between two digits
931_123:NaN
932_123_:NaN
933123_:NaN
9341__23:NaN
9351E1__2:NaN
9361_E12:NaN
9371E_12:NaN
9381_E_12:NaN
939+_1E12:NaN
940+0_1E2:100
941+0_0_1E2:100
942-0_0_1E2:-100
943-0_0_1E+0_0_2:-100
944E1:NaN
945E23:NaN
9461.23E1:NaN
9471.23E-1:NaN
948# bug with two E's in number beeing valid
9491e2e3:NaN
9501e2r:NaN
9511e2.0:NaN
07d34614 952# bug with two '.' in number beeing valid
9531.2.2:NaN
9541.2.3e1:NaN
955-1.2.3:NaN
956-1.2.3e-4:NaN
9571.2e3.4:NaN
9581.2e-3.4:NaN
9591.2.3.4:NaN
9601.2.t:NaN
9611..2:NaN
9621..2e1:NaN
9631..2e1..1:NaN
96412e1..1:NaN
965..2:NaN
966.-2:NaN
61f5c3f5 967# leading zeros
968012:12
9690123:123
97001234:1234
971012345:12345
9720123456:123456
97301234567:1234567
974012345678:12345678
9750123456789:123456789
97601234567891:1234567891
977012345678912:12345678912
9780123456789123:123456789123
97901234567891234:1234567891234
027dc388 980# normal input
6854fd01 9810:0
982+0:0
983+00:0
984+000:0
985000000000000000000:0
986-0:0
987-0000:0
988+1:1
989+01:1
990+001:1
991+00000100000:100000
992123456789:123456789
993-1:-1
994-01:-1
995-001:-1
996-123456789:-123456789
997-00000100000:-100000
9981_2_3:123
6854fd01 99910000000000E-1_0:1
10001E2:100
10011E1:10
10021E0:1
6854fd01 10031.23E2:123
6854fd01 1004100E-1:10
1005# floating point input
027dc388 1006# .2e2:20
10071.E3:1000
6854fd01 10081.01E2:101
10091010E-1:101
1010-1010E0:-1010
1011-1010E1:-10100
027dc388 10121234.00:1234
1013# non-integer numbers
6854fd01 1014-1010E-2:NaN
1015-1.01E+1:NaN
1016-1.01E-1:NaN
6854fd01 1017&bnan
10181:NaN
10192:NaN
1020abc:NaN
1021&bone
61f5c3f5 10222:+:1
6854fd01 10232:-:-1
1024boneNaN:-:-1
61f5c3f5 1025boneNaN:+:1
10262:abc:1
10273::1
6854fd01 1028&binf
10291:+:inf
10302:-:-inf
10313:abc:inf
027dc388 1032&is_nan
1033123:0
1034abc:1
1035NaN:1
1036-123:0
6854fd01 1037&is_inf
1038+inf::1
1039-inf::1
1040abc::0
10411::0
1042NaN::0
1043-1::0
1044+inf:-:0
1045+inf:+:1
1046-inf:-:1
1047-inf:+:0
79c55733 1048-inf:-inf:1
1049-inf:+inf:0
1050+inf:-inf:0
1051+inf:+inf:1
6854fd01 1052# it must be exactly /^[+-]inf$/
1053+infinity::0
1054-infinity::0
1055&blsft
1056abc:abc:NaN
61f5c3f5 1057+2:+2:8
1058+1:+32:4294967296
1059+1:+48:281474976710656
6854fd01 1060+8:-2:NaN
1061# excercise base 10
1062+12345:4:10:123450000
1063-1234:0:10:-1234
61f5c3f5 1064+1234:0:10:1234
6854fd01 1065+2:2:10:200
1066+12:2:10:1200
1067+1234:-3:10:NaN
10681234567890123:12:10:1234567890123000000000000
b3abae2a 1069-3:1:2:-6
1070-5:1:2:-10
1071-2:1:2:-4
1072-102533203:1:2:-205066406
6854fd01 1073&brsft
1074abc:abc:NaN
61f5c3f5 1075+8:+2:2
1076+4294967296:+32:1
1077+281474976710656:+48:1
6854fd01 1078+2:-2:NaN
1079# excercise base 10
1080-1234:0:10:-1234
61f5c3f5 1081+1234:0:10:1234
6854fd01 1082+200:2:10:2
1083+1234:3:10:1
1084+1234:2:10:12
1085+1234:-3:10:NaN
1086310000:4:10:31
108712300000:5:10:123
10881230000000000:10:10:123
108909876123456789067890:12:10:9876123
10901234561234567890123:13:10:123456
b3abae2a 1091820265627:1:2:410132813
1092# test shifting negative numbers in base 2
1093-15:1:2:-8
1094-14:1:2:-7
1095-13:1:2:-7
1096-12:1:2:-6
1097-11:1:2:-6
1098-10:1:2:-5
1099-9:1:2:-5
1100-8:1:2:-4
1101-7:1:2:-4
1102-6:1:2:-3
1103-5:1:2:-3
1104-4:1:2:-2
1105-3:1:2:-2
1106-2:1:2:-1
1107-1:1:2:-1
1108-1640531254:2:2:-410132814
1109-1640531254:1:2:-820265627
1110-820265627:1:2:-410132814
1111-205066405:1:2:-102533203
6854fd01 1112&bsstr
56d9de68 1113+inf:inf
1114-inf:-inf
6854fd01 11151e+34:1e+34
1116123.456E3:123456e+0
1117100:1e+2
56d9de68 1118bsstrabc:NaN
1119-5:-5e+0
1120-100:-1e+2
1121&numify
1122numifyabc:NaN
1123+inf:inf
1124-inf:-inf
11255:5
1126-5:-5
1127100:100
1128-100:-100
6854fd01 1129&bneg
1130bnegNaN:NaN
1131+inf:-inf
1132-inf:inf
1133abd:NaN
61f5c3f5 11340:0
11351:-1
1136-1:1
6854fd01 1137+123456789:-123456789
61f5c3f5 1138-123456789:123456789
6854fd01 1139&babs
1140babsNaN:NaN
1141+inf:inf
1142-inf:inf
61f5c3f5 11430:0
11441:1
1145-1:1
1146+123456789:123456789
1147-123456789:123456789
6854fd01 1148&bcmp
1149bcmpNaN:bcmpNaN:
61f5c3f5 1150bcmpNaN:0:
11510:bcmpNaN:
11520:0:0
1153-1:0:-1
11540:-1:1
11551:0:1
11560:1:-1
1157-1:1:-1
11581:-1:1
6854fd01 1159-1:-1:0
61f5c3f5 11601:1:0
1161123:123:0
1162123:12:1
116312:123:-1
6854fd01 1164-123:-123:0
1165-123:-12:-1
1166-12:-123:1
61f5c3f5 1167123:124:-1
1168124:123:1
6854fd01 1169-123:-124:1
1170-124:-123:-1
61f5c3f5 1171100:5:1
1172-123456789:987654321:-1
6854fd01 1173+123456789:-987654321:1
61f5c3f5 1174-987654321:123456789:-1
6854fd01 1175-inf:5432112345:-1
1176+inf:5432112345:1
1177-inf:-5432112345:-1
1178+inf:-5432112345:1
1179+inf:+inf:0
1180-inf:-inf:0
1181+inf:-inf:1
1182-inf:+inf:-1
11835:inf:-1
11845:inf:-1
1185-5:-inf:1
1186-5:-inf:1
1187# return undef
1188+inf:NaN:
1189NaN:inf:
1190-inf:NaN:
1191NaN:-inf:
1192&binc
1193abc:NaN
1194+inf:inf
1195-inf:-inf
61f5c3f5 1196+0:1
1197+1:2
1198-1:0
6854fd01 1199&bdec
1200abc:NaN
1201+inf:inf
1202-inf:-inf
1203+0:-1
61f5c3f5 1204+1:0
6854fd01 1205-1:-2
1206&badd
1207abc:abc:NaN
61f5c3f5 1208abc:0:NaN
6854fd01 1209+0:abc:NaN
b3abae2a 1210+inf:-inf:NaN
1211-inf:+inf:NaN
6854fd01 1212+inf:+inf:inf
1213-inf:-inf:-inf
1214baddNaN:+inf:NaN
1215baddNaN:+inf:NaN
1216+inf:baddNaN:NaN
1217-inf:baddNaN:NaN
61f5c3f5 12180:0:0
12191:0:1
12200:1:1
12211:1:2
1222-1:0:-1
12230:-1:-1
6854fd01 1224-1:-1:-2
61f5c3f5 1225-1:+1:0
1226+1:-1:0
1227+9:+1:10
1228+99:+1:100
1229+999:+1:1000
1230+9999:+1:10000
1231+99999:+1:100000
1232+999999:+1:1000000
1233+9999999:+1:10000000
1234+99999999:+1:100000000
1235+999999999:+1:1000000000
1236+9999999999:+1:10000000000
1237+99999999999:+1:100000000000
1238+10:-1:9
1239+100:-1:99
1240+1000:-1:999
1241+10000:-1:9999
1242+100000:-1:99999
1243+1000000:-1:999999
1244+10000000:-1:9999999
1245+100000000:-1:99999999
1246+1000000000:-1:999999999
1247+10000000000:-1:9999999999
1248+123456789:987654321:1111111110
1249-123456789:987654321:864197532
6854fd01 1250-123456789:-987654321:-1111111110
1251+123456789:-987654321:-864197532
56b9c951 1252-1:10001:10000
1253-1:100001:100000
1254-1:1000001:1000000
1255-1:10000001:10000000
1256-1:100000001:100000000
1257-1:1000000001:1000000000
1258-1:10000000001:10000000000
1259-1:100000000001:100000000000
1260-1:1000000000001:1000000000000
1261-1:10000000000001:10000000000000
1262-1:-10001:-10002
1263-1:-100001:-100002
1264-1:-1000001:-1000002
1265-1:-10000001:-10000002
1266-1:-100000001:-100000002
1267-1:-1000000001:-1000000002
1268-1:-10000000001:-10000000002
1269-1:-100000000001:-100000000002
1270-1:-1000000000001:-1000000000002
1271-1:-10000000000001:-10000000000002
6854fd01 1272&bsub
1273abc:abc:NaN
1274abc:+0:NaN
1275+0:abc:NaN
1276+inf:-inf:inf
1277-inf:+inf:-inf
b3abae2a 1278+inf:+inf:NaN
1279-inf:-inf:NaN
61f5c3f5 1280+0:+0:0
1281+1:+0:1
6854fd01 1282+0:+1:-1
61f5c3f5 1283+1:+1:0
6854fd01 1284-1:+0:-1
61f5c3f5 1285+0:-1:1
1286-1:-1:0
6854fd01 1287-1:+1:-2
61f5c3f5 1288+1:-1:2
1289+9:+1:8
1290+99:+1:98
1291+999:+1:998
1292+9999:+1:9998
1293+99999:+1:99998
1294+999999:+1:999998
1295+9999999:+1:9999998
1296+99999999:+1:99999998
1297+999999999:+1:999999998
1298+9999999999:+1:9999999998
1299+99999999999:+1:99999999998
1300+10:-1:11
1301+100:-1:101
1302+1000:-1:1001
1303+10000:-1:10001
1304+100000:-1:100001
1305+1000000:-1:1000001
1306+10000000:-1:10000001
1307+100000000:-1:100000001
1308+1000000000:-1:1000000001
1309+10000000000:-1:10000000001
6854fd01 1310+123456789:+987654321:-864197532
1311-123456789:+987654321:-1111111110
61f5c3f5 1312-123456789:-987654321:864197532
1313+123456789:-987654321:1111111110
56b9c951 131410001:1:10000
1315100001:1:100000
13161000001:1:1000000
131710000001:1:10000000
1318100000001:1:100000000
13191000000001:1:1000000000
132010000000001:1:10000000000
1321100000000001:1:100000000000
13221000000000001:1:1000000000000
132310000000000001:1:10000000000000
132410001:-1:10002
1325100001:-1:100002
13261000001:-1:1000002
132710000001:-1:10000002
1328100000001:-1:100000002
13291000000001:-1:1000000002
133010000000001:-1:10000000002
1331100000000001:-1:100000000002
13321000000000001:-1:1000000000002
133310000000000001:-1:10000000000002
6854fd01 1334&bmul
1335abc:abc:NaN
1336abc:+0:NaN
1337+0:abc:NaN
1338NaNmul:+inf:NaN
1339NaNmul:-inf:NaN
1340-inf:NaNmul:NaN
1341+inf:NaNmul:NaN
1342+inf:+inf:inf
1343+inf:-inf:-inf
1344-inf:+inf:-inf
1345-inf:-inf:inf
61f5c3f5 1346+0:+0:0
1347+0:+1:0
1348+1:+0:0
1349+0:-1:0
1350-1:+0:0
1351123456789123456789:0:0
13520:123456789123456789:0
1353-1:-1:1
6854fd01 1354-1:+1:-1
1355+1:-1:-1
61f5c3f5 1356+1:+1:1
1357+2:+3:6
6854fd01 1358-2:+3:-6
1359+2:-3:-6
61f5c3f5 1360-2:-3:6
1361111:111:12321
136210101:10101:102030201
13631001001:1001001:1002003002001
1364100010001:100010001:10002000300020001
136510000100001:10000100001:100002000030000200001
136611111111111:9:99999999999
136722222222222:9:199999999998
136833333333333:9:299999999997
136944444444444:9:399999999996
137055555555555:9:499999999995
137166666666666:9:599999999994
137277777777777:9:699999999993
137388888888888:9:799999999992
137499999999999:9:899999999991
1375+25:+25:625
1376+12345:+12345:152399025
1377+99999:+11111:1111088889
6854fd01 13789999:10000:99990000
137999999:100000:9999900000
1380999999:1000000:999999000000
13819999999:10000000:99999990000000
138299999999:100000000:9999999900000000
1383999999999:1000000000:999999999000000000
13849999999999:10000000000:99999999990000000000
138599999999999:100000000000:9999999999900000000000
1386999999999999:1000000000000:999999999999000000000000
13879999999999999:10000000000000:99999999999990000000000000
138899999999999999:100000000000000:9999999999999900000000000000
1389999999999999999:1000000000000000:999999999999999000000000000000
13909999999999999999:10000000000000000:99999999999999990000000000000000
139199999999999999999:100000000000000000:9999999999999999900000000000000000
1392999999999999999999:1000000000000000000:999999999999999999000000000000000000
13939999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1394&bdiv-list
1395100:20:5,0
13964095:4095:1,0
1397-4095:-4095:1,0
13984095:-4095:-1,0
1399-4095:4095:-1,0
1400123:2:61,1
b3abae2a 14019:5:1,4
14029:4:2,1
6854fd01 1403# inf handling and general remainder
14045:8:0,5
14050:8:0,0
140611:2:5,1
140711:-2:-5,-1
1408-11:2:-5,1
1409# see table in documentation in MBI
14100:inf:0,0
14110:-inf:0,0
14125:inf:0,5
14135:-inf:0,5
1414-5:inf:0,-5
1415-5:-inf:0,-5
1416inf:5:inf,0
1417-inf:5:-inf,0
1418inf:-5:-inf,0
1419-inf:-5:inf,0
14205:5:1,0
1421-5:-5:1,0
b3abae2a 1422inf:inf:NaN,NaN
1423-inf:-inf:NaN,NaN
1424-inf:inf:NaN,NaN
1425inf:-inf:NaN,NaN
6854fd01 14268:0:inf,8
1427inf:0:inf,inf
1428# exceptions to reminder rule
1429-8:0:-inf,-8
1430-inf:0:-inf,-inf
14310:0:NaN,NaN
990fb837 1432# test the shortcut in Calc if @$x == @$yorg
14331234567812345678:123456712345678:10,688888898
143412345671234567:1234561234567:10,58888897
1435123456123456:12345123456:10,4888896
14361234512345:123412345:10,388895
14371234567890999999999:1234567890:1000000000,999999999
14381234567890000000000:1234567890:1000000000,0
14391234567890999999999:9876543210:124999998,9503086419
14401234567890000000000:9876543210:124999998,8503086420
144196969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
6854fd01 1442&bdiv
1443abc:abc:NaN
61f5c3f5 1444abc:1:NaN
14451:abc:NaN
14460:0:NaN
6854fd01 1447# inf handling (see table in doc)
14480:inf:0
14490:-inf:0
14505:inf:0
14515:-inf:0
1452-5:inf:0
1453-5:-inf:0
1454inf:5:inf
1455-inf:5:-inf
1456inf:-5:-inf
1457-inf:-5:inf
14585:5:1
1459-5:-5:1
b3abae2a 1460inf:inf:NaN
1461-inf:-inf:NaN
1462-inf:inf:NaN
1463inf:-inf:NaN
6854fd01 14648:0:inf
1465inf:0:inf
1466-8:0:-inf
1467-inf:0:-inf
14680:0:NaN
146911:2:5
1470-11:-2:5
1471-11:2:-5
147211:-2:-5
61f5c3f5 14730:1:0
14740:-1:0
14751:1:1
1476-1:-1:1
14771:-1:-1
1478-1:1:-1
14791:2:0
14802:1:2
14811:26:0
14821000000000:9:111111111
14832000000000:9:222222222
14843000000000:9:333333333
14854000000000:9:444444444
14865000000000:9:555555555
14876000000000:9:666666666
14887000000000:9:777777777
14898000000000:9:888888888
14909000000000:9:1000000000
149135500000:113:314159
149271000000:226:314159
1493106500000:339:314159
14941000000000:3:333333333
1495+10:+5:2
1496+100:+4:25
1497+1000:+8:125
1498+10000:+16:625
1499999999999999:9:111111111111
1500999999999999:99:10101010101
1501999999999999:999:1001001001
1502999999999999:9999:100010001
1503999999999999999:99999:10000100001
1504+1111088889:99999:11111
6854fd01 1505-5:-3:1
1506-5:3:-1
15074:3:1
15084:-3:-1
15091:3:0
15101:-3:0
1511-2:-3:0
1512-2:3:0
15138:3:2
1514-8:3:-2
151514:-3:-4
1516-14:3:-4
1517-14:-3:4
151814:3:4
1519# bug in Calc with '99999' vs $BASE-1
152010000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1521# test the shortcut in Calc if @$x == @$yorg
15221234567812345678:123456712345678:10
152312345671234567:1234561234567:10
1524123456123456:12345123456:10
15251234512345:123412345:10
15261234567890999999999:1234567890:1000000000
15271234567890000000000:1234567890:1000000000
15281234567890999999999:9876543210:124999998
15291234567890000000000:9876543210:124999998
153096969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1531# bug up to v0.35 in Calc (--$q one too many)
153284696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
153384696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
153484696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
153584696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
07d34614 1536&bmodinv
1537# format: number:modulus:result
1538# bmodinv Data errors
1539abc:abc:NaN
1540abc:5:NaN
15415:abc:NaN
1542# bmodinv Expected Results from normal use
15431:5:1
15443:5:2
1545-2:5:2
15468:5033:4404
56d9de68 15471234567891:13:6
1548-1234567891:13:7
07d34614 1549324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1550## bmodinv Error cases / useless use of function
07d34614 15513:-5:NaN
1552inf:5:NaN
1ddff52a 15535:inf:NaN
1554-inf:5:NaN
15555:-inf:NaN
07d34614 1556&bmodpow
1557# format: number:exponent:modulus:result
1558# bmodpow Data errors
1559abc:abc:abc:NaN
15605:abc:abc:NaN
1561abc:5:abc:NaN
1562abc:abc:5:NaN
15635:5:abc:NaN
15645:abc:5:NaN
1565abc:5:5:NaN
1566# bmodpow Expected results
15670:0:2:1
15681:0:2:1
15690:0:1:0
15708:7:5032:3840
15718:-1:5033:4404
157298436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1573# bmodpow Error cases
15748:8:-5:NaN
15758:-1:16:NaN
1576inf:5:13:NaN
15775:inf:13:NaN
6854fd01 1578&bmod
1579# inf handling, see table in doc
15800:inf:0
15810:-inf:0
15825:inf:5
15835:-inf:5
1584-5:inf:-5
1585-5:-inf:-5
1586inf:5:0
1587-inf:5:0
1588inf:-5:0
1589-inf:-5:0
15905:5:0
1591-5:-5:0
b3abae2a 1592inf:inf:NaN
1593-inf:-inf:NaN
1594-inf:inf:NaN
1595inf:-inf:NaN
6854fd01 15968:0:8
1597inf:0:inf
1598# exceptions to reminder rule
1599-inf:0:-inf
1600-8:0:-8
16010:0:NaN
1602abc:abc:NaN
61f5c3f5 1603abc:1:abc:NaN
16041:abc:NaN
16050:0:NaN
16060:1:0
16071:0:1
16080:-1:0
1609-1:0:-1
16101:1:0
1611-1:-1:0
16121:-1:0
1613-1:1:0
16141:2:1
16152:1:0
16161000000000:9:1
16172000000000:9:2
16183000000000:9:3
16194000000000:9:4
16205000000000:9:5
16216000000000:9:6
16227000000000:9:7
16238000000000:9:8
16249000000000:9:0
162535500000:113:33
162671000000:226:66
1627106500000:339:99
16281000000000:3:1
162910:5:0
1630100:4:0
16311000:8:0
163210000:16:0
1633999999999999:9:0
1634999999999999:99:0
1635999999999999:999:0
1636999999999999:9999:0
1637999999999999999:99999:0
1638-9:+5:1
6854fd01 1639+9:-5:-1
1640-9:-5:-4
1641-5:3:1
1642-2:3:1
16434:3:1
16441:3:1
1645-5:-3:-2
1646-2:-3:-2
16474:-3:-2
16481:-3:-2
16494095:4095:0
027dc388 1650100041000510123:3:0
1651152403346:12345:4321
b3abae2a 16529:5:4
28df3e88 1653# test shortcuts in Calc
1654# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
16551234:9:1
1656123456:9:3
165712345678:9:0
16581234567891:9:1
1659123456789123:9:6
166012345678912345:9:6
16611234567891234567:9:1
1662123456789123456789:9:0
16631234:10:4
1664123456:10:6
166512345678:10:8
16661234567891:10:1
1667123456789123:10:3
166812345678912345:10:5
16691234567891234567:10:7
1670123456789123456789:10:9
16711234:113:104
1672123456:113:60
167312345678:113:89
16741234567891:113:64
1675123456789123:113:95
167612345678912345:113:53
16771234567891234567:113:56
1678123456789123456789:113:39
07d34614 1679# bug in bmod() not modifying the variable in place
1680-629:5033:4404
aef458a0 1681# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1682# when X == X and X was big
1683111111111111111111111111111111:111111111111111111111111111111:0
168412345678901234567890:12345678901234567890:0
6854fd01 1685&bgcd
9b924220 1686inf:12:NaN
1687-inf:12:NaN
168812:inf:NaN
168912:-inf:NaN
1690inf:inf:NaN
1691inf:-inf:NaN
1692-inf:-inf:NaN
6854fd01 1693abc:abc:NaN
1694abc:+0:NaN
1695+0:abc:NaN
61f5c3f5 1696+0:+0:0
1697+0:+1:1
1698+1:+0:1
1699+1:+1:1
1700+2:+3:1
1701+3:+2:1
1702-3:+2:1
9b924220 1703-3:-2:1
1704-144:-60:12
1705144:-60:12
1706144:60:12
61f5c3f5 1707100:625:25
17084096:81:1
17091034:804:2
171027:90:56:1
171127:90:54:9
6854fd01 1712&blcm
1713abc:abc:NaN
1714abc:+0:NaN
1715+0:abc:NaN
1716+0:+0:NaN
61f5c3f5 1717+1:+0:0
1718+0:+1:0
1719+27:+90:270
1720+1034:+804:415668
6854fd01 1721&band
1722abc:abc:NaN
1723abc:0:NaN
17240:abc:NaN
17251:2:0
17263:2:2
61f5c3f5 1727+8:+2:0
1728+281474976710656:0:0
1729+281474976710656:1:0
1730+281474976710656:+281474976710656:281474976710656
9b924220 1731281474976710656:-1:281474976710656
6854fd01 1732-2:-3:-4
1733-1:-1:-1
1734-6:-6:-6
1735-7:-4:-8
1736-7:4:0
1737-4:7:4
9b924220 1738# negative argument is bitwise shorter than positive [perl #26559]
173930:-3:28
1740123:-1:123
394e6ffb 1741# equal arguments are treated special, so also do some test with unequal ones
17420xFFFF:0xFFFF:0x0xFFFF
17430xFFFFFF:0xFFFFFF:0x0xFFFFFF
17440xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
17450xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17460xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17470xF0F0:0xF0F0:0x0xF0F0
17480x0F0F:0x0F0F:0x0x0F0F
17490xF0F0F0:0xF0F0F0:0x0xF0F0F0
17500x0F0F0F:0x0F0F0F:0x0x0F0F0F
17510xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
17520x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
17530xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
17540x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
17550xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
17560x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
17570x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1758&bior
1759abc:abc:NaN
1760abc:0:NaN
17610:abc:NaN
17621:2:3
61f5c3f5 1763+8:+2:10
1764+281474976710656:0:281474976710656
1765+281474976710656:1:281474976710657
1766+281474976710656:281474976710656:281474976710656
6854fd01 1767-2:-3:-1
1768-1:-1:-1
1769-6:-6:-6
1770-7:4:-3
1771-4:7:-1
9b924220 1772+281474976710656:-1:-1
177330:-3:-1
177430:-4:-2
1775300:-76:-68
1776-76:300:-68
394e6ffb 1777# equal arguments are treated special, so also do some test with unequal ones
17780xFFFF:0xFFFF:0x0xFFFF
17790xFFFFFF:0xFFFFFF:0x0xFFFFFF
17800xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
17810xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17820xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17830:0xFFFF:0x0xFFFF
17840:0xFFFFFF:0x0xFFFFFF
17850:0xFFFFFFFF:0x0xFFFFFFFF
17860:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17870:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17880xFFFF:0:0x0xFFFF
17890xFFFFFF:0:0x0xFFFFFF
17900xFFFFFFFF:0:0x0xFFFFFFFF
17910xFFFFFFFFFF:0:0x0xFFFFFFFFFF
17920xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
17930xF0F0:0xF0F0:0x0xF0F0
17940x0F0F:0x0F0F:0x0x0F0F
17950xF0F0:0x0F0F:0x0xFFFF
17960xF0F0F0:0xF0F0F0:0x0xF0F0F0
17970x0F0F0F:0x0F0F0F:0x0x0F0F0F
17980x0F0F0F:0xF0F0F0:0x0xFFFFFF
17990xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
18000x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
18010x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
18020xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
18030x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
18040x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
18050xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
18060x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
18070x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
18080x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1809&bxor
1810abc:abc:NaN
1811abc:0:NaN
18120:abc:NaN
18131:2:3
61f5c3f5 1814+8:+2:10
1815+281474976710656:0:281474976710656
1816+281474976710656:1:281474976710657
1817+281474976710656:281474976710656:0
6854fd01 1818-2:-3:3
1819-1:-1:0
1820-6:-6:0
1821-7:4:-3
1822-4:7:-5
18234:-7:-3
1824-4:-7:5
9b924220 182530:-3:-29
182630:-4:-30
1827300:-76:-360
1828-76:300:-360
394e6ffb 1829# equal arguments are treated special, so also do some test with unequal ones
18300xFFFF:0xFFFF:0
18310xFFFFFF:0xFFFFFF:0
18320xFFFFFFFF:0xFFFFFFFF:0
18330xFFFFFFFFFF:0xFFFFFFFFFF:0
18340xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
18350:0xFFFF:0x0xFFFF
18360:0xFFFFFF:0x0xFFFFFF
18370:0xFFFFFFFF:0x0xFFFFFFFF
18380:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18390:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18400xFFFF:0:0x0xFFFF
18410xFFFFFF:0:0x0xFFFFFF
18420xFFFFFFFF:0:0x0xFFFFFFFF
18430xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18440xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18450xF0F0:0xF0F0:0
18460x0F0F:0x0F0F:0
18470xF0F0:0x0F0F:0x0xFFFF
18480xF0F0F0:0xF0F0F0:0
18490x0F0F0F:0x0F0F0F:0
18500x0F0F0F:0xF0F0F0:0x0xFFFFFF
18510xF0F0F0F0:0xF0F0F0F0:0
18520x0F0F0F0F:0x0F0F0F0F:0
18530x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
18540xF0F0F0F0F0:0xF0F0F0F0F0:0
18550x0F0F0F0F0F:0x0F0F0F0F0F:0
18560x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
18570xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
18580x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
18590x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1860&bnot
1861abc:NaN
1862+0:-1
1863+8:-9
1864+281474976710656:-281474976710657
1865-1:0
1866-2:1
1867-12:11
1868&digit
18690:0:0
187012:0:2
187112:1:1
1872123:0:3
1873123:1:2
1874123:2:1
1875123:-1:1
1876123:-2:2
1877123:-3:3
1878123456:0:6
1879123456:1:5
1880123456:2:4
1881123456:3:3
1882123456:4:2
1883123456:5:1
1884123456:-1:1
1885123456:-2:2
1886123456:-3:3
1887100000:-3:0
1888100000:0:0
1889100000:1:0
1890&mantissa
1891abc:NaN
18921e4:1
18932e0:2
1894123:123
1895-1:-1
1896-2:-2
1897+inf:inf
1898-inf:-inf
1899&exponent
1900abc:NaN
19011e4:4
19022e0:0
1903123:0
1904-1:0
1905-2:0
19060:1
1907+inf:inf
1908-inf:inf
1909&parts
1910abc:NaN,NaN
19111e4:1,4
19122e0:2,0
1913123:123,0
1914-1:-1,0
1915-2:-2,0
19160:0,1
1917+inf:inf,inf
1918-inf:-inf,inf
b3abae2a 1919&bfac
1920-1:NaN
1921NaNfac:NaN
b282a552 1922+inf:inf
b3abae2a 1923-inf:NaN
19240:1
19251:1
19262:2
19273:6
19284:24
19295:120
19306:720
990fb837 19317:5040
19328:40320
19339:362880
b3abae2a 193410:3628800
193511:39916800
193612:479001600
6854fd01 1937&bpow
1938abc:12:NaN
193912:abc:NaN
19400:0:1
19410:1:0
19420:2:0
9b924220 19430:-1:inf
19440:-2:inf
6854fd01 19451:0:1
19461:1:1
19471:2:1
19481:3:1
19491:-1:1
19501:-2:1
19511:-3:1
19522:0:1
19532:1:2
19542:2:4
19552:3:8
19563:3:27
19572:-1:NaN
1958-2:-1:NaN
19592:-2:NaN
1960-2:-2:NaN
1961+inf:1234500012:inf
1962-inf:1234500012:-inf
1963+inf:-12345000123:inf
1964-inf:-12345000123:-inf
1965# 1 ** -x => 1 / (1 ** x)
1966-1:0:1
1967-2:0:1
1968-1:1:-1
1969-1:2:1
1970-1:3:-1
1971-1:4:1
1972-1:5:-1
1973-1:-1:-1
1974-1:-2:1
1975-1:-3:-1
1976-1:-4:1
197710:2:100
197810:3:1000
197910:4:10000
198010:5:100000
198110:6:1000000
198210:7:10000000
198310:8:100000000
198410:9:1000000000
198510:20:100000000000000000000
1986123456:2:15241383936
9b924220 1987-2:2:4
1988-2:3:-8
1989-2:4:16
1990-2:5:-32
1991-3:2:9
1992-3:3:-27
1993-3:4:81
1994-3:5:-243
6854fd01 1995&length
1996100:3
199710:2
19981:1
19990:1
200012345:5
200110000000000000000:17
2002-123:3
2003215960156869840440586892398248:30
990fb837 2004&broot
2005# sqrt()
2006+0:2:0
2007+1:2:1
2008-1:2:NaN
2009# -$x ** (1/2) => -$y, but not in froot()
2010-123:2:NaN
2011+inf:2:inf
2012-inf:2:NaN
20132:2:1
2014-2:2:NaN
20154:2:2
20169:2:3
201716:2:4
2018100:2:10
2019123:2:11
202015241:2:123
2021144:2:12
202212:2:3
20230.49:2:0
20240.0049:2:0
2025# invalid ones
20261:NaN:NaN
2027-1:NaN:NaN
20280:NaN:NaN
2029-inf:NaN:NaN
2030+inf:NaN:NaN
2031NaN:0:NaN
2032NaN:2:NaN
2033NaN:inf:NaN
2034NaN:inf:NaN
203512:-inf:NaN
203612:inf:NaN
2037+0:0:NaN
2038+1:0:NaN
2039-1:0:NaN
2040-2:0:NaN
2041-123.45:0:NaN
2042+inf:0:NaN
204312:1:12
2044-12:1:NaN
20458:-1:NaN
2046-8:-1:NaN
2047# cubic root
20488:3:2
2049-8:3:NaN
2050# fourths root
c38b2de2 205116:4:2
205281:4:3
3a427a11 2053# 2 ** 64
c38b2de2 205418446744073709551616:4:65536
205518446744073709551616:8:256
205618446744073709551616:16:16
205718446744073709551616:32:4
205818446744073709551616:64:2
205918446744073709551616:128:1
3a427a11 2060# 213 ** 15
206184274086103068221283760416414557757:15:213
2062# see t/bigroot for more tests
6854fd01 2063&bsqrt
394e6ffb 2064145:12
6854fd01 2065144:12
394e6ffb 2066143:11
6854fd01 206716:4
394e6ffb 2068170:13
2069169:13
2070168:12
6854fd01 20714:2
394e6ffb 20723:1
6854fd01 20732:1
394e6ffb 20749:3
6854fd01 207512:3
2076256:16
2077100000000:10000
20784000000000000:2000000
394e6ffb 2079152399026:12345
2080152399025:12345
2081152399024:12344
3a427a11 2082# 2 ** 64 => 2 ** 32
208318446744073709551616:4294967296
208484274086103068221283760416414557757:290299993288095377
6854fd01 20851:1
20860:0
2087-2:NaN
394e6ffb 2088-123:NaN
6854fd01 2089Nan:NaN
990fb837 2090+inf:inf
2091-inf:NaN
6854fd01 2092&bround
2093$round_mode('trunc')
20940:12:0
2095NaNbround:12:NaN
2096+inf:12:inf
2097-inf:12:-inf
20981234:0:1234
20991234:2:1200
2100123456:4:123400
2101123456:5:123450
2102123456:6:123456
61f5c3f5 2103+10123456789:5:10123000000
6854fd01 2104-10123456789:5:-10123000000
61f5c3f5 2105+10123456789:9:10123456700
6854fd01 2106-10123456789:9:-10123456700
61f5c3f5 2107+101234500:6:101234000
6854fd01 2108-101234500:6:-101234000
61f5c3f5 2109#+101234500:-4:101234000
6854fd01 2110#-101234500:-4:-101234000
2111$round_mode('zero')
61f5c3f5 2112+20123456789:5:20123000000
6854fd01 2113-20123456789:5:-20123000000
61f5c3f5 2114+20123456789:9:20123456800
6854fd01 2115-20123456789:9:-20123456800
61f5c3f5 2116+201234500:6:201234000
6854fd01 2117-201234500:6:-201234000
61f5c3f5 2118#+201234500:-4:201234000
6854fd01 2119#-201234500:-4:-201234000
2120+12345000:4:12340000
2121-12345000:4:-12340000
2122$round_mode('+inf')
61f5c3f5 2123+30123456789:5:30123000000
6854fd01 2124-30123456789:5:-30123000000
61f5c3f5 2125+30123456789:9:30123456800
6854fd01 2126-30123456789:9:-30123456800
61f5c3f5 2127+301234500:6:301235000
6854fd01 2128-301234500:6:-301234000
61f5c3f5 2129#+301234500:-4:301235000
6854fd01 2130#-301234500:-4:-301234000
2131+12345000:4:12350000
2132-12345000:4:-12340000
2133$round_mode('-inf')
61f5c3f5 2134+40123456789:5:40123000000
6854fd01 2135-40123456789:5:-40123000000
61f5c3f5 2136+40123456789:9:40123456800
6854fd01 2137-40123456789:9:-40123456800
61f5c3f5 2138+401234500:6:401234000
2139+401234500:6:401234000
6854fd01 2140#-401234500:-4:-401235000
2141#-401234500:-4:-401235000
2142+12345000:4:12340000
2143-12345000:4:-12350000
2144$round_mode('odd')
61f5c3f5 2145+50123456789:5:50123000000
6854fd01 2146-50123456789:5:-50123000000
61f5c3f5 2147+50123456789:9:50123456800
6854fd01 2148-50123456789:9:-50123456800
61f5c3f5 2149+501234500:6:501235000
6854fd01 2150-501234500:6:-501235000
61f5c3f5 2151#+501234500:-4:501235000
6854fd01 2152#-501234500:-4:-501235000
2153+12345000:4:12350000
2154-12345000:4:-12350000
2155$round_mode('even')
61f5c3f5 2156+60123456789:5:60123000000
6854fd01 2157-60123456789:5:-60123000000
61f5c3f5 2158+60123456789:9:60123456800
6854fd01 2159-60123456789:9:-60123456800
61f5c3f5 2160+601234500:6:601234000
6854fd01 2161-601234500:6:-601234000
61f5c3f5 2162#+601234500:-4:601234000
6854fd01 2163#-601234500:-4:-601234000
2164#-601234500:-9:0
2165#-501234500:-9:0
2166#-601234500:-8:0
2167#-501234500:-8:0
2168+1234567:7:1234567
2169+1234567:6:1234570
2170+12345000:4:12340000
2171-12345000:4:-12340000
2172&is_zero
21730:1
2174NaNzero:0
2175+inf:0
2176-inf:0
2177123:0
2178-1:0
21791:0
2180&is_one
21810:0
2182NaNone:0
2183+inf:0
2184-inf:0
21851:1
21862:0
2187-1:0
2188-2:0
2189# floor and ceil tests are pretty pointless in integer space...but play safe
2190&bfloor
21910:0
2192NaNfloor:NaN
2193+inf:inf
2194-inf:-inf
2195-1:-1
2196-2:-2
21972:2
21983:3
2199abc:NaN
2200&bceil
2201NaNceil:NaN
2202+inf:inf
2203-inf:-inf
22040:0
2205-1:-1
2206-2:-2
22072:2
22083:3
2209abc:NaN
2210&as_hex
2211128:0x80
2212-128:-0x80
22130:0x0
2214-0:0x0
22151:0x1
22160x123456789123456789:0x123456789123456789
2217+inf:inf
2218-inf:-inf
2219NaNas_hex:NaN
2220&as_bin
2221128:0b10000000
2222-128:-0b10000000
22230:0b0
2224-0:0b0
22251:0b1
22260b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 22270x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2228+inf:inf
2229-inf:-inf
2230NaNas_bin:NaN