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