6 # Verify that addition/subtraction properly upgrade to doubles.
7 # These tests are only significant on machines with 32 bit longs,
8 # and two's complement negation, but shouldn't fail anywhere.
12 cmp_ok($a, '==', 2147483648);
16 cmp_ok($a, '==', 2147483648);
20 cmp_ok($a, '==', 2147483648);
24 cmp_ok($a, '==', -2147483649);
28 cmp_ok($a, '==', -2147483649);
32 cmp_ok($a, '==', -2147483649);
37 cmp_ok($a, '==', -2147483649);
42 cmp_ok($a, '==', -2147483649);
47 cmp_ok($a, '==', -2147483649);
52 cmp_ok($b, '==', -$a-1);
57 cmp_ok($b, '==', -$a-1);
62 cmp_ok($b, '==', -(++$a));
65 is($a++, '0', "postinc undef returns '0'");
68 is($a--, undef, "postdec undef returns undef");
70 # Verify that shared hash keys become unshared.
73 my ($orig, $suspect) = @_;
75 while (my ($key, $value) = each %$suspect) {
76 if (exists $orig->{$key}) {
77 if ($orig->{$key} ne $value) {
78 print "# key '$key' was '$orig->{$key}' now '$value'\n";
82 print "# key '$key' is '$orig->{$key}', unexpect.\n";
86 foreach (keys %$orig) {
87 next if (exists $suspect->{$_});
88 print "# key '$_' was '$orig->{$_}' now missing\n";
94 my (%orig) = my (%inc) = my (%dec) = my (%postinc) = my (%postdec)
95 = (1 => 1, ab => "ab");
96 my %up = (1=>2, ab => 'ac');
97 my %down = (1=>0, ab => -1);
107 check_same (\%orig, \%inc);
109 foreach (keys %dec) {
117 check_same (\%orig, \%dec);
119 foreach (keys %postinc) {
120 my $ans = $postinc{$_};
127 check_same (\%orig, \%postinc);
129 foreach (keys %postdec) {
130 my $ans = $postdec{$_};
137 check_same (\%orig, \%postdec);
140 no warnings 'uninitialized';
154 cmp_ok($p, '==', -1);
160 cmp_ok($a, '==', 2147483647);
165 cmp_ok($a, '==', 2147483647);
171 cmp_ok($x, '==', 1, "(void) i_postinc");
173 cmp_ok($x, '==', 0, "(void) i_postdec");
176 # I'm sure that there's an IBM format with a 48 bit mantissa
177 # IEEE doubles have a 53 bit mantissa
178 # 80 bit long doubles have a 64 bit mantissa
179 # sparcs have a 112 bit mantissa for their long doubles. Just to be awkward :-)
181 my $h_uv_max = 1 + (~0 >> 1);
183 for my $n (47..113) {
184 my $power_of_2 = 2**$n;
185 my $plus_1 = $power_of_2 + 1;
186 next if $plus_1 != $power_of_2;
187 my ($start_p, $start_n);
188 if ($h_uv_max > $power_of_2 / 2) {
189 my $uv_max = 1 + 2 * (~0 >> 1);
190 # UV_MAX is 2**$something - 1, so subtract 1 to get the start value
191 $start_p = $uv_max - 1;
192 # whereas IV_MIN is -(2**$something), so subtract 2
193 $start_n = -$h_uv_max + 2;
194 print "# Mantissa overflows at 2**$n ($power_of_2)\n";
195 print "# But max UV ($uv_max) is greater so testing that\n";
197 print "# Testing 2**$n ($power_of_2) which overflows the mantissa\n";
198 $start_p = int($power_of_2 - 2);
199 $start_n = -$start_p;
200 my $check = $power_of_2 - 2;
201 die "Something wrong with our rounding assumptions: $check vs $start_p"
202 unless $start_p == $check;
205 foreach ([$start_p, '++$i', 'pre-inc', 'inc'],
206 [$start_p, '$i++', 'post-inc', 'inc'],
207 [$start_n, '--$i', 'pre-dec', 'dec'],
208 [$start_n, '$i--', 'post-dec', 'dec']) {
209 my ($start, $action, $description, $act) = @$_;
210 my $code = eval << "EOC" or die $@;
212 no warnings 'imprecision';
220 warning_is($code, undef, "$description under no warnings 'imprecision'");
222 $code = eval << "EOC" or die $@;
224 use warnings 'imprecision';
232 warnings_like($code, [(qr/Lost precision when ${act}rementing -?\d+/) x 2],
233 "$description under use warnings 'imprecision'");
239 die "Could not find a value which overflows the mantissa" unless $found;
241 # these will segfault if they fail
243 sub PVBM () { 'foo' }
244 { my $dummy = index 'foo', PVBM }
246 isnt(scalar eval { my $pvbm = PVBM; $pvbm++ }, undef);
247 isnt(scalar eval { my $pvbm = PVBM; $pvbm-- }, undef);
248 isnt(scalar eval { my $pvbm = PVBM; ++$pvbm }, undef);
249 isnt(scalar eval { my $pvbm = PVBM; --$pvbm }, undef);
253 # don't use pad TARG when the thing you're copying is a ref, or the referent
258 sub DESTROY { $x = 1 }
262 my $b = $_ ? $a++ : $a--;
264 ::is($x, 1, "9466 case $_");