blib/lib/Math/Complex_C/Q.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_q
19.0
new
9.4
CRAP 22.7
↑ Summary Q.xs »
1 16 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Math::Complex_C::Q;
4  
5 16 require Exporter;
6 16 *import = \&Exporter::import;
7 16 require DynaLoader;
8  
9 use overload
10 16 ▶ '**' => \&_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 16 ;
34  
35 16 our $VERSION = '0.07';
36  
37 16 Math::Complex_C::Q->DynaLoader::bootstrap($VERSION);
38  
39 16 @Math::Complex_C::Q::EXPORT = ();
40 16 @Math::Complex_C::Q::EXPORT_OK = qw(
41  
42 create_cq assign_cq mul_cq mul_c_nvq mul_c_ivq mul_c_uvq div_cq div_c_nvq div_c_ivq div_c_uvq add_cq
43 add_c_nvq add_c_ivq add_c_uvq sub_cq sub_c_nvq sub_c_ivq sub_c_uvq real_cq real_cq2F imag_cq2F F2cq
44 cq2F real_cq2str imag_cq2str arg_cq2F arg_cq2str abs_cq2F abs_cq2str
45 imag_cq arg_cq abs_cq conj_cq acos_cq asin_cq atan_cq cos_cq sin_cq tan_cq acosh_cq asinh_cq atanh_cq
46 cosh_cq sinh_cq tanh_cq exp_cq log_cq sqrt_cq proj_cq pow_cq
47 get_nanq get_neg_infq get_infq is_nanq is_infq MCQ
48 add_c_pvq sub_c_pvq mul_c_pvq div_c_pvq
49  
50 str_to_q q_to_str q_to_strp q_set_prec q_get_prec set_real_cq set_imag_cq
51 );
52  
53 16 %Math::Complex_C::Q::EXPORT_TAGS = (all => [qw(
54  
55 create_cq assign_cq mul_cq mul_c_nvq mul_c_ivq mul_c_uvq div_cq div_c_nvq div_c_ivq div_c_uvq add_cq
56 add_c_nvq add_c_ivq add_c_uvq sub_cq sub_c_nvq sub_c_ivq sub_c_uvq real_cq real_cq2F imag_cq2F F2cq
57 cq2F real_cq2str imag_cq2str arg_cq2F arg_cq2str abs_cq2F abs_cq2str
58 imag_cq arg_cq abs_cq conj_cq acos_cq asin_cq atan_cq cos_cq sin_cq tan_cq acosh_cq asinh_cq atanh_cq
59 cosh_cq sinh_cq tanh_cq exp_cq log_cq sqrt_cq proj_cq pow_cq
60 get_nanq get_infq get_neg_infq is_nanq is_infq MCQ
61 add_c_pvq sub_c_pvq mul_c_pvq div_c_pvq
62  
63 str_to_q q_to_str q_to_strp q_set_prec q_get_prec set_real_cq set_imag_cq
64 )]);
65  
66 16 ▶sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking
Subroutine dl_load_flags: called CC=1 SCAR=0.0
Pod undocumented
67  
68 6 ▶sub q_to_str {
Subroutine q_to_str: called CC=1 SCAR=0.0
Pod undocumented
69 6 return join ' ', _q_to_str($_[0]);
70 }
71  
72 3 ▶sub q_to_strp {
Subroutine q_to_strp: called CC=1 SCAR=0.0
Pod undocumented
73 3 return join ' ', _q_to_strp($_[0], $_[1]);
74 }
75  
76 1 ▶sub str_to_q {
Subroutine str_to_q: called CC=8 SCAR=29.4
Pod undocumented
77 1 my($re, $im) = split /\s+/, $_[0];
78 1 ▶ $im = 0 if !defined($im);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $im 0 1 1
79  
80 1 ▶ $re = get_nanq() if $re =~ /^(\+|\-)?nan/i;
Branch: 1 branch
BranchTrueFalseTotal
if $re =~ /^(\+|\-)?nan/i 0 1 1
81 1 ▶ $im = get_nanq() if $im =~ /^(\+|\-)?nan/i;
Branch: 1 branch
BranchTrueFalseTotal
if $im =~ /^(\+|\-)?nan/i 0 1 1
82  
83 1 ▶ if($re =~ /^(\+|\-)?inf/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^(\+|\-)?inf/i) 0 1 1
84 0 ▶ if($re =~ /^\-inf/i) {$re = get_neg_infq()}
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^\-inf/i) { } 0 0 0
85 0 else {$re = get_infq()}
86 }
87  
88 1 ▶ if($im =~ /^(\+|\-)?inf/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($im =~ /^(\+|\-)?inf/i) 0 1 1
89 0 ▶ if($re =~ /^\-inf/i) {$im = get_neg_infq()}
Branch: 1 branch
BranchTrueFalseTotal
if ($re =~ /^\-inf/i) { } 0 0 0
90 0 else {$im = get_infq()}
91 }
92  
93 1 return MCQ($re, $im);
94 }
95  
96 7 ▶sub _overload_string {
Subroutine _overload_string: called CC=15 SCAR=37.2
97 7 my($real, $imag) = (real_cq($_[0]), imag_cq($_[0]));
98 7 my($r, $i) = _q_to_str($_[0]);
99  
100 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
101 0 ▶ $r = $real =~ /^\-/ ? '-0' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$real =~ /^\-/ ? : 0 0 0
102 }
103 elsif($real != $real) {
104 4 $r = 'NaN';
105 }
106 elsif(($real / $real) != ($real / $real)) {
107 0 ▶ $r = $real < 0 ? '-Inf' : 'Inf';
Branch: 1 branch
BranchTrueFalseTotal
$real < 0 ? : 0 0 0
108 }
109 else {
110 3 my @re = split /e/i, $r;
111 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
112 0 chop $re[0];
113 }
114 3 $r = $re[0] . 'e' . $re[1];
115 }
116  
117 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
118 0 ▶ $i = $imag =~ /^\-/ ? '-0' : '0';
Branch: 1 branch
BranchTrueFalseTotal
$imag =~ /^\-/ ? : 0 0 0
119 }
120 elsif($imag != $imag) {
121 4 $i = 'NaN';
122 }
123 elsif(($imag / $imag) != ($imag / $imag)) {
124 0 ▶ $i = $imag < 0 ? '-Inf' : 'Inf';
Branch: 1 branch
BranchTrueFalseTotal
$imag < 0 ? : 0 0 0
125 }
126 else {
127 3 my @im = split /e/i, $i;
128 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
129 0 chop $im[0];
130 }
131 3 $i = $im[0] . 'e' . $im[1];
132 }
133  
134 7 return "(" . $r . " " . $i . ")";
135 }
136  
137 74 ▶sub new {
Subroutine new: called CC=9 SCAR=22.4
Pod undocumented
138  
139  
140 # This function caters for 2 possibilities:
141 # 1) that 'new' has been called OOP style - in which
142 # case there will be a maximum of 3 args
143 # 2) that 'new' has been called as a function - in
144 # which case there will be a maximum of 2 args.
145 # If there are no args, then we just want to return a
146 # Math::Complex_C::Q object
147  
148 74 ▶ if(!@_) {return create_cq()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 9 65 74
149  
150 0 ▶ if(@_ > 3) {die "Too many arguments supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 3) 0 65 65
151  
152 # If 'new' has been called OOP style, the first arg is the string
153 # "Math::Complex_C::Q" which we don't need - so let's remove it.
154  
155 65 ▶ if(!ref($_[0]) && $_[0] eq "Math::Complex_C::Q") {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $_[0] and $_[0] eq "Math::Complex_C::Q") 11 54 65
Condition66%2/3
not ref $_[0] and $_[0] eq "Math::Complex_C::Q"
!ll&&!rl&&r
05411
MC/DC50%1/2
not ref $_[0] and $_[0] eq "Math::Complex_C::Q"
not ref $_[0] $_[0] eq "Math::Complex_C::Q"
Truth table66%2/3
not(A) and B
A= not ref $_[0]B= $_[0] eq "Math::Complex_C::Q"
ABresult
0X0
100
111
156 11 shift;
157 11 ▶ if(!@_) {return create_cq()}
Branch: 1 branch
BranchTrueFalseTotal
unless (@_) 2 9 11
158 }
159  
160 0 ▶ if(@_ > 2) {die "Bad argument list supplied to new()"}
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 2) 0 63 63
161  
162 63 my $ret;
163  
164 63 ▶ if(@_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2) { } 52 11 63
165 52 $ret = create_cq();
166 52 assign_cq($ret, $_[0], $_[1]);
167 }
168 else {
169 11 ▶ return $_[0] if _itsa($_[0]) == 226;
Branch: 1 branch
BranchTrueFalseTotal
if _itsa($_[0]) == 226 0 11 11
170 11 $ret = create_cq();
171 11 assign_cq($ret, $_[0], 0.0);
172 }
173  
174 63 return $ret;
175 }
176  
177 16 *MCQ = \&Math::Complex_C::Q::new;
178  
179 16 1;
180  
181 __END__
↑ Summary Q.xs »