blib/lib/Math/Complex_C/L.pm

filter: Statementstmt 77.6% 59 / 76 Branchbran 46.1% 24 / 52 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 61.7% 97 / 157 SCAR 43.0
CC
30
Cov
64%
_overload_string
41.4
str_to_l
19.0
new
11.5
CRAP 73.8
↑ Summary L.xs »
1 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Math::Complex_C::L;
4  
5 15 require Exporter;
6 15 *import = \&Exporter::import;
7 15 require DynaLoader;
8  
9 use overload
10 15 '**' => \&_overload_pow,
11 '*' => \&_overload_mul,
12 '+' => \&_overload_add,
13 '/' => \&_overload_div,
14 '-' => \&_overload_sub,
15 '**=' => \&_overload_pow_eq,
16 '*=' => \&_overload_mul_eq,
17 '+=' => \&_overload_add_eq,
18 '/=' => \&_overload_div_eq,
19 '-=' => \&_overload_sub_eq,
20 'sqrt' => \&_overload_sqrt,
21 '==' => \&_overload_equiv,
22 '!=' => \&_overload_not_equiv,
23 '!' => \&_overload_not,
24 'bool' => \&_overload_true,
25 '=' => \&_overload_copy,
26 '""' => \&_overload_string,
27 'abs' => \&_overload_abs,
28 'exp' => \&_overload_exp,
29 'log' => \&_overload_log,
30 'sin' => \&_overload_sin,
31 'cos' => \&_overload_cos,
32 'atan2' => \&_overload_atan2,
33 15 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 15 our $VERSION = '0.06';
36  
37 15 DynaLoader::bootstrap Math::Complex_C::L $VERSION;
38  
39 15 @Math::Complex_C::L::EXPORT = ();
40 15 @Math::Complex_C::L::EXPORT_OK = qw(
41  
42 create_cl assign_cl mul_cl mul_c_nvl mul_c_ivl mul_c_uvl div_cl div_c_nvl div_c_ivl div_c_uvl add_cl
43 add_c_nvl add_c_ivl add_c_uvl sub_cl sub_c_nvl sub_c_ivl sub_c_uvl real_cl real_cl2LD imag_cl2LD
44 LD2cl cl2LD real_cl2str imag_cl2str arg_cl2LD arg_cl2str abs_cl2LD abs_cl2str
45 imag_cl arg_cl abs_cl conj_cl acos_cl asin_cl atan_cl cos_cl sin_cl tan_cl acosh_cl asinh_cl atanh_cl
46 cosh_cl sinh_cl tanh_cl exp_cl log_cl sqrt_cl proj_cl pow_cl
47 get_nanl get_neg_infl get_infl is_nanl is_infl MCL
48 add_c_pvl sub_c_pvl mul_c_pvl div_c_pvl
49  
50 str_to_l l_to_str l_to_strp l_set_prec l_get_prec set_real_cl set_imag_cl
51 ld_to_str ld_to_strp long_set_prec long_get_prec
52 );
53  
54 15 %Math::Complex_C::L::EXPORT_TAGS = (all => [qw(
55  
56 create_cl assign_cl mul_cl mul_c_nvl mul_c_ivl mul_c_uvl div_cl div_c_nvl div_c_ivl div_c_uvl add_cl
57 add_c_nvl add_c_ivl add_c_uvl sub_cl sub_c_nvl sub_c_ivl sub_c_uvl real_cl real_cl2LD imag_cl2LD
58 LD2cl cl2LD real_cl2str imag_cl2str arg_cl2LD arg_cl2str abs_cl2LD abs_cl2str
59 imag_cl arg_cl abs_cl conj_cl acos_cl asin_cl atan_cl cos_cl sin_cl tan_cl acosh_cl asinh_cl atanh_cl
60 cosh_cl sinh_cl tanh_cl exp_cl log_cl sqrt_cl proj_cl pow_cl
61 get_nanl get_neg_infl get_infl is_nanl is_infl MCL
62 add_c_pvl sub_c_pvl mul_c_pvl div_c_pvl
63  
64 str_to_l l_to_str l_to_strp l_set_prec l_get_prec set_real_cl set_imag_cl
65 ld_to_str ld_to_strp long_set_prec long_get_prec
66 )]);
67  
68 15 ▶sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod undocumented
69  
70 sub l_to_str {
71 5 ▶ return join ' ', _l_to_str($_[0]);
Subroutine l_to_str: called CC=1 SCAR=0.0
Pod undocumented
72 }
73  
74 sub l_to_strp {
75 3 ▶ return join ' ', _l_to_strp($_[0], $_[1]);
Subroutine l_to_strp: called CC=1 SCAR=0.0
Pod undocumented
76 }
77  
78 sub str_to_l {
79 1 ▶ my($re, $im) = split /\s+/, $_[0];
Subroutine str_to_l: called CC=8 SCAR=29.4
Pod undocumented
80 1 ▶ $im = 0 if !defined($im);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $im 0 1 1
81  
82 1 ▶ $re = get_nanl() if $re =~ /^(\+|\-)?nan/i;
Branch: 1 branch
BranchTrueFalseTotal
if $re =~ /^(\+|\-)?nan/i 0 1 1
83 1 ▶ $im = get_nanl() if $im =~ /^(\+|\-)?nan/i;
Branch: 1 branch
BranchTrueFalseTotal
if $im =~ /^(\+|\-)?nan/i 0 1 1
84  
85 1 ▶ if($re =~ /^(\+|\-)?inf/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^(\+|\-)?inf/i) 0 1 1
86 0 ▶ if($re =~ /^\-inf/i) {$re = get_neg_infl()}
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^\-inf/i) { } 0 0 0
87 0 else {$re = get_infl()}
88 }
89  
90 1 ▶ if($im =~ /^(\+|\-)?inf/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($im =~ /^(\+|\-)?inf/i) 0 1 1
91 0 ▶ if($re =~ /^\-inf/i) {$im = get_neg_infl()}
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^\-inf/i) { } 0 0 0
92 0 else {$im = get_infl()}
93 }
94  
95 1 return MCL($re, $im);
96 }
97  
98 sub _overload_string {
99 7 ▶ my($real, $imag) = (real_cl($_[0]), imag_cl($_[0]));
Subroutine _overload_string: called CC=15 SCAR=37.2
100 7 my($r, $i) = _l_to_str($_[0]);
101  
102 7 ▶ if($real == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($real == 0) { } 0 7 7
elsif ($real != $real) { } 4 3 7
elsif ($real / $real != $real / $real) { } 0 3 3
103 0 ▶ $r = $real =~ /^\-/ ? '-0' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$real =~ /^\-/ ? : 0 0 0
104 }
105 elsif($real != $real) {
106 4 $r = 'NaN';
107 }
108 elsif(($real / $real) != ($real / $real)) {
109 0 ▶ $r = $real < 0 ? '-Inf' : 'Inf';
Branch: 1 branch
BranchTrueFalseTotal
$real < 0 ? : 0 0 0
110 }
111 else {
112 3 my @re = split /e/i, $r;
113 3 ▶ while(substr($re[0], -1, 1) eq '0' && substr($re[0], -2, 1) ne '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($re[0], -1, 1) eq 0 and substr($re[0], -2, 1) ne ".") 0 3 3
Condition33%1/3
substr($re[0], -1, 1) eq 0 and substr($re[0], -2, 1) ne "."
!ll&&!rl&&r
300
MC/DC0%0/2
substr($re[0], -1, 1) eq 0 and substr($re[0], -2, 1) ne "."
substr($re[0], -1, 1) eq 0 substr($re[0], -2, 1) ne "."
Truth table33%1/3
A and B
A= substr($re[0], -1, 1) eq 0B= substr($re[0], -2, 1) ne "."
ABresult
0X0
100
111
114 0 chop $re[0];
115 }
116 3 $r = $re[0] . 'e' . $re[1];
117 }
118  
119 7 ▶ if($imag == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($imag == 0) { } 0 7 7
elsif ($imag != $imag) { } 4 3 7
elsif ($imag / $imag != $imag / $imag) { } 0 3 3
120 0 ▶ $i = $imag =~ /^\-/ ? '-0' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$imag =~ /^\-/ ? : 0 0 0
121 }
122 elsif($imag != $imag) {
123 4 $i = 'NaN';
124 }
125 elsif(($imag / $imag) != ($imag / $imag)) {
126 0 ▶ $i = $imag < 0 ? '-Inf' : 'Inf';
Branch: 1 branch
BranchTrueFalseTotal
$imag < 0 ? : 0 0 0
127 }
128 else {
129 3 my @im = split /e/i, $i;
130 3 ▶ while(substr($im[0], -1, 1) eq '0' && substr($im[0], -2, 1) ne '.') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($im[0], -1, 1) eq 0 and substr($im[0], -2, 1) ne ".") 0 3 3
Condition33%1/3
substr($im[0], -1, 1) eq 0 and substr($im[0], -2, 1) ne "."
!ll&&!rl&&r
300
MC/DC0%0/2
substr($im[0], -1, 1) eq 0 and substr($im[0], -2, 1) ne "."
substr($im[0], -1, 1) eq 0 substr($im[0], -2, 1) ne "."
Truth table33%1/3
A and B
A= substr($im[0], -1, 1) eq 0B= substr($im[0], -2, 1) ne "."
ABresult
0X0
100
111
131 0 chop $im[0];
132 }
133 3 $i = $im[0] . 'e' . $im[1];
134 }
135  
136 7 return "(" . $r . " " . $i . ")";
137 }
138  
139 sub new {
140  
141  
142 # This function caters for 2 possibilities:
143 # 1) that 'new' has been called OOP style - in which
144 # case there will be a maximum of 3 args
145 # 2) that 'new' has been called as a function - in
146 # which case there will be a maximum of 2 args.
147 # If there are no args, then we just want to return a
148 # Math::Complex_C::L object
149  
150 62 ▶ if(!@_) {return create_cl()}
Subroutine new: called CC=9 SCAR=24.4
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 9 53 62
151  
152 53 ▶ if(@_ > 3) {die "Too many arguments supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3) 0 53 53
153  
154 # If 'new' has been called OOP style, the first arg is the string
155 # "Math::Complex_C::L" which we don't need - so let's remove it.
156  
157 53 ▶ if(!ref($_[0]) && $_[0] eq "Math::Complex_C::L") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and $_[0] eq "Math::Complex_C::L") 10 43 53
Condition66%2/3
not ref $_[0] and $_[0] eq "Math::Complex_C::L"
!ll&&!rl&&r
04310
MC/DC50%1/2
not ref $_[0] and $_[0] eq "Math::Complex_C::L"
not ref $_[0] $_[0] eq "Math::Complex_C::L"
Truth table66%2/3
not(A) and B
A= not ref $_[0]B= $_[0] eq "Math::Complex_C::L"
ABresult
0X0
100
111
158 10 shift;
159 10 ▶ if(!@_) {return create_cl()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 2 8 10
160 }
161  
162 51 ▶ if(@_ > 2) {die "Bad argument list supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 0 51 51
163  
164 51 my $ret;
165  
166 51 ▶ if(@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 51 0 51
167 51 $ret = create_cl();
168 51 assign_cl($ret, $_[0], $_[1]);
169 }
170 else {
171 0 ▶ return $_[0] if _itsa($_[0]) == 226;
Branch: 1 branch
BranchTrueFalseTotal
if _itsa($_[0]) == 226 0 0 0
172 0 $ret = create_cl();
173 0 assign_cl($ret, $_[0], 0.0);
174 }
175  
176 51 return $ret;
177 }
178  
179 15 *MCL = \&Math::Complex_C::L::new;
180 15 *long_get_prec = \&l_get_prec; # for backwards-compatibility
181 15 *long_set_prec = \&l_set_prec; # for backwards-compatibility
182 15 *ld_to_str = \&l_to_str; # for backwards-compatibility
183 15 *ld_to_strp = \&l_to_strp; # for backwards-compatibility
184  
185 15 1;
186  
187 __END__
↑ Summary L.xs »