eg_nummacros.h

Go to the documentation of this file.
00001 /* EGlib "Efficient General Library" provides some basic structures and
00002  * algorithms commons in many optimization algorithms.
00003  *
00004  * Copyright (C) 2005 Daniel Espinoza and Marcos Goycoolea.
00005  * 
00006  * This library is free software; you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by the
00008  * Free Software Foundation; either version 2.1 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful, but 
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
00013  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
00014  * License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this library; if not, write to the Free Software Foundation,
00018  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
00019  * */
00020 #ifndef __EG_NUMMACROS_H__
00021 #define __EG_NUMMACROS_H__
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <string.h>
00025 #include <limits.h>
00026 #include <math.h>
00027 #include <float.h>
00028 #include "eg_macros.h"
00029 
00030 /* ========================================================================= */
00031 /** @defgroup EGlpNumMacros General Number Utilities
00032  * Here we put some utilities common for number.
00033  * 
00034  * @par History:
00035  * Revision 0.0.2
00036  *  - 2007-10-08
00037  *            - Move EGabs, EGswap, EGmin and EGmax to this file
00038  * */
00039 /** @{*/
00040 /** @file
00041  * @brief This file provide the user interface and function definitions 
00042  * for general number utilities.
00043  * */
00044 
00045 /* ========================================================================= */
00046 /** @brief Given tree numbers N1, N2 and Ntmp, swap values of N1 and N2 using
00047  * Ntmp as a temporal number. The variables should be of some primitive type of
00048  * C for this macro to work.
00049  * @param N1 first number.
00050  * @param N2 second number.
00051  * @param Ntmp temporal variable.
00052  * */
00053 #define EGswap(N1,N2,Ntmp) do{\
00054   Ntmp = N1;\
00055   N1 = N2;\
00056   N2 = Ntmp;} while(0)
00057 
00058 /* ========================================================================= */
00059 /** @brief given two variables (of the same type, and of some predefined type)
00060  * return the maximum value among the two of them. */
00061 #define EGmax(a,b) ({\
00062   const typeof(a) __EGma = (a);\
00063   const typeof(b) __EGmb = (b);\
00064   (__EGma > __EGmb ? __EGma : __EGmb);})
00065 
00066 /* ========================================================================= */
00067 /** @brief given two variables (of the same type, and of some predefined type)
00068  * return the minimum value among the two of them. */
00069 #define EGmin(a,b) ({\
00070   const typeof(a) __EGma = (a);\
00071   const typeof(b) __EGmb = (b);\
00072   (__EGma < __EGmb ? __EGma : __EGmb);})
00073 
00074 /* ========================================================================= */
00075 /** @brief a general macro to return the absolute value of the given variable
00076  * @param var variable whose absolute value we want to compute.
00077  * @return value of the absolute value of the given variable, note that this
00078  * macro will only work in built-in types, and will use the default comparison
00079  * for those internal types. */
00080 #define EGabs(var) ({\
00081     const typeof(var) __EGav = (var);\
00082     (__EGav < 0) ? -__EGav : __EGav;})
00083 
00084 /* ========================================================================= */
00085 /** @}*/
00086 #endif

Generated on Wed Nov 21 09:38:13 2007 for MTgomory by  doxygen 1.4.6