1df9b49f6f5ca477b988154b2cf4d71ae237bcbb
[scilab.git] / scilab / modules / elementary_functions / includes / elem_func_gw.hxx
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
4 *  Copyright (C) 2010-2011 - DIGITEO - Bruno JOFRET
5 *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14 *
15 */
16
17 #ifndef __ELEM_FUNC_GW_HXX__
18 #define __ELEM_FUNC_GW_HXX__
19
20 #include "cpp_gateway_prototype.hxx"
21 #include "double.hxx"
22 #include "complex"
23
24 extern "C"
25 {
26 #include "dynlib_elementary_functions_gw.h"
27 }
28
29 class ElemFuncModule
30 {
31 private :
32     ElemFuncModule() {};
33     ~ElemFuncModule() {};
34 public :
35     EXTERN_EF_GW static int Load();
36     EXTERN_EF_GW static int Unload()
37     {
38         return 1;
39     }
40 };
41
42 CPP_GATEWAY_PROTOTYPE(sci_abs);
43 CPP_GATEWAY_PROTOTYPE(sci_acos);
44 CPP_GATEWAY_PROTOTYPE(sci_acosh);
45 CPP_GATEWAY_PROTOTYPE(sci_asin);
46 CPP_GATEWAY_PROTOTYPE(sci_asinh);
47 CPP_GATEWAY_PROTOTYPE(sci_atan);
48 CPP_GATEWAY_PROTOTYPE(sci_atanh);
49 CPP_GATEWAY_PROTOTYPE(sci_bitstring);
50 CPP_GATEWAY_PROTOTYPE(sci_ceil);
51 CPP_GATEWAY_PROTOTYPE(sci_clean);
52 CPP_GATEWAY_PROTOTYPE(sci_conj);
53 CPP_GATEWAY_PROTOTYPE(sci_cos);
54 CPP_GATEWAY_PROTOTYPE(sci_cosh);
55 CPP_GATEWAY_PROTOTYPE(sci_cumprod);
56 CPP_GATEWAY_PROTOTYPE(sci_cumsum);
57 CPP_GATEWAY_PROTOTYPE(sci_diag);
58 CPP_GATEWAY_PROTOTYPE(sci_dsearch);
59 CPP_GATEWAY_PROTOTYPE(sci_exp);
60 CPP_GATEWAY_PROTOTYPE(sci_expm);
61 CPP_GATEWAY_PROTOTYPE(sci_eye);
62 CPP_GATEWAY_PROTOTYPE(sci_floor);
63 CPP_GATEWAY_PROTOTYPE(sci_frexp);
64 CPP_GATEWAY_PROTOTYPE(sci_gsort);
65 CPP_GATEWAY_PROTOTYPE(sci_imag);
66 CPP_GATEWAY_PROTOTYPE(sci_imult);
67 CPP_GATEWAY_PROTOTYPE(sci_int);
68 CPP_GATEWAY_PROTOTYPE(sci_isequal);
69 CPP_GATEWAY_PROTOTYPE(sci_isreal);
70 CPP_GATEWAY_PROTOTYPE(sci_kron);
71 CPP_GATEWAY_PROTOTYPE(sci_log);
72 CPP_GATEWAY_PROTOTYPE(sci_log1p);
73 CPP_GATEWAY_PROTOTYPE(sci_matrix);
74 CPP_GATEWAY_PROTOTYPE(sci_max); // Old name sci_maxi
75 CPP_GATEWAY_PROTOTYPE(sci_min); // Old name sci_mini
76 CPP_GATEWAY_PROTOTYPE(sci_nearfloat);
77 CPP_GATEWAY_PROTOTYPE(sci_ones);
78 CPP_GATEWAY_PROTOTYPE(sci_permute);
79 CPP_GATEWAY_PROTOTYPE(sci_prod);
80 CPP_GATEWAY_PROTOTYPE(sci_rand);
81 CPP_GATEWAY_PROTOTYPE(sci_rat);
82 CPP_GATEWAY_PROTOTYPE(sci_real);
83 CPP_GATEWAY_PROTOTYPE(sci_round);
84 CPP_GATEWAY_PROTOTYPE(sci_sign);
85 CPP_GATEWAY_PROTOTYPE(sci_sin);
86 CPP_GATEWAY_PROTOTYPE(sci_sinh);
87 CPP_GATEWAY_PROTOTYPE(sci_size);
88 CPP_GATEWAY_PROTOTYPE(sci_sqrt);
89 CPP_GATEWAY_PROTOTYPE(sci_sum);
90 CPP_GATEWAY_PROTOTYPE(sci_tan);
91 CPP_GATEWAY_PROTOTYPE(sci_tanh);
92 CPP_GATEWAY_PROTOTYPE(sci_tril);
93 CPP_GATEWAY_PROTOTYPE(sci_triu);
94 CPP_GATEWAY_PROTOTYPE(sci_zeros);
95
96
97 bool getDimsFromArguments(types::typed_list& in, const std::string& _pstName, int* _iDims, int** _piDims, bool* _alloc);
98
99 template <class T>
100 types::Double* getAsDouble(T* _val)
101 {
102     types::Double* dbl = new types::Double(_val->getDims(), _val->getDimsArray());
103     double* pOut = dbl->get();
104     typename T::type* pIn = _val->get();
105     int size = dbl->getSize();
106     for (int i = 0; i < size; i++)
107     {
108         pOut[i] = static_cast<double>(pIn[i]);
109     }
110
111     return dbl;
112 }
113
114 template <class T>
115 T* toInt(types::Double* _dbl)
116 {
117     T* pI = new T(_dbl->getDims(), _dbl->getDimsArray());
118     typename T::type* p = pI->get();
119     double* pdbl = _dbl->get();
120     int size = _dbl->getSize();
121     for (int i = 0; i < size; i++)
122     {
123         p[i] = static_cast<typename T::type>(pdbl[i]);
124     }
125
126     return pI;
127 }
128
129 typedef double(*func_real)(double);
130 typedef std::complex<double>(*func_complex)(const std::complex<double>&);
131
132 types::Double* trigo(types::Double* in, func_real func_r, func_complex func_c, bool forceComplex = false);
133
134 #endif /* __ELEM_FUNC_GW_HXX__ */