Blender V2.61 - r43446

BLI_math_base.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: some of this file.
00022  *
00023  * ***** END GPL LICENSE BLOCK *****
00024  * */
00025 
00026 #ifndef BLI_MATH_BASE_H
00027 #define BLI_MATH_BASE_H
00028 
00033 #ifdef WIN32
00034 #define _USE_MATH_DEFINES
00035 #endif
00036 
00037 #include <math.h>
00038 #include "BLI_math_inline.h"
00039 
00040 #ifdef __sun__
00041 #include <ieeefp.h> /* for finite() */
00042 #endif
00043 
00044 #ifndef M_PI
00045 #define M_PI        3.14159265358979323846
00046 #endif
00047 #ifndef M_PI_2
00048 #define M_PI_2      1.57079632679489661923
00049 #endif
00050 #ifndef M_SQRT2
00051 #define M_SQRT2     1.41421356237309504880
00052 #endif
00053 #ifndef M_SQRT1_2
00054 #define M_SQRT1_2   0.70710678118654752440
00055 #endif
00056 #ifndef M_1_PI
00057 #define M_1_PI      0.318309886183790671538
00058 #endif
00059 #ifndef M_E
00060 #define M_E             2.7182818284590452354
00061 #endif
00062 #ifndef M_LOG2E
00063 #define M_LOG2E         1.4426950408889634074
00064 #endif
00065 #ifndef M_LOG10E
00066 #define M_LOG10E        0.43429448190325182765
00067 #endif
00068 #ifndef M_LN2
00069 #define M_LN2           0.69314718055994530942
00070 #endif
00071 #ifndef M_LN10
00072 #define M_LN10          2.30258509299404568402
00073 #endif
00074 
00075 /* non-standard defines, used in some places */
00076 #ifndef MAXFLOAT
00077 #define MAXFLOAT  ((float)3.40282347e+38)
00078 #endif
00079 
00080 #ifndef sqrtf
00081 #define sqrtf(a) ((float)sqrt(a))
00082 #endif
00083 #ifndef powf
00084 #define powf(a, b) ((float)pow(a, b))
00085 #endif
00086 #ifndef cosf
00087 #define cosf(a) ((float)cos(a))
00088 #endif
00089 #ifndef sinf
00090 #define sinf(a) ((float)sin(a))
00091 #endif
00092 #ifndef acosf
00093 #define acosf(a) ((float)acos(a))
00094 #endif
00095 #ifndef asinf
00096 #define asinf(a) ((float)asin(a))
00097 #endif
00098 #ifndef atan2f
00099 #define atan2f(a, b) ((float)atan2(a, b))
00100 #endif
00101 #ifndef tanf
00102 #define tanf(a) ((float)tan(a))
00103 #endif
00104 #ifndef atanf
00105 #define atanf(a) ((float)atan(a))
00106 #endif
00107 #ifndef floorf
00108 #define floorf(a) ((float)floor(a))
00109 #endif
00110 #ifndef ceilf
00111 #define ceilf(a) ((float)ceil(a))
00112 #endif
00113 #ifndef fabsf
00114 #define fabsf(a) ((float)fabs(a))
00115 #endif
00116 #ifndef logf
00117 #define logf(a) ((float)log(a))
00118 #endif
00119 #ifndef expf
00120 #define expf(a) ((float)exp(a))
00121 #endif
00122 #ifndef fmodf
00123 #define fmodf(a, b) ((float)fmod(a, b))
00124 #endif
00125 #ifndef hypotf
00126 #define hypotf(a, b) ((float)hypot(a, b))
00127 #endif
00128 
00129 #ifdef WIN32
00130 #ifndef FREE_WINDOWS
00131 #define isnan(n) _isnan(n)
00132 #define finite _finite
00133 #define hypot _hypot
00134 #endif
00135 #endif
00136 
00137 #ifndef SWAP
00138 #define SWAP(type, a, b)    { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; }
00139 #endif
00140 
00141 #ifndef CLAMP
00142 #define CLAMP(a, b, c)      if((a)<(b)) (a)=(b); else if((a)>(c)) (a)=(c)
00143 #endif
00144 
00145 #ifdef BLI_MATH_INLINE_H
00146 #include "intern/math_base_inline.c"
00147 #endif
00148 
00149 /******************************* Float ******************************/
00150 
00151 MINLINE float sqrt3f(float f);
00152 MINLINE double sqrt3d(double d);
00153 
00154 MINLINE float saacosf(float f);
00155 MINLINE float saasinf(float f);
00156 MINLINE float sasqrtf(float f);
00157 MINLINE float saacos(float fac);
00158 MINLINE float saasin(float fac);
00159 MINLINE float sasqrt(float fac);
00160 
00161 MINLINE float interpf(float a, float b, float t);
00162 
00163 MINLINE float minf(float a, float b);
00164 MINLINE float maxf(float a, float b);
00165 
00166 MINLINE float signf(float f);
00167 
00168 MINLINE float power_of_2(float f);
00169 
00170 /* these dont really fit anywhere but were being copied about a lot */
00171 MINLINE int is_power_of_2_i(int n);
00172 MINLINE int power_of_2_max_i(int n);
00173 MINLINE int power_of_2_min_i(int n);
00174 
00175 MINLINE float shell_angle_to_dist(float angle);
00176 
00177 #if (defined(WIN32) || defined(WIN64)) && !defined(FREE_WINDOWS)
00178 extern double copysign(double x, double y);
00179 extern double round(double x);
00180 #endif
00181 
00182 double double_round(double x, int ndigits);
00183 
00184 #endif /* BLI_MATH_BASE_H */
00185