blib/lib/Math/Complex_C.pm

filter: Statementstmt 80.5% 58 / 72 Branchbran 50.0% 26 / 52 Conditioncond 44.4% 4 / 9 MC/DCmcdc 16.6% 1 / 6 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 64.0% 98 / 153 CC 30 SCAR 31.2
CC
30
Cov
66%
_overload_string
41.4
str_to_d
19.0
new
9.4
CRAP 22.7
↑ Summary Complex_C.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;
4  
5 15 require Exporter;
6 15 *import = \&Exporter::import;
7 15 require DynaLoader;
8  
9 use overload
10 15 ▶ '**' => \&_overload_pow,
Subroutine BEGIN: called CC=1 SCAR=0.0
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 ;
34  
35 15 our $VERSION = '0.16';
36  
37 15 Math::Complex_C->DynaLoader::bootstrap($VERSION);
38  
39 15 @Math::Complex_C::EXPORT = ();
40 15 @Math::Complex_C::EXPORT_OK = qw(
41  
42 create_c assign_c mul_c mul_c_nv mul_c_iv mul_c_uv div_c div_c_nv div_c_iv div_c_uv add_c
43 add_c_nv add_c_iv add_c_uv sub_c sub_c_nv sub_c_iv sub_c_uv real_c
44 imag_c arg_c abs_c conj_c acos_c asin_c atan_c cos_c sin_c tan_c acosh_c asinh_c atanh_c
45 cosh_c sinh_c tanh_c exp_c log_c sqrt_c proj_c pow_c
46 get_nan get_neg_inf get_inf is_nan is_inf MCD
47 add_c_pv sub_c_pv mul_c_pv div_c_pv
48  
49 str_to_d d_to_str d_to_strp d_set_prec d_get_prec set_real_c set_imag_c
50 );
51  
52 15 %Math::Complex_C::EXPORT_TAGS = (all => [qw(
53  
54 create_c assign_c mul_c mul_c_nv mul_c_iv mul_c_uv div_c div_c_nv div_c_iv div_c_uv add_c
55 add_c_nv add_c_iv add_c_uv sub_c sub_c_nv sub_c_iv sub_c_uv real_c
56 imag_c arg_c abs_c conj_c acos_c asin_c atan_c cos_c sin_c tan_c acosh_c asinh_c atanh_c
57 cosh_c sinh_c tanh_c exp_c log_c sqrt_c proj_c pow_c
58 get_nan get_neg_inf get_inf is_nan is_inf MCD
59 add_c_pv sub_c_pv mul_c_pv div_c_pv
60  
61 str_to_d d_to_str d_to_strp d_set_prec d_get_prec set_real_c set_imag_c
62 )]);
63  
64 15 ▶sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod undocumented
65  
66 5 ▶sub d_to_str {
Subroutine d_to_str: called CC=1 SCAR=0.0
Pod undocumented
67 5 return join ' ', _d_to_str($_[0]);
68 }
69  
70 3 ▶sub d_to_strp {
Subroutine d_to_strp: called CC=1 SCAR=0.0
Pod undocumented
71 3 return join ' ', _d_to_strp($_[0], $_[1]);
72 }
73  
74 1 ▶sub str_to_d {
Subroutine str_to_d: called CC=8 SCAR=29.4
Pod undocumented
75 1 my($re, $im) = split /\s+/, $_[0];
76 1 ▶ $im = 0 if !defined($im);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $im 0 1 1
77  
78 1 ▶ $re = get_nan() if $re =~ /^(\+|\-)?nan/i;
Branch: 1 branch
BranchTrueFalseTotal
if $re =~ /^(\+|\-)?nan/i 0 1 1
79 1 ▶ $im = get_nan() if $im =~ /^(\+|\-)?nan/i;
Branch: 1 branch
BranchTrueFalseTotal
if $im =~ /^(\+|\-)?nan/i 0 1 1
80  
81 1 ▶ if($re =~ /^(\+|\-)?inf/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^(\+|\-)?inf/i) 0 1 1
82 0 ▶ if($re =~ /^\-inf/i) {$re = get_neg_inf()}
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^\-inf/i) { } 0 0 0
83 0 else {$re = get_inf()}
84 }
85  
86 1 ▶ if($im =~ /^(\+|\-)?inf/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($im =~ /^(\+|\-)?inf/i) 0 1 1
87 0 ▶ if($re =~ /^\-inf/i) {$im = get_neg_inf()}
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^\-inf/i) { } 0 0 0
88 0 else {$im = get_inf()}
89 }
90  
91 1 return MCD($re, $im);
92 }
93  
94 5 ▶sub _overload_string {
Subroutine _overload_string: called CC=15 SCAR=37.2
95 5 my($real, $imag) = (real_c($_[0]), imag_c($_[0]));
96 5 my($r, $i) = _d_to_str($_[0]);
97  
98 5 ▶ if($real == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($real == 0) { } 0 5 5
elsif ($real != $real) { } 2 3 5
elsif ($real / $real != $real / $real) { } 0 3 3
99 0 ▶ $r = $real =~ /^\-/ ? '-0' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$real =~ /^\-/ ? : 0 0 0
100 }
101 elsif($real != $real) {
102 2 $r = 'NaN';
103 }
104 elsif(($real / $real) != ($real / $real)) {
105 0 ▶ $r = $real < 0 ? '-Inf' : 'Inf';
Branch: 1 branch
BranchTrueFalseTotal
$real < 0 ? : 0 0 0
106 }
107 else {
108 3 my @re = split /e/i, $r;
109 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
110 0 chop $re[0];
111 }
112 3 $r = $re[0] . 'e' . $re[1];
113 }
114  
115 5 ▶ if($imag == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($imag == 0) { } 0 5 5
elsif ($imag != $imag) { } 2 3 5
elsif ($imag / $imag != $imag / $imag) { } 0 3 3
116 0 ▶ $i = $imag =~ /^\-/ ? '-0' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$imag =~ /^\-/ ? : 0 0 0
117 }
118 elsif($imag != $imag) {
119 2 $i = 'NaN';
120 }
121 elsif(($imag / $imag) != ($imag / $imag)) {
122 0 ▶ $i = $imag < 0 ? '-Inf' : 'Inf';
Branch: 1 branch
BranchTrueFalseTotal
$imag < 0 ? : 0 0 0
123 }
124 else {
125 3 my @im = split /e/i, $i;
126 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
127 0 chop $im[0];
128 }
129 3 $i = $im[0] . 'e' . $im[1];
130 }
131  
132 5 return "(" . $r . " " . $i . ")";
133 }
134  
135 72 ▶sub new {
Subroutine new: called CC=9 SCAR=22.4
Pod undocumented
136  
137  
138 # This function caters for 2 possibilities:
139 # 1) that 'new' has been called OOP style - in which
140 # case there will be a maximum of 3 args
141 # 2) that 'new' has been called as a function - in
142 # which case there will be a maximum of 2 args.
143 # If there are no args, then we just want to return a
144 # Math::Complex_C object
145  
146 72 ▶ if(!@_) {return create_c()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 8 64 72
147  
148 0 ▶ if(@_ > 3) {die "Too many arguments supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3) 0 64 64
149  
150 # If 'new' has been called OOP style, the first arg is the string
151 # "Math::Complex_C" which we don't need - so let's remove it.
152  
153 64 ▶ if(!ref($_[0]) && $_[0] eq "Math::Complex_C") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and $_[0] eq "Math::Complex_C") 11 53 64
Condition66%2/3
not ref $_[0] and $_[0] eq "Math::Complex_C"
!ll&&!rl&&r
05311
MC/DC50%1/2
not ref $_[0] and $_[0] eq "Math::Complex_C"
not ref $_[0] $_[0] eq "Math::Complex_C"
Truth table66%2/3
not(A) and B
A= not ref $_[0]B= $_[0] eq "Math::Complex_C"
ABresult
0X0
100
111
154 11 shift;
155 11 ▶ if(!@_) {return create_c()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 2 9 11
156 }
157  
158 0 ▶ if(@_ > 2) {die "Bad argument list supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 0 62 62
159  
160 62 my $ret;
161  
162 62 ▶ if(@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 51 11 62
163 51 $ret = create_c();
164 51 assign_c($ret, $_[0], $_[1]);
165 }
166 else {
167 11 ▶ return $_[0] if _itsa($_[0]) == 226;
Branch: 1 branch
BranchTrueFalseTotal
if _itsa($_[0]) == 226 0 11 11
168 11 $ret = create_c();
169 11 assign_c($ret, $_[0], 0.0);
170 }
171  
172 62 return $ret;
173 }
174  
175 15 *MCD = \&Math::Complex_C::new;
176  
177 15 1;
178  
179 __END__
↑ Summary Complex_C.xs »