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