Fix the swap_rowcol Matrix test and suppress fopen/fclose redefinition warnings.
[Math-GSL.git] / Poly.i
blob704708a41ad9a63c67251b4ccf8a94915dafdeac
1 %module Poly
2 %include "GSL.i"
4 %typemap(in) double * (double dvalue) {
5 SV* tempsv;
6 if (!SvROK($input)) {
7 croak("Math::GSL::Sort : $input is not a reference!\n");
9 tempsv = SvRV($input);
10 if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
11 croak("Math::GSL::Sort : $input is not a reference to number!\n");
13 dvalue = SvNV(tempsv);
14 $1 = &dvalue;
16 %typemap(argout) double * {
17 SV *tempsv;
18 tempsv = SvRV($input);
19 sv_setnv(tempsv, *$1);
22 %typemap(in) gsl_complex const [] {
23 AV *tempav;
24 I32 len;
25 int i, magic, stuff;
26 double x,y;
27 gsl_complex z;
28 SV **elem, **helem, **real, **imag;
29 HV *hash, *htmp;
30 SV *svtmp, tmp;
31 double result[2];
33 printf("gsl_complex typemap\n");
34 if (!SvROK($input))
35 croak("Math::GSL : $input is not a reference!");
36 if (SvTYPE(SvRV($input)) != SVt_PVAV)
37 croak("Math::GSL : $input is not an array ref!");
39 z = gsl_complex_rect(0,0);
40 tempav = (AV*)SvRV($input);
41 len = av_len(tempav);
42 $1 = (gsl_complex *) malloc((len+1)*sizeof(gsl_complex));
43 for (i = 0; i <= len; i++) {
44 elem = av_fetch(tempav, i, 0);
46 hash = (HV*) SvRV(*elem);
47 helem = hv_fetch(hash, "dat", 3, 0);
48 magic = mg_get(*helem);
49 if ( magic != 0)
50 croak("FETCH magic failed!\n");
52 printf("magic = %d\n", magic);
53 if( *helem == NULL)
54 croak("Structure does not contain 'dat' element\n");
55 printf("helem is:\n");
56 Perl_sv_dump(*helem);
57 if( i == 0){
58 svtmp = (SV*)SvRV(*helem);
59 Perl_sv_dump(svtmp);
61 printf("re z = %f\n", GSL_REAL(z) );
62 printf("im z = %f\n", GSL_IMAG(z) );
63 $1[i] = z;
65 //$1[i] = GSL_NAN;
68 #include "/usr/local/include/gsl/gsl_nan.h"
69 #include "/usr/local/include/gsl/gsl_poly.h"
70 #include "/usr/local/include/gsl/gsl_complex.h"
71 #include "/usr/local/include/gsl/gsl_complex_math.h"
74 %include "/usr/local/include/gsl/gsl_nan.h"
75 %include "/usr/local/include/gsl/gsl_poly.h"
76 %include "/usr/local/include/gsl/gsl_complex.h"
77 %include "/usr/local/include/gsl/gsl_complex_math.h"
80 %perlcode %{
82 @EXPORT_OK = qw/
83 gsl_poly_eval
84 gsl_poly_complex_eval
85 gsl_complex_poly_complex_eval
86 gsl_poly_dd_init
87 gsl_poly_dd_eval
88 gsl_poly_dd_taylor
89 gsl_poly_solve_quadratic
90 gsl_poly_complex_solve_quadratic
91 gsl_poly_solve_cubic
92 gsl_poly_complex_solve_cubic
93 gsl_poly_complex_workspace_alloc
94 gsl_poly_complex_workspace_free
95 gsl_poly_complex_solve
96 $GSL_POSZERO $GSL_NEGZERO $GSL_NAN
98 our $GSL_NAN = q{nan};
99 #our $GSL_POSZERO = 0.0;
100 #our $GSL_NEGZERO = -1*0.0;
102 %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
104 __END__
106 =head1 NAME
108 Math::GSL::Poly
109 Functions for evaluating and solving polynomials
111 =head1 SYPNOPSIS
113 use Math::GSL::Poly qw/:all/;
115 =head1 DESCRIPTION
117 Here is a list of all the functions included in this module :
119 gsl_poly_eval
121 gsl_poly_complex_eval
123 gsl_complex_poly_complex_eval
125 gsl_poly_dd_init
127 gsl_poly_dd_eval
129 gsl_poly_dd_taylor
131 gsl_poly_solve_quadratic
133 gsl_poly_complex_solve_quadratic
135 gsl_poly_solve_cubic($a, $b, $c, \$x0, \$x1, \$x2) - find the real roots of the cubic equation x³+$a*+$b*x+$c, return the number of real root (either one or three) and the real roots are returned bye $x0, $x1 and $x2 which are deferenced.
137 gsl_poly_complex_solve_cubic
139 gsl_poly_complex_workspace_alloc
141 gsl_poly_complex_workspace_free
143 gsl_poly_complex_solve
145 For more informations on the functions, we refer you to the GSL offcial documentation: http://www.gnu.org/software/gsl/manual/html_node/
146 Tip : search on google: site:http://www.gnu.org/software/gsl/manual/html_node/ name_of_the_function_you_want
148 =head1 EXAMPLES
150 use Math::GSL::Poly qw/:all/;
151 $a = 1;
152 $b = 6;
153 $c = 9;
154 $x0 = 0;
155 $x1 = 0;
156 $num_roots = gsl_poly_solve_quadratic( $a, $b, $c, \$x0, \$x1);
157 print "x²+6x+9 contains $num_roots roots which are $x0 and $x1. \n";
159 =head1 AUTHOR
161 Jonathan Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com>
163 =head1 COPYRIGHT AND LICENSE
165 Copyright (C) 2008 Jonathan Leto and Thierry Moisan
167 This program is free software; you can redistribute it and/or modify it
168 under the same terms as Perl itself.
170 =cut