blib/lib/smallnum.pm

filter: Statementstmt 100% 31 / 31 Branchbran 100% 12 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod n/a totaltotal 100% 58 / 58 CC 8 SCAR 8.3
CC
8
Cov
100%
_divide
4.0
import
3.0
_num
2.0
CRAP 2.3
↑ Summary
1 package smallnum;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 our $VERSION = '1.02';
8  
9 4 ▶use overload fallback => 1,
Subroutine BEGIN: called CC=1 SCAR=0.0
10 '""' => \&_num,
11 '*' => \&_multiply,
12 4 '/' => \&_divide;
13  
14 4 our $precision = .01;
15 4 our $offset = 0.5555555;
16  
17 4 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
18 4 ▶ $precision = $_[1] if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 2 2 4
19 4 ▶ $offset = $_[2] if $_[2];
Branch: 1 branch
BranchTrueFalseTotal
if $_[2] 1 3 4
20 4 overload::constant integer => \&_smallnum;
21 4 overload::constant float => \&_smallnum;
22 4 overload::constant binary => \&_smallnum;
23 }
24  
25 219 ▶sub _smallnum {
Subroutine _smallnum: called CC=1 SCAR=0.0
26 219 my $n = shift;
27 219 bless \$n, __PACKAGE__;
28 }
29  
30 187 ▶sub _num {
Subroutine _num: called CC=2 SCAR=6.9
31 187 my $num = _sref($_[0]);
32 187 ▶ return $num >= 0
Branch: 1 branch
BranchTrueFalseTotal
$num >= 0 ? : 186 1 187
33 ? $precision * int(($num + ($offset * $precision)) / $precision)
34 : $precision * POSIX::ceil(($num - $offset * $precision) / $precision);
35 }
36  
37 13 ▶sub _divide {
Subroutine _divide: called CC=4 SCAR=13.9
38 13 my (@ot) = (_sref($_[0]), _sref($_[1]));
39 13 ▶ return $ot[0] && $ot[1]
Branch: 2 branches
BranchTrueFalseTotal
$ot[0] && $ot[1] ? : 11 2 13
$_[2] ? : 3 8 11
Condition100%3/3
$ot[0] and $ot[1]
!ll&&!rl&&r
1111
MC/DC100%2/2
$ot[0] and $ot[1]
$ot[0] $ot[1]
Truth table100%3/3
A and B
A= $ot[0]B= $ot[1]
ABresult
0X0
100
111
40 ? _smallnum($_[2] ? ($ot[1] / $ot[0]) : ($ot[0] / $ot[1]))
41 : _smallnum(0);
42 }
43  
44 8 ▶sub _multiply {
Subroutine _multiply: called CC=1 SCAR=0.0
45 8 my (@ot) = (_sref($_[0]), _sref($_[1]));
46 8 return _smallnum($ot[1] * $ot[0]);
47 }
48  
49 229 ▶sub _sref { ref $_[0] ? ${$_[0]} : $_[0] }
Subroutine _sref: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 225 4 229
50  
51 =head1 NAME
52  
53 smallnum - Transparent "SmallNumber" support for Perl
54  
55 =head1 VERSION
56  
57 Version 1.02
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<< <thisusedtobeanemail at gmail.com> >>
91  
92 =head1 BUGS
93  
94 Please report any bugs or feature requests to C<bug-smallnum at rt.cpan.org>, or through
95 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=smallnum>. 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<https://rt.cpan.org/NoAuth/Bugs.html?Dist=smallnum>
111  
112 =item * Search CPAN
113  
114 L<https://metacpan.org/release/smallnum>
115  
116 =back
117  
118 =head1 ACKNOWLEDGEMENTS
119  
120 =head1 LICENSE AND COPYRIGHT
121  
122 This software is Copyright (c) 2020->2025 by LNATION.
123  
124 This is free software, licensed under:
125  
126 The Artistic License 2.0 (GPL Compatible)
127  
128 =cut
129  
130 4 1; # End of smallnum
↑ Summary