1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004 the VideoLAN team
7 * Authors: Cyril Deguet <asmax@videolan.org>
8 * code from projectM http://xmms-projectm.sourceforge.net
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
29 /* Values to optimize the sigmoid function */
33 static inline double int_wrapper(double * arg_list) {
35 return floor(arg_list[0]);
40 static inline double sqr_wrapper(double * arg_list) {
42 return pow(2, arg_list[0]);
46 static inline double sign_wrapper(double * arg_list) {
51 static inline double min_wrapper(double * arg_list) {
53 if (arg_list[0] > arg_list[1])
59 static inline double max_wrapper(double * arg_list) {
61 if (arg_list[0] > arg_list[1])
67 /* consult your AI book */
68 static inline double sigmoid_wrapper(double * arg_list) {
69 return (RR / (1 + exp( -(((double)(arg_list[0])) * arg_list[1]) / R) - R));
73 static inline double bor_wrapper(double * arg_list) {
75 return (double)((int)arg_list[0] || (int)arg_list[1]);
78 static inline double band_wrapper(double * arg_list) {
79 return (double)((int)arg_list[0] && (int)arg_list[1]);
82 static inline double bnot_wrapper(double * arg_list) {
83 return (double)(!(int)arg_list[0]);
86 static inline double if_wrapper(double * arg_list) {
88 if ((int)arg_list[0] == 0)
94 static inline double rand_wrapper(double * arg_list) {
97 // printf("RAND ARG:(%d)\n", (int)arg_list[0]);
98 l = (double)((rand()) % ((int)arg_list[0]));
99 //printf("VAL: %f\n", l);
103 static inline double equal_wrapper(double * arg_list) {
105 return (arg_list[0] == arg_list[1]);
109 static inline double above_wrapper(double * arg_list) {
111 return (arg_list[0] > arg_list[1]);
115 static inline double below_wrapper(double * arg_list) {
117 return (arg_list[0] < arg_list[1]);
120 static inline double sin_wrapper(double * arg_list) {
121 return (sin (arg_list[0]));
125 static inline double cos_wrapper(double * arg_list) {
126 return (cos (arg_list[0]));
129 static inline double tan_wrapper(double * arg_list) {
130 return (tan(arg_list[0]));
133 static inline double asin_wrapper(double * arg_list) {
134 return (asin (arg_list[0]));
137 static inline double acos_wrapper(double * arg_list) {
138 return (acos (arg_list[0]));
141 static inline double atan_wrapper(double * arg_list) {
142 return (atan (arg_list[0]));
145 static inline double atan2_wrapper(double * arg_list) {
146 return (atan2 (arg_list[0], arg_list[1]));
149 static inline double pow_wrapper(double * arg_list) {
150 return (pow (arg_list[0], arg_list[1]));
153 static inline double exp_wrapper(double * arg_list) {
154 return (exp(arg_list[0]));
157 static inline double abs_wrapper(double * arg_list) {
158 return (fabs(arg_list[0]));
161 static inline double log_wrapper(double *arg_list) {
162 return (log (arg_list[0]));
165 static inline double log10_wrapper(double * arg_list) {
166 return (log10 (arg_list[0]));
169 static inline double sqrt_wrapper(double * arg_list) {
170 return (sqrt (arg_list[0]));
174 static inline double nchoosek_wrapper(double * arg_list) {
175 unsigned long cnm = 1UL;
179 n = (int)arg_list[0];
180 m = (int)arg_list[1];
183 for (i=1 ; i <= m; n--, i++)
194 static inline double fact_wrapper(double * arg_list) {
199 int n = (int)arg_list[0];
205 return (double)result;