Hormiga 1.0

/var/www/hormigaproject.com.ar/files/src/function/corefunctions.h

Go to the documentation of this file.
00001 
00002 /*
00003 # Hormiga - Software de cálculo programable.
00004 #
00005 # Copyright (C) 2008, 2009 Leonardo Román, Hugo J. Curti, Norma  Ercoli,
00006 # Universidad Nacional del Centro de la Provincia de Buenos Aires
00007 # (UNCPBA)
00008 #
00009 # Este programa es parte de Hormiga.
00010 #
00011 # Hormiga es software libre. Puede redistribuirlo y/o modificarlo
00012 # bajo los términos de la Licencia Pública General de GNU según es
00013 # publicada por la Free Software Foundation, versión 2. Vea el archivo
00014 # COPIA (español, no oficial) o COPYING (inglés, oficial) en directorio
00015 # raíz.
00016 #
00017 # Hormiga se distribuye con la esperanza de que sea útil, pero SIN
00018 # NINGUNA GARANTÍA, incluso sin la garantía MERCANTIL implícita o sin
00019 # garantizar la CONVENIENCIA PARA UN PROPÓSITO PARTICULAR. Véase la
00020 # Licencia Pública General de GNU para más detalles.
00021 #
00022 # Debería haber recibido una copia de la Licencia Pública General junto
00023 # con Hormiga. Si no ha sido así, escriba a la Free Software
00024 # Foundation, Inc., en 675 Mass Ave, Cambridge, MA 02139, EEUU.
00025 # Añada también información sobre cómo contactar con usted mediante
00026 # correo electrónico y postal.
00027 #
00028 # This file is part of Hormiga.
00029 #
00030 # Hormiga is free software; you can redistribute it and/or modify
00031 # it under the terms of the GNU General Public License version 2
00032 # as published by the Free Software Foundation; see the file COPYING
00033 # in the top directory for details.
00034 #
00035 # Hormiga is distributed in the hope that it will be useful,
00036 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00037 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00038 # GNU General Public License for more details.
00039 #
00040 # You should have received a copy of the GNU General Public License
00041 # along with Hormiga; if not, write to the Free Software
00042 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
00043 # USA
00044 */
00045 
00046 #ifndef COREFUNCTIONS_H
00047 #define COREFUNCTIONS_H
00048 
00049 #include "function.h"
00050 
00051 #include <math.h>
00052 
00053 class FunctionFloor : public Function
00054 {
00055 public:
00056     T_STRING getName () { return ( "floor" ) ; }
00057     int paramsCount() { return ( 1 ) ; }
00058     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00059     {
00060         return ( floor ( argv->at(0)->getValue() ) ) ;
00061     }
00062 };
00063 
00064 class FunctionCeil : public Function
00065 {
00066 public:
00067     T_STRING getName () { return ( "ceil" ) ; }
00068     int paramsCount() { return ( 1 ) ; }
00069     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00070     {
00071         return ( ceil ( argv->at(0)->getValue() ) ) ;
00072     }
00073 };
00074 
00075 class FunctionPow : public Function
00076 {
00077 public:
00078     T_STRING getName () { return ( "pow" ) ; }
00079     int paramsCount() { return ( 2 ) ; }
00080     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00081     { return ( pow ( argv->at(0)->getValue(), argv->at(1)->getValue() ) ) ; }
00082 };
00083 
00084 class FunctionSqrt : public Function
00085 {
00086 public:
00087     T_STRING getName () { return ( "sqrt" ) ; }
00088     int paramsCount() { return ( 1 ) ; }
00089     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00090     {
00091         return ( sqrt ( argv->at(0)->getValue() ) ) ;
00092     }
00093 };
00094 
00095 class FunctionAbs : public Function
00096 {
00097 public:
00098     T_STRING getName () { return ( "abs" ) ; }
00099     int paramsCount() { return ( 1 ) ; }
00100     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00101     { return ( fabs ( argv->at(0)->getValue() ) ) ; }
00102 };
00103 
00104 class FunctionLn : public Function
00105 {
00106 public:
00107     T_STRING getName () { return ( "ln" ) ; }
00108     int paramsCount() { return ( 1 ) ; }
00109     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00110     {
00111         return ( log ( argv->at(0)->getValue() ) ) ;
00112     }
00113 };
00114 
00115 class FunctionLog : public Function
00116 {
00117 public:
00118     T_STRING getName () { return ( "log" ) ; }
00119     int paramsCount() { return ( 2 ) ; } /* ( base , <cosa> ) */
00120     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00121     {
00122         return ( log ( argv->at(1)->getValue() )
00123                / log ( argv->at(0)->getValue() ) ) ;
00124     }
00125 };
00126 
00127 
00128 /* Funciones Trigonometricas, en RADIANES */
00129 class FunctionSin : public Function
00130 {
00131 public:
00132     T_STRING getName () { return ( "sin" ) ; }
00133     int paramsCount() { return ( 1 ) ; }
00134     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00135     {
00136         return ( sin ( argv->at(0)->getValue() ) ) ;
00137     }
00138 };
00139 
00140 class FunctionCos : public Function
00141 {
00142 public:
00143     T_STRING getName () { return ( "cos" ) ; }
00144     int paramsCount() { return ( 1 ) ; }
00145     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00146     {
00147         return ( cos ( argv->at(0)->getValue() ) ) ;
00148     }
00149 };
00150 
00151 class FunctionTan : public Function
00152 {
00153 public:
00154     T_STRING getName () { return ( "tan" ) ; }
00155     int paramsCount() { return ( 1 ) ; }
00156     T_MAGNITUDE eval ( T_FUNCTION_ARGUMENTS *argv )
00157     {
00158         return ( tan ( argv->at(0)->getValue() ) ) ;
00159     }
00160 };
00161 
00162 #endif // COREFUNCTIONS_H