blib/lib/Math/Float32.pm

filter: Statementstmt 84.9% 192 / 226 Branchbran 62.6% 89 / 142 Conditioncond 72.7% 56 / 77 MC/DCmcdc 51.0% 25 / 49 Subroutinesub 97.3% 36 / 37 Podpod 0.0% 0 / 23 totaltotal 71.8% 398 / 554 CC 99 SCAR 19.7
CC
99
Cov
76%
oload_spaceship
13.1
bin2hex
12.0
new
10.7
CRAP 7.2
↑ 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,
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ;
35  
36 10 require Exporter;
37 10 *import = \&Exporter::import;
38 10 require DynaLoader;
39  
40 10 our $VERSION = '0.03';
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
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 9022 ▶sub new {
Subroutine new: called CC=10 SCAR=23.7
Pod undocumented
81 9022 ▶ shift if (@_ > 0 && !ref($_[0]) && _itsa($_[0]) == 4 && $_[0] eq "Math::Float32");
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 1 ▶sub flt_set {
Subroutine flt_set: called CC=3 SCAR=11.8
Pod undocumented
95 1 ▶ die "flt_set expects to receive precisely 2 arguments" if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 1 1
96 1 my $itsa = _itsa($_[1]);
97 0 ▶ 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 101 ▶sub oload_add {
Subroutine oload_add: called CC=6 SCAR=19.0
Pod undocumented
105 101 my $itsa = _itsa($_[1]);
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 ▶ return Math::Bfloat16::oload_add($_[1], $_[0], $_[2]) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
114 0 die "Unrecognized 2nd argument passed to oload_add() function";
115 }
116  
117 141 ▶sub oload_mul {
Subroutine oload_mul: called CC=6 SCAR=19.0
Pod undocumented
118 141 my $itsa = _itsa($_[1]);
119 141 ▶ return _oload_mul(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 64 77 141
120 77 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 77 0 77
121 77 my $coderef = $Math::Float32::handler{$itsa};
122 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
123 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
124 76 return _oload_mul($_[0], $coderef->($_[1]), 0);
125 }
126 0 ▶ return Math::Bfloat16::oload_mul($_[1], $_[0], $_[2]) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
127 0 die "Unrecognized 2nd argument passed to oload_mul() function";
128 }
129  
130 181 ▶sub oload_sub {
Subroutine oload_sub: called CC=6 SCAR=19.0
Pod undocumented
131 181 my $itsa = _itsa($_[1]);
132 181 ▶ return _oload_sub(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 2 179 181
133 179 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 179 0 179
134 179 my $coderef = $Math::Float32::handler{$itsa};
135 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
136 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
137 177 return _oload_sub($_[0], $coderef->($_[1]), $_[2]);
138 }
139 0 ▶ return Math::Bfloat16::oload_sub($_[1], $_[0], 1) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
140 0 die "Unrecognized 2nd argument passed to oload_sub() function";
141 }
142  
143 107 ▶sub oload_div {
Subroutine oload_div: called CC=6 SCAR=19.6
Pod undocumented
144 107 my $itsa = _itsa($_[1]);
145 107 ▶ return _oload_div(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 0 107 107
146 107 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 107 0 107
147 107 my $coderef = $Math::Float32::handler{$itsa};
148 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
149 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
150 105 return _oload_div($_[0], $coderef->($_[1]), $_[2]);
151 }
152 0 ▶ return Math::Bfloat16::oload_div($_[1], $_[0], 1) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
153 0 die "Unrecognized 2nd argument passed to oload_div() function";
154 }
155  
156 12 ▶sub oload_fmod {
Subroutine oload_fmod: called CC=6 SCAR=22.9
Pod undocumented
157 12 my $itsa = _itsa($_[1]);
158 12 ▶ return _oload_fmod(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 10 2 12
159 2 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 2 0 2
160 2 my $coderef = $Math::Float32::handler{$itsa};
161 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
162 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
163 0 return _oload_fmod($_[0], $coderef->($_[1]), $_[2]);
164 }
165 0 ▶ return Math::Bfloat16::oload_fmod($_[1], $_[0], 1) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
166 0 die "Unrecognized 2nd argument passed to oload_fmod() function";
167 }
168  
169 28 ▶sub oload_pow {
Subroutine oload_pow: called CC=6 SCAR=20.5
Pod undocumented
170 28 my $itsa = _itsa($_[1]);
171 28 ▶ return _oload_pow(@_) if $itsa == 22;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 22 0 28 28
172 28 ▶ if($itsa < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa < 5) 28 0 28
173 28 my $coderef = $Math::Float32::handler{$itsa};
174 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
175 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
176 26 return _oload_pow($_[0], $coderef->($_[1]), $_[2]);
177 }
178 0 ▶ return Math::Bfloat16::oload_pow($_[1], $_[0], 1) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
179 0 die "Unrecognized 2nd argument passed to oload_pow() function";
180 }
181  
182 2 ▶sub oload_abs {
Subroutine oload_abs: called CC=2 SCAR=6.9
Pod undocumented
183 2 ▶ return $_[0] * -1 if $_[0] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] < 0 1 1 2
184 1 return $_[0];
185 }
186  
187 8662 ▶sub oload_equiv {
Subroutine oload_equiv: called CC=6 SCAR=19.6
Pod undocumented
188 8662 my $itsa = _itsa($_[1]);
189 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
190 8662 my $coderef = $Math::Float32::handler{$itsa};
191 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
192 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
193 8660 return _oload_equiv($_[0], $coderef->($_[1]), 0);
194 }
195 0 ▶ return Math::Bfloat16::oload_equiv($_[1], $_[0], 0) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
196 0 die "Unrecognized 2nd argument passed to oload_equiv() function";
197 }
198  
199 14 ▶sub oload_not_equiv {
Subroutine oload_not_equiv: called CC=6 SCAR=21.6
Pod undocumented
200 14 my $itsa = _itsa($_[1]);
201 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
202 14 my $coderef = $Math::Float32::handler{$itsa};
203 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
204 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
205 14 return _oload_not_equiv($_[0], $coderef->($_[1]), 0);
206 }
207 0 ▶ return Math::Bfloat16::oload_not_equiv($_[1], $_[0], 0) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
208 0 die "Unrecognized 2nd argument passed to oload_not_equiv() function";
209 }
210  
211 26 ▶sub oload_gt {
Subroutine oload_gt: called CC=6 SCAR=20.5
Pod undocumented
212 26 my $itsa = _itsa($_[1]);
213 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
214 26 my $coderef = $Math::Float32::handler{$itsa};
215 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
216 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
217 24 return _oload_gt($_[0], $coderef->($_[1]), $_[2]);
218 }
219 0 ▶ return Math::Bfloat16::oload_lt($_[1], $_[0], 0) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
220 0 die "Unrecognized 2nd argument passed to oload_gt() function";
221 }
222  
223 66 ▶sub oload_gte {
Subroutine oload_gte: called CC=6 SCAR=20.5
Pod undocumented
224 66 my $itsa = _itsa($_[1]);
225 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
226 66 my $coderef = $Math::Float32::handler{$itsa};
227 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
228 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
229 62 return _oload_gte($_[0], $coderef->($_[1]), $_[2]);
230 }
231 0 ▶ return Math::Bfloat16::oload_lte($_[1], $_[0], 0) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
232 0 die "Unrecognized 2nd argument passed to oload_gte() function";
233 }
234  
235 28 ▶sub oload_lt {
Subroutine oload_lt: called CC=6 SCAR=20.5
Pod undocumented
236 28 my $itsa = _itsa($_[1]);
237 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
238 28 my $coderef = $Math::Float32::handler{$itsa};
239 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
240 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
241 26 return _oload_lt($_[0], $coderef->($_[1]), $_[2]);
242 }
243 0 ▶ return Math::Bfloat16::oload_gt($_[1], $_[0], 0) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
244 0 die "Unrecognized 2nd argument passed to oload_lt() function";
245 }
246  
247 66 ▶sub oload_lte {
Subroutine oload_lte: called CC=6 SCAR=20.5
Pod undocumented
248 66 my $itsa = _itsa($_[1]);
249 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
250 66 my $coderef = $Math::Float32::handler{$itsa};
251 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
252 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
253 62 return _oload_lte($_[0], $coderef->($_[1]), $_[2]);
254 }
255 0 ▶ return Math::Bfloat16::oload_gte($_[1], $_[0], 0) if $itsa == 20;
Branch: 1 branch
BranchTrueFalseTotal
if $itsa == 20 0 0 0
256 0 die "Unrecognized 2nd argument passed to oload_lte() function";
257 }
258  
259 48 ▶sub oload_spaceship {
Subroutine oload_spaceship: called CC=7 SCAR=25.7
Pod undocumented
260 48 my $itsa = _itsa($_[1]);
261 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
262 48 my $coderef = $Math::Float32::handler{$itsa};
263 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
264 if($itsa == 4 && $_[1] =~ /^(\s+)?[\-\+]?0b/i);
265 46 return _oload_spaceship($_[0], $coderef->($_[1]), $_[2]);
266 }
267 0 ▶ if($itsa == 20) {
Branch: 1 branch
BranchTrueFalseTotal
if ($itsa == 20) 0 0 0
268 0 my $ret = Math::Bfloat16::oload_spaceship($_[1], $_[0], 0);
269 0 ▶ return undef if !defined($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ret 0 0 0
270 0 return $ret * -1;
271 }
272 0 die "Unrecognized 2nd argument passed to oload_spaceship() function";
273 }
274  
275 270 ▶sub oload_interp {
Subroutine oload_interp: called CC=1 SCAR=0.0
Pod undocumented
276 270 return sprintf("%.9g", flt_to_NV($_[0]));
277 }
278  
279 3 ▶sub is_flt_zero {
Subroutine is_flt_zero: called CC=3 SCAR=11.4
Pod undocumented
280 3 ▶ if($_[0] == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] == 0) 3 0 3
281 3 ▶ return -1 if flt_signbit($_[0]);
Branch: 1 branch
BranchTrueFalseTotal
if flt_signbit($_[0]) 1 2 3
282 2 return 1;
283 }
284 0 return 0;
285 }
286  
287 13 ▶sub flt_signbit {
Subroutine flt_signbit: called CC=2 SCAR=6.9
Pod undocumented
288 13 ▶ return 1 if hex(substr(unpack_flt_hex($_[0]), 0, 1)) >= 8;
Branch: 1 branch
BranchTrueFalseTotal
if hex substr(unpack_flt_hex($_[0]), 0, 1) >= 8 6 7 13
289 7 return 0;
290 }
291  
292 8310 ▶sub unpack_flt_hex {
Subroutine unpack_flt_hex: called CC=1 SCAR=0.0
Pod undocumented
293 8310 my @ret = _unpack_flt_hex($_[0]);
294 8310 return join('', @ret);
295 }
296  
297 8284 ▶sub pack_flt_hex {
Subroutine pack_flt_hex: called CC=5 SCAR=16.2
Pod undocumented
298 8284 my $arg = shift;
299 8284 my $is_neg = '';
300 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
301 if(length($arg) != 8 || $arg =~ /[^0-9a-fA-F]/);
302  
303 8284 my $binstr = unpack 'B32', pack 'H8', $arg;
304 8284 ▶ $is_neg = '-' if substr($binstr, 0, 1) eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if substr($binstr, 0, 1) eq 1 4142 4142 8284
305 8284 my $power = oct('0b' .substr($binstr,1, 8)) - 127;
306 8284 my $prefix = '1';
307 8284 ▶ if($power < -126) { # Subnormal
Branch: 1 branch
BranchTrueFalseTotal
if ($power < -126) 4142 4142 8284
308 4142 $power = -126;
309 4142 $prefix = '0';
310 }
311  
312 # Unfortunately, C's strtof function (which is used by
313 # Math::Float32::new() does not accommodate binary strings,
314 # so we have to convert the binary string to its hex
315 # equivalent before passing it to new().
316 8284 $power -= 23;
317 8284 my $hexstring = '0x' . lc(unpack 'H6', pack('B24', $prefix . substr($binstr,9, 23)));
318 8284 return Math::Float32->new($is_neg . $hexstring . "p$power");
319 }
320  
321 152 ▶sub bin2hex {
Subroutine bin2hex: called CC=12 SCAR=24.8
Pod undocumented
322 152 my $arg = shift; # It is assumed that $arg =~ /^(\s+)?[\-\+]?0b/i
323 152 $arg =~ s/^\s+//;
324 152 ▶ die "Illegal character(s) in arg ($arg) passed to bin2hex"
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /[^0-9peb\.\-\+]/i 0 152 152
325 if $arg =~ /[^0-9peb\.\-\+]/i;
326 152 my($is_neg, $point_index) = ('');
327 152 ▶ $is_neg = '-' if $arg =~ /^\-/;
Branch: 1 branch
BranchTrueFalseTotal
if $arg =~ /^\-/ 61 91 152
328  
329 152 $arg =~ s/^[\-\+]?0b//i;
330  
331 # Remove all leading zeroes, but retain a leading
332 # '0' if (and only if) it is succeeded by a '.'.
333 152 ▶ substr($arg, 0, 1, '') while $arg =~ /^0[^\.]/;
Branch: 1 branch
BranchTrueFalseTotal
$arg =~ /^0[^\.]/ and do { substr($arg, 0, 1, '') } 111 152 263
334  
335 152 $arg =~ s/e/p/i;
336 152 my @args = split /p/i, $arg;
337  
338 { # Start no warnings 'uninitialized'
339  
340 10 ▶ no warnings 'uninitialized'; # $args[0] might be uninitialized
Subroutine BEGIN: called CC=1 SCAR=0.0
341 # Remove trailing zeroes from beyond the
342 # radix point and remove a trailing '.' (if present)
343 152 ▶ $args[0] =~ s/0+$// if $args[0] =~ /\./;
Branch: 1 branch
BranchTrueFalseTotal
if $args[0] =~ /\./ 104 48 152
344 152 $args[0] =~ s/\.$//;
345  
346 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
347 152 $point_index = index($args[0], '.');
348 152 ▶ if ($args[0] =~ s/^0\.//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] =~ s/^0\.//) 8 144 152
349 8 $args[1]--;
350 8 ▶ while($args[0] =~ /^0/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] =~ /^0/) 12 8 20
351 12 substr($args[0], 0, 1, '');
352 12 $args[1]--;
353 }
354 }
355 152 ▶ return $is_neg . '0x0p0' if $args[0] !~ /1/;
Branch: 1 branch
BranchTrueFalseTotal
unless $args[0] =~ /1/ 30 122 152
356  
357 } # End no warnings 'uninitialized'
358  
359 122 $args[0] =~ s/\.//;
360  
361 122 my $pad = length($args[0]) % 4;
362 122 ▶ if($pad) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pad) 44 78 122
363 44 $pad = 4 - $pad;
364 44 $args[0] .= '0' x $pad;
365 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
366 }
367  
368 122 my $B_quantity = length($args[0]);
369 122 my $H_quantity = $B_quantity / 4;
370  
371 # It may well be that the case (ie "lower" or "upper") makes no difference.
372 # Out of caution, I'll specify lower case and use the (matching) '0x' prefix.
373 122 my $mantissa = lc(unpack "H$H_quantity", pack "B$B_quantity", $args[0]);
374  
375 122 ▶ return $is_neg . '0x' . $mantissa . "p$args[1]" if $point_index < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $point_index < 0 52 70 122
376 70 my $exponent = $point_index - $B_quantity + $args[1];
377 70 return $is_neg . '0x' . $mantissa . "p$exponent";
378 }
379  
380 10 ▶sub _get_norm_max {
Subroutine _get_norm_max: called CC=2 SCAR=6.9
381 10 my $ret = 0;
382 10 for my $p(1 .. flt_MANTBITS) { $ret += 2 ** (flt_EMAX - $p) }
383 10 return $ret;
384 }
385  
386 10 ▶sub _get_denorm_max {
Subroutine _get_denorm_max: called CC=2 SCAR=6.9
387 10 my $ret = 0;
388 10 my $max = -(flt_EMIN - 1);
389 10 my $min = $max - (flt_MANTBITS - 2);
390 10 for my $p($min .. $max) { $ret += 2 ** -$p }
391 10 return $ret;
392 }
393  
394 10 1;
395  
396 __END__
↑ Summary Float32.xs »