PxMath.h
Go to the documentation of this file.00001 // This code contains NVIDIA Confidential Information and is disclosed to you 00002 // under a form of NVIDIA software license agreement provided separately to you. 00003 // 00004 // Notice 00005 // NVIDIA Corporation and its licensors retain all intellectual property and 00006 // proprietary rights in and to this software and related documentation and 00007 // any modifications thereto. Any use, reproduction, disclosure, or 00008 // distribution of this software and related documentation without an express 00009 // license agreement from NVIDIA Corporation is strictly prohibited. 00010 // 00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES 00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO 00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT, 00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE. 00015 // 00016 // Information and code furnished is believed to be accurate and reliable. 00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such 00018 // information or for any infringement of patents or other rights of third parties that may 00019 // result from its use. No license is granted by implication or otherwise under any patent 00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice. 00021 // This code supersedes and replaces all information previously supplied. 00022 // NVIDIA Corporation products are not authorized for use as critical 00023 // components in life support devices or systems without express written approval of 00024 // NVIDIA Corporation. 00025 // 00026 // Copyright (c) 2008-2012 NVIDIA Corporation. All rights reserved. 00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. 00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. 00029 00030 00031 #ifndef PX_FOUNDATION_PX_MATH_H 00032 #define PX_FOUNDATION_PX_MATH_H 00033 00038 #include <math.h> 00039 #include <float.h> 00040 00041 #include "foundation/PxIntrinsics.h" 00042 #include "foundation/PxAssert.h" 00043 00044 #ifndef PX_DOXYGEN 00045 namespace physx 00046 { 00047 #endif 00048 00049 // constants 00050 static const PxReal PxPi = PxReal(3.141592653589793); 00051 static const PxReal PxHalfPi = PxReal(1.57079632679489661923); 00052 static const PxReal PxTwoPi = PxReal(6.28318530717958647692); 00053 static const PxReal PxInvPi = PxReal(0.31830988618379067154); 00054 00055 00059 template<class T> 00060 PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMax(T a, T b) { return a<b ? b : a; } 00061 00063 template<> 00064 PX_CUDA_CALLABLE PX_FORCE_INLINE float PxMax(float a, float b) { return intrinsics::selectMax(a, b); } 00065 00069 template<class T> 00070 PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b) { return a<b ? a : b; } 00071 00072 template<> 00074 PX_CUDA_CALLABLE PX_FORCE_INLINE float PxMin(float a, float b) { return intrinsics::selectMin(a, b); } 00075 00076 /* 00077 Many of these are just implemented as PX_CUDA_CALLABLE PX_FORCE_INLINE calls to the C lib right now, 00078 but later we could replace some of them with some approximations or more 00079 clever stuff. 00080 */ 00081 00085 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAbs(PxF32 a) { return intrinsics::abs(a); } 00086 00087 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxEquals(PxF32 a, PxF32 b,PxF32 eps) { return (PxAbs(a - b) < eps); } 00088 00092 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAbs(PxF64 a) { return ::fabs(a); } 00093 00097 PX_CUDA_CALLABLE PX_FORCE_INLINE PxI32 PxAbs(PxI32 a) { return ::abs(a); } 00098 00102 template<class T> 00103 PX_CUDA_CALLABLE PX_FORCE_INLINE T PxClamp(T v, T lo, T hi) { PX_ASSERT(lo<=hi); return PxMin(hi, PxMax(lo, v)); } 00104 00106 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxSqrt(PxF32 a) { return intrinsics::sqrt(a); } 00107 00109 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxSqrt(PxF64 a) { return ::sqrt(a); } 00110 00112 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxRecipSqrt(PxF32 a) { return intrinsics::recipSqrt(a); } 00113 00115 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxRecipSqrt(PxF64 a) { return 1/::sqrt(a); } 00116 00118 00120 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxSin(PxF32 a) { return intrinsics::sin(a); } 00121 00123 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxSin(PxF64 a) { return ::sin(a); } 00124 00126 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxCos(PxF32 a) { return intrinsics::cos(a); } 00127 00129 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxCos(PxF64 a) { return ::cos(a); } 00130 00135 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxTan(PxF32 a) { return ::tan(a); } 00136 00141 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxTan(PxF64 a) { return ::tan(a); } 00142 00148 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAsin(PxF32 f) { return ::asin(PxClamp(f,-1.0f,1.0f)); } 00149 00155 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAsin(PxF64 f) { return ::asin(PxClamp(f,-1.0,1.0)); } 00156 00162 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAcos(PxF32 f) { return ::acos(PxClamp(f,-1.0f,1.0f)); } 00163 00169 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAcos(PxF64 f) { return ::acos(PxClamp(f,-1.0,1.0)); } 00170 00176 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAtan(PxF32 a) { return ::atan(a); } 00177 00183 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAtan(PxF64 a) { return ::atan(a); } 00184 00190 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAtan2(PxF32 x, PxF32 y) { return ::atan2(x,y); } 00191 00197 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAtan2(PxF64 x, PxF64 y) { return ::atan2(x,y); } 00198 00200 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(PxF32 f) { return intrinsics::isFinite(f); } 00201 00203 PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(PxF64 f) { return intrinsics::isFinite(f); } 00204 00205 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxFloor(PxF32 a) { return ::floorf(a); } 00206 00207 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxExp(PxF32 a) { return ::expf(a); } 00208 00209 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxCeil(PxF32 a) { return ::ceilf(a); } 00210 00211 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxSign(PxF32 a) { return physx::intrinsics::sign(a); } 00212 00213 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxPow(PxF32 x,PxF32 y) { return ::powf(x,y); }; 00214 00215 PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxLog(PxF32 x) { return ::log(x); }; 00216 00217 #ifndef PX_DOXYGEN 00218 } // namespace physx 00219 #endif 00220 00222 #endif // PX_FOUNDATION_PX_MATH_H
Copyright © 2008-2012 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com