Macros.h

00001 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
00002 /* 
00003  * Copyright (C) 2008 Eric Sauser, EPFL
00004  * RobotCub Consortium, European Commission FP6 Project IST-004370
00005  * email:   micha.hersch@robotcub.org
00006  * website: www.robotcub.org
00007  * Permission is granted to copy, distribute, and/or modify this program
00008  * under the terms of the GNU General Public License, version 2 or any
00009  * later version published by the Free Software Foundation.
00010  *
00011  * A copy of the license can be found at
00012  * http://www.robotcub.org/icub/license/gpl.txt
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00017  * Public License for more details
00018  */
00019 
00020 #ifndef __MATHMACROS_H_
00021 #define __MATHMACROS_H_
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <math.h>
00025 #include <stdlib.h>
00026 
00027 #ifndef PIf
00028 #define PIf 3.14159265358979323846f
00029 #endif
00030 
00031 #ifndef DEG2RAD
00032 #define DEG2RAD(x) ((x)*(PIf/180.0f))
00033 #endif
00034 
00035 #ifndef RAD2DEG
00036 #define RAD2DEG(x) ((x)*(180.0f/PIf))
00037 #endif
00038 
00039 #ifndef RND
00040 #define RND(x) (float((x)*((double)rand())/((double)(RAND_MAX+1.0))))
00041 #endif
00042 
00043 #ifndef MIN
00044 #define MIN(x,y) (((x)<(y))?(x):(y))
00045 #endif
00046 
00047 #ifndef MAX
00048 #define MAX(x,y) (((x)>(y))?(x):(y))
00049 #endif
00050 
00051 #ifndef TRUNC
00052 #define TRUNC(x,mn,mx) (MIN(MAX((x),(mn)),(mx)))
00053 #endif
00054 
00055 #ifndef SIGN2
00056 #define SIGN(x) (((x)<0.0f)?(-1.0f):(1.0f))
00057 #endif
00058 
00059 #ifndef SIGN2
00060 #define SIGN2(a,b) ((b) >= 0.0f ? fabs(a) : -fabs(a))
00061 #endif
00062 
00063 #ifndef ROUND
00064 #define ROUND(x) (floor((x)+0.5f))
00065 #endif
00066 
00067 #ifndef EPSILON
00068 #define EPSILON   (1e-6)
00069 #endif
00070 
00071 
00072 inline float hypot_s(float a, float b){
00073   float r;
00074   if (fabs(a) > fabs(b)) {
00075       r = b / a;
00076       r = fabs(a) * sqrtf(1.0f + r * r);
00077   } else if (b != 0.0f) {
00078       r = a / b;
00079       r = fabs(b) * sqrtf(1.0f + r * r);
00080   } else {
00081       r = 0.0f;
00082   }
00083   return r;
00084 } 
00085 
00086 #endif
 All Data Structures Functions Variables

Generated on Wed Sep 22 16:51:25 2010 for Body_Schema_Learning by  doxygen 1.6.1