blib/lib/Math/Float32.pm

filter: Statementstmt 91.4% 192 / 210 Branchbran 78.0% 89 / 114 Conditioncond 72.7% 56 / 77 MC/DCmcdc 51.0% 25 / 49 Subroutinesub 97.3% 36 / 37 Podpod 0.0% 0 / 23 totaltotal 78.0% 398 / 510 CC 85 SCAR 17.2
CC
85
Cov
84%
bin2hex
12.0
new
10.7
oload_fmod
6.3
CRAP 5.6
↑ Summary Float32.xs »
1 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Math::Float32;
4  
5 10 ▶use constant flt_EMIN => -148;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use constant flt_EMAX => 128;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use constant flt_MANTBITS => 24;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 use overload
11 10 '+' => \&oload_add,
12 '-' => \&oload_sub,
13 '*' => \&oload_mul,
14 '/' => \&oload_div,
15 '%' => \&oload_fmod,
16 '**' => \&oload_pow,
17  
18 '==' => \&oload_equiv,
19 '!=' => \&oload_not_equiv,
20 '>' => \&oload_gt,
21 '>=' => \&oload_gte,
22 '<' => \&oload_lt,
23 '<=' => \&oload_lte,
24 '<=>' => \&oload_spaceship,
25  
26 'abs' => \&oload_abs,
27 '""' => \&oload_interp,
28 'sqrt' => \&_oload_sqrt,
29 'exp' => \&_oload_exp,
30 'log' => \&_oload_log,
31 'int' => \&_oload_int,
32 '!' => \&_oload_not,
33 'bool' => \&_oload_bool,
34 10 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 10 require Exporter;
37 10 *import = \&Exporter::import;
38 10 require DynaLoader;
39  
40 10 our $VERSION = '0.02';
41 10 Math::Float32->DynaLoader::bootstrap($VERSION);
42  
43 10 ▶sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod undocumented
44  
45  
46  
47 10 my @tagged = qw( flt_to_NV flt_to_MPFR
48 is_flt_nan is_flt_inf is_flt_zero flt_set_nan flt_set_inf flt_set_zero
49 flt_signbit
50 flt_set
51 flt_nextabove flt_nextbelow
52 unpack_flt_hex pack_flt_hex
53 flt_EMIN flt_EMAX flt_MANTBITS
54 );
55  
56 10 @Math::Float32::EXPORT = ();
57 10 @Math::Float32::EXPORT_OK = @tagged;
58 10 %Math::Float32::EXPORT_TAGS = (all => \@tagged);
59  
60  
61 0 ▶%Math::Float32::handler = (1 => sub {print "OK: 1\n"},
Subroutine __ANON__: not called CC=1 SCAR=6.9
62 399 ▶ 2 => sub {return _fromIV(shift)},
Subroutine __ANON__: called CC=1 SCAR=0.0
63 9028 ▶ 4 => sub {return _fromPV(shift)},
Subroutine __ANON__: called CC=1 SCAR=0.0
64 394 ▶ 3 => sub {return _fromNV(shift)},
Subroutine __ANON__: called CC=1 SCAR=0.0
65  
66 8594 ▶ 22 => sub {return _fromFloat32(shift)},
Subroutine __ANON__: called CC=1 SCAR=0.0
67 10 );
68  
69 10 $Math::Float32::flt_DENORM_MIN = Math::Float32->new(2) ** (flt_EMIN - 1); # 1.40129846e-45
70 10 $Math::Float32::flt_DENORM_MAX = Math::Float32->new(_get_denorm_max()); # 1.17549421e-38
71 10 $Math::Float32::flt_NORM_MIN = Math::Float32->new(2) ** (flt_EMIN + (flt_MANTBITS - 2)); # 1.17549435e-38
72 10 $Math::Float32::flt_NORM_MAX = Math::Float32->new(_get_norm_max()); # 3.402823467e+38
73  
74  
75 # Skip signed zero tests in the test suite if C's strtof()
76 # does not handle '-0' correctly.
77 10 my $signed_zero_tester = Math::Float32->new('-0.0');
78 10 ▶$Math::Float32::broken_signed_zero = "$signed_zero_tester" =~ /^\-/ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
"$signed_zero_tester" =~ /^\-/ ? : 10 0 10
79  
80 sub new {
81 9022 ▶ shift if (@_ > 0 && !ref($_[0]) && _itsa($_[0]) == 4 && $_[0] eq "Math::Float32");
Subroutine new: called CC=10 SCAR=23.7
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 0 and not ref $_[0] and _itsa($_[0]) == 4 and $_[0] eq "Math::Float32" 9020 2 9022
Condition66%6/9
@_ > 0 and not ref $_[0] and _itsa($_[0]) == 4 and $_[0] eq "Math::Float32"
!ll&&!rl&&r
209020
@_ > 0 and not ref $_[0] and _itsa($_[0]) == 4
!ll&&!rl&&r
209020
@_ > 0 and not ref $_[0]
!ll&&!rl&&r
209020
MC/DC25%1/4
@_ > 0 and not ref $_[0] and _itsa($_[0]) == 4 and $_[0] eq "Math::Float32"
@_ > 0 not ref $_[0] _itsa($_[0]) == 4 $_[0] eq "Math::Float32"
Truth table40%2/5
A and not(B) and C and D
A= @_ > 0B= not ref $_[0]C= _itsa($_[0]) == 4D= $_[0] eq "Math::Float32"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
82 9022 ▶ if(!@_) { return _fromPV('NaN');}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 11 9011 9022
83 9011 ▶ die "Too many args given to new()" if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 0 9011 9011
84 9011 my $itsa = _itsa($_[0]);
85 9011 ▶ if($itsa) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa) 9011 0 9011
86 9011 my $coderef = $Math::Float32::handler{$itsa};
87 9011 ▶ return $coderef->(bin2hex($_[0]))
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[0] =~ /^(\s+)?[\-\+]?0b/i 78 8933 9011
Condition100%3/3
$itsa == 4 and $_[0] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
328860578
MC/DC100%2/2
$itsa == 4 and $_[0] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[0] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[0] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
88 if($itsa == 4 && $_[0] =~ /^(\s+)?[\-\+]?0b/i);
89 8933 return $coderef->($_[0]);
90 }
91 0 die "Unrecognized 1st argument passed to new() function";
92 }
93  
94 sub flt_set {
95 1 ▶ die "flt_set expects to receive precisely 2 arguments" if @_ != 2;
Subroutine flt_set: called CC=3 SCAR=11.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 1 1
96 1 my $itsa = _itsa($_[1]);
97 1 ▶ if($itsa == 22) { _flt_set(@_) }
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22) { } 0 1 1
98 else {
99 1 my $coderef = $Math::Float32::handler{$itsa};
100 1 _flt_set( $_[0], $coderef->($_[1]));
101 }
102 }
103  
104 sub oload_add {
105 101 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_add: called CC=5 SCAR=16.2
Pod undocumented
106 101 ▶ return _oload_add(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 1 100 101
107 100 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 100 0 100
108 100 my $coderef = $Math::Float32::handler{$itsa};
109 100 ▶ return _oload_add($_[0], $coderef->(bin2hex($_[1])), 0)
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 1 99 100
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
62371
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
110 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
111 99 return _oload_add($_[0], $coderef->($_[1]), 0);
112 }
113 0 die "Unrecognized 2nd argument passed to oload_add() function";
114 }
115  
116 sub oload_mul {
117 141 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_mul: called CC=5 SCAR=16.2
Pod undocumented
118 141 ▶ return _oload_mul(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 64 77 141
119 77 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 77 0 77
120 77 my $coderef = $Math::Float32::handler{$itsa};
121 77 ▶ return _oload_mul($_[0], $coderef->(bin2hex($_[1])), 0)
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 1 76 77
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
40361
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
122 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
123 76 return _oload_mul($_[0], $coderef->($_[1]), 0);
124 }
125 0 die "Unrecognized 2nd argument passed to oload_mul() function";
126 }
127  
128 sub oload_sub {
129 181 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_sub: called CC=5 SCAR=16.2
Pod undocumented
130 181 ▶ return _oload_sub(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 2 179 181
131 179 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 179 0 179
132 179 my $coderef = $Math::Float32::handler{$itsa};
133 179 ▶ return _oload_sub($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 177 179
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
125522
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
134 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
135 177 return _oload_sub($_[0], $coderef->($_[1]), $_[2]);
136 }
137 0 die "Unrecognized 2nd argument passed to oload_sub() function";
138 }
139  
140 sub oload_div {
141 107 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_div: called CC=5 SCAR=16.4
Pod undocumented
142 107 ▶ return _oload_div(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 0 107 107
143 107 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 107 0 107
144 107 my $coderef = $Math::Float32::handler{$itsa};
145 107 ▶ return _oload_div($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 105 107
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
53522
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
146 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
147 105 return _oload_div($_[0], $coderef->($_[1]), $_[2]);
148 }
149 0 die "Unrecognized 2nd argument passed to oload_div() function";
150 }
151  
152 sub oload_fmod {
153 12 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_fmod: called CC=5 SCAR=18.4
Pod undocumented
154 12 ▶ return _oload_fmod(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 10 2 12
155 2 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 2 0 2
156 2 my $coderef = $Math::Float32::handler{$itsa};
157 2 ▶ return _oload_fmod($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 0 2
Condition33%1/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
002
MC/DC0%0/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table33%1/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
158 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
159 0 return _oload_fmod($_[0], $coderef->($_[1]), $_[2]);
160 }
161 0 die "Unrecognized 2nd argument passed to oload_fmod() function";
162 }
163  
164 sub oload_pow {
165 28 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_pow: called CC=5 SCAR=16.8
Pod undocumented
166 28 ▶ return _oload_pow(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 0 28 28
167 28 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 28 0 28
168 28 my $coderef = $Math::Float32::handler{$itsa};
169 28 ▶ return _oload_pow($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 26 28
Condition66%2/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
2602
MC/DC50%1/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table66%2/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
170 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
171 26 return _oload_pow($_[0], $coderef->($_[1]), $_[2]);
172 }
173 0 die "Unrecognized 2nd argument passed to oload_pow() function";
174 }
175  
176 sub oload_abs {
177 2 ▶ return $_[0] * -1 if $_[0] < 0;
Subroutine oload_abs: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] < 0 1 1 2
178 1 return $_[0];
179 }
180  
181 sub oload_equiv {
182 8662 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_equiv: called CC=5 SCAR=16.4
Pod undocumented
183 8662 ▶ if($itsa == 22 || $itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22 or $itsa < 5) 8662 0 8662
Condition66%2/3
$itsa == 22 or $itsa < 5
l!l&&r!l&&!r
8580820
MC/DC0%0/2
$itsa == 22 or $itsa < 5
$itsa == 22 $itsa < 5
Truth table66%2/3
A or B
A= $itsa == 22B= $itsa < 5
ABresult
1X1
011
000
184 8662 my $coderef = $Math::Float32::handler{$itsa};
185 8662 ▶ return _oload_equiv($_[0], $coderef->(bin2hex($_[1])), 0)
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 8660 8662
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
8598622
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
186 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
187 8660 return _oload_equiv($_[0], $coderef->($_[1]), 0);
188 }
189 0 die "Unrecognized 2nd argument passed to oload_equiv() function";
190 }
191  
192 sub oload_not_equiv {
193 14 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_not_equiv: called CC=5 SCAR=17.5
Pod undocumented
194 14 ▶ if($itsa == 22 || $itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22 or $itsa < 5) 14 0 14
Condition66%2/3
$itsa == 22 or $itsa < 5
l!l&&r!l&&!r
1040
MC/DC0%0/2
$itsa == 22 or $itsa < 5
$itsa == 22 $itsa < 5
Truth table66%2/3
A or B
A= $itsa == 22B= $itsa < 5
ABresult
1X1
011
000
195 14 my $coderef = $Math::Float32::handler{$itsa};
196 14 ▶ return _oload_not_equiv($_[0], $coderef->(bin2hex($_[1])), 0)
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 0 14 14
Condition66%2/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
1220
MC/DC0%0/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table66%2/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
197 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
198 14 return _oload_not_equiv($_[0], $coderef->($_[1]), 0);
199 }
200 0 die "Unrecognized 2nd argument passed to oload_not_equiv() function";
201 }
202  
203 sub oload_gt {
204 26 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_gt: called CC=5 SCAR=16.8
Pod undocumented
205 26 ▶ if($itsa == 22 || $itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22 or $itsa < 5) 26 0 26
Condition33%1/3
$itsa == 22 or $itsa < 5
l!l&&r!l&&!r
0260
MC/DC0%0/2
$itsa == 22 or $itsa < 5
$itsa == 22 $itsa < 5
Truth table33%1/3
A or B
A= $itsa == 22B= $itsa < 5
ABresult
1X1
011
000
206 26 my $coderef = $Math::Float32::handler{$itsa};
207 26 ▶ return _oload_gt($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 24 26
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
10142
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
208 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
209 24 return _oload_gt($_[0], $coderef->($_[1]), $_[2]);
210 }
211 0 die "Unrecognized 2nd argument passed to oload_gt() function";
212 }
213  
214 sub oload_gte {
215 66 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_gte: called CC=5 SCAR=16.8
Pod undocumented
216 66 ▶ if($itsa == 22 || $itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22 or $itsa < 5) 66 0 66
Condition33%1/3
$itsa == 22 or $itsa < 5
l!l&&r!l&&!r
0660
MC/DC0%0/2
$itsa == 22 or $itsa < 5
$itsa == 22 $itsa < 5
Truth table33%1/3
A or B
A= $itsa == 22B= $itsa < 5
ABresult
1X1
011
000
217 66 my $coderef = $Math::Float32::handler{$itsa};
218 66 ▶ return _oload_gte($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 4 62 66
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
45174
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
219 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
220 62 return _oload_gte($_[0], $coderef->($_[1]), $_[2]);
221 }
222 0 die "Unrecognized 2nd argument passed to oload_gte() function";
223 }
224  
225 sub oload_lt {
226 28 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_lt: called CC=5 SCAR=16.8
Pod undocumented
227 28 ▶ if($itsa == 22 || $itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22 or $itsa < 5) 28 0 28
Condition33%1/3
$itsa == 22 or $itsa < 5
l!l&&r!l&&!r
0280
MC/DC0%0/2
$itsa == 22 or $itsa < 5
$itsa == 22 $itsa < 5
Truth table33%1/3
A or B
A= $itsa == 22B= $itsa < 5
ABresult
1X1
011
000
228 28 my $coderef = $Math::Float32::handler{$itsa};
229 28 ▶ return _oload_lt($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 26 28
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
16102
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
230 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
231 26 return _oload_lt($_[0], $coderef->($_[1]), $_[2]);
232 }
233 0 die "Unrecognized 2nd argument passed to oload_lt() function";
234 }
235  
236 sub oload_lte {
237 66 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_lte: called CC=5 SCAR=16.8
Pod undocumented
238 66 ▶ if($itsa == 22 || $itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22 or $itsa < 5) 66 0 66
Condition33%1/3
$itsa == 22 or $itsa < 5
l!l&&r!l&&!r
0660
MC/DC0%0/2
$itsa == 22 or $itsa < 5
$itsa == 22 $itsa < 5
Truth table33%1/3
A or B
A= $itsa == 22B= $itsa < 5
ABresult
1X1
011
000
239 66 my $coderef = $Math::Float32::handler{$itsa};
240 66 ▶ return _oload_lte($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 4 62 66
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
49134
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
241 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
242 62 return _oload_lte($_[0], $coderef->($_[1]), $_[2]);
243 }
244 0 die "Unrecognized 2nd argument passed to oload_lte() function";
245 }
246  
247 sub oload_spaceship {
248 48 ▶ my $itsa = _itsa($_[1]);
Subroutine oload_spaceship: called CC=5 SCAR=16.8
Pod undocumented
249 48 ▶ if($itsa == 22 || $itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 22 or $itsa < 5) 48 0 48
Condition33%1/3
$itsa == 22 or $itsa < 5
l!l&&r!l&&!r
0480
MC/DC0%0/2
$itsa == 22 or $itsa < 5
$itsa == 22 $itsa < 5
Truth table33%1/3
A or B
A= $itsa == 22B= $itsa < 5
ABresult
1X1
011
000
250 48 my $coderef = $Math::Float32::handler{$itsa};
251 48 ▶ return _oload_spaceship($_[0], $coderef->(bin2hex($_[1])), $_[2])
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i 2 46 48
Condition100%3/3
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
!ll&&!rl&&r
23232
MC/DC100%2/2
$itsa == 4 and $_[1] =~ /^(\s+)?[\-\+]?0b/i
$itsa == 4 $_[1] =~ /^(\s+)?[\-\+]?0b/i
Truth table100%3/3
A and B
A= $itsa == 4B= $_[1] =~ /^(\s+)?[\-\+]?0b/i
ABresult
0X0
100
111
252 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
253 46 return _oload_spaceship($_[0], $coderef->($_[1]), $_[2]);
254 }
255 0 die "Unrecognized 2nd argument passed to oload_spaceship() function";
256 }
257  
258 sub oload_interp {
259 270 ▶ return sprintf("%.9g", flt_to_NV($_[0]));
Subroutine oload_interp: called CC=1 SCAR=0.0
Pod undocumented
260 }
261  
262 sub is_flt_zero {
263 3 ▶ if($_[0] == 0) {
Subroutine is_flt_zero: called CC=3 SCAR=11.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] == 0) 3 0 3
264 3 ▶ return -1 if flt_signbit($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if flt_signbit($_[0]) 1 2 3
265 2 return 1;
266 }
267 0 return 0;
268 }
269  
270 sub flt_signbit {
271 13 ▶ return 1 if hex(substr(unpack_flt_hex($_[0]), 0, 1)) >= 8;
Subroutine flt_signbit: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if hex substr(unpack_flt_hex($_[0]), 0, 1) >= 8 6 7 13
272 7 return 0;
273 }
274  
275 sub flt_nextabove {
276 if(is_flt_zero($_[0])) {
277 flt_set($_[0], $Math::Float32::flt_DENORM_MIN);
278 }
279 elsif($_[0] < $Math::Float32::flt_NORM_MIN && $_[0] >= -$Math::Float32::flt_NORM_MIN ) {
280 $_[0] += $Math::Float32::flt_DENORM_MIN;
281 flt_set_zero($_[0], -1) if is_flt_zero($_[0]);
282 }
283 else {
284 _flt_nextabove($_[0]);
285 }
286 }
287  
288 sub flt_nextbelow {
289 if(is_flt_zero($_[0])) {
290 flt_set($_[0], -$Math::Float32::flt_DENORM_MIN);
291 }
292 elsif($_[0] <= $Math::Float32::flt_NORM_MIN && $_[0] > -$Math::Float32::flt_NORM_MIN ) {
293 $_[0] -= $Math::Float32::flt_DENORM_MIN;
294 }
295 else {
296 _flt_nextbelow($_[0]);
297 }
298 }
299  
300 sub unpack_flt_hex {
301 8310 ▶ my @ret = _unpack_flt_hex($_[0]);
Subroutine unpack_flt_hex: called CC=1 SCAR=0.0
Pod undocumented
302 8310 return join('', @ret);
303 }
304  
305 sub pack_flt_hex {
306 8284 ▶ my $arg = shift;
Subroutine pack_flt_hex: called CC=5 SCAR=16.2
Pod undocumented
307 8284 my $is_neg = '';
308 8284 ▶ die "Invalid argument ($arg) given to pack_flt_hex"
Branch: 1 branch
BranchTrueFalseTotal
if length $arg != 8 or $arg =~ /[^0-9a-fA-F]/ 0 8284 8284
Condition33%1/3
length $arg != 8 or $arg =~ /[^0-9a-fA-F]/
l!l&&r!l&&!r
008284
MC/DC0%0/2
length $arg != 8 or $arg =~ /[^0-9a-fA-F]/
length $arg != 8 $arg =~ /[^0-9a-fA-F]/
Truth table33%1/3
A or B
A= length $arg != 8B= $arg =~ /[^0-9a-fA-F]/
ABresult
1X1
011
000
309 if(length($arg) != 8 || $arg =~ /[^0-9a-fA-F]/);
310  
311 8284 my $binstr = unpack 'B32', pack 'H8', $arg;
312 8284 ▶ $is_neg = '-' if substr($binstr, 0, 1) eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if substr($binstr, 0, 1) eq 1 4142 4142 8284
313 8284 my $power = oct('0b' .substr($binstr,1, 8)) - 127;
314 8284 my $prefix = '1';
315 8284 ▶ if($power < -126) { # Subnormal
Branch: 1 branch
BranchTrueFalseTotal
if ($power < -126) 4142 4142 8284
316 4142 $power = -126;
317 4142 $prefix = '0';
318 }
319  
320 # Unfortunately, C's strtof function (which is used by
321 # Math::Float32::new() does not accommodate binary strings,
322 # so we have to convert the binary string to its hex
323 # equivalent before passing it to new().
324 8284 $power -= 23;
325 8284 my $hexstring = '0x' . lc(unpack 'H6', pack('B24', $prefix . substr($binstr,9, 23)));
326 8284 return Math::Float32->new($is_neg . $hexstring . "p$power");
327 }
328  
329 sub bin2hex {
330 152 ▶ my $arg = shift; # It is assumed that $arg =~ /^(\s+)?[\-\+]?0b/i
Subroutine bin2hex: called CC=12 SCAR=24.8
Pod undocumented
331 152 $arg =~ s/^\s+//;
332 152 ▶ die "Illegal character(s) in arg ($arg) passed to bin2hex"
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /[^0-9peb\.\-\+]/i 0 152 152
333 if $arg =~ /[^0-9peb\.\-\+]/i;
334 152 my($is_neg, $point_index) = ('');
335 152 ▶ $is_neg = '-' if $arg =~ /^\-/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /^\-/ 61 91 152
336  
337 152 $arg =~ s/^[\-\+]?0b//i;
338  
339 # Remove all leading zeroes, but retain a leading
340 # '0' if (and only if) it is succeeded by a '.'.
341 152 ▶ substr($arg, 0, 1, '') while $arg =~ /^0[^\.]/;
Branch: 1 branch
BranchTrueFalseTotal
$arg =~ /^0[^\.]/ and do { substr($arg, 0, 1, '') } 111 152 263
342  
343 152 $arg =~ s/e/p/i;
344 152 my @args = split /p/i, $arg;
345  
346 { # Start no warnings 'uninitialized'
347  
348 10 ▶ no warnings 'uninitialized'; # $args[0] might be uninitialized
Subroutine BEGIN: called CC=1 SCAR=0.0
349 # Remove trailing zeroes from beyond the
350 # radix point and remove a trailing '.' (if present)
351 152 ▶ $args[0] =~ s/0+$// if $args[0] =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $args[0] =~ /\./ 104 48 152
352 152 $args[0] =~ s/\.$//;
353  
354 152 ▶ $args[1] //= 0;
Condition100%2/2
$args[1] //= 0
l!l
7775
MC/DC100%1/1
$args[1] //= 0
$args[1]
Truth table100%2/2
A
A= $args[1]
Aresult
11
00
355 152 $point_index = index($args[0], '.');
356 152 ▶ if ($args[0] =~ s/^0\.//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] =~ s/^0\.//) 8 144 152
357 8 $args[1]--;
358 8 ▶ while($args[0] =~ /^0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] =~ /^0/) 12 8 20
359 12 substr($args[0], 0, 1, '');
360 12 $args[1]--;
361 }
362 }
363 152 ▶ return $is_neg . '0x0p0' if $args[0] !~ /1/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args[0] =~ /1/ 30 122 152
364  
365 } # End no warnings 'uninitialized'
366  
367 122 $args[0] =~ s/\.//;
368  
369 122 my $pad = length($args[0]) % 4;
370 122 ▶ if($pad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pad) 44 78 122
371 44 $pad = 4 - $pad;
372 44 $args[0] .= '0' x $pad;
373 44 ▶ $args[1] -= $pad if $point_index < 0; # The string did not contain a radix point
Branch: 1 branch
BranchTrueFalseTotal
if $point_index < 0 24 20 44
374 }
375  
376 122 my $B_quantity = length($args[0]);
377 122 my $H_quantity = $B_quantity / 4;
378  
379 # It may well be that the case (ie "lower" or "upper") makes no difference.
380 # Out of caution, I'll specify lower case and use the (matching) '0x' prefix.
381 122 my $mantissa = lc(unpack "H$H_quantity", pack "B$B_quantity", $args[0]);
382  
383 122 ▶ return $is_neg . '0x' . $mantissa . "p$args[1]" if $point_index < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $point_index < 0 52 70 122
384 70 my $exponent = $point_index - $B_quantity + $args[1];
385 70 return $is_neg . '0x' . $mantissa . "p$exponent";
386 }
387  
388 sub _get_norm_max {
389 10 ▶ my $ret = 0;
Subroutine _get_norm_max: called CC=2 SCAR=6.9
390 10 for my $p(1 .. flt_MANTBITS) { $ret += 2 ** (flt_EMAX - $p) }
391 10 return $ret;
392 }
393  
394 sub _get_denorm_max {
395 10 ▶ my $ret = 0;
Subroutine _get_denorm_max: called CC=2 SCAR=6.9
396 10 my $max = -(flt_EMIN - 1);
397 10 my $min = $max - (flt_MANTBITS - 2);
398 10 for my $p($min .. $max) { $ret += 2 ** -$p }
399 10 return $ret;
400 }
401  
402 10 1;
403  
404 __END__
↑ Summary Float32.xs »