line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::NumOnly; |
2
|
1
|
|
|
1
|
|
444
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
141
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use overload |
6
|
1
|
|
|
|
|
23
|
'+' => \&oload_add, |
7
|
|
|
|
|
|
|
'-' => \&oload_sub, |
8
|
|
|
|
|
|
|
'*' => \&oload_mul, |
9
|
|
|
|
|
|
|
'/' => \&oload_div, |
10
|
|
|
|
|
|
|
'**' => \&oload_pow, |
11
|
|
|
|
|
|
|
'++' => \&oload_inc, |
12
|
|
|
|
|
|
|
'--' => \&oload_dec, |
13
|
|
|
|
|
|
|
'>=' => \&oload_gte, |
14
|
|
|
|
|
|
|
'<=' => \&oload_lte, |
15
|
|
|
|
|
|
|
'==' => \&oload_equiv, |
16
|
|
|
|
|
|
|
'>' => \&oload_gt, |
17
|
|
|
|
|
|
|
'<' => \&oload_lt, |
18
|
|
|
|
|
|
|
'<=>' => \&oload_spaceship, |
19
|
|
|
|
|
|
|
'""' => \&oload_stringify, |
20
|
1
|
|
|
1
|
|
1201
|
; |
|
1
|
|
|
|
|
1182
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
require DynaLoader; |
25
|
|
|
|
|
|
|
Math::NumOnly->DynaLoader::bootstrap($VERSION); |
26
|
1
|
|
|
1
|
0
|
203
|
sub dl_load_flags {0} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new { |
29
|
36
|
50
|
33
|
36
|
0
|
54755
|
shift if(!ref($_[0]) && $_[0] eq "Math::NumOnly"); # 'new' has been called as a method |
30
|
|
|
|
|
|
|
|
31
|
36
|
|
|
|
|
83
|
my $ok = is_ok($_[0]); |
32
|
36
|
100
|
|
|
|
88
|
die "Bad argument (or no argument) given to new" unless $ok; |
33
|
|
|
|
|
|
|
|
34
|
33
|
50
|
|
|
|
68
|
if($ok == 1) { |
35
|
|
|
|
|
|
|
# return a copy of the given Math::NumOnly object |
36
|
0
|
|
|
|
|
0
|
my $ret = shift; |
37
|
0
|
|
|
|
|
0
|
return $ret; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# given arg must be a valid IV or NV |
41
|
33
|
|
|
|
|
84
|
my %h = ('val' => shift); |
42
|
33
|
|
|
|
|
216
|
return bless(\%h, 'Math::NumOnly'); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub oload_add { |
46
|
10
|
50
|
|
10
|
0
|
632
|
die "Wrong number of arguments given to oload_add()" |
47
|
|
|
|
|
|
|
if @_ > 3; |
48
|
|
|
|
|
|
|
|
49
|
10
|
|
|
|
|
29
|
my $ok = is_ok($_[1]); # check that 2nd arg is suitable. |
50
|
10
|
100
|
|
|
|
45
|
die "Bad argument given to oload_add" unless $ok; |
51
|
|
|
|
|
|
|
|
52
|
7
|
100
|
|
|
|
13
|
if($ok == 1) { |
53
|
2
|
|
|
|
|
8
|
return Math::NumOnly->new($_[0]->{val} + $_[1]->{val}); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
5
|
|
|
|
|
17
|
return Math::NumOnly->new($_[0]->{val} + $_[1]); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub oload_mul { |
60
|
5
|
50
|
|
5
|
0
|
278
|
die "Wrong number of arguments given to oload_mul()" |
61
|
|
|
|
|
|
|
if @_ > 3; |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
17
|
my $ok = is_ok($_[1]); # check that 2nd arg is suitable. |
64
|
5
|
100
|
|
|
|
17
|
die "Bad argument given to oload_mul" unless $ok; |
65
|
|
|
|
|
|
|
|
66
|
4
|
100
|
|
|
|
9
|
if($ok == 1) { |
67
|
1
|
|
|
|
|
5
|
return Math::NumOnly->new($_[0]->{val} * $_[1]->{val}); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
11
|
return Math::NumOnly->new($_[0]->{val} * $_[1]); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub oload_sub { |
74
|
6
|
50
|
|
6
|
0
|
588
|
die "Wrong number of arguments given to oload_sub()" |
75
|
|
|
|
|
|
|
if @_ > 3; |
76
|
|
|
|
|
|
|
|
77
|
6
|
|
|
|
|
17
|
my $ok = is_ok($_[1]); # check that 2nd arg is suitable. |
78
|
6
|
100
|
|
|
|
27
|
die "Bad argument given to oload_sub" unless $ok; |
79
|
|
|
|
|
|
|
|
80
|
4
|
|
|
|
|
8
|
my $third_arg = $_[2]; |
81
|
|
|
|
|
|
|
|
82
|
4
|
100
|
|
|
|
9
|
if($ok == 1) { |
83
|
1
|
50
|
|
|
|
5
|
if($third_arg) { |
84
|
0
|
|
|
|
|
0
|
return Math::NumOnly->new($_[1]->{val} - $_[0]->{val}); |
85
|
|
|
|
|
|
|
} |
86
|
1
|
|
|
|
|
5
|
return Math::NumOnly->new($_[0]->{val} - $_[1]->{val}); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
3
|
100
|
|
|
|
8
|
if($third_arg) { |
90
|
1
|
|
|
|
|
4
|
return Math::NumOnly->new($_[1] - $_[0]->{val}); |
91
|
|
|
|
|
|
|
} |
92
|
2
|
|
|
|
|
8
|
return Math::NumOnly->new($_[0]->{val} - $_[1]); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub oload_div { |
96
|
5
|
50
|
|
5
|
0
|
540
|
die "Wrong number of arguments given to oload_div()" |
97
|
|
|
|
|
|
|
if @_ > 3; |
98
|
|
|
|
|
|
|
|
99
|
5
|
|
|
|
|
14
|
my $ok = is_ok($_[1]); # check that 2nd arg is suitable. |
100
|
5
|
100
|
|
|
|
16
|
die "Bad argument given to oload_div" unless $ok; |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
|
|
|
9
|
my $third_arg = $_[2]; |
103
|
|
|
|
|
|
|
|
104
|
4
|
100
|
|
|
|
9
|
if($ok == 1) { |
105
|
1
|
50
|
|
|
|
4
|
if($third_arg) { |
106
|
0
|
|
|
|
|
0
|
return Math::NumOnly->new($_[1]->{val} / $_[0]->{val}); |
107
|
|
|
|
|
|
|
} |
108
|
1
|
|
|
|
|
6
|
return Math::NumOnly->new($_[0]->{val} / $_[1]->{val}); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
3
|
100
|
|
|
|
8
|
if($third_arg) { |
112
|
1
|
|
|
|
|
5
|
return Math::NumOnly->new($_[1] / $_[0]->{val}); |
113
|
|
|
|
|
|
|
} |
114
|
2
|
|
|
|
|
8
|
return Math::NumOnly->new($_[0]->{val} / $_[1]); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub oload_pow { |
118
|
5
|
50
|
|
5
|
0
|
302
|
die "Wrong number of arguments given to oload_pow()" |
119
|
|
|
|
|
|
|
if @_ > 3; |
120
|
|
|
|
|
|
|
|
121
|
5
|
|
|
|
|
15
|
my $ok = is_ok($_[1]); # check that 2nd arg is suitable. |
122
|
5
|
100
|
|
|
|
17
|
die "Bad argument given to oload_div" unless $ok; |
123
|
|
|
|
|
|
|
|
124
|
4
|
|
|
|
|
6
|
my $third_arg = $_[2]; |
125
|
|
|
|
|
|
|
|
126
|
4
|
100
|
|
|
|
9
|
if($ok == 1) { |
127
|
1
|
50
|
|
|
|
4
|
if($third_arg) { |
128
|
0
|
|
|
|
|
0
|
return Math::NumOnly->new($_[1]->{val} ** $_[0]->{val}); |
129
|
|
|
|
|
|
|
} |
130
|
1
|
|
|
|
|
8
|
return Math::NumOnly->new($_[0]->{val} ** $_[1]->{val}); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
3
|
100
|
|
|
|
9
|
if($third_arg) { |
134
|
1
|
|
|
|
|
6
|
return Math::NumOnly->new($_[1] ** $_[0]->{val}); |
135
|
|
|
|
|
|
|
} |
136
|
2
|
|
|
|
|
12
|
return Math::NumOnly->new($_[0]->{val} ** $_[1]); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub oload_inc { |
140
|
1
|
|
|
1
|
0
|
531
|
($_[0]->{val}) += 1;; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub oload_dec { |
144
|
1
|
|
|
1
|
0
|
547
|
($_[0]->{val}) -= 1; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub oload_stringify { |
148
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
149
|
0
|
|
|
|
|
0
|
return $self->{val}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub oload_gte { |
153
|
4
|
50
|
|
4
|
0
|
610
|
die "Wrong number of arguments given to oload_gte()" |
154
|
|
|
|
|
|
|
if @_ > 3; |
155
|
|
|
|
|
|
|
|
156
|
4
|
|
|
|
|
12
|
my $cmp = oload_spaceship($_[0], $_[1], $_[2]); |
157
|
|
|
|
|
|
|
|
158
|
4
|
50
|
|
|
|
47
|
return 1 if $cmp >= 0; |
159
|
0
|
|
|
|
|
0
|
return 0; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub oload_lte { |
163
|
4
|
50
|
|
4
|
0
|
579
|
die "Wrong number of arguments given to oload_lte()" |
164
|
|
|
|
|
|
|
if @_ > 3; |
165
|
|
|
|
|
|
|
|
166
|
4
|
|
|
|
|
12
|
my $cmp = oload_spaceship($_[0], $_[1], $_[2]); |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
#if($_[2]) { |
169
|
|
|
|
|
|
|
# return 1 if $cmp >= 0; |
170
|
|
|
|
|
|
|
# return 0; |
171
|
|
|
|
|
|
|
#} |
172
|
|
|
|
|
|
|
|
173
|
4
|
50
|
|
|
|
56
|
return 1 if $cmp <= 0; |
174
|
0
|
|
|
|
|
0
|
return 0; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub oload_equiv { |
178
|
28
|
50
|
|
28
|
0
|
4281
|
die "Wrong number of arguments given to oload_equiv()" |
179
|
|
|
|
|
|
|
if @_ > 3; |
180
|
|
|
|
|
|
|
|
181
|
28
|
50
|
|
|
|
79
|
return 1 if(oload_spaceship($_[0], $_[1], $_[2]) == 0); |
182
|
0
|
|
|
|
|
0
|
return 0; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub oload_gt { |
186
|
2
|
50
|
|
2
|
0
|
305
|
die "Wrong number of arguments given to oload_gt()" |
187
|
|
|
|
|
|
|
if @_ > 3; |
188
|
|
|
|
|
|
|
|
189
|
2
|
|
|
|
|
6
|
my $cmp = oload_spaceship($_[0], $_[1], $_[2]); |
190
|
|
|
|
|
|
|
|
191
|
2
|
50
|
|
|
|
24
|
return 1 if $cmp > 0; |
192
|
0
|
|
|
|
|
0
|
return 0; |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub oload_lt { |
196
|
2
|
50
|
|
2
|
0
|
306
|
die "Wrong number of arguments given to oload_lt()" |
197
|
|
|
|
|
|
|
if @_ > 3; |
198
|
|
|
|
|
|
|
|
199
|
2
|
|
|
|
|
5
|
my $cmp = oload_spaceship($_[0], $_[1], $_[2]); |
200
|
|
|
|
|
|
|
|
201
|
2
|
50
|
|
|
|
32
|
return 1 if $cmp < 0; |
202
|
0
|
|
|
|
|
0
|
return 0; |
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
sub oload_spaceship { |
206
|
46
|
50
|
|
46
|
0
|
91
|
die "Wrong number of arguments given to oload_spaceship()" |
207
|
|
|
|
|
|
|
if @_ > 3; |
208
|
|
|
|
|
|
|
|
209
|
46
|
|
|
|
|
113
|
my $ok = is_ok($_[1]); # check that 2nd arg is suitable. |
210
|
46
|
50
|
|
|
|
86
|
die "Bad argument given to oload_spaceship" unless $ok; |
211
|
|
|
|
|
|
|
|
212
|
46
|
|
|
|
|
74
|
my $third_arg = $_[2]; |
213
|
|
|
|
|
|
|
|
214
|
46
|
50
|
|
|
|
91
|
if($ok == 1) { |
215
|
0
|
0
|
|
|
|
0
|
if($third_arg) { |
216
|
0
|
|
|
|
|
0
|
return ($_[1]->{val} <=> $_[0]->{val}); |
217
|
|
|
|
|
|
|
} |
218
|
0
|
|
|
|
|
0
|
return ($_[0]->{val} <=> $_[1]->{val}); |
219
|
|
|
|
|
|
|
} |
220
|
46
|
100
|
|
|
|
89
|
if($third_arg) { |
221
|
10
|
|
|
|
|
45
|
return ($_[1] <=> $_[0]->{val}); |
222
|
|
|
|
|
|
|
} |
223
|
36
|
|
|
|
|
346
|
return ($_[0]->{val} <=> $_[1]); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
1; |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
__END__ |