File: pow.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 (82 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use strict;
use warnings;

use Math::Int64 qw(int64 uint64 string_to_int64 string_to_uint64);

use Test::More 0.88;

my $zero = int64(0);
my $one = int64(1);
my $two = int64(2);
my $mone = int64(-1);
my $mtwo = int64(-2);

ok($zero ** 0 == 1);
ok($zero ** 1 == 0);
ok($zero ** 10 == 0);
eval { my $r = $zero ** -1 };
ok($@ =~ /illegal.*division/i);

ok($one ** 0 == 1);
ok($one ** 10 == 1);
ok($one ** -19 == 1);

ok($mone ** 0 == 1);
ok($mone ** 10 == 1);
ok($mone ** 11 == -1);
ok($mone ** -1 == -1);
ok($mone ** -30 == 1);
ok($mone ** -31 == -1);

ok($two ** 0 == 1);
ok($two ** 1 == 2);
ok($two ** 2 == 4);
ok($two ** 31 == string_to_int64("0x8000_0000"));
ok($two ** 32 == string_to_int64("0x1_0000_0000"));
ok($two ** 62 == string_to_int64("0x4000_0000_0000_0000"));
ok($two ** -1 == 0);

ok($mtwo ** 0 == 1);
ok($mtwo ** 1 == -2);
ok($mtwo ** 2 == 4);
ok($mtwo ** 3 == -8);
ok($mtwo ** 4 == 16);
ok($mtwo ** 31 == -string_to_int64("0x8000_0000"));
ok($mtwo ** 32 == string_to_int64("0x1_0000_0000"));
ok($mtwo ** 62 == string_to_int64("0x4000_0000_0000_0000"));
ok($mtwo ** -1 == 0);

ok(int64(12) ** 2 == 144);
ok(int64(-12) ** 2 == 144);
ok(int64(12) ** 3 == 1728);
ok(int64(-12) ** 3 == -1728);
ok(int64(256) ** 5 == 2 ** (8 * 5));
ok(int64(-256) ** 5 == -(2 ** (8 * 5)));
ok(int64(256) ** -5 == 0);

$zero = uint64(0);
$one = uint64(1);
$two = uint64(2);

ok($zero ** 0 == 1);
ok($zero ** 1 == 0);
ok($zero ** 10 == 0);

ok($one ** 0 == 1);
ok($one ** 10 == 1);

ok($two ** 0 == 1);
ok($two ** 1 == 2);
ok($two ** 2 == 4);
ok($two ** 31 == string_to_uint64("0x8000_0000"));
ok($two ** 32 == string_to_uint64("0x1_0000_0000"));
ok($two ** 62 == string_to_uint64("0x4000_0000_0000_0000"));
ok($two ** 63 == string_to_uint64("0x8000_0000_0000_0000"));

ok(int64(12) ** 2 == 144);
ok(int64(12) ** 3 == 1728);
ok(int64(256) ** 5 == 2 ** (8 * 5));

done_testing();