blib/lib/Math/Float128.pm

filter: Statementstmt 91.3% 95 / 104 Branchbran 81.8% 36 / 44 Conditioncond 50.0% 3 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 34 / 34 Podpod 0.0% 0 / 3 totaltotal 87.1% 170 / 195 CC 25 SCAR 20.8
CC
25
Cov
87%
new
19.0
_overload_string
11.3
BEGIN
1.0
CRAP 8.0
↑ Summary blib/lib/Math/Float128/Constant.pm »
1 ## This file generated by InlineX::C2XS (version 0.22) using Inline::C (version 0.53)
2 package Math::Float128;
3 23 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 23 ▶use Math::Float128::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 23 require Exporter;
9 23 *import = \&Exporter::import;
10 23 require DynaLoader;
11  
12 use overload
13 23 ▶ '+' => \&_overload_add,
Subroutine BEGIN: called CC=1 SCAR=0.0
14 '*' => \&_overload_mul,
15 '-' => \&_overload_sub,
16 '/' => \&_overload_div,
17 '**' => \&_overload_pow,
18 '+=' => \&_overload_add_eq,
19 '*=' => \&_overload_mul_eq,
20 '-=' => \&_overload_sub_eq,
21 '/=' => \&_overload_div_eq,
22 '**=' => \&_overload_pow_eq,
23 '==' => \&_overload_equiv,
24 '""' => \&_overload_string,
25 '!=' => \&_overload_not_equiv,
26 'bool' => \&_overload_true,
27 '!' => \&_overload_not,
28 '=' => \&_overload_copy,
29 '<' => \&_overload_lt,
30 '<=' => \&_overload_lte,
31 '>' => \&_overload_gt,
32 '>=' => \&_overload_gte,
33 '<=>' => \&_overload_spaceship,
34 'abs' => \&_overload_abs,
35 'int' => \&_overload_int,
36 'sqrt' => \&_overload_sqrt,
37 'log' => \&_overload_log,
38 'exp' => \&_overload_exp,
39 'sin' => \&_overload_sin,
40 'cos' => \&_overload_cos,
41 'atan2' => \&_overload_atan2,
42 '++' => \&_overload_inc,
43 '--' => \&_overload_dec,
44 23 ;
45  
46 23 ▶use constant F128_PV_NV_BUG => Math::Float128::Constant::_has_pv_nv_bug();
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 # Inspired by https://github.com/Perl/perl5/issues/19550, which affects only perl-5.35.10:
49 23 ▶use constant ISSUE_19550 => Math::Float128::Constant::_issue_19550();
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 23 ▶use subs qw(FLT128_DIG FLT128_MANT_DIG FLT128_MIN_EXP FLT128_MAX_EXP FLT128_MIN_10_EXP FLT128_MAX_10_EXP
Subroutine BEGIN: called CC=1 SCAR=0.0
52 M_Eq M_LOG2Eq M_LOG10Eq M_LN2q M_LN10q M_PIq M_PI_2q M_PI_4q M_1_PIq M_2_PIq
53 M_2_SQRTPIq M_SQRT2q M_SQRT1_2q
54 23 FLT128_MAX FLT128_MIN FLT128_EPSILON FLT128_DENORM_MIN);
55  
56 23 $Math::Float128::VERSION = '0.18';
57  
58 23 Math::Float128->DynaLoader::bootstrap($Math::Float128::VERSION);
59  
60 23 my @tagged = qw(
61 F128_PV_NV_BUG
62 flt128_set_prec flt128_get_prec InfF128 NaNF128 ZeroF128 UnityF128 is_NaNF128
63 is_InfF128 is_InfF128 is_ZeroF128 STRtoF128 NVtoF128 IVtoF128 UVtoF128 F128toSTR
64 F128toSTRP F128toF128 F128toNV
65 FLT128_DIG FLT128_MANT_DIG FLT128_MIN_EXP FLT128_MAX_EXP FLT128_MIN_10_EXP FLT128_MAX_10_EXP
66 M_Eq M_LOG2Eq M_LOG10Eq M_LN2q M_LN10q M_PIq M_PI_2q M_PI_4q M_1_PIq M_2_PIq
67 M_2_SQRTPIq M_SQRT2q M_SQRT1_2q
68 FLT128_MAX FLT128_MIN FLT128_EPSILON FLT128_DENORM_MIN
69 cmp2NV f128_bytes
70 acos_F128 acosh_F128 asin_F128 asinh_F128 atan_F128 atanh_F128 atan2_F128 cbrt_F128 ceil_F128
71 copysign_F128 cosh_F128 cos_F128 erf_F128 erfc_F128 exp_F128 expm1_F128 fabs_F128 fdim_F128
72 finite_F128 floor_F128 fma_F128 fmax_F128 fmin_F128 fmod_F128 frexp_F128 hypot_F128 isinf_F128
73 ilogb_F128 isnan_F128 j0_F128 j1_F128 jn_F128 ldexp_F128 lgamma_F128 llrint_F128 llround_F128
74 log_F128 log10_F128 log2_F128 log1p_F128 lrint_F128 lround_F128 modf_F128 nan_F128
75 nearbyint_F128 nextafter_F128 pow_F128 remainder_F128 remquo_F128 rint_F128 round_F128
76 scalbln_F128 scalbn_F128 signbit_F128 sincos_F128 sinh_F128 sin_F128 sqrt_F128 tan_F128
77 tanh_F128 tgamma_F128 trunc_F128 y0_F128 y1_F128 yn_F128
78 fromSTR fromNV fromIV fromUV fromF128
79 );
80  
81 23 @Math::Float128::EXPORT = ();
82 23 @Math::Float128::EXPORT_OK = @tagged;
83 23 %Math::Float128::EXPORT_TAGS = (all => \@tagged);
84  
85 23 $Math::Float128::NOK_POK = 0; # Set to 1 to allow warnings in new() and overloaded operations when
86 # a scalar that has set both NOK (NV) and POK (PV) flags is encountered
87  
88 23 ▶sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod undocumented
89  
90 8 ▶sub _overload_string {
Subroutine _overload_string: called CC=8 SCAR=24.2
91  
92 8 ▶ if(is_ZeroF128($_[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_ZeroF128($_[0])) 4 4 8
93 4 ▶ return '-0' if is_ZeroF128($_[0]) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if is_ZeroF128($_[0]) < 0 2 2 4
94 2 return '0';
95 }
96  
97 4 ▶ if(is_NaNF128($_[0])) {return 'NaN'}
Branch: 1 branch
BranchTrueFalseTotal
if (is_NaNF128($_[0])) 2 2 4
98  
99 2 my $inf = is_InfF128($_[0]);
100 2 ▶ return '-Inf' if $inf < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $inf < 0 1 1 2
101 1 ▶ return 'Inf' if $inf > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $inf > 0 1 0 1
102  
103 0 my @p = split /e/i, F128toSTR($_[0]);
104 0 ▶ while(substr($p[0], -1, 1) eq '0' && substr($p[0], -2, 1) ne '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($p[0], -1, 1) eq 0 and substr($p[0], -2, 1) ne ".") 0 0 0
Condition0%0/3
substr($p[0], -1, 1) eq 0 and substr($p[0], -2, 1) ne "."
!ll&&!rl&&r
000
MC/DC0%0/2
substr($p[0], -1, 1) eq 0 and substr($p[0], -2, 1) ne "."
substr($p[0], -1, 1) eq 0 substr($p[0], -2, 1) ne "."
Truth table0%0/3
A and B
A= substr($p[0], -1, 1) eq 0B= substr($p[0], -2, 1) ne "."
ABresult
0X0
100
111
105 0 chop $p[0];
106 }
107 0 return $p[0] . 'e' . $p[1];
108 }
109  
110 451 ▶sub new {
Subroutine new: called CC=18 SCAR=29.4
Pod undocumented
111  
112 # This function caters for 2 possibilities:
113 # 1) that 'new' has been called as a method - in which
114 # case there will be a maximum of 2 args
115 # 2) that 'new' has been called as a function - in
116 # which case there will be a maximum of 1 arg.
117 # If there are no args, then we just want to return a
118 # Math::Float128 object that's a NaN.
119  
120 0 ▶ if(!@_) {return NaNF128()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 0 451 451
121  
122 0 ▶ if(@_ > 2) {die "More than 2 arguments supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 0 451 451
123  
124 # If 'new' has been called OOP style, the first arg is the string
125 # "Math::Float128" which we don't need - so let's remove it. However,
126 # if the first arg is a Math::Float128 object (which is a possibility),
127 # then we'll get a fatal error when we check it for equivalence to
128 # the string "Math::Float128". So we first need to check that it's
129 # not an object - which we'll do by using the ref() function:
130 451 ▶ if(!ref($_[0]) && $_[0] eq "Math::Float128") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and $_[0] eq "Math::Float128") 445 6 451
Condition100%3/3
not ref $_[0] and $_[0] eq "Math::Float128"
!ll&&!rl&&r
15445
MC/DC100%2/2
not ref $_[0] and $_[0] eq "Math::Float128"
not ref $_[0] $_[0] eq "Math::Float128"
Truth table100%3/3
not(A) and B
A= not ref $_[0]B= $_[0] eq "Math::Float128"
ABresult
0X0
100
111
131 445 shift;
132 445 ▶ if(!@_) {return NaNF128()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 8 437 445
133 }
134  
135 0 ▶ if(@_ > 1) {die "Too many arguments supplied to new() - expected no more than 1"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 443 443
136  
137 443 my $arg = shift; # At this point, an infnan might acquire a POK flag - thus
138 # assigning to $type a value of 4, instead of 3. Such behaviour also
139 # turns $arg into a PV and NV dualvar. It's a fairly inconsequential
140 # bug - https://github.com/Perl/perl5/issues/19550.
141 # I could workaround this by simply not shifting and re-assigning, but
142 # I'll leave it as it is - otherwise there's nothing to mark that this
143 # minor issue (which might also show up in user code) ever existed.
144 443 my $type = _itsa($arg);
145  
146 443 ▶ return UVtoF128 ($arg) if $type == 1; #UV
Branch: 1 branch
BranchTrueFalseTotal
if $type == 1 26 417 443
147 417 ▶ return IVtoF128 ($arg) if $type == 2; #IV
Branch: 1 branch
BranchTrueFalseTotal
if $type == 2 150 267 417
148  
149 267 ▶ if($type == 4) { #PV
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 4) 95 172 267
150 95 ▶ if(_SvNOK($arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_SvNOK($arg)) 3 92 95
151 3 set_nok_pok(nok_pokflag() + 1);
152 3 ▶ if($Math::Float128::NOK_POK) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Math::Float128::NOK_POK) 0 3 3
153 0 warn "Scalar passed to new() is both NV and PV. Using PV (string) value";
154 }
155 }
156 95 return STRtoF128($arg);
157 }
158  
159 172 ▶ if($type == 3) { # NV
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 3) 145 27 172
160  
161 145 if(F128_PV_NV_BUG) {
162 if(_SvPOK($arg)) {
163 set_nok_pok(nok_pokflag() + 1);
164 if($Math::Float128::NOK_POK) {
165 warn "Scalar passed to new() is both NV and PV. Using NV (numeric) value";
166 }
167 }
168 }
169  
170 145 ▶ if($arg == 0) {return NVtoF128($arg)}
Branch: 1 branch
BranchTrueFalseTotal
if ($arg == 0) 2 143 145
171 143 ▶ if($arg != $arg) { return NaNF128()}
Branch: 1 branch
BranchTrueFalseTotal
if ($arg != $arg) 3 140 143
172 140 ▶ if(($arg / $arg) != 1) { # Inf
Branch: 1 branch
BranchTrueFalseTotal
if ($arg / $arg != 1) 6 134 140
173 6 ▶ if($arg < 0) {return InfF128(-1)}
Branch: 1 branch
BranchTrueFalseTotal
if ($arg < 0) 2 4 6
174 4 return InfF128(1);
175 }
176 134 return NVtoF128($arg);
177 }
178  
179 27 ▶ if($type == 113) { # Math::Float128
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 113) 27 0 27
180 27 return F128toF128($arg);
181 }
182  
183 0 die "Bad argument given to new";
184 }
185  
186  
187 1 ▶sub f128_bytes {
Subroutine f128_bytes: called CC=1 SCAR=0.0
Pod undocumented
188 1 my @ret = _f128_bytes($_[0]);
189 1 return join '', @ret;
190 }
191  
192 2 ▶sub FLT128_DIG () {return _FLT128_DIG()}
Subroutine FLT128_DIG: called CC=1 SCAR=0.0
193 1 ▶sub FLT128_MAX () {return _FLT128_MAX()}
Subroutine FLT128_MAX: called CC=1 SCAR=0.0
194 1 ▶sub FLT128_MIN () {return _FLT128_MIN()}
Subroutine FLT128_MIN: called CC=1 SCAR=0.0
195 1 ▶sub FLT128_EPSILON () {return _FLT128_EPSILON()}
Subroutine FLT128_EPSILON: called CC=1 SCAR=0.0
196 1 ▶sub FLT128_DENORM_MIN () {return _FLT128_DENORM_MIN()}
Subroutine FLT128_DENORM_MIN: called CC=1 SCAR=0.0
197 1 ▶sub FLT128_MANT_DIG () {return _FLT128_MANT_DIG()}
Subroutine FLT128_MANT_DIG: called CC=1 SCAR=0.0
198 1 ▶sub FLT128_MIN_EXP () {return _FLT128_MIN_EXP()}
Subroutine FLT128_MIN_EXP: called CC=1 SCAR=0.0
199 1 ▶sub FLT128_MAX_EXP () {return _FLT128_MAX_EXP()}
Subroutine FLT128_MAX_EXP: called CC=1 SCAR=0.0
200 1 ▶sub FLT128_MIN_10_EXP () {return _FLT128_MIN_10_EXP()}
Subroutine FLT128_MIN_10_EXP: called CC=1 SCAR=0.0
201 1 ▶sub FLT128_MAX_10_EXP () {return _FLT128_MAX_10_EXP()}
Subroutine FLT128_MAX_10_EXP: called CC=1 SCAR=0.0
202 1 ▶sub M_Eq () {return _M_Eq()}
Subroutine M_Eq: called CC=1 SCAR=0.0
203 1 ▶sub M_LOG2Eq () {return _M_LOG2Eq()}
Subroutine M_LOG2Eq: called CC=1 SCAR=0.0
204 1 ▶sub M_LOG10Eq () {return _M_LOG10Eq()}
Subroutine M_LOG10Eq: called CC=1 SCAR=0.0
205 1 ▶sub M_LN2q () {return _M_LN2q()}
Subroutine M_LN2q: called CC=1 SCAR=0.0
206 1 ▶sub M_LN10q () {return _M_LN10q()}
Subroutine M_LN10q: called CC=1 SCAR=0.0
207 1 ▶sub M_PIq () {return _M_PIq()}
Subroutine M_PIq: called CC=1 SCAR=0.0
208 1 ▶sub M_PI_2q () {return _M_PI_2q()}
Subroutine M_PI_2q: called CC=1 SCAR=0.0
209 1 ▶sub M_PI_4q () {return _M_PI_4q()}
Subroutine M_PI_4q: called CC=1 SCAR=0.0
210 1 ▶sub M_1_PIq () {return _M_1_PIq()}
Subroutine M_1_PIq: called CC=1 SCAR=0.0
211 1 ▶sub M_2_PIq () {return _M_2_PIq()}
Subroutine M_2_PIq: called CC=1 SCAR=0.0
212 1 ▶sub M_2_SQRTPIq () {return _M_2_SQRTPIq()}
Subroutine M_2_SQRTPIq: called CC=1 SCAR=0.0
213 1 ▶sub M_SQRT2q () {return _M_SQRT2q()}
Subroutine M_SQRT2q: called CC=1 SCAR=0.0
214 1 ▶sub M_SQRT1_2q () {return _M_SQRT1_2q()}
Subroutine M_SQRT1_2q: called CC=1 SCAR=0.0
215  
216 23 1;
217  
↑ Summary blib/lib/Math/Float128/Constant.pm »