Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

builtin_funcs.c

00001 /*****************************************************************************
00002  * builtin_funcs.c:
00003  *****************************************************************************
00004  * Copyright (C) 2004 the VideoLAN team
00005  * $Id: builtin_funcs.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Cyril Deguet <[email protected]>
00008  *          code from projectM http://xmms-projectm.sourceforge.net
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 
00025 
00026 #include <math.h>
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 /* Values to optimize the sigmoid function */
00030 #define R  32767   
00031 #define RR 65534   
00032  
00033 inline double int_wrapper(double * arg_list) {
00034 
00035   return floor(arg_list[0]);
00036 
00037 }
00038 
00039 
00040 inline double sqr_wrapper(double * arg_list) {
00041         
00042         return pow(2, arg_list[0]);
00043 }       
00044         
00045         
00046 inline double sign_wrapper(double * arg_list) { 
00047         
00048         return -arg_list[0];    
00049 }       
00050 
00051 inline double min_wrapper(double * arg_list) {
00052         
00053         if (arg_list[0] > arg_list[1])
00054                 return arg_list[1];
00055         
00056         return arg_list[0];
00057 }               
00058 
00059 inline double max_wrapper(double * arg_list) {
00060 
00061         if (arg_list[0] > arg_list[1])
00062           return arg_list[0];
00063 
00064         return arg_list[1];
00065 }
00066 
00067 /* consult your AI book */
00068 inline double sigmoid_wrapper(double * arg_list) {
00069   return (RR / (1 + exp( -(((double)(arg_list[0])) * arg_list[1]) / R) - R));
00070 }
00071         
00072         
00073 inline double bor_wrapper(double * arg_list) {
00074 
00075         return (double)((int)arg_list[0] || (int)arg_list[1]);
00076 }       
00077         
00078 inline double band_wrapper(double * arg_list) {
00079         return (double)((int)arg_list[0] && (int)arg_list[1]);
00080 }       
00081 
00082 inline double bnot_wrapper(double * arg_list) {
00083         return (double)(!(int)arg_list[0]);
00084 }               
00085 
00086 inline double if_wrapper(double * arg_list) {
00087 
00088                 if ((int)arg_list[0] == 0)
00089                         return arg_list[2];
00090                 return arg_list[1];
00091 }               
00092 
00093 
00094 inline double rand_wrapper(double * arg_list) {
00095   double l;
00096 
00097   //  printf("RAND ARG:(%d)\n", (int)arg_list[0]);
00098   l = (double)((rand()) % ((int)arg_list[0]));
00099   //printf("VAL: %f\n", l);
00100   return l;
00101 }       
00102 
00103 inline double equal_wrapper(double * arg_list) {
00104 
00105         return (arg_list[0] == arg_list[1]);
00106 }       
00107 
00108 
00109 inline double above_wrapper(double * arg_list) {
00110 
00111         return (arg_list[0] > arg_list[1]);
00112 }       
00113 
00114 
00115 inline double below_wrapper(double * arg_list) {
00116 
00117         return (arg_list[0] < arg_list[1]);
00118 }
00119 
00120 inline double sin_wrapper(double * arg_list) {
00121         return (sin (arg_list[0]));     
00122 }
00123 
00124 
00125 inline double cos_wrapper(double * arg_list) {
00126         return (cos (arg_list[0]));
00127 }
00128 
00129 inline double tan_wrapper(double * arg_list) {
00130         return (tan(arg_list[0]));
00131 }
00132 
00133 inline double asin_wrapper(double * arg_list) {
00134         return (asin (arg_list[0]));
00135 }
00136 
00137 inline double acos_wrapper(double * arg_list) {
00138         return (acos (arg_list[0]));
00139 }
00140 
00141 inline double atan_wrapper(double * arg_list) {
00142         return (atan (arg_list[0]));
00143 }
00144 
00145 inline double atan2_wrapper(double * arg_list) {
00146   return (atan2 (arg_list[0], arg_list[1]));
00147 }
00148 
00149 inline double pow_wrapper(double * arg_list) {
00150   return (pow (arg_list[0], arg_list[1]));
00151 }
00152 
00153 inline double exp_wrapper(double * arg_list) {
00154   return (exp(arg_list[0]));
00155 }
00156 
00157 inline double abs_wrapper(double * arg_list) {
00158   return (fabs(arg_list[0]));
00159 }
00160 
00161 inline double log_wrapper(double *arg_list) {
00162   return (log (arg_list[0]));
00163 }
00164 
00165 inline double log10_wrapper(double * arg_list) {
00166   return (log10 (arg_list[0]));
00167 }
00168 
00169 inline double sqrt_wrapper(double * arg_list) {
00170   return (sqrt (arg_list[0]));
00171 }
00172 
00173 
00174 inline double nchoosek_wrapper(double * arg_list) {
00175       unsigned long cnm = 1UL;
00176       int i, f;
00177       int n, m;
00178 
00179       n = (int)arg_list[0];
00180       m = (int)arg_list[1];
00181 
00182       if (m*2 >n) m = n-m;
00183       for (i=1 ; i <= m; n--, i++)
00184       {
00185             if ((f=n) % i == 0)
00186                   f   /= i;
00187             else  cnm /= i;
00188             cnm *= f;
00189       }
00190       return (double)cnm;
00191 }
00192 
00193 
00194 inline double fact_wrapper(double * arg_list) {
00195 
00196 
00197   int result = 1;
00198   
00199   int n = (int)arg_list[0];
00200   
00201   while (n > 1) {
00202     result = result * n;
00203     n--;
00204   }
00205   return (double)result;
00206 }

Generated on Tue Dec 20 10:14:56 2005 for vlc-0.8.4a by  doxygen 1.4.2