File: Math-UInt64-Native.t

package info (click to toggle)
libmath-int64-perl 0.54-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid, stretch
  • size: 672 kB
  • ctags: 924
  • sloc: perl: 2,805; ansic: 320; makefile: 2
file content (109 lines) | stat: -rw-r--r-- 1,542 bytes parent folder | download
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
#!/usr/bin/perl

use strict;
use warnings;

use Test::More 0.88;

use Math::Int64 qw(:native_if_available
                   uint64 uint64_to_number
                   net_to_uint64 uint64_to_net
                   native_to_uint64 uint64_to_native);

my $iv_backend = (Math::Int64::_backend() eq 'IV');

my $i = uint64('1234567890123456789');
my $j = $i + 1;
my $k = (uint64(1) << 60) + 255;

# 1
ok($i == '1234567890123456789');

ok($j - 1 == '1234567890123456789');

ok (($k & 127) == 127);

ok (($k & 256) == 0);

# 5
ok ($i * 2 == $j + $j - 2);

SKIP: {
    skip "conversion to NV loses low bits", 1;
    ok ($i * $i * $i * $i == ($j * $j - 2 * $j + 1) * ($j * $j - 2 * $j + 1));
};

SKIP: {
    skip "native division semantics differ", 2;
    ok (($i / $j) == 0);
    ok ($j / $i == 1);
};

ok ($i % $j == $i);

# 10
ok ($j % $i == 1);

ok (($j += 1) == $i + 2);

ok ($j == $i + 2);

ok (($j -= 3) == $i - 1);

ok ($j == $i - 1);

$j = $i;
# 15
ok (($j *= 2) == $i << 1);

ok (($j >> 1) == $i);

ok (($j / 2) == $i);

$j = $i + 2;

ok (($j %= $i) == 2);

ok ($j == 2);

# 20
ok (($j <=> $i) < 0);

ok (($i <=> $j) > 0);

ok (($i <=> $i) == 0);

ok (($j <=> 2) == 0);

ok ($j < $i);

# 25
ok ($j <= $i);

ok (!($i < $j));

ok (!($i <= $j));

ok ($i <= $i);

ok ($j >= $j);

# 30
ok ($i > $j);

ok ($i >= $j);

ok (!($j > $i));

ok (!($j >= $i));

ok (int(log(uint64(1)<<50)/log(2)+0.001) == 50);

# 35

SKIP: {
    skip "backend != IV", 3 unless Math::Int64::_backend() eq 'IV';
    ok(ref $_ eq '') for ($i, $j, $k);
}

done_testing();