Commit | Line | Data |
6854fd01 |
1 | #include this file into another for subclass testing |
2 | |
3 | my $version = ${"$class\::VERSION"}; |
4 | |
5 | ############################################################################## |
6 | # for testing inheritance of _swap |
7 | |
8 | package Math::Foo; |
9 | |
10 | use Math::BigInt; |
11 | #use Math::BigInt lib => 'BitVect'; # for testing |
12 | use vars qw/@ISA/; |
13 | @ISA = (qw/Math::BigInt/); |
14 | |
15 | use overload |
16 | # customized overload for sub, since original does not use swap there |
17 | '-' => sub { my @a = ref($_[0])->_swap(@_); |
18 | $a[0]->bsub($a[1])}; |
19 | |
20 | sub _swap |
21 | { |
22 | # a fake _swap, which reverses the params |
23 | my $self = shift; # for override in subclass |
24 | if ($_[2]) |
25 | { |
26 | my $c = ref ($_[0] ) || 'Math::Foo'; |
27 | return ( $_[0]->copy(), $_[1] ); |
28 | } |
29 | else |
30 | { |
31 | return ( Math::Foo->new($_[1]), $_[0] ); |
32 | } |
33 | } |
34 | |
35 | ############################################################################## |
36 | package main; |
37 | |
394e6ffb |
38 | my $CALC = $class->_core_lib(); ok ($CALC,$CL); |
6854fd01 |
39 | |
40 | my ($f,$z,$a,$exp,@a,$m,$e,$round_mode); |
41 | |
42 | while (<DATA>) |
43 | { |
44 | chop; |
45 | next if /^#/; # skip comments |
46 | if (s/^&//) |
47 | { |
48 | $f = $_; |
49 | } |
50 | elsif (/^\$/) |
51 | { |
52 | $round_mode = $_; |
53 | $round_mode =~ s/^\$/$class\->/; |
54 | # print "$round_mode\n"; |
55 | } |
56 | else |
57 | { |
58 | @args = split(/:/,$_,99); |
59 | $ans = pop(@args); |
60 | $try = "\$x = $class->new(\"$args[0]\");"; |
61 | if ($f eq "bnorm"){ |
62 | $try = "\$x = $class->bnorm(\"$args[0]\");"; |
027dc388 |
63 | # some is_xxx tests |
64 | } elsif ($f =~ /^is_(zero|one|odd|even|negative|positive|nan)$/) { |
65 | $try .= "\$x->$f();"; |
6854fd01 |
66 | } elsif ($f eq "as_hex") { |
67 | $try .= '$x->as_hex();'; |
68 | } elsif ($f eq "as_bin") { |
69 | $try .= '$x->as_bin();'; |
70 | } elsif ($f eq "is_inf") { |
71 | $try .= "\$x->is_inf('$args[1]');"; |
72 | } elsif ($f eq "binf") { |
73 | $try .= "\$x->binf('$args[1]');"; |
74 | } elsif ($f eq "bone") { |
75 | $try .= "\$x->bone('$args[1]');"; |
027dc388 |
76 | # some unary ops |
77 | } elsif ($f =~ /^b(nan|floor|ceil|sstr|neg|abs|inc|dec|not|sqrt)$/) { |
78 | $try .= "\$x->$f();"; |
6854fd01 |
79 | }elsif ($f eq "length") { |
80 | $try .= '$x->length();'; |
81 | }elsif ($f eq "exponent"){ |
82 | # ->bstr() to see if an object is returned |
83 | $try .= '$x = $x->exponent()->bstr();'; |
84 | }elsif ($f eq "mantissa"){ |
85 | # ->bstr() to see if an object is returned |
86 | $try .= '$x = $x->mantissa()->bstr();'; |
87 | }elsif ($f eq "parts"){ |
88 | $try .= '($m,$e) = $x->parts();'; |
89 | # ->bstr() to see if an object is returned |
90 | $try .= '$m = $m->bstr(); $m = "NaN" if !defined $m;'; |
91 | $try .= '$e = $e->bstr(); $e = "NaN" if !defined $e;'; |
92 | $try .= '"$m,$e";'; |
93 | } else { |
94 | $try .= "\$y = $class->new('$args[1]');"; |
95 | if ($f eq "bcmp"){ |
96 | $try .= '$x <=> $y;'; |
97 | }elsif ($f eq "bround") { |
98 | $try .= "$round_mode; \$x->bround(\$y);"; |
99 | }elsif ($f eq "bacmp"){ |
100 | $try .= '$x->bacmp($y);'; |
101 | }elsif ($f eq "badd"){ |
102 | $try .= '$x + $y;'; |
103 | }elsif ($f eq "bsub"){ |
104 | $try .= '$x - $y;'; |
105 | }elsif ($f eq "bmul"){ |
106 | $try .= '$x * $y;'; |
107 | }elsif ($f eq "bdiv"){ |
108 | $try .= '$x / $y;'; |
109 | }elsif ($f eq "bdiv-list"){ |
110 | $try .= 'join (",",$x->bdiv($y));'; |
027dc388 |
111 | # overload via x= |
112 | }elsif ($f =~ /^.=$/){ |
113 | $try .= "\$x $f \$y;"; |
114 | # overload via x |
115 | }elsif ($f =~ /^.$/){ |
116 | $try .= "\$x $f \$y;"; |
6854fd01 |
117 | }elsif ($f eq "bmod"){ |
118 | $try .= '$x % $y;'; |
119 | }elsif ($f eq "bgcd") |
120 | { |
121 | if (defined $args[2]) |
122 | { |
123 | $try .= " \$z = $class->new(\"$args[2]\"); "; |
124 | } |
125 | $try .= "$class\::bgcd(\$x, \$y"; |
126 | $try .= ", \$z" if (defined $args[2]); |
127 | $try .= " );"; |
128 | } |
129 | elsif ($f eq "blcm") |
130 | { |
131 | if (defined $args[2]) |
132 | { |
133 | $try .= " \$z = $class->new(\"$args[2]\"); "; |
134 | } |
135 | $try .= "$class\::blcm(\$x, \$y"; |
136 | $try .= ", \$z" if (defined $args[2]); |
137 | $try .= " );"; |
138 | }elsif ($f eq "blsft"){ |
139 | if (defined $args[2]) |
140 | { |
141 | $try .= "\$x->blsft(\$y,$args[2]);"; |
142 | } |
143 | else |
144 | { |
145 | $try .= "\$x << \$y;"; |
146 | } |
147 | }elsif ($f eq "brsft"){ |
148 | if (defined $args[2]) |
149 | { |
150 | $try .= "\$x->brsft(\$y,$args[2]);"; |
151 | } |
152 | else |
153 | { |
154 | $try .= "\$x >> \$y;"; |
155 | } |
156 | }elsif ($f eq "band"){ |
157 | $try .= "\$x & \$y;"; |
158 | }elsif ($f eq "bior"){ |
159 | $try .= "\$x | \$y;"; |
160 | }elsif ($f eq "bxor"){ |
161 | $try .= "\$x ^ \$y;"; |
162 | }elsif ($f eq "bpow"){ |
163 | $try .= "\$x ** \$y;"; |
164 | }elsif ($f eq "digit"){ |
165 | $try = "\$x = $class->new(\"$args[0]\"); \$x->digit($args[1]);"; |
166 | } else { warn "Unknown op '$f'"; } |
167 | } |
394e6ffb |
168 | # print "trying $try\n"; |
6854fd01 |
169 | $ans1 = eval $try; |
394e6ffb |
170 | # remove leading '+' from target |
171 | $ans =~ s/^[+]([0-9])/$1/; |
172 | # convert hex/binary targets to decimal |
173 | if ($ans =~ /^(0x0x|0b0b)/) |
174 | { |
175 | $ans =~ s/^0[xb]//; |
176 | $ans = Math::BigInt->new($ans)->bstr(); |
177 | } |
6854fd01 |
178 | if ($ans eq "") |
179 | { |
180 | ok_undef ($ans1); |
181 | } |
182 | else |
183 | { |
184 | # print "try: $try ans: $ans1 $ans\n"; |
185 | print "# Tried: '$try'\n" if !ok ($ans1, $ans); |
186 | } |
187 | # check internal state of number objects |
188 | is_valid($ans1,$f) if ref $ans1; |
189 | } |
190 | } # endwhile data tests |
191 | close DATA; |
192 | |
193 | # test some more |
194 | @a = (); |
195 | for (my $i = 1; $i < 10; $i++) |
196 | { |
197 | push @a, $i; |
198 | } |
199 | ok "@a", "1 2 3 4 5 6 7 8 9"; |
200 | |
201 | # test whether self-multiplication works correctly (result is 2**64) |
202 | $try = "\$x = $class->new('4294967296');"; |
203 | $try .= '$a = $x->bmul($x);'; |
204 | $ans1 = eval $try; |
205 | print "# Tried: '$try'\n" if !ok ($ans1, $class->new(2) ** 64); |
206 | # test self-pow |
207 | $try = "\$x = $class->new(10);"; |
208 | $try .= '$a = $x->bpow($x);'; |
209 | $ans1 = eval $try; |
210 | print "# Tried: '$try'\n" if !ok ($ans1, $class->new(10) ** 10); |
211 | |
212 | # test whether op destroys args or not (should better not) |
213 | |
214 | $x = $class->new(3); |
215 | $y = $class->new(4); |
216 | $z = $x & $y; |
217 | ok ($x,3); |
218 | ok ($y,4); |
219 | ok ($z,0); |
220 | $z = $x | $y; |
221 | ok ($x,3); |
222 | ok ($y,4); |
223 | ok ($z,7); |
224 | $x = $class->new(1); |
225 | $y = $class->new(2); |
226 | $z = $x | $y; |
227 | ok ($x,1); |
228 | ok ($y,2); |
229 | ok ($z,3); |
230 | |
231 | $x = $class->new(5); |
232 | $y = $class->new(4); |
233 | $z = $x ^ $y; |
234 | ok ($x,5); |
235 | ok ($y,4); |
236 | ok ($z,1); |
237 | |
238 | $x = $class->new(-5); $y = -$x; |
239 | ok ($x, -5); |
240 | |
241 | $x = $class->new(-5); $y = abs($x); |
242 | ok ($x, -5); |
243 | |
244 | # check whether overloading cmp works |
245 | $try = "\$x = $class->new(0);"; |
246 | $try .= "\$y = 10;"; |
247 | $try .= "'false' if \$x ne \$y;"; |
248 | $ans = eval $try; |
249 | print "# For '$try'\n" if (!ok "$ans" , "false" ); |
250 | |
251 | # we cant test for working cmpt with other objects here, we would need a dummy |
252 | # object with stringify overload for this. see Math::String tests as example |
253 | |
254 | ############################################################################### |
6854fd01 |
255 | # check reversed order of arguments |
027dc388 |
256 | |
6854fd01 |
257 | $try = "\$x = $class->new(10); \$x = 2 ** \$x;"; |
258 | $try .= "'ok' if \$x == 1024;"; $ans = eval $try; |
259 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
260 | |
261 | $try = "\$x = $class->new(10); \$x = 2 * \$x;"; |
262 | $try .= "'ok' if \$x == 20;"; $ans = eval $try; |
263 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
264 | |
265 | $try = "\$x = $class->new(10); \$x = 2 + \$x;"; |
266 | $try .= "'ok' if \$x == 12;"; $ans = eval $try; |
267 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
268 | |
269 | $try = "\$x = $class\->new(10); \$x = 2 - \$x;"; |
270 | $try .= "'ok' if \$x == -8;"; $ans = eval $try; |
271 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
272 | |
273 | $try = "\$x = $class\->new(10); \$x = 20 / \$x;"; |
274 | $try .= "'ok' if \$x == 2;"; $ans = eval $try; |
275 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
276 | |
027dc388 |
277 | $try = "\$x = $class\->new(3); \$x = 20 % \$x;"; |
278 | $try .= "'ok' if \$x == 2;"; $ans = eval $try; |
279 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
280 | |
281 | $try = "\$x = $class\->new(7); \$x = 20 & \$x;"; |
282 | $try .= "'ok' if \$x == 4;"; $ans = eval $try; |
283 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
284 | |
285 | $try = "\$x = $class\->new(7); \$x = 0x20 | \$x;"; |
286 | $try .= "'ok' if \$x == 0x27;"; $ans = eval $try; |
287 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
288 | |
289 | $try = "\$x = $class\->new(7); \$x = 0x20 ^ \$x;"; |
290 | $try .= "'ok' if \$x == 0x27;"; $ans = eval $try; |
291 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
292 | |
6854fd01 |
293 | ############################################################################### |
294 | # check badd(4,5) form |
295 | |
296 | $try = "\$x = $class\->badd(4,5);"; |
297 | $try .= "'ok' if \$x == 9;"; |
298 | $ans = eval $try; |
299 | print "# For '$try'\n" if (!ok "$ans" , "ok" ); |
300 | |
301 | ############################################################################### |
302 | # check undefs: NOT DONE YET |
303 | |
304 | ############################################################################### |
305 | # bool |
306 | |
307 | $x = Math::BigInt->new(1); if ($x) { ok (1,1); } else { ok($x,'to be true') } |
308 | $x = Math::BigInt->new(0); if (!$x) { ok (1,1); } else { ok($x,'to be false') } |
309 | |
310 | ############################################################################### |
311 | # objectify() |
312 | |
313 | @args = Math::BigInt::objectify(2,4,5); |
314 | ok (scalar @args,3); # $class, 4, 5 |
315 | ok ($args[0],$class); |
316 | ok ($args[1],4); |
317 | ok ($args[2],5); |
318 | |
319 | @args = Math::BigInt::objectify(0,4,5); |
320 | ok (scalar @args,3); # $class, 4, 5 |
321 | ok ($args[0],$class); |
322 | ok ($args[1],4); |
323 | ok ($args[2],5); |
324 | |
325 | @args = Math::BigInt::objectify(2,4,5); |
326 | ok (scalar @args,3); # $class, 4, 5 |
327 | ok ($args[0],$class); |
328 | ok ($args[1],4); |
329 | ok ($args[2],5); |
330 | |
331 | @args = Math::BigInt::objectify(2,4,5,6,7); |
332 | ok (scalar @args,5); # $class, 4, 5, 6, 7 |
333 | ok ($args[0],$class); |
334 | ok ($args[1],4); ok (ref($args[1]),$args[0]); |
335 | ok ($args[2],5); ok (ref($args[2]),$args[0]); |
336 | ok ($args[3],6); ok (ref($args[3]),''); |
337 | ok ($args[4],7); ok (ref($args[4]),''); |
338 | |
339 | @args = Math::BigInt::objectify(2,$class,4,5,6,7); |
340 | ok (scalar @args,5); # $class, 4, 5, 6, 7 |
341 | ok ($args[0],$class); |
342 | ok ($args[1],4); ok (ref($args[1]),$args[0]); |
343 | ok ($args[2],5); ok (ref($args[2]),$args[0]); |
344 | ok ($args[3],6); ok (ref($args[3]),''); |
345 | ok ($args[4],7); ok (ref($args[4]),''); |
346 | |
347 | ############################################################################### |
348 | # test for floating-point input (other tests in bnorm() below) |
349 | |
350 | $z = 1050000000000000; # may be int on systems with 64bit? |
351 | $x = $class->new($z); ok ($x->bsstr(),'105e+13'); # not 1.05e+15 |
352 | $z = 1e+129; # definitely a float (may fail on UTS) |
353 | # don't compare to $z, since some Perl versions stringify $z into something |
354 | # like '1.e+129' or something equally ugly |
355 | $x = $class->new($z); ok ($x->bsstr(),'1e+129'); |
356 | |
357 | ############################################################################### |
358 | # prime number tests, also test for **= and length() |
359 | # found on: http://www.utm.edu/research/primes/notes/by_year.html |
360 | |
361 | # ((2^148)-1)/17 |
362 | $x = $class->new(2); $x **= 148; $x++; $x = $x / 17; |
363 | ok ($x,"20988936657440586486151264256610222593863921"); |
364 | ok ($x->length(),length "20988936657440586486151264256610222593863921"); |
365 | |
366 | # MM7 = 2^127-1 |
367 | $x = $class->new(2); $x **= 127; $x--; |
368 | ok ($x,"170141183460469231731687303715884105727"); |
369 | |
370 | $x = $class->new('215960156869840440586892398248'); |
371 | ($x,$y) = $x->length(); |
372 | ok ($x,30); ok ($y,0); |
373 | |
374 | $x = $class->new('1_000_000_000_000'); |
375 | ($x,$y) = $x->length(); |
376 | ok ($x,13); ok ($y,0); |
377 | |
378 | # I am afraid the following is not yet possible due to slowness |
379 | # Also, testing for 2 meg output is a bit hard ;) |
380 | #$x = $class->new(2); $x **= 6972593; $x--; |
381 | |
382 | # 593573509*2^332162+1 has exactly 1,000,000 digits |
383 | # takes about 24 mins on 300 Mhz, so cannot be done yet ;) |
384 | #$x = $class->new(2); $x **= 332162; $x *= "593573509"; $x++; |
385 | #ok ($x->length(),1_000_000); |
386 | |
387 | ############################################################################### |
388 | # inheritance and overriding of _swap |
389 | |
390 | $x = Math::Foo->new(5); |
391 | $x = $x - 8; # 8 - 5 instead of 5-8 |
392 | ok ($x,3); |
393 | ok (ref($x),'Math::Foo'); |
394 | |
395 | $x = Math::Foo->new(5); |
396 | $x = 8 - $x; # 5 - 8 instead of 8 - 5 |
397 | ok ($x,-3); |
398 | ok (ref($x),'Math::Foo'); |
399 | |
400 | ############################################################################### |
401 | # Test whether +inf eq inf |
402 | # This tried to test whether BigInt inf equals Perl inf. Unfortunately, Perl |
403 | # hasn't (before 5.7.3 at least) a consistent way to say inf, and some things |
404 | # like 1e100000 crash on some platforms. So simple test for the string 'inf' |
405 | $x = $class->new('+inf'); ok ($x,'inf'); |
406 | |
407 | ############################################################################### |
408 | ############################################################################### |
394e6ffb |
409 | # the followin tests only make sense with Math::BigInt::Calc or BareCalc |
6854fd01 |
410 | |
394e6ffb |
411 | exit if $CALC !~ /^Math::BigInt::(Calc|BareCalc)$/; # for Pari et al. |
6854fd01 |
412 | |
413 | ############################################################################### |
414 | # check proper length of internal arrays |
415 | |
394e6ffb |
416 | my $bl = $CL->_base_len(); |
6854fd01 |
417 | my $BASE = '9' x $bl; |
418 | my $MAX = $BASE; |
419 | $BASE++; |
420 | |
421 | $x = $class->new($MAX); is_valid($x); # f.i. 9999 |
422 | $x += 1; ok ($x,$BASE); is_valid($x); # 10000 |
423 | $x -= 1; ok ($x,$MAX); is_valid($x); # 9999 again |
424 | |
425 | ############################################################################### |
426 | # check numify |
427 | |
428 | $x = $class->new($BASE-1); ok ($x->numify(),$BASE-1); |
429 | $x = $class->new(-($BASE-1)); ok ($x->numify(),-($BASE-1)); |
430 | $x = $class->new($BASE); ok ($x->numify(),$BASE); |
431 | $x = $class->new(-$BASE); ok ($x->numify(),-$BASE); |
432 | $x = $class->new( -($BASE*$BASE*1+$BASE*1+1) ); |
433 | ok($x->numify(),-($BASE*$BASE*1+$BASE*1+1)); |
434 | |
435 | ############################################################################### |
436 | # test bug in _digits with length($c[-1]) where $c[-1] was "00001" instead of 1 |
437 | |
394e6ffb |
438 | $x = $class->new($BASE-2); $x++; $x++; $x++; $x++; |
439 | if ($x > $BASE) { ok (1,1) } else { ok ("$x < $BASE","$x > $BASE"); } |
440 | |
441 | $x = $class->new($BASE+3); $x++; |
442 | if ($x > $BASE) { ok (1,1) } else { ok ("$x > $BASE","$x < $BASE"); } |
6854fd01 |
443 | |
394e6ffb |
444 | # test for +0 instead of int(): |
445 | $x = $class->new($MAX); ok ($x->length(), length($MAX)); |
6854fd01 |
446 | |
447 | ############################################################################### |
448 | # bug in sub where number with at least 6 trailing zeros after any op failed |
449 | |
394e6ffb |
450 | $x = $class->new(123456); $z = $class->new(10000); $z *= 10; $x -= $z; |
6854fd01 |
451 | ok ($z, 100000); |
452 | ok ($x, 23456); |
453 | |
454 | ############################################################################### |
455 | # bug in shortcut in mul() |
456 | |
457 | # construct a number with a zero-hole of BASE_LEN |
458 | $x = '1' x $bl . '0' x $bl . '1' x $bl . '0' x $bl; |
459 | $y = '1' x (2*$bl); |
394e6ffb |
460 | $x = $class->new($x)->bmul($y); |
6854fd01 |
461 | # result is 123..$bl . $bl x (3*bl-1) . $bl...321 . '0' x $bl |
462 | $y = ''; my $d = ''; |
463 | for (my $i = 1; $i <= $bl; $i++) |
464 | { |
465 | $y .= $i; $d = $i.$d; |
466 | } |
6854fd01 |
467 | $y .= $bl x (3*$bl-1) . $d . '0' x $bl; |
468 | ok ($x,$y); |
469 | |
470 | ############################################################################### |
394e6ffb |
471 | # see if mul shortcut for small numbers works |
472 | |
473 | $x = '9' x $bl; |
474 | $x = $class->new($x); |
475 | # 999 * 999 => 998 . 001, 9999*9999 => 9998 . 0001 |
476 | ok ($x*$x, '9' x ($bl-1) . '8' . '0' x ($bl-1) . '1'); |
477 | |
478 | ############################################################################### |
6854fd01 |
479 | # bug with rest "-0" in div, causing further div()s to fail |
480 | |
394e6ffb |
481 | $x = $class->new('-322056000'); ($x,$y) = $x->bdiv('-12882240'); |
6854fd01 |
482 | |
483 | ok ($y,'0','not -0'); # not '-0' |
484 | is_valid($y); |
485 | |
394e6ffb |
486 | ############################################################################### |
487 | # test whether bone/bzero take additional A & P, or reset it etc |
488 | |
489 | $x = $class->new(2); $x->bzero(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); |
490 | $x = $class->new(2); $x->binf(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); |
491 | $x = $class->new(2); $x->bone(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); |
492 | $x = $class->new(2); $x->bnan(); ok_undef ($x->{_a}); ok_undef ($x->{_p}); |
493 | |
494 | $x = $class->new(2); $x->{_a} = 1; $x->{_p} = 2; $x->bnan(); |
495 | ok_undef ($x->{_a}); ok_undef ($x->{_p}); |
496 | $x = $class->new(2); $x->{_a} = 1; $x->{_p} = 2; $x->binf(); |
497 | ok_undef ($x->{_a}); ok_undef ($x->{_p}); |
498 | |
6854fd01 |
499 | ### all tests done ############################################################ |
500 | |
501 | 1; |
502 | |
503 | ############################################################################### |
504 | # Perl 5.005 does not like ok ($x,undef) |
505 | |
506 | sub ok_undef |
507 | { |
508 | my $x = shift; |
509 | |
510 | ok (1,1) and return if !defined $x; |
511 | ok ($x,'undef'); |
512 | } |
513 | |
514 | ############################################################################### |
515 | # sub to check validity of a BigInt internally, to ensure that no op leaves a |
516 | # number object in an invalid state (f.i. "-0") |
517 | |
518 | sub is_valid |
519 | { |
520 | my ($x,$f) = @_; |
521 | |
522 | my $e = 0; # error? |
523 | # ok as reference? |
524 | $e = 'Not a reference to Math::BigInt' if !ref($x); |
525 | |
526 | # has ok sign? |
527 | $e = "Illegal sign $x->{sign} (expected: '+', '-', '-inf', '+inf' or 'NaN'" |
528 | if $e eq '0' && $x->{sign} !~ /^(\+|-|\+inf|-inf|NaN)$/; |
529 | |
530 | $e = "-0 is invalid!" if $e ne '0' && $x->{sign} eq '-' && $x == 0; |
531 | $e = $CALC->_check($x->{value}) if $e eq '0'; |
532 | |
533 | # test done, see if error did crop up |
534 | ok (1,1), return if ($e eq '0'); |
535 | |
027dc388 |
536 | ok (1,$e." after op '$f'"); |
6854fd01 |
537 | } |
538 | |
539 | __DATA__ |
027dc388 |
540 | &.= |
541 | 1234:-345:1234-345 |
542 | &+= |
543 | 1:2:3 |
544 | -1:-2:-3 |
545 | &-= |
546 | 1:2:-1 |
547 | -1:-2:1 |
548 | &*= |
549 | 2:3:6 |
550 | -1:5:-5 |
551 | &%= |
552 | 100:3:1 |
553 | 8:9:8 |
554 | &/= |
555 | 100:3:33 |
556 | -8:2:-4 |
557 | &|= |
558 | 2:1:3 |
559 | &&= |
560 | 5:7:5 |
561 | &^= |
562 | 5:7:2 |
6854fd01 |
563 | &is_negative |
564 | 0:0 |
565 | -1:1 |
566 | 1:0 |
567 | +inf:0 |
568 | -inf:1 |
569 | NaNneg:0 |
570 | &is_positive |
571 | 0:1 |
572 | -1:0 |
573 | 1:1 |
574 | +inf:1 |
575 | -inf:0 |
576 | NaNneg:0 |
577 | &is_odd |
578 | abc:0 |
579 | 0:0 |
580 | 1:1 |
581 | 3:1 |
582 | -1:1 |
583 | -3:1 |
584 | 10000001:1 |
585 | 10000002:0 |
586 | 2:0 |
587 | &is_even |
588 | abc:0 |
589 | 0:1 |
590 | 1:0 |
591 | 3:0 |
592 | -1:0 |
593 | -3:0 |
594 | 10000001:0 |
595 | 10000002:1 |
596 | 2:1 |
597 | &bacmp |
598 | +0:-0:0 |
599 | +0:+1:-1 |
600 | -1:+1:0 |
601 | +1:-1:0 |
602 | -1:+2:-1 |
603 | +2:-1:1 |
604 | -123456789:+987654321:-1 |
605 | +123456789:-987654321:-1 |
606 | +987654321:+123456789:1 |
607 | -987654321:+123456789:1 |
608 | -123:+4567889:-1 |
609 | # NaNs |
610 | acmpNaN:123: |
611 | 123:acmpNaN: |
612 | acmpNaN:acmpNaN: |
613 | # infinity |
614 | +inf:+inf:0 |
615 | -inf:-inf:0 |
616 | +inf:-inf:0 |
617 | -inf:+inf:0 |
618 | +inf:123:1 |
619 | -inf:123:1 |
620 | +inf:-123:1 |
621 | -inf:-123:1 |
622 | # return undef |
623 | +inf:NaN: |
624 | NaN:inf: |
625 | -inf:NaN: |
626 | NaN:-inf: |
627 | &bnorm |
628 | 123:123 |
629 | # binary input |
630 | 0babc:NaN |
631 | 0b123:NaN |
632 | 0b0:0 |
633 | -0b0:0 |
634 | -0b1:-1 |
635 | 0b0001:1 |
636 | 0b001:1 |
637 | 0b011:3 |
638 | 0b101:5 |
639 | 0b1000000000000000000000000000000:1073741824 |
640 | 0b_101:NaN |
641 | 0b1_0_1:5 |
394e6ffb |
642 | 0b0_0_0_1:1 |
6854fd01 |
643 | # hex input |
644 | -0x0:0 |
645 | 0xabcdefgh:NaN |
646 | 0x1234:4660 |
647 | 0xabcdef:11259375 |
648 | -0xABCDEF:-11259375 |
649 | -0x1234:-4660 |
650 | 0x12345678:305419896 |
651 | 0x1_2_3_4_56_78:305419896 |
394e6ffb |
652 | 0xa_b_c_d_e_f:11259375 |
6854fd01 |
653 | 0x_123:NaN |
654 | # inf input |
655 | inf:inf |
656 | +inf:inf |
657 | -inf:-inf |
658 | 0inf:NaN |
027dc388 |
659 | # abnormal input |
6854fd01 |
660 | :NaN |
661 | abc:NaN |
662 | 1 a:NaN |
663 | 1bcd2:NaN |
664 | 11111b:NaN |
665 | +1z:NaN |
666 | -1z:NaN |
027dc388 |
667 | # only one underscore between two digits |
668 | _123:NaN |
669 | _123_:NaN |
670 | 123_:NaN |
671 | 1__23:NaN |
672 | 1E1__2:NaN |
673 | 1_E12:NaN |
674 | 1E_12:NaN |
675 | 1_E_12:NaN |
676 | +_1E12:NaN |
677 | +0_1E2:100 |
678 | +0_0_1E2:100 |
679 | -0_0_1E2:-100 |
680 | -0_0_1E+0_0_2:-100 |
681 | E1:NaN |
682 | E23:NaN |
683 | 1.23E1:NaN |
684 | 1.23E-1:NaN |
685 | # bug with two E's in number beeing valid |
686 | 1e2e3:NaN |
687 | 1e2r:NaN |
688 | 1e2.0:NaN |
689 | # normal input |
6854fd01 |
690 | 0:0 |
691 | +0:0 |
692 | +00:0 |
693 | +000:0 |
694 | 000000000000000000:0 |
695 | -0:0 |
696 | -0000:0 |
697 | +1:1 |
698 | +01:1 |
699 | +001:1 |
700 | +00000100000:100000 |
701 | 123456789:123456789 |
702 | -1:-1 |
703 | -01:-1 |
704 | -001:-1 |
705 | -123456789:-123456789 |
706 | -00000100000:-100000 |
707 | 1_2_3:123 |
6854fd01 |
708 | 10000000000E-1_0:1 |
709 | 1E2:100 |
710 | 1E1:10 |
711 | 1E0:1 |
6854fd01 |
712 | 1.23E2:123 |
6854fd01 |
713 | 100E-1:10 |
714 | # floating point input |
027dc388 |
715 | # .2e2:20 |
716 | 1.E3:1000 |
6854fd01 |
717 | 1.01E2:101 |
718 | 1010E-1:101 |
719 | -1010E0:-1010 |
720 | -1010E1:-10100 |
027dc388 |
721 | 1234.00:1234 |
722 | # non-integer numbers |
6854fd01 |
723 | -1010E-2:NaN |
724 | -1.01E+1:NaN |
725 | -1.01E-1:NaN |
6854fd01 |
726 | &bnan |
727 | 1:NaN |
728 | 2:NaN |
729 | abc:NaN |
730 | &bone |
731 | 2:+:+1 |
732 | 2:-:-1 |
733 | boneNaN:-:-1 |
734 | boneNaN:+:+1 |
735 | 2:abc:+1 |
736 | 3::+1 |
737 | &binf |
738 | 1:+:inf |
739 | 2:-:-inf |
740 | 3:abc:inf |
027dc388 |
741 | &is_nan |
742 | 123:0 |
743 | abc:1 |
744 | NaN:1 |
745 | -123:0 |
6854fd01 |
746 | &is_inf |
747 | +inf::1 |
748 | -inf::1 |
749 | abc::0 |
750 | 1::0 |
751 | NaN::0 |
752 | -1::0 |
753 | +inf:-:0 |
754 | +inf:+:1 |
755 | -inf:-:1 |
756 | -inf:+:0 |
757 | # it must be exactly /^[+-]inf$/ |
758 | +infinity::0 |
759 | -infinity::0 |
760 | &blsft |
761 | abc:abc:NaN |
762 | +2:+2:+8 |
763 | +1:+32:+4294967296 |
764 | +1:+48:+281474976710656 |
765 | +8:-2:NaN |
766 | # excercise base 10 |
767 | +12345:4:10:123450000 |
768 | -1234:0:10:-1234 |
769 | +1234:0:10:+1234 |
770 | +2:2:10:200 |
771 | +12:2:10:1200 |
772 | +1234:-3:10:NaN |
773 | 1234567890123:12:10:1234567890123000000000000 |
774 | &brsft |
775 | abc:abc:NaN |
776 | +8:+2:+2 |
777 | +4294967296:+32:+1 |
778 | +281474976710656:+48:+1 |
779 | +2:-2:NaN |
780 | # excercise base 10 |
781 | -1234:0:10:-1234 |
782 | +1234:0:10:+1234 |
783 | +200:2:10:2 |
784 | +1234:3:10:1 |
785 | +1234:2:10:12 |
786 | +1234:-3:10:NaN |
787 | 310000:4:10:31 |
788 | 12300000:5:10:123 |
789 | 1230000000000:10:10:123 |
790 | 09876123456789067890:12:10:9876123 |
791 | 1234561234567890123:13:10:123456 |
792 | &bsstr |
793 | 1e+34:1e+34 |
794 | 123.456E3:123456e+0 |
795 | 100:1e+2 |
796 | abc:NaN |
797 | &bneg |
798 | bnegNaN:NaN |
799 | +inf:-inf |
800 | -inf:inf |
801 | abd:NaN |
802 | +0:+0 |
803 | +1:-1 |
804 | -1:+1 |
805 | +123456789:-123456789 |
806 | -123456789:+123456789 |
807 | &babs |
808 | babsNaN:NaN |
809 | +inf:inf |
810 | -inf:inf |
811 | +0:+0 |
812 | +1:+1 |
813 | -1:+1 |
814 | +123456789:+123456789 |
815 | -123456789:+123456789 |
816 | &bcmp |
817 | bcmpNaN:bcmpNaN: |
818 | bcmpNaN:+0: |
819 | +0:bcmpNaN: |
820 | +0:+0:0 |
821 | -1:+0:-1 |
822 | +0:-1:1 |
823 | +1:+0:1 |
824 | +0:+1:-1 |
825 | -1:+1:-1 |
826 | +1:-1:1 |
827 | -1:-1:0 |
828 | +1:+1:0 |
829 | +123:+123:0 |
830 | +123:+12:1 |
831 | +12:+123:-1 |
832 | -123:-123:0 |
833 | -123:-12:-1 |
834 | -12:-123:1 |
835 | +123:+124:-1 |
836 | +124:+123:1 |
837 | -123:-124:1 |
838 | -124:-123:-1 |
839 | +100:+5:1 |
840 | -123456789:+987654321:-1 |
841 | +123456789:-987654321:1 |
842 | -987654321:+123456789:-1 |
843 | -inf:5432112345:-1 |
844 | +inf:5432112345:1 |
845 | -inf:-5432112345:-1 |
846 | +inf:-5432112345:1 |
847 | +inf:+inf:0 |
848 | -inf:-inf:0 |
849 | +inf:-inf:1 |
850 | -inf:+inf:-1 |
851 | 5:inf:-1 |
852 | 5:inf:-1 |
853 | -5:-inf:1 |
854 | -5:-inf:1 |
855 | # return undef |
856 | +inf:NaN: |
857 | NaN:inf: |
858 | -inf:NaN: |
859 | NaN:-inf: |
860 | &binc |
861 | abc:NaN |
862 | +inf:inf |
863 | -inf:-inf |
864 | +0:+1 |
865 | +1:+2 |
866 | -1:+0 |
867 | &bdec |
868 | abc:NaN |
869 | +inf:inf |
870 | -inf:-inf |
871 | +0:-1 |
872 | +1:+0 |
873 | -1:-2 |
874 | &badd |
875 | abc:abc:NaN |
876 | abc:+0:NaN |
877 | +0:abc:NaN |
878 | +inf:-inf:0 |
879 | -inf:+inf:0 |
880 | +inf:+inf:inf |
881 | -inf:-inf:-inf |
882 | baddNaN:+inf:NaN |
883 | baddNaN:+inf:NaN |
884 | +inf:baddNaN:NaN |
885 | -inf:baddNaN:NaN |
886 | +0:+0:+0 |
887 | +1:+0:+1 |
888 | +0:+1:+1 |
889 | +1:+1:+2 |
890 | -1:+0:-1 |
891 | +0:-1:-1 |
892 | -1:-1:-2 |
893 | -1:+1:+0 |
894 | +1:-1:+0 |
895 | +9:+1:+10 |
896 | +99:+1:+100 |
897 | +999:+1:+1000 |
898 | +9999:+1:+10000 |
899 | +99999:+1:+100000 |
900 | +999999:+1:+1000000 |
901 | +9999999:+1:+10000000 |
902 | +99999999:+1:+100000000 |
903 | +999999999:+1:+1000000000 |
904 | +9999999999:+1:+10000000000 |
905 | +99999999999:+1:+100000000000 |
906 | +10:-1:+9 |
907 | +100:-1:+99 |
908 | +1000:-1:+999 |
909 | +10000:-1:+9999 |
910 | +100000:-1:+99999 |
911 | +1000000:-1:+999999 |
912 | +10000000:-1:+9999999 |
913 | +100000000:-1:+99999999 |
914 | +1000000000:-1:+999999999 |
915 | +10000000000:-1:+9999999999 |
916 | +123456789:+987654321:+1111111110 |
917 | -123456789:+987654321:+864197532 |
918 | -123456789:-987654321:-1111111110 |
919 | +123456789:-987654321:-864197532 |
920 | &bsub |
921 | abc:abc:NaN |
922 | abc:+0:NaN |
923 | +0:abc:NaN |
924 | +inf:-inf:inf |
925 | -inf:+inf:-inf |
926 | +inf:+inf:0 |
927 | -inf:-inf:0 |
928 | +0:+0:+0 |
929 | +1:+0:+1 |
930 | +0:+1:-1 |
931 | +1:+1:+0 |
932 | -1:+0:-1 |
933 | +0:-1:+1 |
934 | -1:-1:+0 |
935 | -1:+1:-2 |
936 | +1:-1:+2 |
937 | +9:+1:+8 |
938 | +99:+1:+98 |
939 | +999:+1:+998 |
940 | +9999:+1:+9998 |
941 | +99999:+1:+99998 |
942 | +999999:+1:+999998 |
943 | +9999999:+1:+9999998 |
944 | +99999999:+1:+99999998 |
945 | +999999999:+1:+999999998 |
946 | +9999999999:+1:+9999999998 |
947 | +99999999999:+1:+99999999998 |
948 | +10:-1:+11 |
949 | +100:-1:+101 |
950 | +1000:-1:+1001 |
951 | +10000:-1:+10001 |
952 | +100000:-1:+100001 |
953 | +1000000:-1:+1000001 |
954 | +10000000:-1:+10000001 |
955 | +100000000:-1:+100000001 |
956 | +1000000000:-1:+1000000001 |
957 | +10000000000:-1:+10000000001 |
958 | +123456789:+987654321:-864197532 |
959 | -123456789:+987654321:-1111111110 |
960 | -123456789:-987654321:+864197532 |
961 | +123456789:-987654321:+1111111110 |
962 | &bmul |
963 | abc:abc:NaN |
964 | abc:+0:NaN |
965 | +0:abc:NaN |
966 | NaNmul:+inf:NaN |
967 | NaNmul:-inf:NaN |
968 | -inf:NaNmul:NaN |
969 | +inf:NaNmul:NaN |
970 | +inf:+inf:inf |
971 | +inf:-inf:-inf |
972 | -inf:+inf:-inf |
973 | -inf:-inf:inf |
974 | +0:+0:+0 |
975 | +0:+1:+0 |
976 | +1:+0:+0 |
977 | +0:-1:+0 |
978 | -1:+0:+0 |
979 | +123456789123456789:+0:+0 |
980 | +0:+123456789123456789:+0 |
981 | -1:-1:+1 |
982 | -1:+1:-1 |
983 | +1:-1:-1 |
984 | +1:+1:+1 |
985 | +2:+3:+6 |
986 | -2:+3:-6 |
987 | +2:-3:-6 |
988 | -2:-3:+6 |
989 | +111:+111:+12321 |
990 | +10101:+10101:+102030201 |
991 | +1001001:+1001001:+1002003002001 |
992 | +100010001:+100010001:+10002000300020001 |
993 | +10000100001:+10000100001:+100002000030000200001 |
994 | +11111111111:+9:+99999999999 |
995 | +22222222222:+9:+199999999998 |
996 | +33333333333:+9:+299999999997 |
997 | +44444444444:+9:+399999999996 |
998 | +55555555555:+9:+499999999995 |
999 | +66666666666:+9:+599999999994 |
1000 | +77777777777:+9:+699999999993 |
1001 | +88888888888:+9:+799999999992 |
1002 | +99999999999:+9:+899999999991 |
1003 | +25:+25:+625 |
1004 | +12345:+12345:+152399025 |
1005 | +99999:+11111:+1111088889 |
1006 | 9999:10000:99990000 |
1007 | 99999:100000:9999900000 |
1008 | 999999:1000000:999999000000 |
1009 | 9999999:10000000:99999990000000 |
1010 | 99999999:100000000:9999999900000000 |
1011 | 999999999:1000000000:999999999000000000 |
1012 | 9999999999:10000000000:99999999990000000000 |
1013 | 99999999999:100000000000:9999999999900000000000 |
1014 | 999999999999:1000000000000:999999999999000000000000 |
1015 | 9999999999999:10000000000000:99999999999990000000000000 |
1016 | 99999999999999:100000000000000:9999999999999900000000000000 |
1017 | 999999999999999:1000000000000000:999999999999999000000000000000 |
1018 | 9999999999999999:10000000000000000:99999999999999990000000000000000 |
1019 | 99999999999999999:100000000000000000:9999999999999999900000000000000000 |
1020 | 999999999999999999:1000000000000000000:999999999999999999000000000000000000 |
1021 | 9999999999999999999:10000000000000000000:99999999999999999990000000000000000000 |
1022 | &bdiv-list |
1023 | 100:20:5,0 |
1024 | 4095:4095:1,0 |
1025 | -4095:-4095:1,0 |
1026 | 4095:-4095:-1,0 |
1027 | -4095:4095:-1,0 |
1028 | 123:2:61,1 |
1029 | # inf handling and general remainder |
1030 | 5:8:0,5 |
1031 | 0:8:0,0 |
1032 | 11:2:5,1 |
1033 | 11:-2:-5,-1 |
1034 | -11:2:-5,1 |
1035 | # see table in documentation in MBI |
1036 | 0:inf:0,0 |
1037 | 0:-inf:0,0 |
1038 | 5:inf:0,5 |
1039 | 5:-inf:0,5 |
1040 | -5:inf:0,-5 |
1041 | -5:-inf:0,-5 |
1042 | inf:5:inf,0 |
1043 | -inf:5:-inf,0 |
1044 | inf:-5:-inf,0 |
1045 | -inf:-5:inf,0 |
1046 | 5:5:1,0 |
1047 | -5:-5:1,0 |
1048 | inf:inf:1,0 |
1049 | -inf:-inf:1,0 |
1050 | -inf:inf:-1,0 |
1051 | inf:-inf:-1,0 |
1052 | 8:0:inf,8 |
1053 | inf:0:inf,inf |
1054 | # exceptions to reminder rule |
1055 | -8:0:-inf,-8 |
1056 | -inf:0:-inf,-inf |
1057 | 0:0:NaN,NaN |
1058 | &bdiv |
1059 | abc:abc:NaN |
1060 | abc:+1:NaN |
1061 | +1:abc:NaN |
1062 | +0:+0:NaN |
1063 | # inf handling (see table in doc) |
1064 | 0:inf:0 |
1065 | 0:-inf:0 |
1066 | 5:inf:0 |
1067 | 5:-inf:0 |
1068 | -5:inf:0 |
1069 | -5:-inf:0 |
1070 | inf:5:inf |
1071 | -inf:5:-inf |
1072 | inf:-5:-inf |
1073 | -inf:-5:inf |
1074 | 5:5:1 |
1075 | -5:-5:1 |
1076 | inf:inf:1 |
1077 | -inf:-inf:1 |
1078 | -inf:inf:-1 |
1079 | inf:-inf:-1 |
1080 | 8:0:inf |
1081 | inf:0:inf |
1082 | -8:0:-inf |
1083 | -inf:0:-inf |
1084 | 0:0:NaN |
1085 | 11:2:5 |
1086 | -11:-2:5 |
1087 | -11:2:-5 |
1088 | 11:-2:-5 |
1089 | +0:+1:+0 |
1090 | +0:-1:+0 |
1091 | +1:+1:+1 |
1092 | -1:-1:+1 |
1093 | +1:-1:-1 |
1094 | -1:+1:-1 |
1095 | +1:+2:+0 |
1096 | +2:+1:+2 |
1097 | +1:+26:+0 |
1098 | +1000000000:+9:+111111111 |
1099 | +2000000000:+9:+222222222 |
1100 | +3000000000:+9:+333333333 |
1101 | +4000000000:+9:+444444444 |
1102 | +5000000000:+9:+555555555 |
1103 | +6000000000:+9:+666666666 |
1104 | +7000000000:+9:+777777777 |
1105 | +8000000000:+9:+888888888 |
1106 | +9000000000:+9:+1000000000 |
1107 | +35500000:+113:+314159 |
1108 | +71000000:+226:+314159 |
1109 | +106500000:+339:+314159 |
1110 | +1000000000:+3:+333333333 |
1111 | +10:+5:+2 |
1112 | +100:+4:+25 |
1113 | +1000:+8:+125 |
1114 | +10000:+16:+625 |
1115 | +999999999999:+9:+111111111111 |
1116 | +999999999999:+99:+10101010101 |
1117 | +999999999999:+999:+1001001001 |
1118 | +999999999999:+9999:+100010001 |
1119 | +999999999999999:+99999:+10000100001 |
1120 | +1111088889:+99999:+11111 |
1121 | -5:-3:1 |
1122 | -5:3:-1 |
1123 | 4:3:1 |
1124 | 4:-3:-1 |
1125 | 1:3:0 |
1126 | 1:-3:0 |
1127 | -2:-3:0 |
1128 | -2:3:0 |
1129 | 8:3:2 |
1130 | -8:3:-2 |
1131 | 14:-3:-4 |
1132 | -14:3:-4 |
1133 | -14:-3:4 |
1134 | 14:3:4 |
1135 | # bug in Calc with '99999' vs $BASE-1 |
1136 | 10000000000000000000000000000000000000000000000000000000000000000000000000000000000:10000000375084540248994272022843165711074:999999962491547381984643365663244474111576 |
1137 | &bmod |
1138 | # inf handling, see table in doc |
1139 | 0:inf:0 |
1140 | 0:-inf:0 |
1141 | 5:inf:5 |
1142 | 5:-inf:5 |
1143 | -5:inf:-5 |
1144 | -5:-inf:-5 |
1145 | inf:5:0 |
1146 | -inf:5:0 |
1147 | inf:-5:0 |
1148 | -inf:-5:0 |
1149 | 5:5:0 |
1150 | -5:-5:0 |
1151 | inf:inf:0 |
1152 | -inf:-inf:0 |
1153 | -inf:inf:0 |
1154 | inf:-inf:0 |
1155 | 8:0:8 |
1156 | inf:0:inf |
1157 | # exceptions to reminder rule |
1158 | -inf:0:-inf |
1159 | -8:0:-8 |
1160 | 0:0:NaN |
1161 | abc:abc:NaN |
1162 | abc:+1:abc:NaN |
1163 | +1:abc:NaN |
1164 | +0:+0:NaN |
1165 | +0:+1:+0 |
1166 | +1:+0:+1 |
1167 | +0:-1:+0 |
1168 | -1:+0:-1 |
1169 | +1:+1:+0 |
1170 | -1:-1:+0 |
1171 | +1:-1:+0 |
1172 | -1:+1:+0 |
1173 | +1:+2:+1 |
1174 | +2:+1:+0 |
1175 | +1000000000:+9:+1 |
1176 | +2000000000:+9:+2 |
1177 | +3000000000:+9:+3 |
1178 | +4000000000:+9:+4 |
1179 | +5000000000:+9:+5 |
1180 | +6000000000:+9:+6 |
1181 | +7000000000:+9:+7 |
1182 | +8000000000:+9:+8 |
1183 | +9000000000:+9:+0 |
1184 | +35500000:+113:+33 |
1185 | +71000000:+226:+66 |
1186 | +106500000:+339:+99 |
1187 | +1000000000:+3:+1 |
1188 | +10:+5:+0 |
1189 | +100:+4:+0 |
1190 | +1000:+8:+0 |
1191 | +10000:+16:+0 |
1192 | +999999999999:+9:+0 |
1193 | +999999999999:+99:+0 |
1194 | +999999999999:+999:+0 |
1195 | +999999999999:+9999:+0 |
1196 | +999999999999999:+99999:+0 |
1197 | -9:+5:+1 |
1198 | +9:-5:-1 |
1199 | -9:-5:-4 |
1200 | -5:3:1 |
1201 | -2:3:1 |
1202 | 4:3:1 |
1203 | 1:3:1 |
1204 | -5:-3:-2 |
1205 | -2:-3:-2 |
1206 | 4:-3:-2 |
1207 | 1:-3:-2 |
1208 | 4095:4095:0 |
027dc388 |
1209 | 100041000510123:3:0 |
1210 | 152403346:12345:4321 |
6854fd01 |
1211 | &bgcd |
1212 | abc:abc:NaN |
1213 | abc:+0:NaN |
1214 | +0:abc:NaN |
1215 | +0:+0:+0 |
1216 | +0:+1:+1 |
1217 | +1:+0:+1 |
1218 | +1:+1:+1 |
1219 | +2:+3:+1 |
1220 | +3:+2:+1 |
1221 | -3:+2:+1 |
1222 | +100:+625:+25 |
1223 | +4096:+81:+1 |
1224 | +1034:+804:+2 |
1225 | +27:+90:+56:+1 |
1226 | +27:+90:+54:+9 |
1227 | &blcm |
1228 | abc:abc:NaN |
1229 | abc:+0:NaN |
1230 | +0:abc:NaN |
1231 | +0:+0:NaN |
1232 | +1:+0:+0 |
1233 | +0:+1:+0 |
1234 | +27:+90:+270 |
1235 | +1034:+804:+415668 |
1236 | &band |
1237 | abc:abc:NaN |
1238 | abc:0:NaN |
1239 | 0:abc:NaN |
1240 | 1:2:0 |
1241 | 3:2:2 |
1242 | +8:+2:+0 |
1243 | +281474976710656:+0:+0 |
1244 | +281474976710656:+1:+0 |
1245 | +281474976710656:+281474976710656:+281474976710656 |
1246 | -2:-3:-4 |
1247 | -1:-1:-1 |
1248 | -6:-6:-6 |
1249 | -7:-4:-8 |
1250 | -7:4:0 |
1251 | -4:7:4 |
394e6ffb |
1252 | # equal arguments are treated special, so also do some test with unequal ones |
1253 | 0xFFFF:0xFFFF:0x0xFFFF |
1254 | 0xFFFFFF:0xFFFFFF:0x0xFFFFFF |
1255 | 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF |
1256 | 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1257 | 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1258 | 0xF0F0:0xF0F0:0x0xF0F0 |
1259 | 0x0F0F:0x0F0F:0x0x0F0F |
1260 | 0xF0F0F0:0xF0F0F0:0x0xF0F0F0 |
1261 | 0x0F0F0F:0x0F0F0F:0x0x0F0F0F |
1262 | 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 |
1263 | 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F |
1264 | 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 |
1265 | 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F |
1266 | 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 |
1267 | 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F |
1268 | 0x1F0F0F0F0F0F:0x3F0F0F0F0F0F:0x0x1F0F0F0F0F0F |
6854fd01 |
1269 | &bior |
1270 | abc:abc:NaN |
1271 | abc:0:NaN |
1272 | 0:abc:NaN |
1273 | 1:2:3 |
1274 | +8:+2:+10 |
1275 | +281474976710656:+0:+281474976710656 |
1276 | +281474976710656:+1:+281474976710657 |
1277 | +281474976710656:+281474976710656:+281474976710656 |
1278 | -2:-3:-1 |
1279 | -1:-1:-1 |
1280 | -6:-6:-6 |
1281 | -7:4:-3 |
1282 | -4:7:-1 |
394e6ffb |
1283 | # equal arguments are treated special, so also do some test with unequal ones |
1284 | 0xFFFF:0xFFFF:0x0xFFFF |
1285 | 0xFFFFFF:0xFFFFFF:0x0xFFFFFF |
1286 | 0xFFFFFFFF:0xFFFFFFFF:0x0xFFFFFFFF |
1287 | 0xFFFFFFFFFF:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1288 | 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1289 | 0:0xFFFF:0x0xFFFF |
1290 | 0:0xFFFFFF:0x0xFFFFFF |
1291 | 0:0xFFFFFFFF:0x0xFFFFFFFF |
1292 | 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1293 | 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1294 | 0xFFFF:0:0x0xFFFF |
1295 | 0xFFFFFF:0:0x0xFFFFFF |
1296 | 0xFFFFFFFF:0:0x0xFFFFFFFF |
1297 | 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF |
1298 | 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF |
1299 | 0xF0F0:0xF0F0:0x0xF0F0 |
1300 | 0x0F0F:0x0F0F:0x0x0F0F |
1301 | 0xF0F0:0x0F0F:0x0xFFFF |
1302 | 0xF0F0F0:0xF0F0F0:0x0xF0F0F0 |
1303 | 0x0F0F0F:0x0F0F0F:0x0x0F0F0F |
1304 | 0x0F0F0F:0xF0F0F0:0x0xFFFFFF |
1305 | 0xF0F0F0F0:0xF0F0F0F0:0x0xF0F0F0F0 |
1306 | 0x0F0F0F0F:0x0F0F0F0F:0x0x0F0F0F0F |
1307 | 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF |
1308 | 0xF0F0F0F0F0:0xF0F0F0F0F0:0x0xF0F0F0F0F0 |
1309 | 0x0F0F0F0F0F:0x0F0F0F0F0F:0x0x0F0F0F0F0F |
1310 | 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF |
1311 | 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0x0xF0F0F0F0F0F0 |
1312 | 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0x0x0F0F0F0F0F0F |
1313 | 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF |
1314 | 0x1F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF |
6854fd01 |
1315 | &bxor |
1316 | abc:abc:NaN |
1317 | abc:0:NaN |
1318 | 0:abc:NaN |
1319 | 1:2:3 |
1320 | +8:+2:+10 |
1321 | +281474976710656:+0:+281474976710656 |
1322 | +281474976710656:+1:+281474976710657 |
1323 | +281474976710656:+281474976710656:+0 |
1324 | -2:-3:3 |
1325 | -1:-1:0 |
1326 | -6:-6:0 |
1327 | -7:4:-3 |
1328 | -4:7:-5 |
1329 | 4:-7:-3 |
1330 | -4:-7:5 |
394e6ffb |
1331 | # equal arguments are treated special, so also do some test with unequal ones |
1332 | 0xFFFF:0xFFFF:0 |
1333 | 0xFFFFFF:0xFFFFFF:0 |
1334 | 0xFFFFFFFF:0xFFFFFFFF:0 |
1335 | 0xFFFFFFFFFF:0xFFFFFFFFFF:0 |
1336 | 0xFFFFFFFFFFFF:0xFFFFFFFFFFFF:0 |
1337 | 0:0xFFFF:0x0xFFFF |
1338 | 0:0xFFFFFF:0x0xFFFFFF |
1339 | 0:0xFFFFFFFF:0x0xFFFFFFFF |
1340 | 0:0xFFFFFFFFFF:0x0xFFFFFFFFFF |
1341 | 0:0xFFFFFFFFFFFF:0x0xFFFFFFFFFFFF |
1342 | 0xFFFF:0:0x0xFFFF |
1343 | 0xFFFFFF:0:0x0xFFFFFF |
1344 | 0xFFFFFFFF:0:0x0xFFFFFFFF |
1345 | 0xFFFFFFFFFF:0:0x0xFFFFFFFFFF |
1346 | 0xFFFFFFFFFFFF:0:0x0xFFFFFFFFFFFF |
1347 | 0xF0F0:0xF0F0:0 |
1348 | 0x0F0F:0x0F0F:0 |
1349 | 0xF0F0:0x0F0F:0x0xFFFF |
1350 | 0xF0F0F0:0xF0F0F0:0 |
1351 | 0x0F0F0F:0x0F0F0F:0 |
1352 | 0x0F0F0F:0xF0F0F0:0x0xFFFFFF |
1353 | 0xF0F0F0F0:0xF0F0F0F0:0 |
1354 | 0x0F0F0F0F:0x0F0F0F0F:0 |
1355 | 0x0F0F0F0F:0xF0F0F0F0:0x0xFFFFFFFF |
1356 | 0xF0F0F0F0F0:0xF0F0F0F0F0:0 |
1357 | 0x0F0F0F0F0F:0x0F0F0F0F0F:0 |
1358 | 0x0F0F0F0F0F:0xF0F0F0F0F0:0x0xFFFFFFFFFF |
1359 | 0xF0F0F0F0F0F0:0xF0F0F0F0F0F0:0 |
1360 | 0x0F0F0F0F0F0F:0x0F0F0F0F0F0F:0 |
1361 | 0x0F0F0F0F0F0F:0xF0F0F0F0F0F0:0x0xFFFFFFFFFFFF |
6854fd01 |
1362 | &bnot |
1363 | abc:NaN |
1364 | +0:-1 |
1365 | +8:-9 |
1366 | +281474976710656:-281474976710657 |
1367 | -1:0 |
1368 | -2:1 |
1369 | -12:11 |
1370 | &digit |
1371 | 0:0:0 |
1372 | 12:0:2 |
1373 | 12:1:1 |
1374 | 123:0:3 |
1375 | 123:1:2 |
1376 | 123:2:1 |
1377 | 123:-1:1 |
1378 | 123:-2:2 |
1379 | 123:-3:3 |
1380 | 123456:0:6 |
1381 | 123456:1:5 |
1382 | 123456:2:4 |
1383 | 123456:3:3 |
1384 | 123456:4:2 |
1385 | 123456:5:1 |
1386 | 123456:-1:1 |
1387 | 123456:-2:2 |
1388 | 123456:-3:3 |
1389 | 100000:-3:0 |
1390 | 100000:0:0 |
1391 | 100000:1:0 |
1392 | &mantissa |
1393 | abc:NaN |
1394 | 1e4:1 |
1395 | 2e0:2 |
1396 | 123:123 |
1397 | -1:-1 |
1398 | -2:-2 |
1399 | +inf:inf |
1400 | -inf:-inf |
1401 | &exponent |
1402 | abc:NaN |
1403 | 1e4:4 |
1404 | 2e0:0 |
1405 | 123:0 |
1406 | -1:0 |
1407 | -2:0 |
1408 | 0:1 |
1409 | +inf:inf |
1410 | -inf:inf |
1411 | &parts |
1412 | abc:NaN,NaN |
1413 | 1e4:1,4 |
1414 | 2e0:2,0 |
1415 | 123:123,0 |
1416 | -1:-1,0 |
1417 | -2:-2,0 |
1418 | 0:0,1 |
1419 | +inf:inf,inf |
1420 | -inf:-inf,inf |
1421 | &bpow |
1422 | abc:12:NaN |
1423 | 12:abc:NaN |
1424 | 0:0:1 |
1425 | 0:1:0 |
1426 | 0:2:0 |
1427 | 0:-1:NaN |
1428 | 0:-2:NaN |
1429 | 1:0:1 |
1430 | 1:1:1 |
1431 | 1:2:1 |
1432 | 1:3:1 |
1433 | 1:-1:1 |
1434 | 1:-2:1 |
1435 | 1:-3:1 |
1436 | 2:0:1 |
1437 | 2:1:2 |
1438 | 2:2:4 |
1439 | 2:3:8 |
1440 | 3:3:27 |
1441 | 2:-1:NaN |
1442 | -2:-1:NaN |
1443 | 2:-2:NaN |
1444 | -2:-2:NaN |
1445 | +inf:1234500012:inf |
1446 | -inf:1234500012:-inf |
1447 | +inf:-12345000123:inf |
1448 | -inf:-12345000123:-inf |
1449 | # 1 ** -x => 1 / (1 ** x) |
1450 | -1:0:1 |
1451 | -2:0:1 |
1452 | -1:1:-1 |
1453 | -1:2:1 |
1454 | -1:3:-1 |
1455 | -1:4:1 |
1456 | -1:5:-1 |
1457 | -1:-1:-1 |
1458 | -1:-2:1 |
1459 | -1:-3:-1 |
1460 | -1:-4:1 |
1461 | 10:2:100 |
1462 | 10:3:1000 |
1463 | 10:4:10000 |
1464 | 10:5:100000 |
1465 | 10:6:1000000 |
1466 | 10:7:10000000 |
1467 | 10:8:100000000 |
1468 | 10:9:1000000000 |
1469 | 10:20:100000000000000000000 |
1470 | 123456:2:15241383936 |
1471 | &length |
1472 | 100:3 |
1473 | 10:2 |
1474 | 1:1 |
1475 | 0:1 |
1476 | 12345:5 |
1477 | 10000000000000000:17 |
1478 | -123:3 |
1479 | 215960156869840440586892398248:30 |
1480 | &bsqrt |
394e6ffb |
1481 | 145:12 |
6854fd01 |
1482 | 144:12 |
394e6ffb |
1483 | 143:11 |
6854fd01 |
1484 | 16:4 |
394e6ffb |
1485 | 170:13 |
1486 | 169:13 |
1487 | 168:12 |
6854fd01 |
1488 | 4:2 |
394e6ffb |
1489 | 3:1 |
6854fd01 |
1490 | 2:1 |
394e6ffb |
1491 | 9:3 |
6854fd01 |
1492 | 12:3 |
1493 | 256:16 |
1494 | 100000000:10000 |
1495 | 4000000000000:2000000 |
394e6ffb |
1496 | 152399026:12345 |
1497 | 152399025:12345 |
1498 | 152399024:12344 |
6854fd01 |
1499 | 1:1 |
1500 | 0:0 |
1501 | -2:NaN |
394e6ffb |
1502 | -123:NaN |
6854fd01 |
1503 | Nan:NaN |
394e6ffb |
1504 | +inf:NaN |
6854fd01 |
1505 | &bround |
1506 | $round_mode('trunc') |
1507 | 0:12:0 |
1508 | NaNbround:12:NaN |
1509 | +inf:12:inf |
1510 | -inf:12:-inf |
1511 | 1234:0:1234 |
1512 | 1234:2:1200 |
1513 | 123456:4:123400 |
1514 | 123456:5:123450 |
1515 | 123456:6:123456 |
1516 | +10123456789:5:+10123000000 |
1517 | -10123456789:5:-10123000000 |
1518 | +10123456789:9:+10123456700 |
1519 | -10123456789:9:-10123456700 |
1520 | +101234500:6:+101234000 |
1521 | -101234500:6:-101234000 |
1522 | #+101234500:-4:+101234000 |
1523 | #-101234500:-4:-101234000 |
1524 | $round_mode('zero') |
1525 | +20123456789:5:+20123000000 |
1526 | -20123456789:5:-20123000000 |
1527 | +20123456789:9:+20123456800 |
1528 | -20123456789:9:-20123456800 |
1529 | +201234500:6:+201234000 |
1530 | -201234500:6:-201234000 |
1531 | #+201234500:-4:+201234000 |
1532 | #-201234500:-4:-201234000 |
1533 | +12345000:4:12340000 |
1534 | -12345000:4:-12340000 |
1535 | $round_mode('+inf') |
1536 | +30123456789:5:+30123000000 |
1537 | -30123456789:5:-30123000000 |
1538 | +30123456789:9:+30123456800 |
1539 | -30123456789:9:-30123456800 |
1540 | +301234500:6:+301235000 |
1541 | -301234500:6:-301234000 |
1542 | #+301234500:-4:+301235000 |
1543 | #-301234500:-4:-301234000 |
1544 | +12345000:4:12350000 |
1545 | -12345000:4:-12340000 |
1546 | $round_mode('-inf') |
1547 | +40123456789:5:+40123000000 |
1548 | -40123456789:5:-40123000000 |
1549 | +40123456789:9:+40123456800 |
1550 | -40123456789:9:-40123456800 |
1551 | +401234500:6:+401234000 |
1552 | +401234500:6:+401234000 |
1553 | #-401234500:-4:-401235000 |
1554 | #-401234500:-4:-401235000 |
1555 | +12345000:4:12340000 |
1556 | -12345000:4:-12350000 |
1557 | $round_mode('odd') |
1558 | +50123456789:5:+50123000000 |
1559 | -50123456789:5:-50123000000 |
1560 | +50123456789:9:+50123456800 |
1561 | -50123456789:9:-50123456800 |
1562 | +501234500:6:+501235000 |
1563 | -501234500:6:-501235000 |
1564 | #+501234500:-4:+501235000 |
1565 | #-501234500:-4:-501235000 |
1566 | +12345000:4:12350000 |
1567 | -12345000:4:-12350000 |
1568 | $round_mode('even') |
1569 | +60123456789:5:+60123000000 |
1570 | -60123456789:5:-60123000000 |
1571 | +60123456789:9:+60123456800 |
1572 | -60123456789:9:-60123456800 |
1573 | +601234500:6:+601234000 |
1574 | -601234500:6:-601234000 |
1575 | #+601234500:-4:+601234000 |
1576 | #-601234500:-4:-601234000 |
1577 | #-601234500:-9:0 |
1578 | #-501234500:-9:0 |
1579 | #-601234500:-8:0 |
1580 | #-501234500:-8:0 |
1581 | +1234567:7:1234567 |
1582 | +1234567:6:1234570 |
1583 | +12345000:4:12340000 |
1584 | -12345000:4:-12340000 |
1585 | &is_zero |
1586 | 0:1 |
1587 | NaNzero:0 |
1588 | +inf:0 |
1589 | -inf:0 |
1590 | 123:0 |
1591 | -1:0 |
1592 | 1:0 |
1593 | &is_one |
1594 | 0:0 |
1595 | NaNone:0 |
1596 | +inf:0 |
1597 | -inf:0 |
1598 | 1:1 |
1599 | 2:0 |
1600 | -1:0 |
1601 | -2:0 |
1602 | # floor and ceil tests are pretty pointless in integer space...but play safe |
1603 | &bfloor |
1604 | 0:0 |
1605 | NaNfloor:NaN |
1606 | +inf:inf |
1607 | -inf:-inf |
1608 | -1:-1 |
1609 | -2:-2 |
1610 | 2:2 |
1611 | 3:3 |
1612 | abc:NaN |
1613 | &bceil |
1614 | NaNceil:NaN |
1615 | +inf:inf |
1616 | -inf:-inf |
1617 | 0:0 |
1618 | -1:-1 |
1619 | -2:-2 |
1620 | 2:2 |
1621 | 3:3 |
1622 | abc:NaN |
1623 | &as_hex |
1624 | 128:0x80 |
1625 | -128:-0x80 |
1626 | 0:0x0 |
1627 | -0:0x0 |
1628 | 1:0x1 |
1629 | 0x123456789123456789:0x123456789123456789 |
1630 | +inf:inf |
1631 | -inf:-inf |
1632 | NaNas_hex:NaN |
1633 | &as_bin |
1634 | 128:0b10000000 |
1635 | -128:-0b10000000 |
1636 | 0:0b0 |
1637 | -0:0b0 |
1638 | 1:0b1 |
1639 | 0b1010111101010101010110110110110110101:0b1010111101010101010110110110110110101 |
1640 | +inf:inf |
1641 | -inf:-inf |
1642 | NaNas_bin:NaN |