Commit | Line | Data |
6854fd01 |
1 | #include this file into another for subclass testing |
2 | |
3 | my $version = ${"$class\::VERSION"}; |
4 | |
56d9de68 |
5 | use strict; |
6 | |
6854fd01 |
7 | ############################################################################## |
8 | # for testing inheritance of _swap |
9 | |
10 | package Math::Foo; |
11 | |
61f5c3f5 |
12 | use Math::BigInt lib => $main::CL; |
6854fd01 |
13 | use vars qw/@ISA/; |
14 | @ISA = (qw/Math::BigInt/); |
15 | |
16 | use overload |
17 | # customized overload for sub, since original does not use swap there |
18 | '-' => sub { my @a = ref($_[0])->_swap(@_); |
19 | $a[0]->bsub($a[1])}; |
20 | |
21 | sub _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 | ############################################################################## |
37 | package main; |
38 | |
b3abae2a |
39 | my $CALC = $class->config()->{lib}; ok ($CALC,$CL); |
6854fd01 |
40 | |
b3abae2a |
41 | my ($f,$z,$a,$exp,@a,$m,$e,$round_mode,$expected_class); |
6854fd01 |
42 | |
43 | while (<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 | } |
157 | }elsif ($f eq "band"){ |
158 | $try .= "\$x & \$y;"; |
159 | }elsif ($f eq "bior"){ |
160 | $try .= "\$x | \$y;"; |
161 | }elsif ($f eq "bxor"){ |
162 | $try .= "\$x ^ \$y;"; |
163 | }elsif ($f eq "bpow"){ |
164 | $try .= "\$x ** \$y;"; |
d614cd8b |
165 | } elsif( $f eq "bmodinv") { |
166 | $try .= "\$x->bmodinv(\$y);"; |
6854fd01 |
167 | }elsif ($f eq "digit"){ |
56b9c951 |
168 | $try .= "\$x->digit(\$y);"; |
d614cd8b |
169 | } else { |
170 | $try .= "\$z = $class->new(\"$args[2]\");"; |
171 | |
172 | # Functions with three arguments |
173 | if( $f eq "bmodpow") { |
174 | $try .= "\$x->bmodpow(\$y,\$z);"; |
175 | } else { warn "Unknown op '$f'"; } |
176 | } |
61f5c3f5 |
177 | } # end else all other ops |
178 | |
179 | $ans1 = eval $try; |
180 | # convert hex/binary targets to decimal |
181 | if ($ans =~ /^(0x0x|0b0b)/) |
182 | { |
183 | $ans =~ s/^0[xb]//; $ans = Math::BigInt->new($ans)->bstr(); |
6854fd01 |
184 | } |
61f5c3f5 |
185 | if ($ans eq "") |
186 | { |
187 | ok_undef ($ans1); |
188 | } |
189 | else |
190 | { |
191 | # print "try: $try ans: $ans1 $ans\n"; |
192 | print "# Tried: '$try'\n" if !ok ($ans1, $ans); |
b3abae2a |
193 | ok (ref($ans),$expected_class) if $expected_class ne $class; |
6854fd01 |
194 | } |
61f5c3f5 |
195 | # check internal state of number objects |
196 | is_valid($ans1,$f) if ref $ans1; |
6854fd01 |
197 | } # endwhile data tests |
198 | close DATA; |
199 | |
200 | # test some more |
201 | @a = (); |
202 | for (my $i = 1; $i < 10; $i++) |
203 | { |
204 | push @a, $i; |
205 | } |
206 | ok "@a", "1 2 3 4 5 6 7 8 9"; |
207 | |
208 | # test whether self-multiplication works correctly (result is 2**64) |
209 | $try = "\$x = $class->new('4294967296');"; |
210 | $try .= '$a = $x->bmul($x);'; |
211 | $ans1 = eval $try; |
212 | print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64); |
213 | # test self-pow |
214 | $try = "\$x = $class->new(10);"; |
215 | $try .= '$a = $x->bpow($x);'; |
216 | $ans1 = eval $try; |
217 | print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10); |
218 | |
07d34614 |
219 | ############################################################################### |
6854fd01 |
220 | # test whether op destroys args or not (should better not) |
221 | |
222 | $x = $class->new(3); |
223 | $y = $class->new(4); |
224 | $z = $x & $y; |
225 | ok ($x,3); |
226 | ok ($y,4); |
227 | ok ($z,0); |
228 | $z = $x | $y; |
229 | ok ($x,3); |
230 | ok ($y,4); |
231 | ok ($z,7); |
232 | $x = $class->new(1); |
233 | $y = $class->new(2); |
234 | $z = $x | $y; |
235 | ok ($x,1); |
236 | ok ($y,2); |
237 | ok ($z,3); |
238 | |
239 | $x = $class->new(5); |
240 | $y = $class->new(4); |
241 | $z = $x ^ $y; |
242 | ok ($x,5); |
243 | ok ($y,4); |
244 | ok ($z,1); |
245 | |
246 | $x = $class->new(-5); $y = -$x; |
247 | ok ($x, -5); |
248 | |
249 | $x = $class->new(-5); $y = abs($x); |
250 | ok ($x, -5); |
251 | |
07d34614 |
252 | $x = $class->new(8); |
253 | $y = $class->new(-1); |
254 | $z = $class->new(5033); |
255 | my $u = $x->copy()->bmodpow($y,$z); |
256 | ok ($u,4404); |
257 | ok ($y,-1); |
258 | ok ($z,5033); |
259 | |
260 | $x = $class->new(-5); $y = -$x; ok ($x,-5); ok ($y,5); |
261 | $x = $class->new(-5); $y = $x->copy()->bneg(); ok ($x,-5); ok ($y,5); |
262 | |
263 | $x = $class->new(-5); $y = $class->new(3); $x->bmul($y); ok ($x,-15); ok ($y,3); |
264 | $x = $class->new(-5); $y = $class->new(3); $x->badd($y); ok ($x,-2); ok ($y,3); |
265 | $x = $class->new(-5); $y = $class->new(3); $x->bsub($y); ok ($x,-8); ok ($y,3); |
266 | $x = $class->new(-15); $y = $class->new(3); $x->bdiv($y); ok ($x,-5); ok ($y,3); |
267 | $x = $class->new(-5); $y = $class->new(3); $x->bmod($y); ok ($x,1); ok ($y,3); |
268 | |
269 | $x = $class->new(5); $y = $class->new(3); $x->bmul($y); ok ($x,15); ok ($y,3); |
270 | $x = $class->new(5); $y = $class->new(3); $x->badd($y); ok ($x,8); ok ($y,3); |
271 | $x = $class->new(5); $y = $class->new(3); $x->bsub($y); ok ($x,2); ok ($y,3); |
272 | $x = $class->new(15); $y = $class->new(3); $x->bdiv($y); ok ($x,5); ok ($y,3); |
273 | $x = $class->new(5); $y = $class->new(3); $x->bmod($y); ok ($x,2); ok ($y,3); |
274 | |
275 | $x = $class->new(5); $y = $class->new(-3); $x->bmul($y); ok ($x,-15); ok($y,-3); |
276 | $x = $class->new(5); $y = $class->new(-3); $x->badd($y); ok ($x,2); ok($y,-3); |
277 | $x = $class->new(5); $y = $class->new(-3); $x->bsub($y); ok ($x,8); ok($y,-3); |
278 | $x = $class->new(15); $y = $class->new(-3); $x->bdiv($y); ok ($x,-5); ok($y,-3); |
279 | $x = $class->new(5); $y = $class->new(-3); $x->bmod($y); ok ($x,-1); ok($y,-3); |
280 | |
281 | ############################################################################### |
6854fd01 |
282 | # check whether overloading cmp works |
283 | $try = "\$x = $class->new(0);"; |
284 | $try .= "\$y = 10;"; |
285 | $try .= "'false' if \$x ne \$y;"; |
286 | $ans = eval $try; |
287 | print "# For '$try'\n" if (!ok "$ans" , "false" ); |
288 | |
289 | # we cant test for working cmpt with other objects here, we would need a dummy |
290 | # object with stringify overload for this. see Math::String tests as example |
291 | |
292 | ############################################################################### |
6854fd01 |
293 | # check reversed order of arguments |
027dc388 |
294 | |
6854fd01 |
295 | $try = "\$x = $class->new(10); \$x = 2 ** \$x;"; |
296 | $try .= "'ok' if \$x == 1024;"; $ans = eval $try; |
297 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
298 | |
299 | $try = "\$x = $class->new(10); \$x = 2 * \$x;"; |
300 | $try .= "'ok' if \$x == 20;"; $ans = eval $try; |
301 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
302 | |
303 | $try = "\$x = $class->new(10); \$x = 2 + \$x;"; |
304 | $try .= "'ok' if \$x == 12;"; $ans = eval $try; |
305 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
306 | |
307 | $try = "\$x = $class\->new(10); \$x = 2 - \$x;"; |
308 | $try .= "'ok' if \$x == -8;"; $ans = eval $try; |
309 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
310 | |
311 | $try = "\$x = $class\->new(10); \$x = 20 / \$x;"; |
312 | $try .= "'ok' if \$x == 2;"; $ans = eval $try; |
313 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
314 | |
027dc388 |
315 | $try = "\$x = $class\->new(3); \$x = 20 % \$x;"; |
316 | $try .= "'ok' if \$x == 2;"; $ans = eval $try; |
317 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
318 | |
319 | $try = "\$x = $class\->new(7); \$x = 20 & \$x;"; |
320 | $try .= "'ok' if \$x == 4;"; $ans = eval $try; |
321 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
322 | |
323 | $try = "\$x = $class\->new(7); \$x = 0x20 | \$x;"; |
324 | $try .= "'ok' if \$x == 0x27;"; $ans = eval $try; |
325 | print "# 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; |
329 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
330 | |
6854fd01 |
331 | ############################################################################### |
332 | # check badd(4,5) form |
333 | |
334 | $try = "\$x = $class\->badd(4,5);"; |
335 | $try .= "'ok' if \$x == 9;"; |
336 | $ans = eval $try; |
337 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
338 | |
339 | ############################################################################### |
340 | # check undefs: NOT DONE YET |
341 | |
342 | ############################################################################### |
343 | # bool |
344 | |
f9a08e12 |
345 | $x = $class->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') } |
346 | $x = $class->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') } |
6854fd01 |
347 | |
348 | ############################################################################### |
349 | # objectify() |
350 | |
351 | @args = Math::BigInt::objectify(2,4,5); |
352 | ok (scalar @args,3); # $class, 4, 5 |
56b9c951 |
353 | ok ($args[0] =~ /^Math::BigInt/); |
6854fd01 |
354 | ok ($args[1],4); |
355 | ok ($args[2],5); |
356 | |
357 | @args = Math::BigInt::objectify(0,4,5); |
358 | ok (scalar @args,3); # $class, 4, 5 |
56b9c951 |
359 | ok ($args[0] =~ /^Math::BigInt/); |
6854fd01 |
360 | ok ($args[1],4); |
361 | ok ($args[2],5); |
362 | |
363 | @args = Math::BigInt::objectify(2,4,5); |
364 | ok (scalar @args,3); # $class, 4, 5 |
56b9c951 |
365 | ok ($args[0] =~ /^Math::BigInt/); |
6854fd01 |
366 | ok ($args[1],4); |
367 | ok ($args[2],5); |
368 | |
369 | @args = Math::BigInt::objectify(2,4,5,6,7); |
370 | ok (scalar @args,5); # $class, 4, 5, 6, 7 |
56b9c951 |
371 | ok ($args[0] =~ /^Math::BigInt/); |
6854fd01 |
372 | ok ($args[1],4); ok (ref($args[1]),$args[0]); |
373 | ok ($args[2],5); ok (ref($args[2]),$args[0]); |
374 | ok ($args[3],6); ok (ref($args[3]),''); |
375 | ok ($args[4],7); ok (ref($args[4]),''); |
376 | |
377 | @args = Math::BigInt::objectify(2,$class,4,5,6,7); |
378 | ok (scalar @args,5); # $class, 4, 5, 6, 7 |
379 | ok ($args[0],$class); |
380 | ok ($args[1],4); ok (ref($args[1]),$args[0]); |
381 | ok ($args[2],5); ok (ref($args[2]),$args[0]); |
382 | ok ($args[3],6); ok (ref($args[3]),''); |
383 | ok ($args[4],7); ok (ref($args[4]),''); |
384 | |
385 | ############################################################################### |
f9a08e12 |
386 | # test whether an opp calls objectify properly or not (or at least does what |
387 | # it should do given non-objects, w/ or w/o objectify()) |
388 | |
389 | ok ($class->new(123)->badd(123),246); |
390 | ok ($class->badd(123,321),444); |
391 | ok ($class->badd(123,$class->new(321)),444); |
392 | |
393 | ok ($class->new(123)->bsub(122),1); |
394 | ok ($class->bsub(321,123),198); |
395 | ok ($class->bsub(321,$class->new(123)),198); |
396 | |
397 | ok ($class->new(123)->bmul(123),15129); |
398 | ok ($class->bmul(123,123),15129); |
399 | ok ($class->bmul(123,$class->new(123)),15129); |
400 | |
401 | ok ($class->new(15129)->bdiv(123),123); |
402 | ok ($class->bdiv(15129,123),123); |
403 | ok ($class->bdiv(15129,$class->new(123)),123); |
404 | |
405 | ok ($class->new(15131)->bmod(123),2); |
406 | ok ($class->bmod(15131,123),2); |
407 | ok ($class->bmod(15131,$class->new(123)),2); |
408 | |
409 | ok ($class->new(2)->bpow(16),65536); |
410 | ok ($class->bpow(2,16),65536); |
411 | ok ($class->bpow(2,$class->new(16)),65536); |
412 | |
413 | ok ($class->new(2**15)->brsft(1),2**14); |
414 | ok ($class->brsft(2**15,1),2**14); |
415 | ok ($class->brsft(2**15,$class->new(1)),2**14); |
416 | |
417 | ok ($class->new(2**13)->blsft(1),2**14); |
418 | ok ($class->blsft(2**13,1),2**14); |
419 | ok ($class->blsft(2**13,$class->new(1)),2**14); |
420 | |
421 | ############################################################################### |
6854fd01 |
422 | # test for floating-point input (other tests in bnorm() below) |
423 | |
424 | $z = 1050000000000000; # may be int on systems with 64bit? |
425 | $x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15 |
426 | $z = 1e+129; # definitely a float (may fail on UTS) |
427 | # don't compare to $z, since some Perl versions stringify $z into something |
428 | # like '1.e+129' or something equally ugly |
429 | $x = $class->new($z); ok ($x->bsstr(),'1e+129'); |
430 | |
431 | ############################################################################### |
56d9de68 |
432 | # test for whitespace inlcuding newlines to be handled correctly |
433 | |
434 | # ok ($Math::BigInt::strict,1); # the default |
435 | |
436 | foreach my $c ( |
437 | qw/1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890/) |
438 | { |
439 | my $m = $class->new($c); |
440 | ok ($class->new("$c"),$m); |
441 | ok ($class->new(" $c"),$m); |
442 | ok ($class->new("$c "),$m); |
443 | ok ($class->new(" $c "),$m); |
444 | ok ($class->new("\n$c"),$m); |
445 | ok ($class->new("$c\n"),$m); |
446 | ok ($class->new("\n$c\n"),$m); |
447 | ok ($class->new(" \n$c\n"),$m); |
448 | ok ($class->new(" \n$c \n"),$m); |
449 | ok ($class->new(" \n$c\n "),$m); |
450 | ok ($class->new(" \n$c\n1"),'NaN'); |
451 | ok ($class->new("1 \n$c\n1"),'NaN'); |
452 | } |
453 | |
454 | ############################################################################### |
6854fd01 |
455 | # prime number tests, also test for **= and length() |
456 | # found on: http://www.utm.edu/research/primes/notes/by_year.html |
457 | |
458 | # ((2^148)-1)/17 |
459 | $x = $class->new(2); $x **= 148; $x++; $x = $x / 17; |
460 | ok ($x,"20988936657440586486151264256610222593863921"); |
461 | ok ($x->length(),length "20988936657440586486151264256610222593863921"); |
462 | |
463 | # MM7 = 2^127-1 |
464 | $x = $class->new(2); $x **= 127; $x--; |
465 | ok ($x,"170141183460469231731687303715884105727"); |
466 | |
467 | $x = $class->new('215960156869840440586892398248'); |
468 | ($x,$y) = $x->length(); |
469 | ok ($x,30); ok ($y,0); |
470 | |
471 | $x = $class->new('1_000_000_000_000'); |
472 | ($x,$y) = $x->length(); |
473 | ok ($x,13); ok ($y,0); |
474 | |
475 | # I am afraid the following is not yet possible due to slowness |
476 | # Also, testing for 2 meg output is a bit hard ;) |
477 | #$x = $class->new(2); $x **= 6972593; $x--; |
478 | |
479 | # 593573509*2^332162+1 has exactly 1,000,000 digits |
480 | # takes about 24 mins on 300 Mhz, so cannot be done yet ;) |
481 | #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++; |
482 | #ok ($x->length(),1_000_000); |
483 | |
484 | ############################################################################### |
485 | # inheritance and overriding of _swap |
486 | |
487 | $x = Math::Foo->new(5); |
488 | $x = $x - 8; # 8 - 5 instead of 5-8 |
489 | ok ($x,3); |
490 | ok (ref($x),'Math::Foo'); |
491 | |
492 | $x = Math::Foo->new(5); |
493 | $x = 8 - $x; # 5 - 8 instead of 8 - 5 |
494 | ok ($x,-3); |
495 | ok (ref($x),'Math::Foo'); |
496 | |
497 | ############################################################################### |
498 | # Test whether +inf eq inf |
499 | # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl |
500 | # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things |
501 | # like 1e100000 crash on some platforms. So simple test for the string 'inf' |
502 | $x = $class->new('+inf'); ok ($x,'inf'); |
503 | |
504 | ############################################################################### |
505 | ############################################################################### |
56d9de68 |
506 | # the followin tests only make sense with Math::BigInt::Calc or BareCalc or |
507 | # FastCalc |
6854fd01 |
508 | |
56d9de68 |
509 | exit if $CALC !~ /^Math::BigInt::(|Bare|Fast)Calc$/; # for Pari et al. |
6854fd01 |
510 | |
511 | ############################################################################### |
512 | # check proper length of internal arrays |
513 | |
394e6ffb |
514 | my $bl = $CL->_base_len(); |
6854fd01 |
515 | my $BASE = '9' x $bl; |
516 | my $MAX = $BASE; |
517 | $BASE++; |
518 | |
519 | $x = $class->new($MAX); is_valid($x); # f.i. 9999 |
520 | $x += 1; ok ($x,$BASE); is_valid($x); # 10000 |
521 | $x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again |
522 | |
523 | ############################################################################### |
524 | # check numify |
525 | |
526 | $x = $class->new($BASE-1); ok ($x->numify(),$BASE-1); |
527 | $x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1)); |
61f5c3f5 |
528 | |
529 | # +0 is to protect from 1e15 vs 100000000 (stupid to_string aaaarglburblll...) |
530 | $x = $class->new($BASE); ok ($x->numify()+0,$BASE+0); |
6854fd01 |
531 | $x = $class->new(-$BASE); ok ($x->numify(),-$BASE); |
532 | $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) ); |
533 | ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); |
534 | |
535 | ############################################################################### |
536 | # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1 |
537 | |
394e6ffb |
538 | $x = $class->new($BASE-2); $x++; $x++; $x++; $x++; |
539 | if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); } |
540 | |
541 | $x = $class->new($BASE+3); $x++; |
542 | if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); } |
6854fd01 |
543 | |
394e6ffb |
544 | # test for +0 instead of int(): |
545 | $x = $class->new($MAX); ok ($x->length(), length($MAX)); |
6854fd01 |
546 | |
547 | ############################################################################### |
56b9c951 |
548 | # test bug that $class->digit($string) did not work |
549 | |
550 | ok ($class->digit(123,2),1); |
551 | |
552 | ############################################################################### |
6854fd01 |
553 | # bug in sub where number with at least 6 trailing zeros after any op failed |
554 | |
394e6ffb |
555 | $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z; |
6854fd01 |
556 | ok ($z, 100000); |
557 | ok ($x, 23456); |
558 | |
559 | ############################################################################### |
560 | # bug in shortcut in mul() |
561 | |
61f5c3f5 |
562 | # construct a number with a zero-hole of BASE_LEN_SMALL |
563 | { |
564 | my @bl = $CL->_base_len(); my $bl = $bl[4]; |
565 | |
566 | $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl; |
567 | $y = '1' x (2*$bl); |
568 | $x = $class->new($x)->bmul($y); |
569 | # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl |
570 | $y = ''; my $d = ''; |
571 | for (my $i = 1; $i <= $bl; $i++) |
572 | { |
573 | $y .= $i; $d = $i.$d; |
574 | } |
575 | $y .= $bl x (3*$bl-1) . $d . '0' x $bl; |
576 | ok ($x,$y); |
577 | |
6854fd01 |
578 | |
f9a08e12 |
579 | ############################################################################# |
580 | # see if mul shortcut for small numbers works |
394e6ffb |
581 | |
f9a08e12 |
582 | $x = '9' x $bl; |
583 | $x = $class->new($x); |
584 | # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001 |
585 | ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1'); |
586 | } |
61f5c3f5 |
587 | |
394e6ffb |
588 | ############################################################################### |
6854fd01 |
589 | # bug with rest "-0" in div, causing further div()s to fail |
590 | |
394e6ffb |
591 | $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240'); |
6854fd01 |
592 | |
61f5c3f5 |
593 | ok ($y,'0'); is_valid($y); # $y not '-0' |
394e6ffb |
594 | |
79c55733 |
595 | ############################################################################### |
f9a08e12 |
596 | # bug in $x->bmod($y) |
07d34614 |
597 | |
f9a08e12 |
598 | # if $x < 0 and $y > 0 |
07d34614 |
599 | $x = $class->new('-629'); ok ($x->bmod(5033),4404); |
600 | |
601 | ############################################################################### |
56b9c951 |
602 | # bone/binf etc as plain calls (Lite failed them) |
603 | |
604 | ok ($class->bzero(),0); |
605 | ok ($class->bone(),1); |
606 | ok ($class->bone('+'),1); |
607 | ok ($class->bone('-'),-1); |
608 | ok ($class->bnan(),'NaN'); |
609 | ok ($class->binf(),'inf'); |
610 | ok ($class->binf('+'),'inf'); |
611 | ok ($class->binf('-'),'-inf'); |
612 | ok ($class->binf('-inf'),'-inf'); |
613 | |
614 | ############################################################################### |
61f5c3f5 |
615 | # all tests done |
6854fd01 |
616 | |
617 | 1; |
618 | |
619 | ############################################################################### |
61f5c3f5 |
620 | ############################################################################### |
6854fd01 |
621 | # Perl 5.005 does not like ok ($x,undef) |
622 | |
623 | sub ok_undef |
624 | { |
625 | my $x = shift; |
626 | |
627 | ok (1,1) and return if !defined $x; |
628 | ok ($x,'undef'); |
629 | } |
630 | |
631 | ############################################################################### |
632 | # sub to check validity of a BigInt internally, to ensure that no op leaves a |
633 | # number object in an invalid state (f.i. "-0") |
634 | |
635 | sub is_valid |
636 | { |
637 | my ($x,$f) = @_; |
638 | |
639 | my $e = 0; # error? |
6854fd01 |
640 | |
56b9c951 |
641 | # allow the check to pass for all Lite, and all MBI and subclasses |
642 | # ok as reference? |
643 | $e = 'Not a reference to Math::BigInt' if ref($x) !~ /^Math::BigInt/; |
6854fd01 |
644 | |
56b9c951 |
645 | if (ref($x) ne 'Math::BigInt::Lite') |
646 | { |
647 | # has ok sign? |
648 | $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'" |
649 | if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/; |
650 | |
651 | $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0; |
652 | $e = $CALC->_check($x->{value}) if $e eq '0'; |
653 | } |
6854fd01 |
654 | |
655 | # test done, see if error did crop up |
656 | ok (1,1), return if ($e eq '0'); |
657 | |
027dc388 |
658 | ok (1,$e." after op '$f'"); |
6854fd01 |
659 | } |
660 | |
661 | __DATA__ |
027dc388 |
662 | &.= |
663 | 1234:-345:1234-345 |
664 | &+= |
665 | 1:2:3 |
666 | -1:-2:-3 |
667 | &-= |
668 | 1:2:-1 |
669 | -1:-2:1 |
670 | &*= |
671 | 2:3:6 |
672 | -1:5:-5 |
673 | &%= |
674 | 100:3:1 |
675 | 8:9:8 |
07d34614 |
676 | -629:5033:4404 |
027dc388 |
677 | &/= |
678 | 100:3:33 |
679 | -8:2:-4 |
680 | &|= |
681 | 2:1:3 |
682 | &&= |
683 | 5:7:5 |
684 | &^= |
685 | 5:7:2 |
6854fd01 |
686 | &is_negative |
687 | 0:0 |
688 | -1:1 |
689 | 1:0 |
690 | +inf:0 |
691 | -inf:1 |
692 | NaNneg:0 |
693 | &is_positive |
694 | 0:1 |
695 | -1:0 |
696 | 1:1 |
697 | +inf:1 |
698 | -inf:0 |
699 | NaNneg:0 |
b3abae2a |
700 | &is_int |
701 | -inf:0 |
702 | +inf:0 |
703 | NaNis_int:0 |
704 | 1:1 |
705 | 0:1 |
706 | 123e12:1 |
6854fd01 |
707 | &is_odd |
708 | abc:0 |
709 | 0:0 |
710 | 1:1 |
711 | 3:1 |
712 | -1:1 |
713 | -3:1 |
714 | 10000001:1 |
715 | 10000002:0 |
716 | 2:0 |
b3abae2a |
717 | 120:0 |
718 | 121:1 |
6854fd01 |
719 | &is_even |
720 | abc:0 |
721 | 0:1 |
722 | 1:0 |
723 | 3:0 |
724 | -1:0 |
725 | -3:0 |
726 | 10000001:0 |
727 | 10000002:1 |
728 | 2:1 |
b3abae2a |
729 | 120:1 |
730 | 121:0 |
6854fd01 |
731 | &bacmp |
732 | +0:-0:0 |
733 | +0:+1:-1 |
734 | -1:+1:0 |
735 | +1:-1:0 |
736 | -1:+2:-1 |
737 | +2:-1:1 |
738 | -123456789:+987654321:-1 |
739 | +123456789:-987654321:-1 |
740 | +987654321:+123456789:1 |
741 | -987654321:+123456789:1 |
742 | -123:+4567889:-1 |
743 | # NaNs |
744 | acmpNaN:123: |
745 | 123:acmpNaN: |
746 | acmpNaN:acmpNaN: |
747 | # infinity |
748 | +inf:+inf:0 |
749 | -inf:-inf:0 |
750 | +inf:-inf:0 |
751 | -inf:+inf:0 |
752 | +inf:123:1 |
753 | -inf:123:1 |
754 | +inf:-123:1 |
755 | -inf:-123:1 |
756 | # return undef |
757 | +inf:NaN: |
758 | NaN:inf: |
759 | -inf:NaN: |
760 | NaN:-inf: |
761 | &bnorm |
762 | 123:123 |
763 | # binary input |
764 | 0babc:NaN |
765 | 0b123:NaN |
766 | 0b0:0 |
767 | -0b0:0 |
768 | -0b1:-1 |
769 | 0b0001:1 |
770 | 0b001:1 |
771 | 0b011:3 |
772 | 0b101:5 |
61f5c3f5 |
773 | 0b1001:9 |
774 | 0b10001:17 |
775 | 0b100001:33 |
776 | 0b1000001:65 |
777 | 0b10000001:129 |
778 | 0b100000001:257 |
779 | 0b1000000001:513 |
780 | 0b10000000001:1025 |
781 | 0b100000000001:2049 |
782 | 0b1000000000001:4097 |
783 | 0b10000000000001:8193 |
784 | 0b100000000000001:16385 |
785 | 0b1000000000000001:32769 |
786 | 0b10000000000000001:65537 |
787 | 0b100000000000000001:131073 |
788 | 0b1000000000000000001:262145 |
789 | 0b10000000000000000001:524289 |
790 | 0b100000000000000000001:1048577 |
791 | 0b1000000000000000000001:2097153 |
792 | 0b10000000000000000000001:4194305 |
793 | 0b100000000000000000000001:8388609 |
794 | 0b1000000000000000000000001:16777217 |
795 | 0b10000000000000000000000001:33554433 |
796 | 0b100000000000000000000000001:67108865 |
797 | 0b1000000000000000000000000001:134217729 |
798 | 0b10000000000000000000000000001:268435457 |
799 | 0b100000000000000000000000000001:536870913 |
800 | 0b1000000000000000000000000000001:1073741825 |
801 | 0b10000000000000000000000000000001:2147483649 |
802 | 0b100000000000000000000000000000001:4294967297 |
803 | 0b1000000000000000000000000000000001:8589934593 |
804 | 0b10000000000000000000000000000000001:17179869185 |
6854fd01 |
805 | 0b_101:NaN |
806 | 0b1_0_1:5 |
394e6ffb |
807 | 0b0_0_0_1:1 |
6854fd01 |
808 | # hex input |
809 | -0x0:0 |
810 | 0xabcdefgh:NaN |
811 | 0x1234:4660 |
812 | 0xabcdef:11259375 |
813 | -0xABCDEF:-11259375 |
814 | -0x1234:-4660 |
815 | 0x12345678:305419896 |
816 | 0x1_2_3_4_56_78:305419896 |
394e6ffb |
817 | 0xa_b_c_d_e_f:11259375 |
6854fd01 |
818 | 0x_123:NaN |
61f5c3f5 |
819 | 0x9:9 |
820 | 0x11:17 |
821 | 0x21:33 |
822 | 0x41:65 |
823 | 0x81:129 |
824 | 0x101:257 |
825 | 0x201:513 |
826 | 0x401:1025 |
827 | 0x801:2049 |
828 | 0x1001:4097 |
829 | 0x2001:8193 |
830 | 0x4001:16385 |
831 | 0x8001:32769 |
832 | 0x10001:65537 |
833 | 0x20001:131073 |
834 | 0x40001:262145 |
835 | 0x80001:524289 |
836 | 0x100001:1048577 |
837 | 0x200001:2097153 |
838 | 0x400001:4194305 |
839 | 0x800001:8388609 |
840 | 0x1000001:16777217 |
841 | 0x2000001:33554433 |
842 | 0x4000001:67108865 |
843 | 0x8000001:134217729 |
844 | 0x10000001:268435457 |
845 | 0x20000001:536870913 |
846 | 0x40000001:1073741825 |
847 | 0x80000001:2147483649 |
848 | 0x100000001:4294967297 |
849 | 0x200000001:8589934593 |
850 | 0x400000001:17179869185 |
851 | 0x800000001:34359738369 |
6854fd01 |
852 | # inf input |
853 | inf:inf |
854 | +inf:inf |
855 | -inf:-inf |
856 | 0inf:NaN |
027dc388 |
857 | # abnormal input |
6854fd01 |
858 | :NaN |
859 | abc:NaN |
860 | 1 a:NaN |
861 | 1bcd2:NaN |
862 | 11111b:NaN |
863 | +1z:NaN |
864 | -1z:NaN |
027dc388 |
865 | # only one underscore between two digits |
866 | _123:NaN |
867 | _123_:NaN |
868 | 123_:NaN |
869 | 1__23:NaN |
870 | 1E1__2:NaN |
871 | 1_E12:NaN |
872 | 1E_12:NaN |
873 | 1_E_12:NaN |
874 | +_1E12:NaN |
875 | +0_1E2:100 |
876 | +0_0_1E2:100 |
877 | -0_0_1E2:-100 |
878 | -0_0_1E+0_0_2:-100 |
879 | E1:NaN |
880 | E23:NaN |
881 | 1.23E1:NaN |
882 | 1.23E-1:NaN |
883 | # bug with two E's in number beeing valid |
884 | 1e2e3:NaN |
885 | 1e2r:NaN |
886 | 1e2.0:NaN |
07d34614 |
887 | # bug with two '.' in number beeing valid |
888 | 1.2.2:NaN |
889 | 1.2.3e1:NaN |
890 | -1.2.3:NaN |
891 | -1.2.3e-4:NaN |
892 | 1.2e3.4:NaN |
893 | 1.2e-3.4:NaN |
894 | 1.2.3.4:NaN |
895 | 1.2.t:NaN |
896 | 1..2:NaN |
897 | 1..2e1:NaN |
898 | 1..2e1..1:NaN |
899 | 12e1..1:NaN |
900 | ..2:NaN |
901 | .-2:NaN |
61f5c3f5 |
902 | # leading zeros |
903 | 012:12 |
904 | 0123:123 |
905 | 01234:1234 |
906 | 012345:12345 |
907 | 0123456:123456 |
908 | 01234567:1234567 |
909 | 012345678:12345678 |
910 | 0123456789:123456789 |
911 | 01234567891:1234567891 |
912 | 012345678912:12345678912 |
913 | 0123456789123:123456789123 |
914 | 01234567891234:1234567891234 |
027dc388 |
915 | # normal input |
6854fd01 |
916 | 0:0 |
917 | +0:0 |
918 | +00:0 |
919 | +000:0 |
920 | 000000000000000000:0 |
921 | -0:0 |
922 | -0000:0 |
923 | +1:1 |
924 | +01:1 |
925 | +001:1 |
926 | +00000100000:100000 |
927 | 123456789:123456789 |
928 | -1:-1 |
929 | -01:-1 |
930 | -001:-1 |
931 | -123456789:-123456789 |
932 | -00000100000:-100000 |
933 | 1_2_3:123 |
6854fd01 |
934 | 10000000000E-1_0:1 |
935 | 1E2:100 |
936 | 1E1:10 |
937 | 1E0:1 |
6854fd01 |
938 | 1.23E2:123 |
6854fd01 |
939 | 100E-1:10 |
940 | # floating point input |
027dc388 |
941 | # .2e2:20 |
942 | 1.E3:1000 |
6854fd01 |
943 | 1.01E2:101 |
944 | 1010E-1:101 |
945 | -1010E0:-1010 |
946 | -1010E1:-10100 |
027dc388 |
947 | 1234.00:1234 |
948 | # non-integer numbers |
6854fd01 |
949 | -1010E-2:NaN |
950 | -1.01E+1:NaN |
951 | -1.01E-1:NaN |
6854fd01 |
952 | &bnan |
953 | 1:NaN |
954 | 2:NaN |
955 | abc:NaN |
956 | &bone |
61f5c3f5 |
957 | 2:+:1 |
6854fd01 |
958 | 2:-:-1 |
959 | boneNaN:-:-1 |
61f5c3f5 |
960 | boneNaN:+:1 |
961 | 2:abc:1 |
962 | 3::1 |
6854fd01 |
963 | &binf |
964 | 1:+:inf |
965 | 2:-:-inf |
966 | 3:abc:inf |
027dc388 |
967 | &is_nan |
968 | 123:0 |
969 | abc:1 |
970 | NaN:1 |
971 | -123:0 |
6854fd01 |
972 | &is_inf |
973 | +inf::1 |
974 | -inf::1 |
975 | abc::0 |
976 | 1::0 |
977 | NaN::0 |
978 | -1::0 |
979 | +inf:-:0 |
980 | +inf:+:1 |
981 | -inf:-:1 |
982 | -inf:+:0 |
79c55733 |
983 | -inf:-inf:1 |
984 | -inf:+inf:0 |
985 | +inf:-inf:0 |
986 | +inf:+inf:1 |
6854fd01 |
987 | # it must be exactly /^[+-]inf$/ |
988 | +infinity::0 |
989 | -infinity::0 |
990 | &blsft |
991 | abc:abc:NaN |
61f5c3f5 |
992 | +2:+2:8 |
993 | +1:+32:4294967296 |
994 | +1:+48:281474976710656 |
6854fd01 |
995 | +8:-2:NaN |
996 | # excercise base 10 |
997 | +12345:4:10:123450000 |
998 | -1234:0:10:-1234 |
61f5c3f5 |
999 | +1234:0:10:1234 |
6854fd01 |
1000 | +2:2:10:200 |
1001 | +12:2:10:1200 |
1002 | +1234:-3:10:NaN |
1003 | 1234567890123:12:10:1234567890123000000000000 |
b3abae2a |
1004 | -3:1:2:-6 |
1005 | -5:1:2:-10 |
1006 | -2:1:2:-4 |
1007 | -102533203:1:2:-205066406 |
6854fd01 |
1008 | &brsft |
1009 | abc:abc:NaN |
61f5c3f5 |
1010 | +8:+2:2 |
1011 | +4294967296:+32:1 |
1012 | +281474976710656:+48:1 |
6854fd01 |
1013 | +2:-2:NaN |
1014 | # excercise base 10 |
1015 | -1234:0:10:-1234 |
61f5c3f5 |
1016 | +1234:0:10:1234 |
6854fd01 |
1017 | +200:2:10:2 |
1018 | +1234:3:10:1 |
1019 | +1234:2:10:12 |
1020 | +1234:-3:10:NaN |
1021 | 310000:4:10:31 |
1022 | 12300000:5:10:123 |
1023 | 1230000000000:10:10:123 |
1024 | 09876123456789067890:12:10:9876123 |
1025 | 1234561234567890123:13:10:123456 |
b3abae2a |
1026 | 820265627:1:2:410132813 |
1027 | # test shifting negative numbers in base 2 |
1028 | -15:1:2:-8 |
1029 | -14:1:2:-7 |
1030 | -13:1:2:-7 |
1031 | -12:1:2:-6 |
1032 | -11:1:2:-6 |
1033 | -10:1:2:-5 |
1034 | -9:1:2:-5 |
1035 | -8:1:2:-4 |
1036 | -7:1:2:-4 |
1037 | -6:1:2:-3 |
1038 | -5:1:2:-3 |
1039 | -4:1:2:-2 |
1040 | -3:1:2:-2 |
1041 | -2:1:2:-1 |
1042 | -1:1:2:-1 |
1043 | -1640531254:2:2:-410132814 |
1044 | -1640531254:1:2:-820265627 |
1045 | -820265627:1:2:-410132814 |
1046 | -205066405:1:2:-102533203 |
6854fd01 |
1047 | &bsstr |
56d9de68 |
1048 | +inf:inf |
1049 | -inf:-inf |
6854fd01 |
1050 | 1e+34:1e+34 |
1051 | 123.456E3:123456e+0 |
1052 | 100:1e+2 |
56d9de68 |
1053 | bsstrabc:NaN |
1054 | -5:-5e+0 |
1055 | -100:-1e+2 |
1056 | &numify |
1057 | numifyabc:NaN |
1058 | +inf:inf |
1059 | -inf:-inf |
1060 | 5:5 |
1061 | -5:-5 |
1062 | 100:100 |
1063 | -100:-100 |
6854fd01 |
1064 | &bneg |
1065 | bnegNaN:NaN |
1066 | +inf:-inf |
1067 | -inf:inf |
1068 | abd:NaN |
61f5c3f5 |
1069 | 0:0 |
1070 | 1:-1 |
1071 | -1:1 |
6854fd01 |
1072 | +123456789:-123456789 |
61f5c3f5 |
1073 | -123456789:123456789 |
6854fd01 |
1074 | &babs |
1075 | babsNaN:NaN |
1076 | +inf:inf |
1077 | -inf:inf |
61f5c3f5 |
1078 | 0:0 |
1079 | 1:1 |
1080 | -1:1 |
1081 | +123456789:123456789 |
1082 | -123456789:123456789 |
6854fd01 |
1083 | &bcmp |
1084 | bcmpNaN:bcmpNaN: |
61f5c3f5 |
1085 | bcmpNaN:0: |
1086 | 0:bcmpNaN: |
1087 | 0:0:0 |
1088 | -1:0:-1 |
1089 | 0:-1:1 |
1090 | 1:0:1 |
1091 | 0:1:-1 |
1092 | -1:1:-1 |
1093 | 1:-1:1 |
6854fd01 |
1094 | -1:-1:0 |
61f5c3f5 |
1095 | 1:1:0 |
1096 | 123:123:0 |
1097 | 123:12:1 |
1098 | 12:123:-1 |
6854fd01 |
1099 | -123:-123:0 |
1100 | -123:-12:-1 |
1101 | -12:-123:1 |
61f5c3f5 |
1102 | 123:124:-1 |
1103 | 124:123:1 |
6854fd01 |
1104 | -123:-124:1 |
1105 | -124:-123:-1 |
61f5c3f5 |
1106 | 100:5:1 |
1107 | -123456789:987654321:-1 |
6854fd01 |
1108 | +123456789:-987654321:1 |
61f5c3f5 |
1109 | -987654321:123456789:-1 |
6854fd01 |
1110 | -inf:5432112345:-1 |
1111 | +inf:5432112345:1 |
1112 | -inf:-5432112345:-1 |
1113 | +inf:-5432112345:1 |
1114 | +inf:+inf:0 |
1115 | -inf:-inf:0 |
1116 | +inf:-inf:1 |
1117 | -inf:+inf:-1 |
1118 | 5:inf:-1 |
1119 | 5:inf:-1 |
1120 | -5:-inf:1 |
1121 | -5:-inf:1 |
1122 | # return undef |
1123 | +inf:NaN: |
1124 | NaN:inf: |
1125 | -inf:NaN: |
1126 | NaN:-inf: |
1127 | &binc |
1128 | abc:NaN |
1129 | +inf:inf |
1130 | -inf:-inf |
61f5c3f5 |
1131 | +0:1 |
1132 | +1:2 |
1133 | -1:0 |
6854fd01 |
1134 | &bdec |
1135 | abc:NaN |
1136 | +inf:inf |
1137 | -inf:-inf |
1138 | +0:-1 |
61f5c3f5 |
1139 | +1:0 |
6854fd01 |
1140 | -1:-2 |
1141 | &badd |
1142 | abc:abc:NaN |
61f5c3f5 |
1143 | abc:0:NaN |
6854fd01 |
1144 | +0:abc:NaN |
b3abae2a |
1145 | +inf:-inf:NaN |
1146 | -inf:+inf:NaN |
6854fd01 |
1147 | +inf:+inf:inf |
1148 | -inf:-inf:-inf |
1149 | baddNaN:+inf:NaN |
1150 | baddNaN:+inf:NaN |
1151 | +inf:baddNaN:NaN |
1152 | -inf:baddNaN:NaN |
61f5c3f5 |
1153 | 0:0:0 |
1154 | 1:0:1 |
1155 | 0:1:1 |
1156 | 1:1:2 |
1157 | -1:0:-1 |
1158 | 0:-1:-1 |
6854fd01 |
1159 | -1:-1:-2 |
61f5c3f5 |
1160 | -1:+1:0 |
1161 | +1:-1:0 |
1162 | +9:+1:10 |
1163 | +99:+1:100 |
1164 | +999:+1:1000 |
1165 | +9999:+1:10000 |
1166 | +99999:+1:100000 |
1167 | +999999:+1:1000000 |
1168 | +9999999:+1:10000000 |
1169 | +99999999:+1:100000000 |
1170 | +999999999:+1:1000000000 |
1171 | +9999999999:+1:10000000000 |
1172 | +99999999999:+1:100000000000 |
1173 | +10:-1:9 |
1174 | +100:-1:99 |
1175 | +1000:-1:999 |
1176 | +10000:-1:9999 |
1177 | +100000:-1:99999 |
1178 | +1000000:-1:999999 |
1179 | +10000000:-1:9999999 |
1180 | +100000000:-1:99999999 |
1181 | +1000000000:-1:999999999 |
1182 | +10000000000:-1:9999999999 |
1183 | +123456789:987654321:1111111110 |
1184 | -123456789:987654321:864197532 |
6854fd01 |
1185 | -123456789:-987654321:-1111111110 |
1186 | +123456789:-987654321:-864197532 |
56b9c951 |
1187 | -1:10001:10000 |
1188 | -1:100001:100000 |
1189 | -1:1000001:1000000 |
1190 | -1:10000001:10000000 |
1191 | -1:100000001:100000000 |
1192 | -1:1000000001:1000000000 |
1193 | -1:10000000001:10000000000 |
1194 | -1:100000000001:100000000000 |
1195 | -1:1000000000001:1000000000000 |
1196 | -1:10000000000001:10000000000000 |
1197 | -1:-10001:-10002 |
1198 | -1:-100001:-100002 |
1199 | -1:-1000001:-1000002 |
1200 | -1:-10000001:-10000002 |
1201 | -1:-100000001:-100000002 |
1202 | -1:-1000000001:-1000000002 |
1203 | -1:-10000000001:-10000000002 |
1204 | -1:-100000000001:-100000000002 |
1205 | -1:-1000000000001:-1000000000002 |
1206 | -1:-10000000000001:-10000000000002 |
6854fd01 |
1207 | &bsub |
1208 | abc:abc:NaN |
1209 | abc:+0:NaN |
1210 | +0:abc:NaN |
1211 | +inf:-inf:inf |
1212 | -inf:+inf:-inf |
b3abae2a |
1213 | +inf:+inf:NaN |
1214 | -inf:-inf:NaN |
61f5c3f5 |
1215 | +0:+0:0 |
1216 | +1:+0:1 |
6854fd01 |
1217 | +0:+1:-1 |
61f5c3f5 |
1218 | +1:+1:0 |
6854fd01 |
1219 | -1:+0:-1 |
61f5c3f5 |
1220 | +0:-1:1 |
1221 | -1:-1:0 |
6854fd01 |
1222 | -1:+1:-2 |
61f5c3f5 |
1223 | +1:-1:2 |
1224 | +9:+1:8 |
1225 | +99:+1:98 |
1226 | +999:+1:998 |
1227 | +9999:+1:9998 |
1228 | +99999:+1:99998 |
1229 | +999999:+1:999998 |
1230 | +9999999:+1:9999998 |
1231 | +99999999:+1:99999998 |
1232 | +999999999:+1:999999998 |
1233 | +9999999999:+1:9999999998 |
1234 | +99999999999:+1:99999999998 |
1235 | +10:-1:11 |
1236 | +100:-1:101 |
1237 | +1000:-1:1001 |
1238 | +10000:-1:10001 |
1239 | +100000:-1:100001 |
1240 | +1000000:-1:1000001 |
1241 | +10000000:-1:10000001 |
1242 | +100000000:-1:100000001 |
1243 | +1000000000:-1:1000000001 |
1244 | +10000000000:-1:10000000001 |
6854fd01 |
1245 | +123456789:+987654321:-864197532 |
1246 | -123456789:+987654321:-1111111110 |
61f5c3f5 |
1247 | -123456789:-987654321:864197532 |
1248 | +123456789:-987654321:1111111110 |
56b9c951 |
1249 | 10001:1:10000 |
1250 | 100001:1:100000 |
1251 | 1000001:1:1000000 |
1252 | 10000001:1:10000000 |
1253 | 100000001:1:100000000 |
1254 | 1000000001:1:1000000000 |
1255 | 10000000001:1:10000000000 |
1256 | 100000000001:1:100000000000 |
1257 | 1000000000001:1:1000000000000 |
1258 | 10000000000001:1:10000000000000 |
1259 | 10001:-1:10002 |
1260 | 100001:-1:100002 |
1261 | 1000001:-1:1000002 |
1262 | 10000001:-1:10000002 |
1263 | 100000001:-1:100000002 |
1264 | 1000000001:-1:1000000002 |
1265 | 10000000001:-1:10000000002 |
1266 | 100000000001:-1:100000000002 |
1267 | 1000000000001:-1:1000000000002 |
1268 | 10000000000001:-1:10000000000002 |
6854fd01 |
1269 | &bmul |
1270 | abc:abc:NaN |
1271 | abc:+0:NaN |
1272 | +0:abc:NaN |
1273 | NaNmul:+inf:NaN |
1274 | NaNmul:-inf:NaN |
1275 | -inf:NaNmul:NaN |
1276 | +inf:NaNmul:NaN |
1277 | +inf:+inf:inf |
1278 | +inf:-inf:-inf |
1279 | -inf:+inf:-inf |
1280 | -inf:-inf:inf |
61f5c3f5 |
1281 | +0:+0:0 |
1282 | +0:+1:0 |
1283 | +1:+0:0 |
1284 | +0:-1:0 |
1285 | -1:+0:0 |
1286 | 123456789123456789:0:0 |
1287 | 0:123456789123456789:0 |
1288 | -1:-1:1 |
6854fd01 |
1289 | -1:+1:-1 |
1290 | +1:-1:-1 |
61f5c3f5 |
1291 | +1:+1:1 |
1292 | +2:+3:6 |
6854fd01 |
1293 | -2:+3:-6 |
1294 | +2:-3:-6 |
61f5c3f5 |
1295 | -2:-3:6 |
1296 | 111:111:12321 |
1297 | 10101:10101:102030201 |
1298 | 1001001:1001001:1002003002001 |
1299 | 100010001:100010001:10002000300020001 |
1300 | 10000100001:10000100001:100002000030000200001 |
1301 | 11111111111:9:99999999999 |
1302 | 22222222222:9:199999999998 |
1303 | 33333333333:9:299999999997 |
1304 | 44444444444:9:399999999996 |
1305 | 55555555555:9:499999999995 |
1306 | 66666666666:9:599999999994 |
1307 | 77777777777:9:699999999993 |
1308 | 88888888888:9:799999999992 |
1309 | 99999999999:9:899999999991 |
1310 | +25:+25:625 |
1311 | +12345:+12345:152399025 |
1312 | +99999:+11111:1111088889 |
6854fd01 |
1313 | 9999:10000:99990000 |
1314 | 99999:100000:9999900000 |
1315 | 999999:1000000:999999000000 |
1316 | 9999999:10000000:99999990000000 |
1317 | 99999999:100000000:9999999900000000 |
1318 | 999999999:1000000000:999999999000000000 |
1319 | 9999999999:10000000000:99999999990000000000 |
1320 | 99999999999:100000000000:9999999999900000000000 |
1321 | 999999999999:1000000000000:999999999999000000000000 |
1322 | 9999999999999:10000000000000:99999999999990000000000000 |
1323 | 99999999999999:100000000000000:9999999999999900000000000000 |
1324 | 999999999999999:1000000000000000:999999999999999000000000000000 |
1325 | 9999999999999999:10000000000000000:99999999999999990000000000000000 |
1326 | 99999999999999999:100000000000000000:9999999999999999900000000000000000 |
1327 | 999999999999999999:1000000000000000000:999999999999999999000000000000000000 |
1328 | 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000 |
1329 | &bdiv-list |
1330 | 100:20:5,0 |
1331 | 4095:4095:1,0 |
1332 | -4095:-4095:1,0 |
1333 | 4095:-4095:-1,0 |
1334 | -4095:4095:-1,0 |
1335 | 123:2:61,1 |
b3abae2a |
1336 | 9:5:1,4 |
1337 | 9:4:2,1 |
6854fd01 |
1338 | # inf handling and general remainder |
1339 | 5:8:0,5 |
1340 | 0:8:0,0 |
1341 | 11:2:5,1 |
1342 | 11:-2:-5,-1 |
1343 | -11:2:-5,1 |
1344 | # see table in documentation in MBI |
1345 | 0:inf:0,0 |
1346 | 0:-inf:0,0 |
1347 | 5:inf:0,5 |
1348 | 5:-inf:0,5 |
1349 | -5:inf:0,-5 |
1350 | -5:-inf:0,-5 |
1351 | inf:5:inf,0 |
1352 | -inf:5:-inf,0 |
1353 | inf:-5:-inf,0 |
1354 | -inf:-5:inf,0 |
1355 | 5:5:1,0 |
1356 | -5:-5:1,0 |
b3abae2a |
1357 | inf:inf:NaN,NaN |
1358 | -inf:-inf:NaN,NaN |
1359 | -inf:inf:NaN,NaN |
1360 | inf:-inf:NaN,NaN |
6854fd01 |
1361 | 8:0:inf,8 |
1362 | inf:0:inf,inf |
1363 | # exceptions to reminder rule |
1364 | -8:0:-inf,-8 |
1365 | -inf:0:-inf,-inf |
1366 | 0:0:NaN,NaN |
1367 | &bdiv |
1368 | abc:abc:NaN |
61f5c3f5 |
1369 | abc:1:NaN |
1370 | 1:abc:NaN |
1371 | 0:0:NaN |
6854fd01 |
1372 | # inf handling (see table in doc) |
1373 | 0:inf:0 |
1374 | 0:-inf:0 |
1375 | 5:inf:0 |
1376 | 5:-inf:0 |
1377 | -5:inf:0 |
1378 | -5:-inf:0 |
1379 | inf:5:inf |
1380 | -inf:5:-inf |
1381 | inf:-5:-inf |
1382 | -inf:-5:inf |
1383 | 5:5:1 |
1384 | -5:-5:1 |
b3abae2a |
1385 | inf:inf:NaN |
1386 | -inf:-inf:NaN |
1387 | -inf:inf:NaN |
1388 | inf:-inf:NaN |
6854fd01 |
1389 | 8:0:inf |
1390 | inf:0:inf |
1391 | -8:0:-inf |
1392 | -inf:0:-inf |
1393 | 0:0:NaN |
1394 | 11:2:5 |
1395 | -11:-2:5 |
1396 | -11:2:-5 |
1397 | 11:-2:-5 |
61f5c3f5 |
1398 | 0:1:0 |
1399 | 0:-1:0 |
1400 | 1:1:1 |
1401 | -1:-1:1 |
1402 | 1:-1:-1 |
1403 | -1:1:-1 |
1404 | 1:2:0 |
1405 | 2:1:2 |
1406 | 1:26:0 |
1407 | 1000000000:9:111111111 |
1408 | 2000000000:9:222222222 |
1409 | 3000000000:9:333333333 |
1410 | 4000000000:9:444444444 |
1411 | 5000000000:9:555555555 |
1412 | 6000000000:9:666666666 |
1413 | 7000000000:9:777777777 |
1414 | 8000000000:9:888888888 |
1415 | 9000000000:9:1000000000 |
1416 | 35500000:113:314159 |
1417 | 71000000:226:314159 |
1418 | 106500000:339:314159 |
1419 | 1000000000:3:333333333 |
1420 | +10:+5:2 |
1421 | +100:+4:25 |
1422 | +1000:+8:125 |
1423 | +10000:+16:625 |
1424 | 999999999999:9:111111111111 |
1425 | 999999999999:99:10101010101 |
1426 | 999999999999:999:1001001001 |
1427 | 999999999999:9999:100010001 |
1428 | 999999999999999:99999:10000100001 |
1429 | +1111088889:99999:11111 |
6854fd01 |
1430 | -5:-3:1 |
1431 | -5:3:-1 |
1432 | 4:3:1 |
1433 | 4:-3:-1 |
1434 | 1:3:0 |
1435 | 1:-3:0 |
1436 | -2:-3:0 |
1437 | -2:3:0 |
1438 | 8:3:2 |
1439 | -8:3:-2 |
1440 | 14:-3:-4 |
1441 | -14:3:-4 |
1442 | -14:-3:4 |
1443 | 14:3:4 |
1444 | # bug in Calc with '99999' vs $BASE-1 |
1445 | 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576 |
07d34614 |
1446 | &bmodinv |
1447 | # format: number:modulus:result |
1448 | # bmodinv Data errors |
1449 | abc:abc:NaN |
1450 | abc:5:NaN |
1451 | 5:abc:NaN |
1452 | # bmodinv Expected Results from normal use |
1453 | 1:5:1 |
1454 | 3:5:2 |
1455 | -2:5:2 |
1456 | 8:5033:4404 |
56d9de68 |
1457 | 1234567891:13:6 |
1458 | -1234567891:13:7 |
07d34614 |
1459 | 324958749843759385732954874325984357439658735983745:2348249874968739:1741662881064902 |
d614cd8b |
1460 | ## bmodinv Error cases / useless use of function |
07d34614 |
1461 | 3:-5:NaN |
1462 | inf:5:NaN |
1ddff52a |
1463 | 5:inf:NaN |
1464 | -inf:5:NaN |
1465 | 5:-inf:NaN |
07d34614 |
1466 | &bmodpow |
1467 | # format: number:exponent:modulus:result |
1468 | # bmodpow Data errors |
1469 | abc:abc:abc:NaN |
1470 | 5:abc:abc:NaN |
1471 | abc:5:abc:NaN |
1472 | abc:abc:5:NaN |
1473 | 5:5:abc:NaN |
1474 | 5:abc:5:NaN |
1475 | abc:5:5:NaN |
1476 | # bmodpow Expected results |
1477 | 0:0:2:1 |
1478 | 1:0:2:1 |
1479 | 0:0:1:0 |
1480 | 8:7:5032:3840 |
1481 | 8:-1:5033:4404 |
1482 | 98436739867439843769485798542749827593285729587325:43698764986460981048259837659386739857456983759328457:6943857329857295827698367:3104744730915914415259518 |
1483 | # bmodpow Error cases |
1484 | 8:8:-5:NaN |
1485 | 8:-1:16:NaN |
1486 | inf:5:13:NaN |
1487 | 5:inf:13:NaN |
6854fd01 |
1488 | &bmod |
1489 | # inf handling, see table in doc |
1490 | 0:inf:0 |
1491 | 0:-inf:0 |
1492 | 5:inf:5 |
1493 | 5:-inf:5 |
1494 | -5:inf:-5 |
1495 | -5:-inf:-5 |
1496 | inf:5:0 |
1497 | -inf:5:0 |
1498 | inf:-5:0 |
1499 | -inf:-5:0 |
1500 | 5:5:0 |
1501 | -5:-5:0 |
b3abae2a |
1502 | inf:inf:NaN |
1503 | -inf:-inf:NaN |
1504 | -inf:inf:NaN |
1505 | inf:-inf:NaN |
6854fd01 |
1506 | 8:0:8 |
1507 | inf:0:inf |
1508 | # exceptions to reminder rule |
1509 | -inf:0:-inf |
1510 | -8:0:-8 |
1511 | 0:0:NaN |
1512 | abc:abc:NaN |
61f5c3f5 |
1513 | abc:1:abc:NaN |
1514 | 1:abc:NaN |
1515 | 0:0:NaN |
1516 | 0:1:0 |
1517 | 1:0:1 |
1518 | 0:-1:0 |
1519 | -1:0:-1 |
1520 | 1:1:0 |
1521 | -1:-1:0 |
1522 | 1:-1:0 |
1523 | -1:1:0 |
1524 | 1:2:1 |
1525 | 2:1:0 |
1526 | 1000000000:9:1 |
1527 | 2000000000:9:2 |
1528 | 3000000000:9:3 |
1529 | 4000000000:9:4 |
1530 | 5000000000:9:5 |
1531 | 6000000000:9:6 |
1532 | 7000000000:9:7 |
1533 | 8000000000:9:8 |
1534 | 9000000000:9:0 |
1535 | 35500000:113:33 |
1536 | 71000000:226:66 |
1537 | 106500000:339:99 |
1538 | 1000000000:3:1 |
1539 | 10:5:0 |
1540 | 100:4:0 |
1541 | 1000:8:0 |
1542 | 10000:16:0 |
1543 | 999999999999:9:0 |
1544 | 999999999999:99:0 |
1545 | 999999999999:999:0 |
1546 | 999999999999:9999:0 |
1547 | 999999999999999:99999:0 |
1548 | -9:+5:1 |
6854fd01 |
1549 | +9:-5:-1 |
1550 | -9:-5:-4 |
1551 | -5:3:1 |
1552 | -2:3:1 |
1553 | 4:3:1 |
1554 | 1:3:1 |
1555 | -5:-3:-2 |
1556 | -2:-3:-2 |
1557 | 4:-3:-2 |
1558 | 1:-3:-2 |
1559 | 4095:4095:0 |
027dc388 |
1560 | 100041000510123:3:0 |
1561 | 152403346:12345:4321 |
b3abae2a |
1562 | 9:5:4 |
28df3e88 |
1563 | # test shortcuts in Calc |
1564 | # 1ex % 9 is always == 1, 1ex % 113 is != 1 for x = (4..9), 1ex % 10 = 0 |
1565 | 1234:9:1 |
1566 | 123456:9:3 |
1567 | 12345678:9:0 |
1568 | 1234567891:9:1 |
1569 | 123456789123:9:6 |
1570 | 12345678912345:9:6 |
1571 | 1234567891234567:9:1 |
1572 | 123456789123456789:9:0 |
1573 | 1234:10:4 |
1574 | 123456:10:6 |
1575 | 12345678:10:8 |
1576 | 1234567891:10:1 |
1577 | 123456789123:10:3 |
1578 | 12345678912345:10:5 |
1579 | 1234567891234567:10:7 |
1580 | 123456789123456789:10:9 |
1581 | 1234:113:104 |
1582 | 123456:113:60 |
1583 | 12345678:113:89 |
1584 | 1234567891:113:64 |
1585 | 123456789123:113:95 |
1586 | 12345678912345:113:53 |
1587 | 1234567891234567:113:56 |
1588 | 123456789123456789:113:39 |
07d34614 |
1589 | # bug in bmod() not modifying the variable in place |
1590 | -629:5033:4404 |
6854fd01 |
1591 | &bgcd |
1592 | abc:abc:NaN |
1593 | abc:+0:NaN |
1594 | +0:abc:NaN |
61f5c3f5 |
1595 | +0:+0:0 |
1596 | +0:+1:1 |
1597 | +1:+0:1 |
1598 | +1:+1:1 |
1599 | +2:+3:1 |
1600 | +3:+2:1 |
1601 | -3:+2:1 |
1602 | 100:625:25 |
1603 | 4096:81:1 |
1604 | 1034:804:2 |
1605 | 27:90:56:1 |
1606 | 27:90:54:9 |
6854fd01 |
1607 | &blcm |
1608 | abc:abc:NaN |
1609 | abc:+0:NaN |
1610 | +0:abc:NaN |
1611 | +0:+0:NaN |
61f5c3f5 |
1612 | +1:+0:0 |
1613 | +0:+1:0 |
1614 | +27:+90:270 |
1615 | +1034:+804:415668 |
6854fd01 |
1616 | &band |
1617 | abc:abc:NaN |
1618 | abc:0:NaN |
1619 | 0:abc:NaN |
1620 | 1:2:0 |
1621 | 3:2:2 |
61f5c3f5 |
1622 | +8:+2:0 |
1623 | +281474976710656:0:0 |
1624 | +281474976710656:1:0 |
1625 | +281474976710656:+281474976710656:281474976710656 |
6854fd01 |
1626 | -2:-3:-4 |
1627 | -1:-1:-1 |
1628 | -6:-6:-6 |
1629 | -7:-4:-8 |
1630 | -7:4:0 |
1631 | -4:7:4 |
394e6ffb |
1632 | # equal arguments are treated special, so also do some test with unequal ones |
1633 | 0xFFFF:0xFFFF:0x0xFFFF |
1634 | 0xFFFFFF:0xFFFFFF:0x0xFFFFFF |
1635 | 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF |
1636 | 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1637 | 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1638 | 0xF0F0:0xF0F0:0x0xF0F0 |
1639 | 0x0F0F:0x0F0F:0x0x0F0F |
1640 | 0xF0F0F0:0xF0F0F0:0x0xF0F0F0 |
1641 | 0x0F0F0F:0x0F0F0F:0x0x0F0F0F |
1642 | 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 |
1643 | 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F |
1644 | 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 |
1645 | 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F |
1646 | 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 |
1647 | 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F |
1648 | 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F |
6854fd01 |
1649 | &bior |
1650 | abc:abc:NaN |
1651 | abc:0:NaN |
1652 | 0:abc:NaN |
1653 | 1:2:3 |
61f5c3f5 |
1654 | +8:+2:10 |
1655 | +281474976710656:0:281474976710656 |
1656 | +281474976710656:1:281474976710657 |
1657 | +281474976710656:281474976710656:281474976710656 |
6854fd01 |
1658 | -2:-3:-1 |
1659 | -1:-1:-1 |
1660 | -6:-6:-6 |
1661 | -7:4:-3 |
1662 | -4:7:-1 |
394e6ffb |
1663 | # equal arguments are treated special, so also do some test with unequal ones |
1664 | 0xFFFF:0xFFFF:0x0xFFFF |
1665 | 0xFFFFFF:0xFFFFFF:0x0xFFFFFF |
1666 | 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF |
1667 | 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1668 | 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1669 | 0:0xFFFF:0x0xFFFF |
1670 | 0:0xFFFFFF:0x0xFFFFFF |
1671 | 0:0xFFFFFFFF:0x0xFFFFFFFF |
1672 | 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1673 | 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1674 | 0xFFFF:0:0x0xFFFF |
1675 | 0xFFFFFF:0:0x0xFFFFFF |
1676 | 0xFFFFFFFF:0:0x0xFFFFFFFF |
1677 | 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF |
1678 | 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF |
1679 | 0xF0F0:0xF0F0:0x0xF0F0 |
1680 | 0x0F0F:0x0F0F:0x0x0F0F |
1681 | 0xF0F0:0x0F0F:0x0xFFFF |
1682 | 0xF0F0F0:0xF0F0F0:0x0xF0F0F0 |
1683 | 0x0F0F0F:0x0F0F0F:0x0x0F0F0F |
1684 | 0x0F0F0F:0xF0F0F0:0x0xFFFFFF |
1685 | 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 |
1686 | 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F |
1687 | 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF |
1688 | 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 |
1689 | 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F |
1690 | 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF |
1691 | 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 |
1692 | 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F |
1693 | 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF |
1694 | 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF |
6854fd01 |
1695 | &bxor |
1696 | abc:abc:NaN |
1697 | abc:0:NaN |
1698 | 0:abc:NaN |
1699 | 1:2:3 |
61f5c3f5 |
1700 | +8:+2:10 |
1701 | +281474976710656:0:281474976710656 |
1702 | +281474976710656:1:281474976710657 |
1703 | +281474976710656:281474976710656:0 |
6854fd01 |
1704 | -2:-3:3 |
1705 | -1:-1:0 |
1706 | -6:-6:0 |
1707 | -7:4:-3 |
1708 | -4:7:-5 |
1709 | 4:-7:-3 |
1710 | -4:-7:5 |
394e6ffb |
1711 | # equal arguments are treated special, so also do some test with unequal ones |
1712 | 0xFFFF:0xFFFF:0 |
1713 | 0xFFFFFF:0xFFFFFF:0 |
1714 | 0xFFFFFFFF:0xFFFFFFFF:0 |
1715 | 0xFFFFFFFFFF:0xFFFFFFFFFF:0 |
1716 | 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0 |
1717 | 0:0xFFFF:0x0xFFFF |
1718 | 0:0xFFFFFF:0x0xFFFFFF |
1719 | 0:0xFFFFFFFF:0x0xFFFFFFFF |
1720 | 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1721 | 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1722 | 0xFFFF:0:0x0xFFFF |
1723 | 0xFFFFFF:0:0x0xFFFFFF |
1724 | 0xFFFFFFFF:0:0x0xFFFFFFFF |
1725 | 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF |
1726 | 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF |
1727 | 0xF0F0:0xF0F0:0 |
1728 | 0x0F0F:0x0F0F:0 |
1729 | 0xF0F0:0x0F0F:0x0xFFFF |
1730 | 0xF0F0F0:0xF0F0F0:0 |
1731 | 0x0F0F0F:0x0F0F0F:0 |
1732 | 0x0F0F0F:0xF0F0F0:0x0xFFFFFF |
1733 | 0xF0F0F0F0:0xF0F0F0F0:0 |
1734 | 0x0F0F0F0F:0x0F0F0F0F:0 |
1735 | 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF |
1736 | 0xF0F0F0F0F0:0xF0F0F0F0F0:0 |
1737 | 0x0F0F0F0F0F:0x0F0F0F0F0F:0 |
1738 | 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF |
1739 | 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0 |
1740 | 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0 |
1741 | 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF |
6854fd01 |
1742 | &bnot |
1743 | abc:NaN |
1744 | +0:-1 |
1745 | +8:-9 |
1746 | +281474976710656:-281474976710657 |
1747 | -1:0 |
1748 | -2:1 |
1749 | -12:11 |
1750 | &digit |
1751 | 0:0:0 |
1752 | 12:0:2 |
1753 | 12:1:1 |
1754 | 123:0:3 |
1755 | 123:1:2 |
1756 | 123:2:1 |
1757 | 123:-1:1 |
1758 | 123:-2:2 |
1759 | 123:-3:3 |
1760 | 123456:0:6 |
1761 | 123456:1:5 |
1762 | 123456:2:4 |
1763 | 123456:3:3 |
1764 | 123456:4:2 |
1765 | 123456:5:1 |
1766 | 123456:-1:1 |
1767 | 123456:-2:2 |
1768 | 123456:-3:3 |
1769 | 100000:-3:0 |
1770 | 100000:0:0 |
1771 | 100000:1:0 |
1772 | &mantissa |
1773 | abc:NaN |
1774 | 1e4:1 |
1775 | 2e0:2 |
1776 | 123:123 |
1777 | -1:-1 |
1778 | -2:-2 |
1779 | +inf:inf |
1780 | -inf:-inf |
1781 | &exponent |
1782 | abc:NaN |
1783 | 1e4:4 |
1784 | 2e0:0 |
1785 | 123:0 |
1786 | -1:0 |
1787 | -2:0 |
1788 | 0:1 |
1789 | +inf:inf |
1790 | -inf:inf |
1791 | &parts |
1792 | abc:NaN,NaN |
1793 | 1e4:1,4 |
1794 | 2e0:2,0 |
1795 | 123:123,0 |
1796 | -1:-1,0 |
1797 | -2:-2,0 |
1798 | 0:0,1 |
1799 | +inf:inf,inf |
1800 | -inf:-inf,inf |
b3abae2a |
1801 | &bfac |
1802 | -1:NaN |
1803 | NaNfac:NaN |
1804 | +inf:NaN |
1805 | -inf:NaN |
1806 | 0:1 |
1807 | 1:1 |
1808 | 2:2 |
1809 | 3:6 |
1810 | 4:24 |
1811 | 5:120 |
1812 | 6:720 |
1813 | 10:3628800 |
1814 | 11:39916800 |
1815 | 12:479001600 |
6854fd01 |
1816 | &bpow |
1817 | abc:12:NaN |
1818 | 12:abc:NaN |
1819 | 0:0:1 |
1820 | 0:1:0 |
1821 | 0:2:0 |
1822 | 0:-1:NaN |
1823 | 0:-2:NaN |
1824 | 1:0:1 |
1825 | 1:1:1 |
1826 | 1:2:1 |
1827 | 1:3:1 |
1828 | 1:-1:1 |
1829 | 1:-2:1 |
1830 | 1:-3:1 |
1831 | 2:0:1 |
1832 | 2:1:2 |
1833 | 2:2:4 |
1834 | 2:3:8 |
1835 | 3:3:27 |
1836 | 2:-1:NaN |
1837 | -2:-1:NaN |
1838 | 2:-2:NaN |
1839 | -2:-2:NaN |
1840 | +inf:1234500012:inf |
1841 | -inf:1234500012:-inf |
1842 | +inf:-12345000123:inf |
1843 | -inf:-12345000123:-inf |
1844 | # 1 ** -x => 1 / (1 ** x) |
1845 | -1:0:1 |
1846 | -2:0:1 |
1847 | -1:1:-1 |
1848 | -1:2:1 |
1849 | -1:3:-1 |
1850 | -1:4:1 |
1851 | -1:5:-1 |
1852 | -1:-1:-1 |
1853 | -1:-2:1 |
1854 | -1:-3:-1 |
1855 | -1:-4:1 |
1856 | 10:2:100 |
1857 | 10:3:1000 |
1858 | 10:4:10000 |
1859 | 10:5:100000 |
1860 | 10:6:1000000 |
1861 | 10:7:10000000 |
1862 | 10:8:100000000 |
1863 | 10:9:1000000000 |
1864 | 10:20:100000000000000000000 |
1865 | 123456:2:15241383936 |
1866 | &length |
1867 | 100:3 |
1868 | 10:2 |
1869 | 1:1 |
1870 | 0:1 |
1871 | 12345:5 |
1872 | 10000000000000000:17 |
1873 | -123:3 |
1874 | 215960156869840440586892398248:30 |
1875 | &bsqrt |
394e6ffb |
1876 | 145:12 |
6854fd01 |
1877 | 144:12 |
394e6ffb |
1878 | 143:11 |
6854fd01 |
1879 | 16:4 |
394e6ffb |
1880 | 170:13 |
1881 | 169:13 |
1882 | 168:12 |
6854fd01 |
1883 | 4:2 |
394e6ffb |
1884 | 3:1 |
6854fd01 |
1885 | 2:1 |
394e6ffb |
1886 | 9:3 |
6854fd01 |
1887 | 12:3 |
1888 | 256:16 |
1889 | 100000000:10000 |
1890 | 4000000000000:2000000 |
394e6ffb |
1891 | 152399026:12345 |
1892 | 152399025:12345 |
1893 | 152399024:12344 |
6854fd01 |
1894 | 1:1 |
1895 | 0:0 |
1896 | -2:NaN |
394e6ffb |
1897 | -123:NaN |
6854fd01 |
1898 | Nan:NaN |
394e6ffb |
1899 | +inf:NaN |
6854fd01 |
1900 | &bround |
1901 | $round_mode('trunc') |
1902 | 0:12:0 |
1903 | NaNbround:12:NaN |
1904 | +inf:12:inf |
1905 | -inf:12:-inf |
1906 | 1234:0:1234 |
1907 | 1234:2:1200 |
1908 | 123456:4:123400 |
1909 | 123456:5:123450 |
1910 | 123456:6:123456 |
61f5c3f5 |
1911 | +10123456789:5:10123000000 |
6854fd01 |
1912 | -10123456789:5:-10123000000 |
61f5c3f5 |
1913 | +10123456789:9:10123456700 |
6854fd01 |
1914 | -10123456789:9:-10123456700 |
61f5c3f5 |
1915 | +101234500:6:101234000 |
6854fd01 |
1916 | -101234500:6:-101234000 |
61f5c3f5 |
1917 | #+101234500:-4:101234000 |
6854fd01 |
1918 | #-101234500:-4:-101234000 |
1919 | $round_mode('zero') |
61f5c3f5 |
1920 | +20123456789:5:20123000000 |
6854fd01 |
1921 | -20123456789:5:-20123000000 |
61f5c3f5 |
1922 | +20123456789:9:20123456800 |
6854fd01 |
1923 | -20123456789:9:-20123456800 |
61f5c3f5 |
1924 | +201234500:6:201234000 |
6854fd01 |
1925 | -201234500:6:-201234000 |
61f5c3f5 |
1926 | #+201234500:-4:201234000 |
6854fd01 |
1927 | #-201234500:-4:-201234000 |
1928 | +12345000:4:12340000 |
1929 | -12345000:4:-12340000 |
1930 | $round_mode('+inf') |
61f5c3f5 |
1931 | +30123456789:5:30123000000 |
6854fd01 |
1932 | -30123456789:5:-30123000000 |
61f5c3f5 |
1933 | +30123456789:9:30123456800 |
6854fd01 |
1934 | -30123456789:9:-30123456800 |
61f5c3f5 |
1935 | +301234500:6:301235000 |
6854fd01 |
1936 | -301234500:6:-301234000 |
61f5c3f5 |
1937 | #+301234500:-4:301235000 |
6854fd01 |
1938 | #-301234500:-4:-301234000 |
1939 | +12345000:4:12350000 |
1940 | -12345000:4:-12340000 |
1941 | $round_mode('-inf') |
61f5c3f5 |
1942 | +40123456789:5:40123000000 |
6854fd01 |
1943 | -40123456789:5:-40123000000 |
61f5c3f5 |
1944 | +40123456789:9:40123456800 |
6854fd01 |
1945 | -40123456789:9:-40123456800 |
61f5c3f5 |
1946 | +401234500:6:401234000 |
1947 | +401234500:6:401234000 |
6854fd01 |
1948 | #-401234500:-4:-401235000 |
1949 | #-401234500:-4:-401235000 |
1950 | +12345000:4:12340000 |
1951 | -12345000:4:-12350000 |
1952 | $round_mode('odd') |
61f5c3f5 |
1953 | +50123456789:5:50123000000 |
6854fd01 |
1954 | -50123456789:5:-50123000000 |
61f5c3f5 |
1955 | +50123456789:9:50123456800 |
6854fd01 |
1956 | -50123456789:9:-50123456800 |
61f5c3f5 |
1957 | +501234500:6:501235000 |
6854fd01 |
1958 | -501234500:6:-501235000 |
61f5c3f5 |
1959 | #+501234500:-4:501235000 |
6854fd01 |
1960 | #-501234500:-4:-501235000 |
1961 | +12345000:4:12350000 |
1962 | -12345000:4:-12350000 |
1963 | $round_mode('even') |
61f5c3f5 |
1964 | +60123456789:5:60123000000 |
6854fd01 |
1965 | -60123456789:5:-60123000000 |
61f5c3f5 |
1966 | +60123456789:9:60123456800 |
6854fd01 |
1967 | -60123456789:9:-60123456800 |
61f5c3f5 |
1968 | +601234500:6:601234000 |
6854fd01 |
1969 | -601234500:6:-601234000 |
61f5c3f5 |
1970 | #+601234500:-4:601234000 |
6854fd01 |
1971 | #-601234500:-4:-601234000 |
1972 | #-601234500:-9:0 |
1973 | #-501234500:-9:0 |
1974 | #-601234500:-8:0 |
1975 | #-501234500:-8:0 |
1976 | +1234567:7:1234567 |
1977 | +1234567:6:1234570 |
1978 | +12345000:4:12340000 |
1979 | -12345000:4:-12340000 |
1980 | &is_zero |
1981 | 0:1 |
1982 | NaNzero:0 |
1983 | +inf:0 |
1984 | -inf:0 |
1985 | 123:0 |
1986 | -1:0 |
1987 | 1:0 |
1988 | &is_one |
1989 | 0:0 |
1990 | NaNone:0 |
1991 | +inf:0 |
1992 | -inf:0 |
1993 | 1:1 |
1994 | 2:0 |
1995 | -1:0 |
1996 | -2:0 |
1997 | # floor and ceil tests are pretty pointless in integer space...but play safe |
1998 | &bfloor |
1999 | 0:0 |
2000 | NaNfloor:NaN |
2001 | +inf:inf |
2002 | -inf:-inf |
2003 | -1:-1 |
2004 | -2:-2 |
2005 | 2:2 |
2006 | 3:3 |
2007 | abc:NaN |
2008 | &bceil |
2009 | NaNceil:NaN |
2010 | +inf:inf |
2011 | -inf:-inf |
2012 | 0:0 |
2013 | -1:-1 |
2014 | -2:-2 |
2015 | 2:2 |
2016 | 3:3 |
2017 | abc:NaN |
2018 | &as_hex |
2019 | 128:0x80 |
2020 | -128:-0x80 |
2021 | 0:0x0 |
2022 | -0:0x0 |
2023 | 1:0x1 |
2024 | 0x123456789123456789:0x123456789123456789 |
2025 | +inf:inf |
2026 | -inf:-inf |
2027 | NaNas_hex:NaN |
2028 | &as_bin |
2029 | 128:0b10000000 |
2030 | -128:-0b10000000 |
2031 | 0:0b0 |
2032 | -0:0b0 |
2033 | 1:0b1 |
2034 | 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101 |
1ddff52a |
2035 | 0x123456789123456789:0b100100011010001010110011110001001000100100011010001010110011110001001 |
6854fd01 |
2036 | +inf:inf |
2037 | -inf:-inf |
2038 | NaNas_bin:NaN |