line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package smallnum; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
234127
|
use strict; |
|
4
|
|
|
|
|
35
|
|
|
4
|
|
|
|
|
106
|
|
4
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
88
|
|
5
|
4
|
|
|
4
|
|
1769
|
use POSIX (); |
|
4
|
|
|
|
|
22685
|
|
|
4
|
|
|
|
|
226
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.01'; |
8
|
|
|
|
|
|
|
|
9
|
4
|
|
|
|
|
38
|
use overload fallback => 1, |
10
|
|
|
|
|
|
|
'""' => \&_num, |
11
|
|
|
|
|
|
|
'*' => \&_multiply, |
12
|
4
|
|
|
4
|
|
4088
|
'/' => \&_divide; |
|
4
|
|
|
|
|
3443
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $precision = .01; |
15
|
|
|
|
|
|
|
our $offset = 0.5555555; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub import { |
18
|
4
|
100
|
|
4
|
|
40
|
$precision = $_[1] if $_[1]; |
19
|
4
|
100
|
|
|
|
13
|
$offset = $_[2] if $_[2]; |
20
|
4
|
|
|
|
|
15
|
overload::constant integer => \&_smallnum; |
21
|
4
|
|
|
|
|
99
|
overload::constant float => \&_smallnum; |
22
|
4
|
|
|
|
|
50
|
overload::constant binary => \&_smallnum; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _smallnum { |
26
|
219
|
|
|
219
|
|
420
|
my $n = shift; |
27
|
219
|
|
|
|
|
2974
|
bless \$n, __PACKAGE__; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _num { |
31
|
187
|
|
|
187
|
|
14678
|
my $num = _sref($_[0]); |
32
|
187
|
100
|
|
|
|
4236
|
return $num >= 0 |
33
|
|
|
|
|
|
|
? $precision * int(($num + ($offset * $precision)) / $precision) |
34
|
|
|
|
|
|
|
: $precision * POSIX::ceil(($num - $offset * $precision) / $precision); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _divide { |
38
|
13
|
|
|
13
|
|
29
|
my (@ot) = (_sref($_[0]), _sref($_[1])); |
39
|
13
|
100
|
100
|
|
|
104
|
return $ot[0] && $ot[1] |
|
|
100
|
|
|
|
|
|
40
|
|
|
|
|
|
|
? _smallnum($_[2] ? ($ot[1] / $ot[0]) : ($ot[0] / $ot[1])) |
41
|
|
|
|
|
|
|
: _smallnum(0); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _multiply { |
45
|
8
|
|
|
8
|
|
15
|
my (@ot) = (_sref($_[0]), _sref($_[1])); |
46
|
8
|
|
|
|
|
24
|
return _smallnum($ot[1] * $ot[0]); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
229
|
100
|
|
229
|
|
422
|
sub _sref { ref $_[0] ? ${$_[0]} : $_[0] } |
|
225
|
|
|
|
|
446
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
smallnum - Transparent "SmallNumber" support for Perl |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Version 1.01 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use smallnum; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
10 + 20.452433483 # 30.45 |
66
|
|
|
|
|
|
|
20.3743543 - 10.1 # 10.27 |
67
|
|
|
|
|
|
|
15 / 5.34, # 2.81 |
68
|
|
|
|
|
|
|
9 * 0.01, # 0.09 |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
... |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
use smallnum '0.1'; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
10 + 20.452433483 # 30.5 |
75
|
|
|
|
|
|
|
20.3743543 - 10.1 # 10.3 |
76
|
|
|
|
|
|
|
15 / 5.34, # 2.8 |
77
|
|
|
|
|
|
|
9 * 0.01, # 0.1 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
... |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use smallnum '1'; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
10 + 20.452433483 # 31 |
84
|
|
|
|
|
|
|
20.3743543 - 10.1 # 10 |
85
|
|
|
|
|
|
|
15 / 5.34, # 3 |
86
|
|
|
|
|
|
|
9 * 0.01, # 0 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
LNATION, C<< >> |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head1 BUGS |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
95
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
96
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SUPPORT |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
perldoc smallnum |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
You can also look for information at: |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
L |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
L |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=item * CPAN Ratings |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
L |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=item * Search CPAN |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
L |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=back |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This software is Copyright (c) 2020->2021 by LNATION. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This is free software, licensed under: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; # End of smallnum |