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