1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
|
#!./perl
BEGIN {
chdir 't' if -d 't';
@INC = '../lib';
require './test.pl';
eval { my $q = pack "q", 0 };
skip_all('no 64-bit types') if $@;
}
# This could use many more tests.
# so that using > 0xfffffff constants and
# 32+ bit integers don't cause noise
use warnings;
no warnings qw(overflow portable);
use Config;
# as 6 * 6 = 36, the last digit of 6**n will always be six. Hence the last
# digit of 16**n will always be six. Hence 16**n - 1 will always end in 5.
# Assumption is that UVs will always be a multiple of 4 bits long.
my $UV_max = ~0;
die "UV_max eq '$UV_max', doesn't end in 5; your UV isn't 4n bits long :-(."
unless $UV_max =~ /5$/;
my $UV_max_less3 = $UV_max - 3;
my $maths_preserves_UVs = $UV_max_less3 =~ /^\d+2$/; # 5 - 3 is 2.
if ($maths_preserves_UVs) {
print "# This perl's maths preserves all bits of a UV.\n";
} else {
print "# This perl's maths does not preserve all bits of a UV.\n";
}
my $q = 12345678901;
my $r = 23456789012;
my $f = 0xffffffff;
my $x;
my $y;
$x = unpack "q", pack "q", $q;
cmp_ok($x, '==', $q);
cmp_ok($x, '>', $f);
$x = sprintf("%lld", 12345678901);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%lld", $q);
cmp_ok($x, '==', $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%Ld", $q);
cmp_ok($x, '==', $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%qd", $q);
cmp_ok($x, '==', $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%llx", $q);
cmp_ok(hex $x, '==', 0x2dfdc1c35);
cmp_ok(hex $x, '>', $f);
$x = sprintf("%Lx", $q);
cmp_ok(hex $x, '==', 0x2dfdc1c35);
cmp_ok(hex $x, '>', $f);
$x = sprintf("%qx", $q);
cmp_ok(hex $x, '==', 0x2dfdc1c35);
cmp_ok(hex $x, '>', $f);
$x = sprintf("%llo", $q);
cmp_ok(oct "0$x", '==', 0133767016065);
cmp_ok(oct $x, '>', $f);
$x = sprintf("%Lo", $q);
cmp_ok(oct "0$x", '==', 0133767016065);
cmp_ok(oct $x, '>', $f);
$x = sprintf("%qo", $q);
cmp_ok(oct "0$x", '==', 0133767016065);
cmp_ok(oct $x, '>', $f);
$x = sprintf("%llb", $q);
cmp_ok(oct "0b$x", '==', 0b1011011111110111000001110000110101);
cmp_ok(oct "0b$x", '>', $f);
$x = sprintf("%Lb", $q);
cmp_ok(oct "0b$x", '==', 0b1011011111110111000001110000110101);
cmp_ok(oct "0b$x", '>', $f);
$x = sprintf("%qb", $q);
cmp_ok(oct "0b$x", '==', 0b1011011111110111000001110000110101);
cmp_ok(oct "0b$x", '>', $f);
$x = sprintf("%llu", $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%Lu", $q);
cmp_ok($x, '==', $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%qu", $q);
cmp_ok($x, '==', $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%D", $q);
cmp_ok($x, '==', $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%U", $q);
cmp_ok($x, '==', $q);
is($x, $q);
cmp_ok($x, '>', $f);
$x = sprintf("%O", $q);
cmp_ok(oct $x, '==', $q);
cmp_ok(oct $x, '>', $f);
$x = $q + $r;
cmp_ok($x, '==', 35802467913);
cmp_ok($x, '>', $f);
$x = $q - $r;
cmp_ok($x, '==', -11111110111);
cmp_ok(-$x, '>', $f);
SKIP: {
# Unicos has imprecise doubles (14 decimal digits or so),
# especially if operating near the UV/IV limits the low-order bits
# become mangled even by simple arithmetic operations.
skip('too imprecise numbers on unicos') if $^O eq 'unicos';
$x = $q * 1234567;
cmp_ok($x, '==', 15241567763770867);
cmp_ok($x, '>', $f);
$x /= 1234567;
cmp_ok($x, '==', $q);
cmp_ok($x, '>', $f);
$x = 98765432109 % 12345678901;
cmp_ok($x, '==', 901);
# The following 12 tests adapted from op/inc.
$a = 9223372036854775807;
$c = $a++;
cmp_ok($a, '==', 9223372036854775808);
$a = 9223372036854775807;
$c = ++$a;
cmp_ok($a, '==', 9223372036854775808);
cmp_ok($c, '==', $a);
$a = 9223372036854775807;
$c = $a + 1;
cmp_ok($a, '==', 9223372036854775807);
cmp_ok($c, '==', 9223372036854775808);
$a = -9223372036854775808;
{
no warnings 'imprecision';
$c = $a--;
}
cmp_ok($a, '==', -9223372036854775809);
cmp_ok($c, '==', -9223372036854775808);
$a = -9223372036854775808;
{
no warnings 'imprecision';
$c = --$a;
}
cmp_ok($a, '==', -9223372036854775809);
cmp_ok($c, '==', $a);
$a = -9223372036854775808;
$c = $a - 1;
cmp_ok($a, '==', -9223372036854775808);
cmp_ok($c, '==', -9223372036854775809);
$a = 9223372036854775808;
$a = -$a;
{
no warnings 'imprecision';
$c = $a--;
}
cmp_ok($a, '==', -9223372036854775809);
cmp_ok($c, '==', -9223372036854775808);
$a = 9223372036854775808;
$a = -$a;
{
no warnings 'imprecision';
$c = --$a;
}
cmp_ok($a, '==', -9223372036854775809);
cmp_ok($c, '==', $a);
$a = 9223372036854775808;
$a = -$a;
$c = $a - 1;
cmp_ok($a, '==', -9223372036854775808);
cmp_ok($c, '==', -9223372036854775809);
$a = 9223372036854775808;
$b = -$a;
{
no warnings 'imprecision';
$c = $b--;
}
cmp_ok($b, '==', -$a-1);
cmp_ok($c, '==', -$a);
$a = 9223372036854775808;
$b = -$a;
{
no warnings 'imprecision';
$c = --$b;
}
cmp_ok($b, '==', -$a-1);
cmp_ok($c, '==', $b);
$a = 9223372036854775808;
$b = -$a;
$b = $b - 1;
cmp_ok($b, '==', -(++$a));
}
$x = '';
cmp_ok((vec($x, 1, 64) = $q), '==', $q);
cmp_ok(vec($x, 1, 64), '==', $q);
cmp_ok(vec($x, 1, 64), '>', $f);
cmp_ok(vec($x, 0, 64), '==', 0);
cmp_ok(vec($x, 2, 64), '==', 0);
cmp_ok(~0, '==', 0xffffffffffffffff);
cmp_ok((0xffffffff<<32), '==', 0xffffffff00000000);
cmp_ok(((0xffffffff)<<32)>>32, '==', 0xffffffff);
cmp_ok(1<<63, '==', 0x8000000000000000);
is((sprintf "%#Vx", 1<<63), '0x8000000000000000');
cmp_ok((0x8000000000000000 | 1), '==', 0x8000000000000001);
cmp_ok((0xf000000000000000 & 0x8000000000000000), '==', 0x8000000000000000);
cmp_ok((0xf000000000000000 ^ 0xfffffffffffffff0), '==', 0x0ffffffffffffff0);
is((sprintf "%b", ~0),
'1111111111111111111111111111111111111111111111111111111111111111');
is((sprintf "%64b", ~0),
'1111111111111111111111111111111111111111111111111111111111111111');
is((sprintf "%d", ~0>>1),'9223372036854775807');
is((sprintf "%u", ~0),'18446744073709551615');
# If the 53..55 fail you have problems in the parser's string->int conversion,
# see toke.c:scan_num().
$q = -9223372036854775808;
is("$q","-9223372036854775808");
$q = 9223372036854775807;
is("$q","9223372036854775807");
$q = 18446744073709551615;
is("$q","18446744073709551615");
# Test that sv_2nv then sv_2iv is the same as sv_2iv direct
# fails if whatever Atol is defined as can't actually cope with >32 bits.
my $num = 4294967297;
my $string = "4294967297";
{
use integer;
$num += 0;
$string += 0;
}
is($num, $string);
# Test that sv_2nv then sv_2uv is the same as sv_2uv direct
$num = 4294967297;
$string = "4294967297";
$num &= 0;
$string &= 0;
is($num, $string);
$q = "18446744073709551616e0";
$q += 0;
isnt($q, "18446744073709551615");
# 0xFFFFFFFFFFFFFFFF == 1 * 3 * 5 * 17 * 257 * 641 * 65537 * 6700417'
$q = 0xFFFFFFFFFFFFFFFF / 3;
cmp_ok($q, '==', 0x5555555555555555);
SKIP: {
skip("Maths does not preserve UVs", 2) unless $maths_preserves_UVs;
cmp_ok($q, '!=', 0x5555555555555556);
skip("All UV division is precise as NVs, so is done as NVs", 1)
if $Config{d_nv_preserves_uv};
unlike($q, qr/[e.]/);
}
$q = 0xFFFFFFFFFFFFFFFF % 0x5555555555555555;
cmp_ok($q, '==', 0);
$q = 0xFFFFFFFFFFFFFFFF % 0xFFFFFFFFFFFFFFF0;
cmp_ok($q, '==', 0xF);
$q = 0x8000000000000000 % 9223372036854775807;
cmp_ok($q, '==', 1);
$q = 0x8000000000000000 % -9223372036854775807;
cmp_ok($q, '==', -9223372036854775806);
{
use integer;
$q = hex "0x123456789abcdef0";
cmp_ok($q, '==', 0x123456789abcdef0);
cmp_ok($q, '!=', 0x123456789abcdef1);
unlike($q, qr/[e.]/, 'Should not be floating point');
$q = oct "0x123456789abcdef0";
cmp_ok($q, '==', 0x123456789abcdef0);
cmp_ok($q, '!=', 0x123456789abcdef1);
unlike($q, qr/[e.]/, 'Should not be floating point');
$q = oct "765432176543217654321";
cmp_ok($q, '==', 0765432176543217654321);
cmp_ok($q, '!=', 0765432176543217654322);
unlike($q, qr/[e.]/, 'Should not be floating point');
$q = oct "0b0101010101010101010101010101010101010101010101010101010101010101";
cmp_ok($q, '==', 0x5555555555555555);
cmp_ok($q, '!=', 0x5555555555555556);
unlike($q, qr/[e.]/, 'Should not be floating point');
}
done_testing();
|