-Dx could coredump on threaded builds because consts are now
[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
1686abc:abc:NaN
1687abc:+0:NaN
1688+0:abc:NaN
61f5c3f5 1689+0:+0:0
1690+0:+1:1
1691+1:+0:1
1692+1:+1:1
1693+2:+3:1
1694+3:+2:1
1695-3:+2:1
1696100:625:25
16974096:81:1
16981034:804:2
169927:90:56:1
170027:90:54:9
6854fd01 1701&blcm
1702abc:abc:NaN
1703abc:+0:NaN
1704+0:abc:NaN
1705+0:+0:NaN
61f5c3f5 1706+1:+0:0
1707+0:+1:0
1708+27:+90:270
1709+1034:+804:415668
6854fd01 1710&band
1711abc:abc:NaN
1712abc:0:NaN
17130:abc:NaN
17141:2:0
17153:2:2
61f5c3f5 1716+8:+2:0
1717+281474976710656:0:0
1718+281474976710656:1:0
1719+281474976710656:+281474976710656:281474976710656
6854fd01 1720-2:-3:-4
1721-1:-1:-1
1722-6:-6:-6
1723-7:-4:-8
1724-7:4:0
1725-4:7:4
394e6ffb 1726# equal arguments are treated special, so also do some test with unequal ones
17270xFFFF:0xFFFF:0x0xFFFF
17280xFFFFFF:0xFFFFFF:0x0xFFFFFF
17290xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
17300xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17310xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17320xF0F0:0xF0F0:0x0xF0F0
17330x0F0F:0x0F0F:0x0x0F0F
17340xF0F0F0:0xF0F0F0:0x0xF0F0F0
17350x0F0F0F:0x0F0F0F:0x0x0F0F0F
17360xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
17370x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
17380xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
17390x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
17400xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
17410x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
17420x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1743&bior
1744abc:abc:NaN
1745abc:0:NaN
17460:abc:NaN
17471:2:3
61f5c3f5 1748+8:+2:10
1749+281474976710656:0:281474976710656
1750+281474976710656:1:281474976710657
1751+281474976710656:281474976710656:281474976710656
6854fd01 1752-2:-3:-1
1753-1:-1:-1
1754-6:-6:-6
1755-7:4:-3
1756-4:7:-1
394e6ffb 1757# equal arguments are treated special, so also do some test with unequal ones
17580xFFFF:0xFFFF:0x0xFFFF
17590xFFFFFF:0xFFFFFF:0x0xFFFFFF
17600xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
17610xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17620xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17630:0xFFFF:0x0xFFFF
17640:0xFFFFFF:0x0xFFFFFF
17650:0xFFFFFFFF:0x0xFFFFFFFF
17660:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17670:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17680xFFFF:0:0x0xFFFF
17690xFFFFFF:0:0x0xFFFFFF
17700xFFFFFFFF:0:0x0xFFFFFFFF
17710xFFFFFFFFFF:0:0x0xFFFFFFFFFF
17720xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
17730xF0F0:0xF0F0:0x0xF0F0
17740x0F0F:0x0F0F:0x0x0F0F
17750xF0F0:0x0F0F:0x0xFFFF
17760xF0F0F0:0xF0F0F0:0x0xF0F0F0
17770x0F0F0F:0x0F0F0F:0x0x0F0F0F
17780x0F0F0F:0xF0F0F0:0x0xFFFFFF
17790xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
17800x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
17810x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
17820xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
17830x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
17840x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
17850xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
17860x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
17870x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
17880x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1789&bxor
1790abc:abc:NaN
1791abc:0:NaN
17920:abc:NaN
17931:2:3
61f5c3f5 1794+8:+2:10
1795+281474976710656:0:281474976710656
1796+281474976710656:1:281474976710657
1797+281474976710656:281474976710656:0
6854fd01 1798-2:-3:3
1799-1:-1:0
1800-6:-6:0
1801-7:4:-3
1802-4:7:-5
18034:-7:-3
1804-4:-7:5
394e6ffb 1805# equal arguments are treated special, so also do some test with unequal ones
18060xFFFF:0xFFFF:0
18070xFFFFFF:0xFFFFFF:0
18080xFFFFFFFF:0xFFFFFFFF:0
18090xFFFFFFFFFF:0xFFFFFFFFFF:0
18100xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
18110:0xFFFF:0x0xFFFF
18120:0xFFFFFF:0x0xFFFFFF
18130:0xFFFFFFFF:0x0xFFFFFFFF
18140:0xFFFFFFFFFF:0x0xFFFFFFFFFF
18150:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
18160xFFFF:0:0x0xFFFF
18170xFFFFFF:0:0x0xFFFFFF
18180xFFFFFFFF:0:0x0xFFFFFFFF
18190xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18200xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18210xF0F0:0xF0F0:0
18220x0F0F:0x0F0F:0
18230xF0F0:0x0F0F:0x0xFFFF
18240xF0F0F0:0xF0F0F0:0
18250x0F0F0F:0x0F0F0F:0
18260x0F0F0F:0xF0F0F0:0x0xFFFFFF
18270xF0F0F0F0:0xF0F0F0F0:0
18280x0F0F0F0F:0x0F0F0F0F:0
18290x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
18300xF0F0F0F0F0:0xF0F0F0F0F0:0
18310x0F0F0F0F0F:0x0F0F0F0F0F:0
18320x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
18330xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
18340x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
18350x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1836&bnot
1837abc:NaN
1838+0:-1
1839+8:-9
1840+281474976710656:-281474976710657
1841-1:0
1842-2:1
1843-12:11
1844&digit
18450:0:0
184612:0:2
184712:1:1
1848123:0:3
1849123:1:2
1850123:2:1
1851123:-1:1
1852123:-2:2
1853123:-3:3
1854123456:0:6
1855123456:1:5
1856123456:2:4
1857123456:3:3
1858123456:4:2
1859123456:5:1
1860123456:-1:1
1861123456:-2:2
1862123456:-3:3
1863100000:-3:0
1864100000:0:0
1865100000:1:0
1866&mantissa
1867abc:NaN
18681e4:1
18692e0:2
1870123:123
1871-1:-1
1872-2:-2
1873+inf:inf
1874-inf:-inf
1875&exponent
1876abc:NaN
18771e4:4
18782e0:0
1879123:0
1880-1:0
1881-2:0
18820:1
1883+inf:inf
1884-inf:inf
1885&parts
1886abc:NaN,NaN
18871e4:1,4
18882e0:2,0
1889123:123,0
1890-1:-1,0
1891-2:-2,0
18920:0,1
1893+inf:inf,inf
1894-inf:-inf,inf
b3abae2a 1895&bfac
1896-1:NaN
1897NaNfac:NaN
b282a552 1898+inf:inf
b3abae2a 1899-inf:NaN
19000:1
19011:1
19022:2
19033:6
19044:24
19055:120
19066:720
990fb837 19077:5040
19088:40320
19099:362880
b3abae2a 191010:3628800
191111:39916800
191212:479001600
6854fd01 1913&bpow
1914abc:12:NaN
191512:abc:NaN
19160:0:1
19170:1:0
19180:2:0
19190:-1:NaN
19200:-2:NaN
19211:0:1
19221:1:1
19231:2:1
19241:3:1
19251:-1:1
19261:-2:1
19271:-3:1
19282:0:1
19292:1:2
19302:2:4
19312:3:8
19323:3:27
19332:-1:NaN
1934-2:-1:NaN
19352:-2:NaN
1936-2:-2:NaN
1937+inf:1234500012:inf
1938-inf:1234500012:-inf
1939+inf:-12345000123:inf
1940-inf:-12345000123:-inf
1941# 1 ** -x => 1 / (1 ** x)
1942-1:0:1
1943-2:0:1
1944-1:1:-1
1945-1:2:1
1946-1:3:-1
1947-1:4:1
1948-1:5:-1
1949-1:-1:-1
1950-1:-2:1
1951-1:-3:-1
1952-1:-4:1
195310:2:100
195410:3:1000
195510:4:10000
195610:5:100000
195710:6:1000000
195810:7:10000000
195910:8:100000000
196010:9:1000000000
196110:20:100000000000000000000
1962123456:2:15241383936
1963&length
1964100:3
196510:2
19661:1
19670:1
196812345:5
196910000000000000000:17
1970-123:3
1971215960156869840440586892398248:30
990fb837 1972&broot
1973# sqrt()
1974+0:2:0
1975+1:2:1
1976-1:2:NaN
1977# -$x ** (1/2) => -$y, but not in froot()
1978-123:2:NaN
1979+inf:2:inf
1980-inf:2:NaN
19812:2:1
1982-2:2:NaN
19834:2:2
19849:2:3
198516:2:4
1986100:2:10
1987123:2:11
198815241:2:123
1989144:2:12
199012:2:3
19910.49:2:0
19920.0049:2:0
1993# invalid ones
19941:NaN:NaN
1995-1:NaN:NaN
19960:NaN:NaN
1997-inf:NaN:NaN
1998+inf:NaN:NaN
1999NaN:0:NaN
2000NaN:2:NaN
2001NaN:inf:NaN
2002NaN:inf:NaN
200312:-inf:NaN
200412:inf:NaN
2005+0:0:NaN
2006+1:0:NaN
2007-1:0:NaN
2008-2:0:NaN
2009-123.45:0:NaN
2010+inf:0:NaN
201112:1:12
2012-12:1:NaN
20138:-1:NaN
2014-8:-1:NaN
2015# cubic root
20168:3:2
2017-8:3:NaN
2018# fourths root
c38b2de2 201916:4:2
202081:4:3
3a427a11 2021# 2 ** 64
c38b2de2 202218446744073709551616:4:65536
202318446744073709551616:8:256
202418446744073709551616:16:16
202518446744073709551616:32:4
202618446744073709551616:64:2
202718446744073709551616:128:1
3a427a11 2028# 213 ** 15
202984274086103068221283760416414557757:15:213
2030# see t/bigroot for more tests
6854fd01 2031&bsqrt
394e6ffb 2032145:12
6854fd01 2033144:12
394e6ffb 2034143:11
6854fd01 203516:4
394e6ffb 2036170:13
2037169:13
2038168:12
6854fd01 20394:2
394e6ffb 20403:1
6854fd01 20412:1
394e6ffb 20429:3
6854fd01 204312:3
2044256:16
2045100000000:10000
20464000000000000:2000000
394e6ffb 2047152399026:12345
2048152399025:12345
2049152399024:12344
3a427a11 2050# 2 ** 64 => 2 ** 32
205118446744073709551616:4294967296
205284274086103068221283760416414557757:290299993288095377
6854fd01 20531:1
20540:0
2055-2:NaN
394e6ffb 2056-123:NaN
6854fd01 2057Nan:NaN
990fb837 2058+inf:inf
2059-inf:NaN
6854fd01 2060&bround
2061$round_mode('trunc')
20620:12:0
2063NaNbround:12:NaN
2064+inf:12:inf
2065-inf:12:-inf
20661234:0:1234
20671234:2:1200
2068123456:4:123400
2069123456:5:123450
2070123456:6:123456
61f5c3f5 2071+10123456789:5:10123000000
6854fd01 2072-10123456789:5:-10123000000
61f5c3f5 2073+10123456789:9:10123456700
6854fd01 2074-10123456789:9:-10123456700
61f5c3f5 2075+101234500:6:101234000
6854fd01 2076-101234500:6:-101234000
61f5c3f5 2077#+101234500:-4:101234000
6854fd01 2078#-101234500:-4:-101234000
2079$round_mode('zero')
61f5c3f5 2080+20123456789:5:20123000000
6854fd01 2081-20123456789:5:-20123000000
61f5c3f5 2082+20123456789:9:20123456800
6854fd01 2083-20123456789:9:-20123456800
61f5c3f5 2084+201234500:6:201234000
6854fd01 2085-201234500:6:-201234000
61f5c3f5 2086#+201234500:-4:201234000
6854fd01 2087#-201234500:-4:-201234000
2088+12345000:4:12340000
2089-12345000:4:-12340000
2090$round_mode('+inf')
61f5c3f5 2091+30123456789:5:30123000000
6854fd01 2092-30123456789:5:-30123000000
61f5c3f5 2093+30123456789:9:30123456800
6854fd01 2094-30123456789:9:-30123456800
61f5c3f5 2095+301234500:6:301235000
6854fd01 2096-301234500:6:-301234000
61f5c3f5 2097#+301234500:-4:301235000
6854fd01 2098#-301234500:-4:-301234000
2099+12345000:4:12350000
2100-12345000:4:-12340000
2101$round_mode('-inf')
61f5c3f5 2102+40123456789:5:40123000000
6854fd01 2103-40123456789:5:-40123000000
61f5c3f5 2104+40123456789:9:40123456800
6854fd01 2105-40123456789:9:-40123456800
61f5c3f5 2106+401234500:6:401234000
2107+401234500:6:401234000
6854fd01 2108#-401234500:-4:-401235000
2109#-401234500:-4:-401235000
2110+12345000:4:12340000
2111-12345000:4:-12350000
2112$round_mode('odd')
61f5c3f5 2113+50123456789:5:50123000000
6854fd01 2114-50123456789:5:-50123000000
61f5c3f5 2115+50123456789:9:50123456800
6854fd01 2116-50123456789:9:-50123456800
61f5c3f5 2117+501234500:6:501235000
6854fd01 2118-501234500:6:-501235000
61f5c3f5 2119#+501234500:-4:501235000
6854fd01 2120#-501234500:-4:-501235000
2121+12345000:4:12350000
2122-12345000:4:-12350000
2123$round_mode('even')
61f5c3f5 2124+60123456789:5:60123000000
6854fd01 2125-60123456789:5:-60123000000
61f5c3f5 2126+60123456789:9:60123456800
6854fd01 2127-60123456789:9:-60123456800
61f5c3f5 2128+601234500:6:601234000
6854fd01 2129-601234500:6:-601234000
61f5c3f5 2130#+601234500:-4:601234000
6854fd01 2131#-601234500:-4:-601234000
2132#-601234500:-9:0
2133#-501234500:-9:0
2134#-601234500:-8:0
2135#-501234500:-8:0
2136+1234567:7:1234567
2137+1234567:6:1234570
2138+12345000:4:12340000
2139-12345000:4:-12340000
2140&is_zero
21410:1
2142NaNzero:0
2143+inf:0
2144-inf:0
2145123:0
2146-1:0
21471:0
2148&is_one
21490:0
2150NaNone:0
2151+inf:0
2152-inf:0
21531:1
21542:0
2155-1:0
2156-2:0
2157# floor and ceil tests are pretty pointless in integer space...but play safe
2158&bfloor
21590:0
2160NaNfloor:NaN
2161+inf:inf
2162-inf:-inf
2163-1:-1
2164-2:-2
21652:2
21663:3
2167abc:NaN
2168&bceil
2169NaNceil:NaN
2170+inf:inf
2171-inf:-inf
21720:0
2173-1:-1
2174-2:-2
21752:2
21763:3
2177abc:NaN
2178&as_hex
2179128:0x80
2180-128:-0x80
21810:0x0
2182-0:0x0
21831:0x1
21840x123456789123456789:0x123456789123456789
2185+inf:inf
2186-inf:-inf
2187NaNas_hex:NaN
2188&as_bin
2189128:0b10000000
2190-128:-0b10000000
21910:0b0
2192-0:0b0
21931:0b1
21940b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 21950x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2196+inf:inf
2197-inf:-inf
2198NaNas_bin:NaN