d_u32align for win32
[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
721# $x == $base => result 1
7223:3:1
723# $x < $base => result 0 ($base ** 0 <= $x)
7243:4:0
725# $x == 1 => result 0
7261:5:0
6854fd01 727&is_negative
7280:0
729-1:1
7301:0
731+inf:0
732-inf:1
733NaNneg:0
734&is_positive
7350:1
736-1:0
7371:1
738+inf:1
739-inf:0
740NaNneg:0
b3abae2a 741&is_int
742-inf:0
743+inf:0
744NaNis_int:0
7451:1
7460:1
747123e12:1
6854fd01 748&is_odd
749abc:0
7500:0
7511:1
7523:1
753-1:1
754-3:1
75510000001:1
75610000002:0
7572:0
b3abae2a 758120:0
759121:1
6854fd01 760&is_even
761abc:0
7620:1
7631:0
7643:0
765-1:0
766-3:0
76710000001:0
76810000002:1
7692:1
b3abae2a 770120:1
771121:0
6854fd01 772&bacmp
773+0:-0:0
774+0:+1:-1
775-1:+1:0
776+1:-1:0
777-1:+2:-1
778+2:-1:1
779-123456789:+987654321:-1
780+123456789:-987654321:-1
781+987654321:+123456789:1
782-987654321:+123456789:1
783-123:+4567889:-1
784# NaNs
785acmpNaN:123:
786123:acmpNaN:
787acmpNaN:acmpNaN:
788# infinity
789+inf:+inf:0
790-inf:-inf:0
791+inf:-inf:0
792-inf:+inf:0
793+inf:123:1
794-inf:123:1
795+inf:-123:1
796-inf:-123:1
797# return undef
798+inf:NaN:
799NaN:inf:
800-inf:NaN:
801NaN:-inf:
802&bnorm
aef458a0 8030e999:0
8040e-999:0
805-0e999:0
806-0e-999:0
6854fd01 807123:123
808# binary input
8090babc:NaN
8100b123:NaN
8110b0:0
812-0b0:0
813-0b1:-1
8140b0001:1
8150b001:1
8160b011:3
8170b101:5
61f5c3f5 8180b1001:9
8190b10001:17
8200b100001:33
8210b1000001:65
8220b10000001:129
8230b100000001:257
8240b1000000001:513
8250b10000000001:1025
8260b100000000001:2049
8270b1000000000001:4097
8280b10000000000001:8193
8290b100000000000001:16385
8300b1000000000000001:32769
8310b10000000000000001:65537
8320b100000000000000001:131073
8330b1000000000000000001:262145
8340b10000000000000000001:524289
8350b100000000000000000001:1048577
8360b1000000000000000000001:2097153
8370b10000000000000000000001:4194305
8380b100000000000000000000001:8388609
8390b1000000000000000000000001:16777217
8400b10000000000000000000000001:33554433
8410b100000000000000000000000001:67108865
8420b1000000000000000000000000001:134217729
8430b10000000000000000000000000001:268435457
8440b100000000000000000000000000001:536870913
8450b1000000000000000000000000000001:1073741825
8460b10000000000000000000000000000001:2147483649
8470b100000000000000000000000000000001:4294967297
8480b1000000000000000000000000000000001:8589934593
8490b10000000000000000000000000000000001:17179869185
6854fd01 8500b_101:NaN
8510b1_0_1:5
394e6ffb 8520b0_0_0_1:1
6854fd01 853# hex input
854-0x0:0
8550xabcdefgh:NaN
8560x1234:4660
8570xabcdef:11259375
858-0xABCDEF:-11259375
859-0x1234:-4660
8600x12345678:305419896
8610x1_2_3_4_56_78:305419896
394e6ffb 8620xa_b_c_d_e_f:11259375
6854fd01 8630x_123:NaN
61f5c3f5 8640x9:9
8650x11:17
8660x21:33
8670x41:65
8680x81:129
8690x101:257
8700x201:513
8710x401:1025
8720x801:2049
8730x1001:4097
8740x2001:8193
8750x4001:16385
8760x8001:32769
8770x10001:65537
8780x20001:131073
8790x40001:262145
8800x80001:524289
8810x100001:1048577
8820x200001:2097153
8830x400001:4194305
8840x800001:8388609
8850x1000001:16777217
8860x2000001:33554433
8870x4000001:67108865
8880x8000001:134217729
8890x10000001:268435457
8900x20000001:536870913
8910x40000001:1073741825
8920x80000001:2147483649
8930x100000001:4294967297
8940x200000001:8589934593
8950x400000001:17179869185
8960x800000001:34359738369
6854fd01 897# inf input
898inf:inf
899+inf:inf
900-inf:-inf
9010inf:NaN
027dc388 902# abnormal input
6854fd01 903:NaN
904abc:NaN
905 1 a:NaN
9061bcd2:NaN
90711111b:NaN
908+1z:NaN
909-1z:NaN
027dc388 910# only one underscore between two digits
911_123:NaN
912_123_:NaN
913123_:NaN
9141__23:NaN
9151E1__2:NaN
9161_E12:NaN
9171E_12:NaN
9181_E_12:NaN
919+_1E12:NaN
920+0_1E2:100
921+0_0_1E2:100
922-0_0_1E2:-100
923-0_0_1E+0_0_2:-100
924E1:NaN
925E23:NaN
9261.23E1:NaN
9271.23E-1:NaN
928# bug with two E's in number beeing valid
9291e2e3:NaN
9301e2r:NaN
9311e2.0:NaN
07d34614 932# bug with two '.' in number beeing valid
9331.2.2:NaN
9341.2.3e1:NaN
935-1.2.3:NaN
936-1.2.3e-4:NaN
9371.2e3.4:NaN
9381.2e-3.4:NaN
9391.2.3.4:NaN
9401.2.t:NaN
9411..2:NaN
9421..2e1:NaN
9431..2e1..1:NaN
94412e1..1:NaN
945..2:NaN
946.-2:NaN
61f5c3f5 947# leading zeros
948012:12
9490123:123
95001234:1234
951012345:12345
9520123456:123456
95301234567:1234567
954012345678:12345678
9550123456789:123456789
95601234567891:1234567891
957012345678912:12345678912
9580123456789123:123456789123
95901234567891234:1234567891234
027dc388 960# normal input
6854fd01 9610:0
962+0:0
963+00:0
964+000:0
965000000000000000000:0
966-0:0
967-0000:0
968+1:1
969+01:1
970+001:1
971+00000100000:100000
972123456789:123456789
973-1:-1
974-01:-1
975-001:-1
976-123456789:-123456789
977-00000100000:-100000
9781_2_3:123
6854fd01 97910000000000E-1_0:1
9801E2:100
9811E1:10
9821E0:1
6854fd01 9831.23E2:123
6854fd01 984100E-1:10
985# floating point input
027dc388 986# .2e2:20
9871.E3:1000
6854fd01 9881.01E2:101
9891010E-1:101
990-1010E0:-1010
991-1010E1:-10100
027dc388 9921234.00:1234
993# non-integer numbers
6854fd01 994-1010E-2:NaN
995-1.01E+1:NaN
996-1.01E-1:NaN
6854fd01 997&bnan
9981:NaN
9992:NaN
1000abc:NaN
1001&bone
61f5c3f5 10022:+:1
6854fd01 10032:-:-1
1004boneNaN:-:-1
61f5c3f5 1005boneNaN:+:1
10062:abc:1
10073::1
6854fd01 1008&binf
10091:+:inf
10102:-:-inf
10113:abc:inf
027dc388 1012&is_nan
1013123:0
1014abc:1
1015NaN:1
1016-123:0
6854fd01 1017&is_inf
1018+inf::1
1019-inf::1
1020abc::0
10211::0
1022NaN::0
1023-1::0
1024+inf:-:0
1025+inf:+:1
1026-inf:-:1
1027-inf:+:0
79c55733 1028-inf:-inf:1
1029-inf:+inf:0
1030+inf:-inf:0
1031+inf:+inf:1
6854fd01 1032# it must be exactly /^[+-]inf$/
1033+infinity::0
1034-infinity::0
1035&blsft
1036abc:abc:NaN
61f5c3f5 1037+2:+2:8
1038+1:+32:4294967296
1039+1:+48:281474976710656
6854fd01 1040+8:-2:NaN
1041# excercise base 10
1042+12345:4:10:123450000
1043-1234:0:10:-1234
61f5c3f5 1044+1234:0:10:1234
6854fd01 1045+2:2:10:200
1046+12:2:10:1200
1047+1234:-3:10:NaN
10481234567890123:12:10:1234567890123000000000000
b3abae2a 1049-3:1:2:-6
1050-5:1:2:-10
1051-2:1:2:-4
1052-102533203:1:2:-205066406
6854fd01 1053&brsft
1054abc:abc:NaN
61f5c3f5 1055+8:+2:2
1056+4294967296:+32:1
1057+281474976710656:+48:1
6854fd01 1058+2:-2:NaN
1059# excercise base 10
1060-1234:0:10:-1234
61f5c3f5 1061+1234:0:10:1234
6854fd01 1062+200:2:10:2
1063+1234:3:10:1
1064+1234:2:10:12
1065+1234:-3:10:NaN
1066310000:4:10:31
106712300000:5:10:123
10681230000000000:10:10:123
106909876123456789067890:12:10:9876123
10701234561234567890123:13:10:123456
b3abae2a 1071820265627:1:2:410132813
1072# test shifting negative numbers in base 2
1073-15:1:2:-8
1074-14:1:2:-7
1075-13:1:2:-7
1076-12:1:2:-6
1077-11:1:2:-6
1078-10:1:2:-5
1079-9:1:2:-5
1080-8:1:2:-4
1081-7:1:2:-4
1082-6:1:2:-3
1083-5:1:2:-3
1084-4:1:2:-2
1085-3:1:2:-2
1086-2:1:2:-1
1087-1:1:2:-1
1088-1640531254:2:2:-410132814
1089-1640531254:1:2:-820265627
1090-820265627:1:2:-410132814
1091-205066405:1:2:-102533203
6854fd01 1092&bsstr
56d9de68 1093+inf:inf
1094-inf:-inf
6854fd01 10951e+34:1e+34
1096123.456E3:123456e+0
1097100:1e+2
56d9de68 1098bsstrabc:NaN
1099-5:-5e+0
1100-100:-1e+2
1101&numify
1102numifyabc:NaN
1103+inf:inf
1104-inf:-inf
11055:5
1106-5:-5
1107100:100
1108-100:-100
6854fd01 1109&bneg
1110bnegNaN:NaN
1111+inf:-inf
1112-inf:inf
1113abd:NaN
61f5c3f5 11140:0
11151:-1
1116-1:1
6854fd01 1117+123456789:-123456789
61f5c3f5 1118-123456789:123456789
6854fd01 1119&babs
1120babsNaN:NaN
1121+inf:inf
1122-inf:inf
61f5c3f5 11230:0
11241:1
1125-1:1
1126+123456789:123456789
1127-123456789:123456789
6854fd01 1128&bcmp
1129bcmpNaN:bcmpNaN:
61f5c3f5 1130bcmpNaN:0:
11310:bcmpNaN:
11320:0:0
1133-1:0:-1
11340:-1:1
11351:0:1
11360:1:-1
1137-1:1:-1
11381:-1:1
6854fd01 1139-1:-1:0
61f5c3f5 11401:1:0
1141123:123:0
1142123:12:1
114312:123:-1
6854fd01 1144-123:-123:0
1145-123:-12:-1
1146-12:-123:1
61f5c3f5 1147123:124:-1
1148124:123:1
6854fd01 1149-123:-124:1
1150-124:-123:-1
61f5c3f5 1151100:5:1
1152-123456789:987654321:-1
6854fd01 1153+123456789:-987654321:1
61f5c3f5 1154-987654321:123456789:-1
6854fd01 1155-inf:5432112345:-1
1156+inf:5432112345:1
1157-inf:-5432112345:-1
1158+inf:-5432112345:1
1159+inf:+inf:0
1160-inf:-inf:0
1161+inf:-inf:1
1162-inf:+inf:-1
11635:inf:-1
11645:inf:-1
1165-5:-inf:1
1166-5:-inf:1
1167# return undef
1168+inf:NaN:
1169NaN:inf:
1170-inf:NaN:
1171NaN:-inf:
1172&binc
1173abc:NaN
1174+inf:inf
1175-inf:-inf
61f5c3f5 1176+0:1
1177+1:2
1178-1:0
6854fd01 1179&bdec
1180abc:NaN
1181+inf:inf
1182-inf:-inf
1183+0:-1
61f5c3f5 1184+1:0
6854fd01 1185-1:-2
1186&badd
1187abc:abc:NaN
61f5c3f5 1188abc:0:NaN
6854fd01 1189+0:abc:NaN
b3abae2a 1190+inf:-inf:NaN
1191-inf:+inf:NaN
6854fd01 1192+inf:+inf:inf
1193-inf:-inf:-inf
1194baddNaN:+inf:NaN
1195baddNaN:+inf:NaN
1196+inf:baddNaN:NaN
1197-inf:baddNaN:NaN
61f5c3f5 11980:0:0
11991:0:1
12000:1:1
12011:1:2
1202-1:0:-1
12030:-1:-1
6854fd01 1204-1:-1:-2
61f5c3f5 1205-1:+1:0
1206+1:-1:0
1207+9:+1:10
1208+99:+1:100
1209+999:+1:1000
1210+9999:+1:10000
1211+99999:+1:100000
1212+999999:+1:1000000
1213+9999999:+1:10000000
1214+99999999:+1:100000000
1215+999999999:+1:1000000000
1216+9999999999:+1:10000000000
1217+99999999999:+1:100000000000
1218+10:-1:9
1219+100:-1:99
1220+1000:-1:999
1221+10000:-1:9999
1222+100000:-1:99999
1223+1000000:-1:999999
1224+10000000:-1:9999999
1225+100000000:-1:99999999
1226+1000000000:-1:999999999
1227+10000000000:-1:9999999999
1228+123456789:987654321:1111111110
1229-123456789:987654321:864197532
6854fd01 1230-123456789:-987654321:-1111111110
1231+123456789:-987654321:-864197532
56b9c951 1232-1:10001:10000
1233-1:100001:100000
1234-1:1000001:1000000
1235-1:10000001:10000000
1236-1:100000001:100000000
1237-1:1000000001:1000000000
1238-1:10000000001:10000000000
1239-1:100000000001:100000000000
1240-1:1000000000001:1000000000000
1241-1:10000000000001:10000000000000
1242-1:-10001:-10002
1243-1:-100001:-100002
1244-1:-1000001:-1000002
1245-1:-10000001:-10000002
1246-1:-100000001:-100000002
1247-1:-1000000001:-1000000002
1248-1:-10000000001:-10000000002
1249-1:-100000000001:-100000000002
1250-1:-1000000000001:-1000000000002
1251-1:-10000000000001:-10000000000002
6854fd01 1252&bsub
1253abc:abc:NaN
1254abc:+0:NaN
1255+0:abc:NaN
1256+inf:-inf:inf
1257-inf:+inf:-inf
b3abae2a 1258+inf:+inf:NaN
1259-inf:-inf:NaN
61f5c3f5 1260+0:+0:0
1261+1:+0:1
6854fd01 1262+0:+1:-1
61f5c3f5 1263+1:+1:0
6854fd01 1264-1:+0:-1
61f5c3f5 1265+0:-1:1
1266-1:-1:0
6854fd01 1267-1:+1:-2
61f5c3f5 1268+1:-1:2
1269+9:+1:8
1270+99:+1:98
1271+999:+1:998
1272+9999:+1:9998
1273+99999:+1:99998
1274+999999:+1:999998
1275+9999999:+1:9999998
1276+99999999:+1:99999998
1277+999999999:+1:999999998
1278+9999999999:+1:9999999998
1279+99999999999:+1:99999999998
1280+10:-1:11
1281+100:-1:101
1282+1000:-1:1001
1283+10000:-1:10001
1284+100000:-1:100001
1285+1000000:-1:1000001
1286+10000000:-1:10000001
1287+100000000:-1:100000001
1288+1000000000:-1:1000000001
1289+10000000000:-1:10000000001
6854fd01 1290+123456789:+987654321:-864197532
1291-123456789:+987654321:-1111111110
61f5c3f5 1292-123456789:-987654321:864197532
1293+123456789:-987654321:1111111110
56b9c951 129410001:1:10000
1295100001:1:100000
12961000001:1:1000000
129710000001:1:10000000
1298100000001:1:100000000
12991000000001:1:1000000000
130010000000001:1:10000000000
1301100000000001:1:100000000000
13021000000000001:1:1000000000000
130310000000000001:1:10000000000000
130410001:-1:10002
1305100001:-1:100002
13061000001:-1:1000002
130710000001:-1:10000002
1308100000001:-1:100000002
13091000000001:-1:1000000002
131010000000001:-1:10000000002
1311100000000001:-1:100000000002
13121000000000001:-1:1000000000002
131310000000000001:-1:10000000000002
6854fd01 1314&bmul
1315abc:abc:NaN
1316abc:+0:NaN
1317+0:abc:NaN
1318NaNmul:+inf:NaN
1319NaNmul:-inf:NaN
1320-inf:NaNmul:NaN
1321+inf:NaNmul:NaN
1322+inf:+inf:inf
1323+inf:-inf:-inf
1324-inf:+inf:-inf
1325-inf:-inf:inf
61f5c3f5 1326+0:+0:0
1327+0:+1:0
1328+1:+0:0
1329+0:-1:0
1330-1:+0:0
1331123456789123456789:0:0
13320:123456789123456789:0
1333-1:-1:1
6854fd01 1334-1:+1:-1
1335+1:-1:-1
61f5c3f5 1336+1:+1:1
1337+2:+3:6
6854fd01 1338-2:+3:-6
1339+2:-3:-6
61f5c3f5 1340-2:-3:6
1341111:111:12321
134210101:10101:102030201
13431001001:1001001:1002003002001
1344100010001:100010001:10002000300020001
134510000100001:10000100001:100002000030000200001
134611111111111:9:99999999999
134722222222222:9:199999999998
134833333333333:9:299999999997
134944444444444:9:399999999996
135055555555555:9:499999999995
135166666666666:9:599999999994
135277777777777:9:699999999993
135388888888888:9:799999999992
135499999999999:9:899999999991
1355+25:+25:625
1356+12345:+12345:152399025
1357+99999:+11111:1111088889
6854fd01 13589999:10000:99990000
135999999:100000:9999900000
1360999999:1000000:999999000000
13619999999:10000000:99999990000000
136299999999:100000000:9999999900000000
1363999999999:1000000000:999999999000000000
13649999999999:10000000000:99999999990000000000
136599999999999:100000000000:9999999999900000000000
1366999999999999:1000000000000:999999999999000000000000
13679999999999999:10000000000000:99999999999990000000000000
136899999999999999:100000000000000:9999999999999900000000000000
1369999999999999999:1000000000000000:999999999999999000000000000000
13709999999999999999:10000000000000000:99999999999999990000000000000000
137199999999999999999:100000000000000000:9999999999999999900000000000000000
1372999999999999999999:1000000000000000000:999999999999999999000000000000000000
13739999999999999999999:10000000000000000000:99999999999999999990000000000000000000
1374&bdiv-list
1375100:20:5,0
13764095:4095:1,0
1377-4095:-4095:1,0
13784095:-4095:-1,0
1379-4095:4095:-1,0
1380123:2:61,1
b3abae2a 13819:5:1,4
13829:4:2,1
6854fd01 1383# inf handling and general remainder
13845:8:0,5
13850:8:0,0
138611:2:5,1
138711:-2:-5,-1
1388-11:2:-5,1
1389# see table in documentation in MBI
13900:inf:0,0
13910:-inf:0,0
13925:inf:0,5
13935:-inf:0,5
1394-5:inf:0,-5
1395-5:-inf:0,-5
1396inf:5:inf,0
1397-inf:5:-inf,0
1398inf:-5:-inf,0
1399-inf:-5:inf,0
14005:5:1,0
1401-5:-5:1,0
b3abae2a 1402inf:inf:NaN,NaN
1403-inf:-inf:NaN,NaN
1404-inf:inf:NaN,NaN
1405inf:-inf:NaN,NaN
6854fd01 14068:0:inf,8
1407inf:0:inf,inf
1408# exceptions to reminder rule
1409-8:0:-inf,-8
1410-inf:0:-inf,-inf
14110:0:NaN,NaN
990fb837 1412# test the shortcut in Calc if @$x == @$yorg
14131234567812345678:123456712345678:10,688888898
141412345671234567:1234561234567:10,58888897
1415123456123456:12345123456:10,4888896
14161234512345:123412345:10,388895
14171234567890999999999:1234567890:1000000000,999999999
14181234567890000000000:1234567890:1000000000,0
14191234567890999999999:9876543210:124999998,9503086419
14201234567890000000000:9876543210:124999998,8503086420
142196969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199,484848484848484848484848123012121211954972727272727272727451
6854fd01 1422&bdiv
1423abc:abc:NaN
61f5c3f5 1424abc:1:NaN
14251:abc:NaN
14260:0:NaN
6854fd01 1427# inf handling (see table in doc)
14280:inf:0
14290:-inf:0
14305:inf:0
14315:-inf:0
1432-5:inf:0
1433-5:-inf:0
1434inf:5:inf
1435-inf:5:-inf
1436inf:-5:-inf
1437-inf:-5:inf
14385:5:1
1439-5:-5:1
b3abae2a 1440inf:inf:NaN
1441-inf:-inf:NaN
1442-inf:inf:NaN
1443inf:-inf:NaN
6854fd01 14448:0:inf
1445inf:0:inf
1446-8:0:-inf
1447-inf:0:-inf
14480:0:NaN
144911:2:5
1450-11:-2:5
1451-11:2:-5
145211:-2:-5
61f5c3f5 14530:1:0
14540:-1:0
14551:1:1
1456-1:-1:1
14571:-1:-1
1458-1:1:-1
14591:2:0
14602:1:2
14611:26:0
14621000000000:9:111111111
14632000000000:9:222222222
14643000000000:9:333333333
14654000000000:9:444444444
14665000000000:9:555555555
14676000000000:9:666666666
14687000000000:9:777777777
14698000000000:9:888888888
14709000000000:9:1000000000
147135500000:113:314159
147271000000:226:314159
1473106500000:339:314159
14741000000000:3:333333333
1475+10:+5:2
1476+100:+4:25
1477+1000:+8:125
1478+10000:+16:625
1479999999999999:9:111111111111
1480999999999999:99:10101010101
1481999999999999:999:1001001001
1482999999999999:9999:100010001
1483999999999999999:99999:10000100001
1484+1111088889:99999:11111
6854fd01 1485-5:-3:1
1486-5:3:-1
14874:3:1
14884:-3:-1
14891:3:0
14901:-3:0
1491-2:-3:0
1492-2:3:0
14938:3:2
1494-8:3:-2
149514:-3:-4
1496-14:3:-4
1497-14:-3:4
149814:3:4
1499# bug in Calc with '99999' vs $BASE-1
150010000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576
990fb837 1501# test the shortcut in Calc if @$x == @$yorg
15021234567812345678:123456712345678:10
150312345671234567:1234561234567:10
1504123456123456:12345123456:10
15051234512345:123412345:10
15061234567890999999999:1234567890:1000000000
15071234567890000000000:1234567890:1000000000
15081234567890999999999:9876543210:124999998
15091234567890000000000:9876543210:124999998
151096969696969696969696969696969678787878626262626262626262626262:484848484848484848484848486666666666666689898989898989898989:199
aef458a0 1511# bug up to v0.35 in Calc (--$q one too many)
151284696969696969696956565656566184292929292929292847474747436308080808080808086765396464646464646465:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999999
151384696969696969696943434343434871161616161616161452525252486813131313131313143230042929292929292930:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999998
151484696969696969696969696969697497424242424242424242424242385803030303030303030300750000000000000000:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6450000000000000000
151584696969696969696930303030303558030303030303030057575757537318181818181818199694689393939393939395:13131313131313131313131313131394949494949494949494949494943535353535353535353535:6449999999999999997
07d34614 1516&bmodinv
1517# format: number:modulus:result
1518# bmodinv Data errors
1519abc:abc:NaN
1520abc:5:NaN
15215:abc:NaN
1522# bmodinv Expected Results from normal use
15231:5:1
15243:5:2
1525-2:5:2
15268:5033:4404
56d9de68 15271234567891:13:6
1528-1234567891:13:7
07d34614 1529324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902
d614cd8b 1530## bmodinv Error cases / useless use of function
07d34614 15313:-5:NaN
1532inf:5:NaN
1ddff52a 15335:inf:NaN
1534-inf:5:NaN
15355:-inf:NaN
07d34614 1536&bmodpow
1537# format: number:exponent:modulus:result
1538# bmodpow Data errors
1539abc:abc:abc:NaN
15405:abc:abc:NaN
1541abc:5:abc:NaN
1542abc:abc:5:NaN
15435:5:abc:NaN
15445:abc:5:NaN
1545abc:5:5:NaN
1546# bmodpow Expected results
15470:0:2:1
15481:0:2:1
15490:0:1:0
15508:7:5032:3840
15518:-1:5033:4404
155298436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518
1553# bmodpow Error cases
15548:8:-5:NaN
15558:-1:16:NaN
1556inf:5:13:NaN
15575:inf:13:NaN
6854fd01 1558&bmod
1559# inf handling, see table in doc
15600:inf:0
15610:-inf:0
15625:inf:5
15635:-inf:5
1564-5:inf:-5
1565-5:-inf:-5
1566inf:5:0
1567-inf:5:0
1568inf:-5:0
1569-inf:-5:0
15705:5:0
1571-5:-5:0
b3abae2a 1572inf:inf:NaN
1573-inf:-inf:NaN
1574-inf:inf:NaN
1575inf:-inf:NaN
6854fd01 15768:0:8
1577inf:0:inf
1578# exceptions to reminder rule
1579-inf:0:-inf
1580-8:0:-8
15810:0:NaN
1582abc:abc:NaN
61f5c3f5 1583abc:1:abc:NaN
15841:abc:NaN
15850:0:NaN
15860:1:0
15871:0:1
15880:-1:0
1589-1:0:-1
15901:1:0
1591-1:-1:0
15921:-1:0
1593-1:1:0
15941:2:1
15952:1:0
15961000000000:9:1
15972000000000:9:2
15983000000000:9:3
15994000000000:9:4
16005000000000:9:5
16016000000000:9:6
16027000000000:9:7
16038000000000:9:8
16049000000000:9:0
160535500000:113:33
160671000000:226:66
1607106500000:339:99
16081000000000:3:1
160910:5:0
1610100:4:0
16111000:8:0
161210000:16:0
1613999999999999:9:0
1614999999999999:99:0
1615999999999999:999:0
1616999999999999:9999:0
1617999999999999999:99999:0
1618-9:+5:1
6854fd01 1619+9:-5:-1
1620-9:-5:-4
1621-5:3:1
1622-2:3:1
16234:3:1
16241:3:1
1625-5:-3:-2
1626-2:-3:-2
16274:-3:-2
16281:-3:-2
16294095:4095:0
027dc388 1630100041000510123:3:0
1631152403346:12345:4321
b3abae2a 16329:5:4
28df3e88 1633# test shortcuts in Calc
1634# 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0
16351234:9:1
1636123456:9:3
163712345678:9:0
16381234567891:9:1
1639123456789123:9:6
164012345678912345:9:6
16411234567891234567:9:1
1642123456789123456789:9:0
16431234:10:4
1644123456:10:6
164512345678:10:8
16461234567891:10:1
1647123456789123:10:3
164812345678912345:10:5
16491234567891234567:10:7
1650123456789123456789:10:9
16511234:113:104
1652123456:113:60
165312345678:113:89
16541234567891:113:64
1655123456789123:113:95
165612345678912345:113:53
16571234567891234567:113:56
1658123456789123456789:113:39
07d34614 1659# bug in bmod() not modifying the variable in place
1660-629:5033:4404
aef458a0 1661# bug in bmod() in Calc in the _div_use_div() shortcut code path,
1662# when X == X and X was big
1663111111111111111111111111111111:111111111111111111111111111111:0
166412345678901234567890:12345678901234567890:0
6854fd01 1665&bgcd
1666abc:abc:NaN
1667abc:+0:NaN
1668+0:abc:NaN
61f5c3f5 1669+0:+0:0
1670+0:+1:1
1671+1:+0:1
1672+1:+1:1
1673+2:+3:1
1674+3:+2:1
1675-3:+2:1
1676100:625:25
16774096:81:1
16781034:804:2
167927:90:56:1
168027:90:54:9
6854fd01 1681&blcm
1682abc:abc:NaN
1683abc:+0:NaN
1684+0:abc:NaN
1685+0:+0:NaN
61f5c3f5 1686+1:+0:0
1687+0:+1:0
1688+27:+90:270
1689+1034:+804:415668
6854fd01 1690&band
1691abc:abc:NaN
1692abc:0:NaN
16930:abc:NaN
16941:2:0
16953:2:2
61f5c3f5 1696+8:+2:0
1697+281474976710656:0:0
1698+281474976710656:1:0
1699+281474976710656:+281474976710656:281474976710656
6854fd01 1700-2:-3:-4
1701-1:-1:-1
1702-6:-6:-6
1703-7:-4:-8
1704-7:4:0
1705-4:7:4
394e6ffb 1706# equal arguments are treated special, so also do some test with unequal ones
17070xFFFF:0xFFFF:0x0xFFFF
17080xFFFFFF:0xFFFFFF:0x0xFFFFFF
17090xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
17100xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17110xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17120xF0F0:0xF0F0:0x0xF0F0
17130x0F0F:0x0F0F:0x0x0F0F
17140xF0F0F0:0xF0F0F0:0x0xF0F0F0
17150x0F0F0F:0x0F0F0F:0x0x0F0F0F
17160xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
17170x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
17180xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
17190x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
17200xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
17210x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
17220x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F
6854fd01 1723&bior
1724abc:abc:NaN
1725abc:0:NaN
17260:abc:NaN
17271:2:3
61f5c3f5 1728+8:+2:10
1729+281474976710656:0:281474976710656
1730+281474976710656:1:281474976710657
1731+281474976710656:281474976710656:281474976710656
6854fd01 1732-2:-3:-1
1733-1:-1:-1
1734-6:-6:-6
1735-7:4:-3
1736-4:7:-1
394e6ffb 1737# equal arguments are treated special, so also do some test with unequal ones
17380xFFFF:0xFFFF:0x0xFFFF
17390xFFFFFF:0xFFFFFF:0x0xFFFFFF
17400xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF
17410xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17420xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17430:0xFFFF:0x0xFFFF
17440:0xFFFFFF:0x0xFFFFFF
17450:0xFFFFFFFF:0x0xFFFFFFFF
17460:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17470:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17480xFFFF:0:0x0xFFFF
17490xFFFFFF:0:0x0xFFFFFF
17500xFFFFFFFF:0:0x0xFFFFFFFF
17510xFFFFFFFFFF:0:0x0xFFFFFFFFFF
17520xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
17530xF0F0:0xF0F0:0x0xF0F0
17540x0F0F:0x0F0F:0x0x0F0F
17550xF0F0:0x0F0F:0x0xFFFF
17560xF0F0F0:0xF0F0F0:0x0xF0F0F0
17570x0F0F0F:0x0F0F0F:0x0x0F0F0F
17580x0F0F0F:0xF0F0F0:0x0xFFFFFF
17590xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0
17600x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F
17610x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
17620xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0
17630x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F
17640x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
17650xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0
17660x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F
17670x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
17680x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1769&bxor
1770abc:abc:NaN
1771abc:0:NaN
17720:abc:NaN
17731:2:3
61f5c3f5 1774+8:+2:10
1775+281474976710656:0:281474976710656
1776+281474976710656:1:281474976710657
1777+281474976710656:281474976710656:0
6854fd01 1778-2:-3:3
1779-1:-1:0
1780-6:-6:0
1781-7:4:-3
1782-4:7:-5
17834:-7:-3
1784-4:-7:5
394e6ffb 1785# equal arguments are treated special, so also do some test with unequal ones
17860xFFFF:0xFFFF:0
17870xFFFFFF:0xFFFFFF:0
17880xFFFFFFFF:0xFFFFFFFF:0
17890xFFFFFFFFFF:0xFFFFFFFFFF:0
17900xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0
17910:0xFFFF:0x0xFFFF
17920:0xFFFFFF:0x0xFFFFFF
17930:0xFFFFFFFF:0x0xFFFFFFFF
17940:0xFFFFFFFFFF:0x0xFFFFFFFFFF
17950:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF
17960xFFFF:0:0x0xFFFF
17970xFFFFFF:0:0x0xFFFFFF
17980xFFFFFFFF:0:0x0xFFFFFFFF
17990xFFFFFFFFFF:0:0x0xFFFFFFFFFF
18000xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF
18010xF0F0:0xF0F0:0
18020x0F0F:0x0F0F:0
18030xF0F0:0x0F0F:0x0xFFFF
18040xF0F0F0:0xF0F0F0:0
18050x0F0F0F:0x0F0F0F:0
18060x0F0F0F:0xF0F0F0:0x0xFFFFFF
18070xF0F0F0F0:0xF0F0F0F0:0
18080x0F0F0F0F:0x0F0F0F0F:0
18090x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF
18100xF0F0F0F0F0:0xF0F0F0F0F0:0
18110x0F0F0F0F0F:0x0F0F0F0F0F:0
18120x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF
18130xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0
18140x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0
18150x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF
6854fd01 1816&bnot
1817abc:NaN
1818+0:-1
1819+8:-9
1820+281474976710656:-281474976710657
1821-1:0
1822-2:1
1823-12:11
1824&digit
18250:0:0
182612:0:2
182712:1:1
1828123:0:3
1829123:1:2
1830123:2:1
1831123:-1:1
1832123:-2:2
1833123:-3:3
1834123456:0:6
1835123456:1:5
1836123456:2:4
1837123456:3:3
1838123456:4:2
1839123456:5:1
1840123456:-1:1
1841123456:-2:2
1842123456:-3:3
1843100000:-3:0
1844100000:0:0
1845100000:1:0
1846&mantissa
1847abc:NaN
18481e4:1
18492e0:2
1850123:123
1851-1:-1
1852-2:-2
1853+inf:inf
1854-inf:-inf
1855&exponent
1856abc:NaN
18571e4:4
18582e0:0
1859123:0
1860-1:0
1861-2:0
18620:1
1863+inf:inf
1864-inf:inf
1865&parts
1866abc:NaN,NaN
18671e4:1,4
18682e0:2,0
1869123:123,0
1870-1:-1,0
1871-2:-2,0
18720:0,1
1873+inf:inf,inf
1874-inf:-inf,inf
b3abae2a 1875&bfac
1876-1:NaN
1877NaNfac:NaN
1878+inf:NaN
1879-inf:NaN
18800:1
18811:1
18822:2
18833:6
18844:24
18855:120
18866:720
990fb837 18877:5040
18888:40320
18899:362880
b3abae2a 189010:3628800
189111:39916800
189212:479001600
6854fd01 1893&bpow
1894abc:12:NaN
189512:abc:NaN
18960:0:1
18970:1:0
18980:2:0
18990:-1:NaN
19000:-2:NaN
19011:0:1
19021:1:1
19031:2:1
19041:3:1
19051:-1:1
19061:-2:1
19071:-3:1
19082:0:1
19092:1:2
19102:2:4
19112:3:8
19123:3:27
19132:-1:NaN
1914-2:-1:NaN
19152:-2:NaN
1916-2:-2:NaN
1917+inf:1234500012:inf
1918-inf:1234500012:-inf
1919+inf:-12345000123:inf
1920-inf:-12345000123:-inf
1921# 1 ** -x => 1 / (1 ** x)
1922-1:0:1
1923-2:0:1
1924-1:1:-1
1925-1:2:1
1926-1:3:-1
1927-1:4:1
1928-1:5:-1
1929-1:-1:-1
1930-1:-2:1
1931-1:-3:-1
1932-1:-4:1
193310:2:100
193410:3:1000
193510:4:10000
193610:5:100000
193710:6:1000000
193810:7:10000000
193910:8:100000000
194010:9:1000000000
194110:20:100000000000000000000
1942123456:2:15241383936
1943&length
1944100:3
194510:2
19461:1
19470:1
194812345:5
194910000000000000000:17
1950-123:3
1951215960156869840440586892398248:30
990fb837 1952&broot
1953# sqrt()
1954+0:2:0
1955+1:2:1
1956-1:2:NaN
1957# -$x ** (1/2) => -$y, but not in froot()
1958-123:2:NaN
1959+inf:2:inf
1960-inf:2:NaN
19612:2:1
1962-2:2:NaN
19634:2:2
19649:2:3
196516:2:4
1966100:2:10
1967123:2:11
196815241:2:123
1969144:2:12
197012:2:3
19710.49:2:0
19720.0049:2:0
1973# invalid ones
19741:NaN:NaN
1975-1:NaN:NaN
19760:NaN:NaN
1977-inf:NaN:NaN
1978+inf:NaN:NaN
1979NaN:0:NaN
1980NaN:2:NaN
1981NaN:inf:NaN
1982NaN:inf:NaN
198312:-inf:NaN
198412:inf:NaN
1985+0:0:NaN
1986+1:0:NaN
1987-1:0:NaN
1988-2:0:NaN
1989-123.45:0:NaN
1990+inf:0:NaN
199112:1:12
1992-12:1:NaN
19938:-1:NaN
1994-8:-1:NaN
1995# cubic root
19968:3:2
1997-8:3:NaN
1998# fourths root
c38b2de2 199916:4:2
200081:4:3
2001# 2 ** 32
200218446744073709551616:4:65536
200318446744073709551616:8:256
200418446744073709551616:16:16
200518446744073709551616:32:4
200618446744073709551616:64:2
200718446744073709551616:128:1
6854fd01 2008&bsqrt
394e6ffb 2009145:12
6854fd01 2010144:12
394e6ffb 2011143:11
6854fd01 201216:4
394e6ffb 2013170:13
2014169:13
2015168:12
6854fd01 20164:2
394e6ffb 20173:1
6854fd01 20182:1
394e6ffb 20199:3
6854fd01 202012:3
2021256:16
2022100000000:10000
20234000000000000:2000000
394e6ffb 2024152399026:12345
2025152399025:12345
2026152399024:12344
6854fd01 20271:1
20280:0
2029-2:NaN
394e6ffb 2030-123:NaN
6854fd01 2031Nan:NaN
990fb837 2032+inf:inf
2033-inf:NaN
6854fd01 2034&bround
2035$round_mode('trunc')
20360:12:0
2037NaNbround:12:NaN
2038+inf:12:inf
2039-inf:12:-inf
20401234:0:1234
20411234:2:1200
2042123456:4:123400
2043123456:5:123450
2044123456:6:123456
61f5c3f5 2045+10123456789:5:10123000000
6854fd01 2046-10123456789:5:-10123000000
61f5c3f5 2047+10123456789:9:10123456700
6854fd01 2048-10123456789:9:-10123456700
61f5c3f5 2049+101234500:6:101234000
6854fd01 2050-101234500:6:-101234000
61f5c3f5 2051#+101234500:-4:101234000
6854fd01 2052#-101234500:-4:-101234000
2053$round_mode('zero')
61f5c3f5 2054+20123456789:5:20123000000
6854fd01 2055-20123456789:5:-20123000000
61f5c3f5 2056+20123456789:9:20123456800
6854fd01 2057-20123456789:9:-20123456800
61f5c3f5 2058+201234500:6:201234000
6854fd01 2059-201234500:6:-201234000
61f5c3f5 2060#+201234500:-4:201234000
6854fd01 2061#-201234500:-4:-201234000
2062+12345000:4:12340000
2063-12345000:4:-12340000
2064$round_mode('+inf')
61f5c3f5 2065+30123456789:5:30123000000
6854fd01 2066-30123456789:5:-30123000000
61f5c3f5 2067+30123456789:9:30123456800
6854fd01 2068-30123456789:9:-30123456800
61f5c3f5 2069+301234500:6:301235000
6854fd01 2070-301234500:6:-301234000
61f5c3f5 2071#+301234500:-4:301235000
6854fd01 2072#-301234500:-4:-301234000
2073+12345000:4:12350000
2074-12345000:4:-12340000
2075$round_mode('-inf')
61f5c3f5 2076+40123456789:5:40123000000
6854fd01 2077-40123456789:5:-40123000000
61f5c3f5 2078+40123456789:9:40123456800
6854fd01 2079-40123456789:9:-40123456800
61f5c3f5 2080+401234500:6:401234000
2081+401234500:6:401234000
6854fd01 2082#-401234500:-4:-401235000
2083#-401234500:-4:-401235000
2084+12345000:4:12340000
2085-12345000:4:-12350000
2086$round_mode('odd')
61f5c3f5 2087+50123456789:5:50123000000
6854fd01 2088-50123456789:5:-50123000000
61f5c3f5 2089+50123456789:9:50123456800
6854fd01 2090-50123456789:9:-50123456800
61f5c3f5 2091+501234500:6:501235000
6854fd01 2092-501234500:6:-501235000
61f5c3f5 2093#+501234500:-4:501235000
6854fd01 2094#-501234500:-4:-501235000
2095+12345000:4:12350000
2096-12345000:4:-12350000
2097$round_mode('even')
61f5c3f5 2098+60123456789:5:60123000000
6854fd01 2099-60123456789:5:-60123000000
61f5c3f5 2100+60123456789:9:60123456800
6854fd01 2101-60123456789:9:-60123456800
61f5c3f5 2102+601234500:6:601234000
6854fd01 2103-601234500:6:-601234000
61f5c3f5 2104#+601234500:-4:601234000
6854fd01 2105#-601234500:-4:-601234000
2106#-601234500:-9:0
2107#-501234500:-9:0
2108#-601234500:-8:0
2109#-501234500:-8:0
2110+1234567:7:1234567
2111+1234567:6:1234570
2112+12345000:4:12340000
2113-12345000:4:-12340000
2114&is_zero
21150:1
2116NaNzero:0
2117+inf:0
2118-inf:0
2119123:0
2120-1:0
21211:0
2122&is_one
21230:0
2124NaNone:0
2125+inf:0
2126-inf:0
21271:1
21282:0
2129-1:0
2130-2:0
2131# floor and ceil tests are pretty pointless in integer space...but play safe
2132&bfloor
21330:0
2134NaNfloor:NaN
2135+inf:inf
2136-inf:-inf
2137-1:-1
2138-2:-2
21392:2
21403:3
2141abc:NaN
2142&bceil
2143NaNceil:NaN
2144+inf:inf
2145-inf:-inf
21460:0
2147-1:-1
2148-2:-2
21492:2
21503:3
2151abc:NaN
2152&as_hex
2153128:0x80
2154-128:-0x80
21550:0x0
2156-0:0x0
21571:0x1
21580x123456789123456789:0x123456789123456789
2159+inf:inf
2160-inf:-inf
2161NaNas_hex:NaN
2162&as_bin
2163128:0b10000000
2164-128:-0b10000000
21650:0b0
2166-0:0b0
21671:0b1
21680b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101
1ddff52a 21690x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001
6854fd01 2170+inf:inf
2171-inf:-inf
2172NaNas_bin:NaN