Add typemaps to Complex subsystem
[Math-GSL.git] / Complex.i
blob895e82b0a33a27b2b80a8e4cbfad495aeb18f363
1 %module "Math::GSL::Complex"
2 %include "typemaps.i"
3 %include "gsl_typemaps.i"
4 %{
5 #include "gsl/gsl_complex.h"
6 #include "gsl/gsl_complex_math.h"
7 %}
9 %include "gsl/gsl_complex.h"
10 %include "gsl/gsl_complex_math.h"
13 %include "carrays.i"
14 %array_functions(double, doubleArray);
16 %perlcode %{
18 @EXPORT_OK = qw(
19 gsl_complex_arg gsl_complex_abs gsl_complex_rect gsl_complex_polar doubleArray_getitem
20 gsl_complex_rect gsl_complex_polar gsl_complex_arg gsl_complex_abs gsl_complex_abs2
21 gsl_complex_logabs gsl_complex_add gsl_complex_sub gsl_complex_mul gsl_complex_div
22 gsl_complex_add_real gsl_complex_sub_real gsl_complex_mul_real gsl_complex_div_real
23 gsl_complex_add_imag gsl_complex_sub_imag gsl_complex_mul_imag gsl_complex_div_imag
24 gsl_complex_conjugate gsl_complex_inverse gsl_complex_negative gsl_complex_sqrt
25 gsl_complex_sqrt_real gsl_complex_pow gsl_complex_pow_real gsl_complex_exp
26 gsl_complex_log gsl_complex_log10 gsl_complex_log_b gsl_complex_sin
27 gsl_complex_cos gsl_complex_sec gsl_complex_csc gsl_complex_tan
28 gsl_complex_cot gsl_complex_arcsin gsl_complex_arcsin_real gsl_complex_arccos
29 gsl_complex_arccos_real gsl_complex_arcsec gsl_complex_arcsec_real gsl_complex_arccsc
30 gsl_complex_arccsc_real gsl_complex_arctan gsl_complex_arccot gsl_complex_sinh
31 gsl_complex_cosh gsl_complex_sech gsl_complex_csch gsl_complex_tanh
32 gsl_complex_coth gsl_complex_arcsinh gsl_complex_arccosh gsl_complex_arccosh_real
33 gsl_complex_arcsech gsl_complex_arccsch gsl_complex_arctanh gsl_complex_arctanh_real
34 gsl_complex_arccoth new_doubleArray delete_doubleArray doubleArray_setitem
35 gsl_real gsl_imag gsl_parts
36 gsl_complex_eq gsl_set_real gsl_set_imag gsl_set_complex
37 $GSL_COMPLEX_ONE $GSL_COMPLEX_ZERO $GSL_COMPLEX_NEGONE
39 # macros to implement
40 # gsl_set_complex gsl_set_complex_packed
41 our ($GSL_COMPLEX_ONE, $GSL_COMPLEX_ZERO, $GSL_COMPLEX_NEGONE) = map { gsl_complex_rect($_, 0) } qw(1 0 -1);
44 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
46 ### wrapper interface ###
47 sub new {
48 my ($class, @values) = @_;
49 my $this = {};
50 $this->{_complex} = gsl_complex_rect($values[0], $values[1]);
51 bless $this, $class;
53 sub real {
54 my ($self) = @_;
55 gsl_real($self->{_complex}->{dat});
58 sub imag {
59 my ($self) = @_;
60 gsl_imag($self->{_complex}->{dat});
63 sub parts {
64 my ($self) = @_;
65 gsl_parts($self->{_complex}->{dat});
68 sub raw { (shift)->{_complex} }
70 ### end wrapper interface ###
72 ### some important macros that are in gsl_complex.h
73 sub gsl_complex_eq {
74 my ($z,$w) = @_;
75 gsl_real($z) == gsl_real($w) && gsl_imag($z) == gsl_imag($w) ? 1 : 0;
78 sub gsl_set_real {
79 my ($z,$r) = @_;
80 doubleArray_setitem($z->{dat}, 0, $r);
83 sub gsl_set_imag {
84 my ($z,$i) = @_;
85 doubleArray_setitem($z->{dat}, 1, $i);
88 sub gsl_real {
89 my $z = shift;
90 return doubleArray_getitem($z->{dat}, 0 );
93 sub gsl_imag {
94 my $z = shift;
95 return doubleArray_getitem($z->{dat}, 1 );
98 sub gsl_parts {
99 my $z = shift;
100 return (gsl_real($z), gsl_imag($z));
103 sub gsl_set_complex {
104 my ($z, $r, $i) = @_;
105 gsl_set_real($z, $r);
106 gsl_set_imag($z, $i);
109 __END__
111 =head1 NAME
113 Math::GSL::Complex
114 Functions concerning complex numbers.
116 =head1 SYNOPSIS
118 use Math::GSL::Complex qw/:all/;
119 my $complex = Math::GSL::Complex->new([3,2]); # creates a complex number 3+2*i
120 my $real = $complex->real; # returns the real value of the complex number
121 my $imag = $complex->imag; # returns the imaginary value of the complex number
122 $complex->gsl_set_real(5); # changes the real value of the complex number to 5
123 $complex->gsl_set_imag(4); # changes the imaginary value of the complex number to 4
124 $complex->gsl_set_complex(7,6); # changes the real value of the complex number to 7 and the imaginary value to 6
125 ($real, $imag) = $complex->parts; # returns the real and imaginary values of the complex number
126 my $abs = gsl_complex_abs2($complex->raw); # the raw method gives access to the underlying gsl_complex structure, it is needed for the functions below.
128 =head1 DESCRIPTION
130 Here is a list of all the functions included in this module :
132 =over 1
134 =item C<gsl_complex_arg($z)> - return the argument of the complex number $z
136 =item C<gsl_complex_abs($z)> - return |$z|, the magnitude of the complex number $z
138 =item C<gsl_complex_rect($x,$y)> - create a complex number in cartesian form $x + $y*I
140 =item C<gsl_complex_polar($r,$theta)> - create a complex number in polar form $r*exp(I*$theta)
142 =item C<gsl_complex_abs2($z)> - return |$z|^2, the squared magnitude of the complex number $z
144 =item C<gsl_complex_logabs($z)> - return log(|$z|), the natural logarithm of the magnitude of the complex number $z
146 =item C<gsl_complex_add($c1, $c2)> - return a complex number which is the sum of the complex numbers $c1 and $c2
148 =item C<gsl_complex_sub($c1, $c2)> - return a complex number which is the difference between $c1 and $c2 ($c1 - $c2)
150 =item C<gsl_complex_mul($c1, $c2)> - return a complex number which is the product of the complex numbers $c1 and $c2
152 =item C<gsl_complex_div($c1, $c2)> - return a complex number which is the quotient of the complex numbers $c1 and $c2 ($c1 / $c2)
154 =item C<gsl_complex_add_real($c, $x)> - return the sum of the complex number $c and the real number $x
156 =item C<gsl_complex_sub_real($c, $x)> - return the difference of the complex number $c and the real number $x
158 =item C<gsl_complex_mul_real($c, $x)> - return the product of the complex number $c and the real number $x
160 =item C<gsl_complex_div_real($c, $x)> - return the quotient of the complex number $c and the real number $x
162 =item C<gsl_complex_add_imag($c, $y)> - return sum of the complex number $c and the imaginary number i*$x
164 =item C<gsl_complex_sub_imag($c, $y)> - return the diffrence of the complex number $c and the imaginary number i*$x
166 =item C<gsl_complex_mul_imag($c, $y)> - return the product of the complex number $c and the imaginary number i*$x
168 =item C<gsl_complex_div_imag($c, $y)> - return the quotient of the complex number $c and the imaginary number i*$x
170 =item C<gsl_complex_conjugate($c)> - return the conjugate of the of the complex number $c (x - i*y)
172 =item C<gsl_complex_inverse($c)> - return the inverse, or reciprocal of the complex number $c (1/$c)
174 =item C<gsl_complex_negative($c)> - return the negative of the complex number $c (-x -i*y)
176 =item C<gsl_complex_sqrt($c)> - return the square root of the complex number $c
178 =item C<gsl_complex_sqrt_real($x)> - return the complex square root of the real number $x, where $x may be negative
180 =item C<gsl_complex_pow($c1, $c2)> - return the complex number $c1 raised to the complex power $c2
182 =item C<gsl_complex_pow_real($c, $x)> - return the complex number raised to the real power $x
184 =item C<gsl_complex_exp($c)> - return the complex exponential of the complex number $c
186 =item C<gsl_complex_log($c)> - return the complex natural logarithm (base e) of the complex number $c
188 =item C<gsl_complex_log10($c)> - return the complex base-10 logarithm of the complex number $c
190 =item C<gsl_complex_log_b($c, $b)> - return the complex base-$b of the complex number $c
192 =item C<gsl_complex_sin($c)> - return the complex sine of the complex number $c
194 =item C<gsl_complex_cos($c)> - return the complex cosine of the complex number $c
196 =item C<gsl_complex_sec($c)> - return the complex secant of the complex number $c
198 =item C<gsl_complex_csc($c)> - return the complex cosecant of the complex number $c
200 =item C<gsl_complex_tan($c)> - return the complex tangent of the complex number $c
202 =item C<gsl_complex_cot($c)> - return the complex cotangent of the complex number $c
204 =item C<gsl_complex_arcsin($c)> - return the complex arcsine of the complex number $c
206 =item C<gsl_complex_arcsin_real($x)> - return the complex arcsine of the real number $x
208 =item C<gsl_complex_arccos($c)> - return the complex arccosine of the complex number $c
210 =item C<gsl_complex_arccos_real($x)> - return the complex arccosine of the real number $x
212 =item C<gsl_complex_arcsec($c)> - return the complex arcsecant of the complex number $c
214 =item C<gsl_complex_arcsec_real($x)> - return the complex arcsecant of the real number $x
216 =item C<gsl_complex_arccsc($c)> - return the complex arccosecant of the complex number $c
218 =item C<gsl_complex_arccsc_real($x)> - return the complex arccosecant of the real number $x
220 =item C<gsl_complex_arctan($c)> - return the complex arctangent of the complex number $c
222 =item C<gsl_complex_arccot($c)> - return the complex arccotangent of the complex number $c
224 =item C<gsl_complex_sinh($c)> - return the complex hyperbolic sine of the complex number $c
226 =item C<gsl_complex_cosh($c)> - return the complex hyperbolic cosine of the complex number $cy
228 =item C<gsl_complex_sech($c)> - return the complex hyperbolic secant of the complex number $c
230 =item C<gsl_complex_csch($c)> - return the complex hyperbolic cosecant of the complex number $c
232 =item C<gsl_complex_tanh($c)> - return the complex hyperbolic tangent of the complex number $c
234 =item C<gsl_complex_coth($c)> - return the complex hyperbolic cotangent of the complex number $c
236 =item C<gsl_complex_arcsinh($c)> - return the complex hyperbolic arcsine of the complex number $c
238 =item C<gsl_complex_arccosh($c)> - return the complex hyperbolic arccosine of the complex number $c
240 =item C<gsl_complex_arccosh_real($x)> - return the complex hyperbolic arccosine of the real number $x
242 =item C<gsl_complex_arcsech($c)> - return the complex hyperbolic arcsecant of the complex number $c
244 =item C<gsl_complex_arccsch($c)> - return the complex hyperbolic arccosecant of the complex number $c
246 =item C<gsl_complex_arctanh($c)> - return the complex hyperbolic arctangent of the complex number $c
248 =item C<gsl_complex_arctanh_real($x)> - return the complex hyperbolic arctangent of the real number $x
250 =item C<gsl_complex_arccoth($c)> - return the complex hyperbolic arccotangent of the complex number $c
252 =item C<gsl_real($z)> - return the real part of $z
254 =item C<gsl_imag($z)> - return the imaginary part of $z
256 =item C<gsl_parts($z)> - return a list of the real and imaginary parts of $z
258 =item C<gsl_set_real($z, $x)> - sets the real part of $z to $x
260 =item C<gsl_set_imag($z, $y)> - sets the imaginary part of $z to $y
262 =item C<gsl_set_complex($z, $x, $h)> - sets the real part of $z to $x and the imaginary part to $y
264 =back
266 You have to add the functions you want to use inside the qw /put_funtion_here / with spaces between each function.
267 You can also write use Math::GSL::Complex qw/:all/ to use all avaible functions of the module.
269 For more informations on the functions, we refer you to the GSL offcial documentation: L<http://www.gnu.org/software/gsl/manual/html_node/>
270 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
272 =head1 EXAMPLES
274 This code defines $z as 6 + 4*I, takes the complex conjugate of that number, then prints it out.
276 =over 1
278 =item C<my $z = gsl_complex_rect(6,4);>
280 =item C<my $y = gsl_complex_conjugate($z);>
282 =item C<my ($real, $imag) = gsl_parts($y);>
284 =item C<print "z = $real + $imag*I\n";>
286 =back
288 This code defines $z as 5 + 3*I, multiplies it by 2 and then prints it out.
290 =over 1
292 =item C<my $x = gsl_complex_rect(5,3);>
294 =item C<my $z = gsl_complex_mul_real($x, 2);>
296 =item C<my $real = gsl_real($z);>
298 =item C<my $imag = gsl_imag($z);>
300 =item C<print "Re(\$z) = $real\n";>
302 =back
304 =head1 AUTHORS
306 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
308 =head1 COPYRIGHT AND LICENSE
310 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
312 This program is free software; you can redistribute it and/or modify it
313 under the same terms as Perl itself.
315 =cut