line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
14
|
|
|
14
|
|
8827
|
use strict; |
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
345
|
|
2
|
14
|
|
|
14
|
|
67
|
use warnings; |
|
14
|
|
|
|
|
21
|
|
|
14
|
|
|
|
|
3496
|
|
3
|
|
|
|
|
|
|
package Math::Complex_C; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
|
|
|
|
|
|
*import = \&Exporter::import; |
7
|
|
|
|
|
|
|
require DynaLoader; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use overload |
10
|
14
|
|
|
|
|
321
|
'**' => \&_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
|
14
|
|
|
14
|
|
21864
|
; |
|
14
|
|
|
|
|
14628
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
DynaLoader::bootstrap Math::Complex_C $VERSION; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
@Math::Complex_C::EXPORT = (); |
40
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
%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
|
14
|
|
|
14
|
0
|
7763
|
sub dl_load_flags {0} # Prevent DynaLoader from complaining and croaking |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub d_to_str { |
67
|
5
|
|
|
5
|
0
|
45
|
return join ' ', _d_to_str($_[0]); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub d_to_strp { |
71
|
3
|
|
|
3
|
0
|
23
|
return join ' ', _d_to_strp($_[0], $_[1]); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub str_to_d { |
75
|
1
|
|
|
1
|
0
|
8
|
my($re, $im) = split /\s+/, $_[0]; |
76
|
1
|
50
|
|
|
|
3
|
$im = 0 if !defined($im); |
77
|
|
|
|
|
|
|
|
78
|
1
|
50
|
|
|
|
8
|
$re = get_nan() if $re =~ /^(\+|\-)?nan/i; |
79
|
1
|
50
|
|
|
|
4
|
$im = get_nan() if $im =~ /^(\+|\-)?nan/i; |
80
|
|
|
|
|
|
|
|
81
|
1
|
50
|
|
|
|
5
|
if($re =~ /^(\+|\-)?inf/i) { |
82
|
0
|
0
|
|
|
|
0
|
if($re =~ /^\-inf/i) {$re = get_neg_inf()} |
|
0
|
|
|
|
|
0
|
|
83
|
0
|
|
|
|
|
0
|
else {$re = get_inf()} |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
1
|
50
|
|
|
|
4
|
if($im =~ /^(\+|\-)?inf/i) { |
87
|
0
|
0
|
|
|
|
0
|
if($re =~ /^\-inf/i) {$im = get_neg_inf()} |
|
0
|
|
|
|
|
0
|
|
88
|
0
|
|
|
|
|
0
|
else {$im = get_inf()} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
1
|
|
|
|
|
4
|
return MCD($re, $im); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _overload_string { |
95
|
5
|
|
|
5
|
|
133
|
my($real, $imag) = (real_c($_[0]), imag_c($_[0])); |
96
|
5
|
|
|
|
|
46
|
my($r, $i) = _d_to_str($_[0]); |
97
|
|
|
|
|
|
|
|
98
|
5
|
50
|
|
|
|
24
|
if($real == 0) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
0
|
$r = $real =~ /^\-/ ? '-0' : '0'; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
elsif($real != $real) { |
102
|
2
|
|
|
|
|
4
|
$r = 'NaN'; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
elsif(($real / $real) != ($real / $real)) { |
105
|
0
|
0
|
|
|
|
0
|
$r = $real < 0 ? '-Inf' : 'Inf'; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
else { |
108
|
3
|
|
|
|
|
14
|
my @re = split /e/i, $r; |
109
|
3
|
|
33
|
|
|
13
|
while(substr($re[0], -1, 1) eq '0' && substr($re[0], -2, 1) ne '.') { |
110
|
0
|
|
|
|
|
0
|
chop $re[0]; |
111
|
|
|
|
|
|
|
} |
112
|
3
|
|
|
|
|
8
|
$r = $re[0] . 'e' . $re[1]; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
5
|
50
|
|
|
|
21
|
if($imag == 0) { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
0
|
$i = $imag =~ /^\-/ ? '-0' : '0'; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
elsif($imag != $imag) { |
119
|
2
|
|
|
|
|
4
|
$i = 'NaN'; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
elsif(($imag / $imag) != ($imag / $imag)) { |
122
|
0
|
0
|
|
|
|
0
|
$i = $imag < 0 ? '-Inf' : 'Inf'; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
else { |
125
|
3
|
|
|
|
|
9
|
my @im = split /e/i, $i; |
126
|
3
|
|
33
|
|
|
17
|
while(substr($im[0], -1, 1) eq '0' && substr($im[0], -2, 1) ne '.') { |
127
|
0
|
|
|
|
|
0
|
chop $im[0]; |
128
|
|
|
|
|
|
|
} |
129
|
3
|
|
|
|
|
8
|
$i = $im[0] . 'e' . $im[1]; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
5
|
|
|
|
|
22
|
return "(" . $r . " " . $i . ")"; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub new { |
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
|
61
|
100
|
|
61
|
0
|
1441
|
if(!@_) {return create_c()} |
|
8
|
|
|
|
|
66
|
|
147
|
|
|
|
|
|
|
|
148
|
53
|
50
|
|
|
|
136
|
if(@_ > 3) {die "Too many arguments supplied to new()"} |
|
0
|
|
|
|
|
0
|
|
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
|
53
|
100
|
66
|
|
|
337
|
if(!ref($_[0]) && $_[0] eq "Math::Complex_C") { |
154
|
10
|
|
|
|
|
15
|
shift; |
155
|
10
|
100
|
|
|
|
31
|
if(!@_) {return create_c()} |
|
2
|
|
|
|
|
30
|
|
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
51
|
50
|
|
|
|
116
|
if(@_ > 2) {die "Bad argument list supplied to new()"} |
|
0
|
|
|
|
|
0
|
|
159
|
|
|
|
|
|
|
|
160
|
51
|
|
|
|
|
62
|
my $ret; |
161
|
|
|
|
|
|
|
|
162
|
51
|
50
|
|
|
|
112
|
if(@_ == 2) { |
163
|
51
|
|
|
|
|
366
|
$ret = create_c(); |
164
|
51
|
|
|
|
|
219
|
assign_c($ret, $_[0], $_[1]); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
else { |
167
|
0
|
0
|
|
|
|
0
|
return $_[0] if _itsa($_[0]) == 226; |
168
|
0
|
|
|
|
|
0
|
$ret = create_c(); |
169
|
0
|
|
|
|
|
0
|
assign_c($ret, $_[0], 0.0); |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
51
|
|
|
|
|
291
|
return $ret; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
*MCD = \&Math::Complex_C::new; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |