| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Number::Convert; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
22349
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use vars qw/$VERSION/; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
83
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION="1.0.2"; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use overload ( |
|
11
|
1
|
|
|
|
|
5
|
'+', 'add', |
|
12
|
|
|
|
|
|
|
'-', 'subtract', |
|
13
|
|
|
|
|
|
|
'*', 'multiply', |
|
14
|
|
|
|
|
|
|
'/', 'divide', |
|
15
|
|
|
|
|
|
|
'&', 'and', |
|
16
|
|
|
|
|
|
|
'|', 'or', |
|
17
|
|
|
|
|
|
|
'^', 'xor' |
|
18
|
1
|
|
|
1
|
|
1502
|
); |
|
|
1
|
|
|
|
|
985
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new |
|
21
|
|
|
|
|
|
|
{ |
|
22
|
1
|
|
|
1
|
0
|
11
|
my ($class, $param) = @_; |
|
23
|
|
|
|
|
|
|
|
|
24
|
1
|
50
|
|
|
|
3
|
die "Invalid number of parameters passed to constructor. Expected was 1, found ".(scalar(@_) - 1).".\n" if(scalar(@_) != 2); |
|
25
|
|
|
|
|
|
|
|
|
26
|
1
|
50
|
|
|
|
5
|
die "Invalid value passed to parameter. $param is not a number" if(!isNumber($param)); |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
4
|
my $self = { |
|
29
|
|
|
|
|
|
|
number => $param |
|
30
|
|
|
|
|
|
|
}; |
|
31
|
1
|
|
|
|
|
2
|
bless ($self, $class); |
|
32
|
1
|
|
|
|
|
4
|
return $self; |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub ToDecimal |
|
36
|
|
|
|
|
|
|
{ |
|
37
|
2
|
|
|
2
|
1
|
589
|
my $self = shift; |
|
38
|
2
|
|
|
|
|
68
|
return sprintf "%d", $self->{number}; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub ToBinary |
|
42
|
|
|
|
|
|
|
{ |
|
43
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
|
44
|
1
|
|
|
|
|
7
|
return sprintf "%b", $self->{number}; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub ToHex |
|
48
|
|
|
|
|
|
|
{ |
|
49
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
|
50
|
2
|
|
|
|
|
11
|
return sprintf "%x", $self->{number}; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub ToUpperCaseHex |
|
54
|
|
|
|
|
|
|
{ |
|
55
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
56
|
1
|
|
|
|
|
8
|
return sprintf "%X", $self->{number}; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub ToOctal |
|
60
|
|
|
|
|
|
|
{ |
|
61
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
|
62
|
1
|
|
|
|
|
6
|
return sprintf "%O", $self->{number}; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub add |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
68
|
0
|
|
|
|
|
0
|
my $value = shift; |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
0
|
|
|
0
|
die "Can't add non numeric value to number\n" if(!defined($value) || !isNumber($value)); |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
|
|
|
|
0
|
$self->{number} += $value; |
|
73
|
0
|
|
|
|
|
0
|
return $self; |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub subtract |
|
77
|
|
|
|
|
|
|
{ |
|
78
|
1
|
|
|
1
|
0
|
5
|
my $self = shift; |
|
79
|
1
|
|
|
|
|
1
|
my $value = shift; |
|
80
|
|
|
|
|
|
|
|
|
81
|
1
|
50
|
33
|
|
|
6
|
die "Can't subtract non numeric value from number\n" if(!defined($value) || !isNumber($value)); |
|
82
|
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
2
|
$self->{number} -= $value; |
|
84
|
1
|
|
|
|
|
2
|
return $self; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub multiply |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
90
|
0
|
|
|
|
|
0
|
my $value = shift; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
0
|
|
|
0
|
die "Can't multiple number by non numeric value\n" if(!defined($value) || !isNumber($value)); |
|
93
|
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
$self->{number} *= $value; |
|
95
|
0
|
|
|
|
|
0
|
return $self; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub divide |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
|
101
|
1
|
|
|
|
|
2
|
my $value = shift; |
|
102
|
|
|
|
|
|
|
|
|
103
|
1
|
50
|
33
|
|
|
7
|
die "Can't divide number by non numeric value\n" if(!defined($value) || !isNumber($value)); |
|
104
|
|
|
|
|
|
|
|
|
105
|
1
|
50
|
|
|
|
3
|
die "Division by zero not supported\n" if ($value == 0); |
|
106
|
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
3
|
$self->{number} /= $value; |
|
108
|
1
|
|
|
|
|
2
|
return $self; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub and |
|
112
|
|
|
|
|
|
|
{ |
|
113
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
114
|
0
|
|
|
|
|
0
|
my $value = shift; |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
0
|
0
|
|
|
0
|
die "Can't AND number with non numeric value\n" if(!defined($value) || !isNumber($value)); |
|
117
|
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
$self->{number} &= $value; |
|
119
|
0
|
|
|
|
|
0
|
return $self; |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub or |
|
123
|
|
|
|
|
|
|
{ |
|
124
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
125
|
0
|
|
|
|
|
0
|
my $value = shift; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
0
|
0
|
|
|
0
|
die "Can't OR number with non numeric value\n" if(!defined($value) || !isNumber($value)); |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
$self->{number} |= $value; |
|
130
|
0
|
|
|
|
|
0
|
return $self; |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub xor |
|
134
|
|
|
|
|
|
|
{ |
|
135
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
136
|
0
|
|
|
|
|
0
|
my $value = shift; |
|
137
|
|
|
|
|
|
|
|
|
138
|
0
|
0
|
0
|
|
|
0
|
die "Can't XOR number by non numeric value\n" if(!defined($value) || !isNumber($value)); |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
0
|
$self->{number} = $self->{number} ^ $value; |
|
141
|
0
|
|
|
|
|
0
|
return $self; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub isNumber |
|
145
|
|
|
|
|
|
|
{ |
|
146
|
1
|
|
|
1
|
|
1592
|
use POSIX qw(strtod); |
|
|
1
|
|
|
|
|
6315
|
|
|
|
1
|
|
|
|
|
6
|
|
|
147
|
3
|
|
|
3
|
0
|
5
|
my $str = shift; |
|
148
|
3
|
|
|
|
|
9
|
$str =~ s/^\s+//; |
|
149
|
3
|
|
|
|
|
6
|
$str =~ s/\s+$//; |
|
150
|
3
|
|
|
|
|
5
|
$! = 0; |
|
151
|
3
|
|
|
|
|
43
|
my($num, $unparsed) = strtod($str); |
|
152
|
3
|
50
|
33
|
|
|
25
|
if (($str eq '') || ($unparsed != 0) || $!) { |
|
|
|
|
33
|
|
|
|
|
|
153
|
0
|
|
|
|
|
0
|
return 0; |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
else { |
|
156
|
3
|
|
|
|
|
11
|
return 1; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
1; |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
__END__ |