|
| 1 | +#!./perl -- -*- mode: cperl; cperl-indent-level: 4 -*- |
| 2 | + |
| 3 | +BEGIN { |
| 4 | + chdir 't' if -d 't'; |
| 5 | + @INC = ( '.', '../lib' ); |
| 6 | +} |
| 7 | + |
| 8 | +use strict; |
| 9 | +require '../t/test.pl'; |
| 10 | +plan(8); |
| 11 | + |
| 12 | +$|=1; |
| 13 | +my $a = 18446744073709551614; |
| 14 | + |
| 15 | +# test it at compile-time in constant folding |
| 16 | +use exact_arith; |
| 17 | +my $n = 18446744073709551614 * 2; # => 36893488147419103228, Math::BigInt or *::GMP |
| 18 | +like(ref $n, qr/^Math::BigInt/, '* type (c)'); |
| 19 | +ok($n eq '36893488147419103228', '* val (c)') or |
| 20 | + is($n, '36893488147419103228'); |
| 21 | + |
| 22 | +{ |
| 23 | + no exact_arith; |
| 24 | + my $m = 18446744073709551614 * 2; |
| 25 | + is(ref $m, '', '* no type (c)'); |
| 26 | + is($m, 3.68934881474191e+19, '* no val (c)'); |
| 27 | +} |
| 28 | + |
| 29 | +my $two = 2; |
| 30 | +$n = 18446744073709551614 * $two; # run-time |
| 31 | +like(ref $n, qr/^Math::BigInt/, '* type (r)'); |
| 32 | +ok($n eq '36893488147419103228', '* val (r)') or |
| 33 | + is($n, '36893488147419103228'); |
| 34 | + |
| 35 | +{ |
| 36 | + no exact_arith; |
| 37 | + my $m = 18446744073709551614 * $two; |
| 38 | + is(ref $m, '', '* no type (r)'); |
| 39 | + is($m, 3.68934881474191e+19, '* no val (r)'); |
| 40 | +} |
| 41 | + |
| 42 | +my $c = 18446744073709551614 + 10000; |
| 43 | +like(ref $c, qr/^Math::BigInt/, '+ type (c)'); |
| 44 | +my $r = $a + 10000; |
| 45 | +like(ref $r, qr/^Math::BigInt/, '+ type (r)'); |
| 46 | + |
| 47 | +$c = 18446744073709551624 - 2; |
| 48 | +like(ref $c, qr/^Math::BigInt/, '- type (c)'); |
| 49 | +$r = $c - 1; |
| 50 | +like(ref $r, qr/^Math::BigInt/, '- type (r)'); |
| 51 | + |
| 52 | +$c = 1844674407370955162400 / 0.3; |
| 53 | +like(ref $c, qr/^Math::BigInt/, '/ type (c)'); |
| 54 | +$r = 1844674407370955162400 / 0.3; |
| 55 | +like(ref $r, qr/^Math::BigInt/, '/ type (r)'); |
| 56 | + |
| 57 | +$c = 18446744073709551614 ** 2; |
| 58 | +like(ref $c, qr/^Math::BigInt/, '** type (c)'); |
| 59 | +$r = $a ** 2; |
| 60 | +like(ref $r, qr/^Math::BigInt/, '** type (r)'); |
| 61 | + |
| 62 | +$r = $a++; |
| 63 | +like(ref $r, qr/^Math::BigInt/, '++ type (r)'); |
| 64 | + |
0 commit comments