blib/lib/Math/GSL/Complex.pm

filter: Statementstmt 23.1% 19 / 82 Branchbran 0.0% 0 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 26.9% 7 / 26 Podpod n/a totaltotal 19.7% 26 / 132 CC 13 SCAR 20.9
CC
13
Cov
18%
DESTROY
20.0
DESTROY
20.0
DESTROY
20.0
CRAP 8.1
« blib/lib/Math/GSL/SF.pm ↑ Summary blib/lib/Math/GSL/Histogram.pm »
1 # This file was automatically generated by SWIG (https://www.swig.org).
2 # Version 4.2.0
3 #
4 # Do not make changes to this file unless you know what you are doing - modify
5 # the SWIG interface file instead.
6  
7 package Math::GSL::Complex;
8 1 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use base qw(DynaLoader);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 package Math::GSL::Complexc;
11 bootstrap Math::GSL::Complex;
12 package Math::GSL::Complex;
13 @EXPORT = qw();
14  
15 # ---------- BASE METHODS -------------
16  
17 package Math::GSL::Complex;
18  
19 0 ▶sub TIEHASH {
Subroutine TIEHASH: not called CC=1 SCAR=6.9
20 0 my ($classname,$obj) = @_;
21 0 return bless $obj, $classname;
22 }
23  
24 0 ▶sub CLEAR { }
Subroutine CLEAR: not called CC=1 SCAR=0.0
25  
26 0 ▶sub FIRSTKEY { }
Subroutine FIRSTKEY: not called CC=1 SCAR=0.0
27  
28 0 ▶sub NEXTKEY { }
Subroutine NEXTKEY: not called CC=1 SCAR=0.0
29  
30 0 ▶sub FETCH {
Subroutine FETCH: not called CC=1 SCAR=6.9
31 0 my ($self,$field) = @_;
32 0 my $member_func = "swig_${field}_get";
33 0 $self->$member_func();
34 }
35  
36 0 ▶sub STORE {
Subroutine STORE: not called CC=1 SCAR=6.9
37 0 my ($self,$field,$newval) = @_;
38 0 my $member_func = "swig_${field}_set";
39 0 $self->$member_func($newval);
40 }
41  
42 0 ▶sub this {
Subroutine this: not called CC=1 SCAR=6.9
43 0 my $ptr = shift;
44 0 return tied(%$ptr);
45 }
46  
47  
48 # ------- FUNCTION WRAPPERS --------
49  
50 package Math::GSL::Complex;
51  
52 *gsl_error = *Math::GSL::Complexc::gsl_error;
53 *gsl_stream_printf = *Math::GSL::Complexc::gsl_stream_printf;
54 *gsl_strerror = *Math::GSL::Complexc::gsl_strerror;
55 *gsl_set_error_handler = *Math::GSL::Complexc::gsl_set_error_handler;
56 *gsl_set_error_handler_off = *Math::GSL::Complexc::gsl_set_error_handler_off;
57 *gsl_set_stream_handler = *Math::GSL::Complexc::gsl_set_stream_handler;
58 *gsl_set_stream = *Math::GSL::Complexc::gsl_set_stream;
59 *gsl_complex_polar = *Math::GSL::Complexc::gsl_complex_polar;
60 *gsl_complex_rect = *Math::GSL::Complexc::gsl_complex_rect;
61 *gsl_complex_arg = *Math::GSL::Complexc::gsl_complex_arg;
62 *gsl_complex_abs = *Math::GSL::Complexc::gsl_complex_abs;
63 *gsl_complex_abs2 = *Math::GSL::Complexc::gsl_complex_abs2;
64 *gsl_complex_logabs = *Math::GSL::Complexc::gsl_complex_logabs;
65 *gsl_complex_add = *Math::GSL::Complexc::gsl_complex_add;
66 *gsl_complex_sub = *Math::GSL::Complexc::gsl_complex_sub;
67 *gsl_complex_mul = *Math::GSL::Complexc::gsl_complex_mul;
68 *gsl_complex_div = *Math::GSL::Complexc::gsl_complex_div;
69 *gsl_complex_add_real = *Math::GSL::Complexc::gsl_complex_add_real;
70 *gsl_complex_sub_real = *Math::GSL::Complexc::gsl_complex_sub_real;
71 *gsl_complex_mul_real = *Math::GSL::Complexc::gsl_complex_mul_real;
72 *gsl_complex_div_real = *Math::GSL::Complexc::gsl_complex_div_real;
73 *gsl_complex_add_imag = *Math::GSL::Complexc::gsl_complex_add_imag;
74 *gsl_complex_sub_imag = *Math::GSL::Complexc::gsl_complex_sub_imag;
75 *gsl_complex_mul_imag = *Math::GSL::Complexc::gsl_complex_mul_imag;
76 *gsl_complex_div_imag = *Math::GSL::Complexc::gsl_complex_div_imag;
77 *gsl_complex_conjugate = *Math::GSL::Complexc::gsl_complex_conjugate;
78 *gsl_complex_inverse = *Math::GSL::Complexc::gsl_complex_inverse;
79 *gsl_complex_negative = *Math::GSL::Complexc::gsl_complex_negative;
80 *gsl_complex_sqrt = *Math::GSL::Complexc::gsl_complex_sqrt;
81 *gsl_complex_sqrt_real = *Math::GSL::Complexc::gsl_complex_sqrt_real;
82 *gsl_complex_pow = *Math::GSL::Complexc::gsl_complex_pow;
83 *gsl_complex_pow_real = *Math::GSL::Complexc::gsl_complex_pow_real;
84 *gsl_complex_exp = *Math::GSL::Complexc::gsl_complex_exp;
85 *gsl_complex_log = *Math::GSL::Complexc::gsl_complex_log;
86 *gsl_complex_log10 = *Math::GSL::Complexc::gsl_complex_log10;
87 *gsl_complex_log_b = *Math::GSL::Complexc::gsl_complex_log_b;
88 *gsl_complex_sin = *Math::GSL::Complexc::gsl_complex_sin;
89 *gsl_complex_cos = *Math::GSL::Complexc::gsl_complex_cos;
90 *gsl_complex_sec = *Math::GSL::Complexc::gsl_complex_sec;
91 *gsl_complex_csc = *Math::GSL::Complexc::gsl_complex_csc;
92 *gsl_complex_tan = *Math::GSL::Complexc::gsl_complex_tan;
93 *gsl_complex_cot = *Math::GSL::Complexc::gsl_complex_cot;
94 *gsl_complex_arcsin = *Math::GSL::Complexc::gsl_complex_arcsin;
95 *gsl_complex_arcsin_real = *Math::GSL::Complexc::gsl_complex_arcsin_real;
96 *gsl_complex_arccos = *Math::GSL::Complexc::gsl_complex_arccos;
97 *gsl_complex_arccos_real = *Math::GSL::Complexc::gsl_complex_arccos_real;
98 *gsl_complex_arcsec = *Math::GSL::Complexc::gsl_complex_arcsec;
99 *gsl_complex_arcsec_real = *Math::GSL::Complexc::gsl_complex_arcsec_real;
100 *gsl_complex_arccsc = *Math::GSL::Complexc::gsl_complex_arccsc;
101 *gsl_complex_arccsc_real = *Math::GSL::Complexc::gsl_complex_arccsc_real;
102 *gsl_complex_arctan = *Math::GSL::Complexc::gsl_complex_arctan;
103 *gsl_complex_arccot = *Math::GSL::Complexc::gsl_complex_arccot;
104 *gsl_complex_sinh = *Math::GSL::Complexc::gsl_complex_sinh;
105 *gsl_complex_cosh = *Math::GSL::Complexc::gsl_complex_cosh;
106 *gsl_complex_sech = *Math::GSL::Complexc::gsl_complex_sech;
107 *gsl_complex_csch = *Math::GSL::Complexc::gsl_complex_csch;
108 *gsl_complex_tanh = *Math::GSL::Complexc::gsl_complex_tanh;
109 *gsl_complex_coth = *Math::GSL::Complexc::gsl_complex_coth;
110 *gsl_complex_arcsinh = *Math::GSL::Complexc::gsl_complex_arcsinh;
111 *gsl_complex_arccosh = *Math::GSL::Complexc::gsl_complex_arccosh;
112 *gsl_complex_arccosh_real = *Math::GSL::Complexc::gsl_complex_arccosh_real;
113 *gsl_complex_arcsech = *Math::GSL::Complexc::gsl_complex_arcsech;
114 *gsl_complex_arccsch = *Math::GSL::Complexc::gsl_complex_arccsch;
115 *gsl_complex_arctanh = *Math::GSL::Complexc::gsl_complex_arctanh;
116 *gsl_complex_arctanh_real = *Math::GSL::Complexc::gsl_complex_arctanh_real;
117 *gsl_complex_arccoth = *Math::GSL::Complexc::gsl_complex_arccoth;
118 *new_doubleArray = *Math::GSL::Complexc::new_doubleArray;
119 *delete_doubleArray = *Math::GSL::Complexc::delete_doubleArray;
120 *doubleArray_getitem = *Math::GSL::Complexc::doubleArray_getitem;
121 *doubleArray_setitem = *Math::GSL::Complexc::doubleArray_setitem;
122  
123 ############# Class : Math::GSL::Complex::gsl_complex ##############
124  
125 package Math::GSL::Complex::gsl_complex;
126 1 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
127 @ISA = qw( Math::GSL::Complex );
128 %OWNER = ();
129 %ITERATORS = ();
130 *swig_dat_get = *Math::GSL::Complexc::gsl_complex_dat_get;
131 *swig_dat_set = *Math::GSL::Complexc::gsl_complex_dat_set;
132 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
133 0 my $pkg = shift;
134 0 my $self = Math::GSL::Complexc::new_gsl_complex(@_);
135 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
136 }
137  
138 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
139 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
140 0 my $self = tied(%{$_[0]});
141 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
142 0 delete $ITERATORS{$self};
143 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
144 0 Math::GSL::Complexc::delete_gsl_complex($self);
145 0 delete $OWNER{$self};
146 }
147 }
148  
149 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
150 0 my $self = shift;
151 0 my $ptr = tied(%$self);
152 0 delete $OWNER{$ptr};
153 }
154  
155 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
156 0 my $self = shift;
157 0 my $ptr = tied(%$self);
158 0 $OWNER{$ptr} = 1;
159 }
160  
161  
162 ############# Class : Math::GSL::Complex::gsl_complex_long_double ##############
163  
164 package Math::GSL::Complex::gsl_complex_long_double;
165 1 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
166 @ISA = qw( Math::GSL::Complex );
167 %OWNER = ();
168 %ITERATORS = ();
169 *swig_dat_get = *Math::GSL::Complexc::gsl_complex_long_double_dat_get;
170 *swig_dat_set = *Math::GSL::Complexc::gsl_complex_long_double_dat_set;
171 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
172 0 my $pkg = shift;
173 0 my $self = Math::GSL::Complexc::new_gsl_complex_long_double(@_);
174 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
175 }
176  
177 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
178 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
179 0 my $self = tied(%{$_[0]});
180 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
181 0 delete $ITERATORS{$self};
182 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
183 0 Math::GSL::Complexc::delete_gsl_complex_long_double($self);
184 0 delete $OWNER{$self};
185 }
186 }
187  
188 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
189 0 my $self = shift;
190 0 my $ptr = tied(%$self);
191 0 delete $OWNER{$ptr};
192 }
193  
194 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
195 0 my $self = shift;
196 0 my $ptr = tied(%$self);
197 0 $OWNER{$ptr} = 1;
198 }
199  
200  
201 ############# Class : Math::GSL::Complex::gsl_complex_float ##############
202  
203 package Math::GSL::Complex::gsl_complex_float;
204 1 ▶use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
Subroutine BEGIN: called CC=1 SCAR=0.0
205 @ISA = qw( Math::GSL::Complex );
206 %OWNER = ();
207 %ITERATORS = ();
208 *swig_dat_get = *Math::GSL::Complexc::gsl_complex_float_dat_get;
209 *swig_dat_set = *Math::GSL::Complexc::gsl_complex_float_dat_set;
210 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
211 0 my $pkg = shift;
212 0 my $self = Math::GSL::Complexc::new_gsl_complex_float(@_);
213 0 ▶ bless $self, $pkg if defined($self);
Branch: 1 branch
BranchTrueFalseTotal
if defined $self 0 0 0
214 }
215  
216 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
217 0 ▶ return unless $_[0]->isa('HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->isa("HASH") 0 0 0
218 0 my $self = tied(%{$_[0]});
219 0 ▶ return unless defined $self;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self 0 0 0
220 0 delete $ITERATORS{$self};
221 0 ▶ if (exists $OWNER{$self}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $OWNER{$self}) 0 0 0
222 0 Math::GSL::Complexc::delete_gsl_complex_float($self);
223 0 delete $OWNER{$self};
224 }
225 }
226  
227 0 ▶sub DISOWN {
Subroutine DISOWN: not called CC=1 SCAR=6.9
228 0 my $self = shift;
229 0 my $ptr = tied(%$self);
230 0 delete $OWNER{$ptr};
231 }
232  
233 0 ▶sub ACQUIRE {
Subroutine ACQUIRE: not called CC=1 SCAR=6.9
234 0 my $self = shift;
235 0 my $ptr = tied(%$self);
236 0 $OWNER{$ptr} = 1;
237 }
238  
239  
240 # ------- VARIABLE STUBS --------
241  
242 package Math::GSL::Complex;
243  
244 *GSL_VERSION = *Math::GSL::Complexc::GSL_VERSION;
245 *GSL_MAJOR_VERSION = *Math::GSL::Complexc::GSL_MAJOR_VERSION;
246 *GSL_MINOR_VERSION = *Math::GSL::Complexc::GSL_MINOR_VERSION;
247 *GSL_POSZERO = *Math::GSL::Complexc::GSL_POSZERO;
248 *GSL_NEGZERO = *Math::GSL::Complexc::GSL_NEGZERO;
249 *GSL_SUCCESS = *Math::GSL::Complexc::GSL_SUCCESS;
250 *GSL_FAILURE = *Math::GSL::Complexc::GSL_FAILURE;
251 *GSL_CONTINUE = *Math::GSL::Complexc::GSL_CONTINUE;
252 *GSL_EDOM = *Math::GSL::Complexc::GSL_EDOM;
253 *GSL_ERANGE = *Math::GSL::Complexc::GSL_ERANGE;
254 *GSL_EFAULT = *Math::GSL::Complexc::GSL_EFAULT;
255 *GSL_EINVAL = *Math::GSL::Complexc::GSL_EINVAL;
256 *GSL_EFAILED = *Math::GSL::Complexc::GSL_EFAILED;
257 *GSL_EFACTOR = *Math::GSL::Complexc::GSL_EFACTOR;
258 *GSL_ESANITY = *Math::GSL::Complexc::GSL_ESANITY;
259 *GSL_ENOMEM = *Math::GSL::Complexc::GSL_ENOMEM;
260 *GSL_EBADFUNC = *Math::GSL::Complexc::GSL_EBADFUNC;
261 *GSL_ERUNAWAY = *Math::GSL::Complexc::GSL_ERUNAWAY;
262 *GSL_EMAXITER = *Math::GSL::Complexc::GSL_EMAXITER;
263 *GSL_EZERODIV = *Math::GSL::Complexc::GSL_EZERODIV;
264 *GSL_EBADTOL = *Math::GSL::Complexc::GSL_EBADTOL;
265 *GSL_ETOL = *Math::GSL::Complexc::GSL_ETOL;
266 *GSL_EUNDRFLW = *Math::GSL::Complexc::GSL_EUNDRFLW;
267 *GSL_EOVRFLW = *Math::GSL::Complexc::GSL_EOVRFLW;
268 *GSL_ELOSS = *Math::GSL::Complexc::GSL_ELOSS;
269 *GSL_EROUND = *Math::GSL::Complexc::GSL_EROUND;
270 *GSL_EBADLEN = *Math::GSL::Complexc::GSL_EBADLEN;
271 *GSL_ENOTSQR = *Math::GSL::Complexc::GSL_ENOTSQR;
272 *GSL_ESING = *Math::GSL::Complexc::GSL_ESING;
273 *GSL_EDIVERGE = *Math::GSL::Complexc::GSL_EDIVERGE;
274 *GSL_EUNSUP = *Math::GSL::Complexc::GSL_EUNSUP;
275 *GSL_EUNIMPL = *Math::GSL::Complexc::GSL_EUNIMPL;
276 *GSL_ECACHE = *Math::GSL::Complexc::GSL_ECACHE;
277 *GSL_ETABLE = *Math::GSL::Complexc::GSL_ETABLE;
278 *GSL_ENOPROG = *Math::GSL::Complexc::GSL_ENOPROG;
279 *GSL_ENOPROGJ = *Math::GSL::Complexc::GSL_ENOPROGJ;
280 *GSL_ETOLF = *Math::GSL::Complexc::GSL_ETOLF;
281 *GSL_ETOLX = *Math::GSL::Complexc::GSL_ETOLX;
282 *GSL_ETOLG = *Math::GSL::Complexc::GSL_ETOLG;
283 *GSL_EOF = *Math::GSL::Complexc::GSL_EOF;
284  
285 1 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
286 0 ▶use Math::GSL::Errno qw/$GSL_SUCCESS gsl_strerror/;
Subroutine BEGIN: called CC=1 SCAR=2.6
287 use Data::Dumper;
288  
289 use strict;
290 use warnings;
291 use Carp qw/croak/;
292 use Scalar::Util 'blessed';
293  
294 use overload
295 '*' => \&_multiplication,
296 '/' => \&_division,
297 '+' => \&_addition,
298 '-' => \&_subtract,
299 '==' => \&_equal,
300 '!=' => \&_not_equal,
301 fallback => 1;
302  
303 our @EXPORT_OK = qw(
304 gsl_complex_arg gsl_complex_abs gsl_complex_rect gsl_complex_polar doubleArray_getitem
305 gsl_complex_rect gsl_complex_polar gsl_complex_arg gsl_complex_abs gsl_complex_abs2
306 gsl_complex_logabs gsl_complex_add gsl_complex_sub gsl_complex_mul gsl_complex_div
307 gsl_complex_add_real gsl_complex_sub_real gsl_complex_mul_real gsl_complex_div_real
308 gsl_complex_add_imag gsl_complex_sub_imag gsl_complex_mul_imag gsl_complex_div_imag
309 gsl_complex_conjugate gsl_complex_inverse gsl_complex_negative gsl_complex_sqrt
310 gsl_complex_sqrt_real gsl_complex_pow gsl_complex_pow_real gsl_complex_exp
311 gsl_complex_log gsl_complex_log10 gsl_complex_log_b gsl_complex_sin
312 gsl_complex_cos gsl_complex_sec gsl_complex_csc gsl_complex_tan
313 gsl_complex_cot gsl_complex_arcsin gsl_complex_arcsin_real gsl_complex_arccos
314 gsl_complex_arccos_real gsl_complex_arcsec gsl_complex_arcsec_real gsl_complex_arccsc
315 gsl_complex_arccsc_real gsl_complex_arctan gsl_complex_arccot gsl_complex_sinh
316 gsl_complex_cosh gsl_complex_sech gsl_complex_csch gsl_complex_tanh
317 gsl_complex_coth gsl_complex_arcsinh gsl_complex_arccosh gsl_complex_arccosh_real
318 gsl_complex_arcsech gsl_complex_arccsch gsl_complex_arctanh gsl_complex_arctanh_real
319 gsl_complex_arccoth new_doubleArray delete_doubleArray doubleArray_setitem
320 gsl_real gsl_imag gsl_parts
321 gsl_complex_eq gsl_set_real gsl_set_imag gsl_set_complex
322 $GSL_COMPLEX_ONE $GSL_COMPLEX_ZERO $GSL_COMPLEX_NEGONE
323 );
324 # macros to implement
325 # gsl_set_complex gsl_set_complex_packed
326 our ($GSL_COMPLEX_ONE, $GSL_COMPLEX_ZERO, $GSL_COMPLEX_NEGONE) = map { gsl_complex_rect($_, 0) } qw(1 0 -1);
327  
328  
329 our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
330  
331 =encoding utf8
332  
333 =head2 copy()
334  
335 Returns a copy of the Complex number, which resides at a different location in
336 memory.
337  
338 my $z = Math::GSL::Complex->new([10,5]);
339 my $copy = $z->copy;
340  
341 =cut
342  
343  
344 sub copy {
345 my $self = shift;
346 my $copy = Math::GSL::Complex->new(
347 gsl_real($self->raw), gsl_imag($self->raw)
348 );
349  
350 return $copy;
351 }
352  
353 sub _not_equal {
354 my ($left, $right) = @_;
355 return ! _equal($left, $right);
356 }
357  
358 sub _equal {
359 my ($left, $right) = @_;
360  
361 if ( blessed $right && $right->isa('Math::GSL::Complex') && blessed $left && $left->isa('Math::GSL::Complex') ) {
362 return gsl_complex_eq($left->raw, $right->raw);
363 } else {
364 # If both are not Complex objects, they can't be the same
365 return 0;
366 }
367 }
368  
369 sub _division {
370 my ($left, $right) = @_;
371 my $raw;
372  
373 if ( blessed $right && $right->isa('Math::GSL::Complex') && blessed $left && $left->isa('Math::GSL::Complex') ) {
374 my $rcopy = $right->copy;
375 $raw = gsl_complex_div($left->raw, $right->raw);
376 $rcopy->set_raw( $raw );
377 return $rcopy;
378 } else {
379 my $lcopy = $left->copy;
380 $raw = gsl_complex_div_real($lcopy->raw, $right);
381 $lcopy->set_raw($raw);
382 return $lcopy;
383 }
384 }
385  
386 sub _multiplication {
387 my ($left, $right) = @_;
388 my $raw;
389  
390 if ( blessed $right && $right->isa('Math::GSL::Complex') && blessed $left && $left->isa('Math::GSL::Complex') ) {
391 my $rcopy = $right->copy;
392 $raw = gsl_complex_mul($left->raw, $right->raw);
393 $rcopy->set_raw( $raw );
394 return $rcopy;
395 } else {
396 my $lcopy = $left->copy;
397 $raw = gsl_complex_mul_real($lcopy->raw, $right);
398 $lcopy->set_raw($raw);
399 return $lcopy;
400 }
401 }
402  
403 sub _subtract {
404 my ($left, $right) = @_;
405 my $rcopy = $right->copy;
406 my $raw = gsl_complex_negative($right->raw);
407  
408 $rcopy->set_raw($raw);
409  
410 return _addition($left, $rcopy);
411 }
412  
413 sub _addition {
414 my ($left, $right) = @_;
415  
416 my $lcopy = $left->copy;
417 my $raw;
418  
419 if ( blessed $right && $right->isa('Math::GSL::Complex') && blessed $left && $left->isa('Math::GSL::Complex') ) {
420 $raw = gsl_complex_add($lcopy->raw, $right->raw);
421 } else {
422 $raw = gsl_complex_add_constant($lcopy->raw, $right);
423 }
424 $lcopy->set_raw($raw);
425 return $lcopy;
426 }
427  
428 sub set_raw {
429 my ($self, $raw) = @_;
430 $self->{_complex} = $raw;
431 return $self;
432 }
433  
434 sub new {
435 my ($class, @values) = @_;
436 my $this = {};
437 $this->{_complex} = gsl_complex_rect($values[0], $values[1]);
438 bless $this, $class;
439 }
440 sub real {
441 my ($self) = @_;
442 gsl_real($self->raw);
443 }
444  
445 sub imag {
446 my ($self) = @_;
447 gsl_imag($self->raw);
448 }
449  
450 sub parts {
451 my ($self) = @_;
452 gsl_parts($self->raw);
453 }
454  
455 sub raw { (shift)->{_complex} }
456  
457  
458 ### some important macros that are in gsl_complex.h
459 sub gsl_complex_eq {
460 my ($z,$w) = @_;
461 gsl_real($z) == gsl_real($w) && gsl_imag($z) == gsl_imag($w) ? 1 : 0;
462 }
463  
464 sub gsl_set_real {
465 my ($z,$r) = @_;
466 doubleArray_setitem($z->{dat}, 0, $r);
467 }
468  
469 sub gsl_set_imag {
470 my ($z,$i) = @_;
471 doubleArray_setitem($z->{dat}, 1, $i);
472 }
473  
474 sub gsl_real {
475 my $z = shift;
476 return doubleArray_getitem($z->{dat}, 0 );
477 }
478  
479 sub gsl_imag {
480 my $z = shift;
481 return doubleArray_getitem($z->{dat}, 1 );
482 }
483  
484 sub gsl_parts {
485 my $z = shift;
486 return (gsl_real($z), gsl_imag($z));
487 }
488  
489 sub gsl_set_complex {
490 my ($z, $r, $i) = @_;
491 gsl_set_real($z, $r);
492 gsl_set_imag($z, $i);
493 }
494  
495 =head1 NAME
496  
497 Math::GSL::Complex - Complex Numbers
498  
499 =head1 SYNOPSIS
500  
501 use Math::GSL::Complex qw/:all/;
502 my $complex = Math::GSL::Complex->new([3,2]); # creates a complex number 3+2*i
503 my $real = $complex->real; # returns the real part
504 my $imag = $complex->imag; # returns the imaginary part
505 $complex->gsl_set_real(5); # changes the real part to 5
506 $complex->gsl_set_imag(4); # changes the imaginary part to 4
507 $complex->gsl_set_complex(7,6); # changes it to 7 + 6*i
508 ($real, $imag) = $complex->parts; # get both at once
509  
510 =head1 DESCRIPTION
511  
512 Here is a list of all the functions included in this module :
513  
514 =over 1
515  
516 =item C<gsl_complex_arg($z)>
517  
518 Return the argument of the complex number $z
519  
520 =item C<gsl_complex_abs($z)>
521  
522 Return |$z|, the magnitude of the complex number $z
523  
524 =item C<gsl_complex_rect($x,$y)>
525  
526 Create a complex number in cartesian form $x + $y*i
527  
528 =item C<gsl_complex_polar($r,$theta)>
529  
530 Create a complex number in polar form $r*exp(i*$theta)
531  
532 =item C<gsl_complex_abs2($z)>
533  
534 Return |$z|^2, the squared magnitude of the complex number $z
535  
536 =item C<gsl_complex_logabs($z)>
537  
538 Return log(|$z|), the natural logarithm of the magnitude of the complex number $z
539  
540 =item C<gsl_complex_add($c1, $c2)>
541  
542 Return a complex number which is the sum of the complex numbers $c1 and $c2
543  
544 =item C<gsl_complex_sub($c1, $c2)>
545  
546 Return a complex number which is the difference between $c1 and $c2 ($c1 - $c2)
547  
548 =item C<gsl_complex_mul($c1, $c2)>
549  
550 Return a complex number which is the product of the complex numbers $c1 and $c2
551  
552 =item C<gsl_complex_div($c1, $c2)>
553  
554 Return a complex number which is the quotient of the complex numbers $c1 and $c2 ($c1 / $c2)
555  
556 =item C<gsl_complex_add_real($c, $x)>
557  
558 Return the sum of the complex number $c and the real number $x
559  
560 =item C<gsl_complex_sub_real($c, $x)>
561  
562 Return the difference of the complex number $c and the real number $x
563  
564 =item C<gsl_complex_mul_real($c, $x)>
565  
566 Return the product of the complex number $c and the real number $x
567  
568 =item C<gsl_complex_div_real($c, $x)>
569  
570 Return the quotient of the complex number $c and the real number $x
571  
572 =item C<gsl_complex_add_imag($c, $y)>
573  
574 Return sum of the complex number $c and the imaginary number i*$x
575  
576 =item C<gsl_complex_sub_imag($c, $y)>
577  
578 Return the diffrence of the complex number $c and the imaginary number i*$x
579  
580 =item C<gsl_complex_mul_imag($c, $y)>
581  
582 Return the product of the complex number $c and the imaginary number i*$x
583  
584 =item C<gsl_complex_div_imag($c, $y)>
585  
586 Return the quotient of the complex number $c and the imaginary number i*$x
587  
588 =item C<gsl_complex_conjugate($c)>
589  
590 Return the conjugate of the of the complex number $c (x - i*y)
591  
592 =item C<gsl_complex_inverse($c)>
593  
594 Return the inverse, or reciprocal of the complex number $c (1/$c)
595  
596 =item C<gsl_complex_negative($c)>
597  
598 Return the negative of the complex number $c (-x -i*y)
599  
600 =item C<gsl_complex_sqrt($c)>
601  
602 Return the square root of the complex number $c
603  
604 =item C<gsl_complex_sqrt_real($x)>
605  
606 Return the complex square root of the real number $x, where $x may be negative
607  
608 =item C<gsl_complex_pow($c1, $c2)>
609  
610 Return the complex number $c1 raised to the complex power $c2
611  
612 =item C<gsl_complex_pow_real($c, $x)>
613  
614 Return the complex number raised to the real power $x
615  
616 =item C<gsl_complex_exp($c)>
617  
618 Return the complex exponential of the complex number $c
619  
620 =item C<gsl_complex_log($c)>
621  
622 Return the complex natural logarithm (base e) of the complex number $c
623  
624 =item C<gsl_complex_log10($c)>
625  
626 Return the complex base-10 logarithm of the complex number $c
627  
628 =item C<gsl_complex_log_b($c, $b)>
629  
630 Return the complex base-$b of the complex number $c
631  
632 =item C<gsl_complex_sin($c)>
633  
634 Return the complex sine of the complex number $c
635  
636 =item C<gsl_complex_cos($c)>
637  
638 Return the complex cosine of the complex number $c
639  
640 =item C<gsl_complex_sec($c)>
641  
642 Return the complex secant of the complex number $c
643  
644 =item C<gsl_complex_csc($c)>
645  
646 Return the complex cosecant of the complex number $c
647  
648 =item C<gsl_complex_tan($c)>
649  
650 Return the complex tangent of the complex number $c
651  
652 =item C<gsl_complex_cot($c)>
653  
654 Return the complex cotangent of the complex number $c
655  
656 =item C<gsl_complex_arcsin($c)>
657  
658 Return the complex arcsine of the complex number $c
659  
660 =item C<gsl_complex_arcsin_real($x)>
661  
662 Return the complex arcsine of the real number $x
663  
664 =item C<gsl_complex_arccos($c)>
665  
666 Return the complex arccosine of the complex number $c
667  
668 =item C<gsl_complex_arccos_real($x)>
669  
670 Return the complex arccosine of the real number $x
671  
672 =item C<gsl_complex_arcsec($c)>
673  
674 Return the complex arcsecant of the complex number $c
675  
676 =item C<gsl_complex_arcsec_real($x)>
677  
678 Return the complex arcsecant of the real number $x
679  
680 =item C<gsl_complex_arccsc($c)>
681  
682 Return the complex arccosecant of the complex number $c
683  
684 =item C<gsl_complex_arccsc_real($x)>
685  
686 Return the complex arccosecant of the real number $x
687  
688 =item C<gsl_complex_arctan($c)>
689  
690 Return the complex arctangent of the complex number $c
691  
692 =item C<gsl_complex_arccot($c)>
693  
694 Return the complex arccotangent of the complex number $c
695  
696 =item C<gsl_complex_sinh($c)>
697  
698 Return the complex hyperbolic sine of the complex number $c
699  
700 =item C<gsl_complex_cosh($c)>
701  
702 Return the complex hyperbolic cosine of the complex number $cy
703  
704 =item C<gsl_complex_sech($c)>
705  
706 Return the complex hyperbolic secant of the complex number $c
707  
708 =item C<gsl_complex_csch($c)>
709  
710 Return the complex hyperbolic cosecant of the complex number $c
711  
712 =item C<gsl_complex_tanh($c)>
713  
714 Return the complex hyperbolic tangent of the complex number $c
715  
716 =item C<gsl_complex_coth($c)>
717  
718 Return the complex hyperbolic cotangent of the complex number $c
719  
720 =item C<gsl_complex_arcsinh($c)>
721  
722 Return the complex hyperbolic arcsine of the complex number $c
723  
724 =item C<gsl_complex_arccosh($c)>
725  
726 Return the complex hyperbolic arccosine of the complex number $c
727  
728 =item C<gsl_complex_arccosh_real($x)>
729  
730 Return the complex hyperbolic arccosine of the real number $x
731  
732 =item C<gsl_complex_arcsech($c)>
733  
734 Return the complex hyperbolic arcsecant of the complex number $c
735  
736 =item C<gsl_complex_arccsch($c)>
737  
738 Return the complex hyperbolic arccosecant of the complex number $c
739  
740 =item C<gsl_complex_arctanh($c)>
741  
742 Return the complex hyperbolic arctangent of the complex number $c
743  
744 =item C<gsl_complex_arctanh_real($x)>
745  
746 Return the complex hyperbolic arctangent of the real number $x
747  
748 =item C<gsl_complex_arccoth($c)>
749  
750 Return the complex hyperbolic arccotangent of the complex number $c
751  
752 =item C<gsl_real($z)>
753  
754 Return the real part of $z
755  
756 =item C<gsl_imag($z)>
757  
758 Return the imaginary part of $z
759  
760 =item C<gsl_parts($z)>
761  
762 Return a list of the real and imaginary parts of $z
763  
764 =item C<gsl_set_real($z, $x)>
765  
766 Sets the real part of $z to $x
767  
768 =item C<gsl_set_imag($z, $y)>
769  
770 Sets the imaginary part of $z to $y
771  
772 =item C<gsl_set_complex($z, $x, $h)>
773  
774 Sets the real part of $z to $x and the imaginary part to $y
775  
776 =back
777  
778 =head1 EXAMPLES
779  
780 This code defines $z as 6 + 4*i, takes the complex conjugate of that number, then prints it out.
781  
782 =over 1
783  
784 my $z = gsl_complex_rect(6,4);
785 my $y = gsl_complex_conjugate($z);
786 my ($real, $imag) = gsl_parts($y);
787 print "z = $real + $imag*i\n";
788  
789 =back
790  
791 This code defines $z as 5 + 3*i, multiplies it by 2 and then prints it out.
792  
793 =over 1
794  
795 my $x = gsl_complex_rect(5,3);
796 my $z = gsl_complex_mul_real($x, 2);
797 my $real = gsl_real($z);
798 my $imag = gsl_imag($z);
799 print "Re(\$z) = $real\n";
800  
801 =back
802  
803 =head1 AUTHORS
804  
805 Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
806  
807 =head1 COPYRIGHT AND LICENSE
808  
809 Copyright (C) 2008-2024 Jonathan "Duke" Leto and Thierry Moisan
810  
811 This program is free software; you can redistribute it and/or modify it
812 under the same terms as Perl itself.
813  
814 =cut
815 1;
« blib/lib/Math/GSL/SF.pm ↑ Summary blib/lib/Math/GSL/Histogram.pm »