PxMath.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2015, NVIDIA CORPORATION. All rights reserved.
3  *
4  * NVIDIA CORPORATION and its licensors retain all intellectual property
5  * and proprietary rights in and to this software, related documentation
6  * and any modifications thereto. Any use, reproduction, disclosure or
7  * distribution of this software and related documentation without an express
8  * license agreement from NVIDIA CORPORATION is strictly prohibited.
9  */
10 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
11 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
12 
13 
14 #ifndef PX_FOUNDATION_PX_MATH_H
15 #define PX_FOUNDATION_PX_MATH_H
16 
22 
23 #ifdef PX_VC
24 #pragma warning(push)
25 #pragma warning( disable : 4985 ) // 'symbol name': attributes not present on previous declaration
26 #endif
27 #include <math.h>
28 #ifdef PX_VC
29 #pragma warning(pop)
30 #endif
31 
32 #include <float.h>
34 #include "foundation/PxAssert.h"
35 
36 
37 #ifndef PX_DOXYGEN
38 namespace physx
39 {
40 #endif
41 
43  enum PxZERO { PxZero };
44 
47 
48 
49  // constants
50  static const PxReal PxPi = PxReal(3.141592653589793);
51  static const PxReal PxHalfPi = PxReal(1.57079632679489661923);
52  static const PxReal PxTwoPi = PxReal(6.28318530717958647692);
53  static const PxReal PxInvPi = PxReal(0.31830988618379067154);
54  static const PxReal PxInvTwoPi = PxReal(0.15915494309189533577);
55  static const PxReal PxPiDivTwo = PxReal(1.57079632679489661923);
56  static const PxReal PxPiDivFour = PxReal(0.78539816339744830962);
57 
58 
62  template<class T>
63  PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMax(T a, T b) { return a<b ? b : a; }
64 
66  template<>
67  PX_CUDA_CALLABLE PX_FORCE_INLINE float PxMax(float a, float b) { return intrinsics::selectMax(a, b); }
68 
72  template<class T>
73  PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b) { return a<b ? a : b; }
74 
75  template<>
77  PX_CUDA_CALLABLE PX_FORCE_INLINE float PxMin(float a, float b) { return intrinsics::selectMin(a, b); }
78 
79  /*
80  Many of these are just implemented as PX_CUDA_CALLABLE PX_FORCE_INLINE calls to the C lib right now,
81  but later we could replace some of them with some approximations or more
82  clever stuff.
83  */
84 
88  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAbs(PxF32 a) { return intrinsics::abs(a); }
89 
90  PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxEquals(PxF32 a, PxF32 b,PxF32 eps) { return (PxAbs(a - b) < eps); }
91 
96 
101 
105  template<class T>
106  PX_CUDA_CALLABLE PX_FORCE_INLINE T PxClamp(T v, T lo, T hi) { PX_ASSERT(lo<=hi); return PxMin(hi, PxMax(lo, v)); }
107 
109  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxSqrt(PxF32 a) { return intrinsics::sqrt(a); }
110 
113 
115  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxRecipSqrt(PxF32 a) { return intrinsics::recipSqrt(a); }
116 
119 
121 
123  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxSin(PxF32 a) { return intrinsics::sin(a); }
124 
127 
129  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxCos(PxF32 a) { return intrinsics::cos(a); }
130 
133 
139 
145 
151  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAsin(PxF32 f) { return ::asinf(PxClamp(f,-1.0f,1.0f)); }
152 
158  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAsin(PxF64 f) { return ::asin(PxClamp(f,-1.0,1.0)); }
159 
165  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAcos(PxF32 f) { return ::acosf(PxClamp(f,-1.0f,1.0f)); }
166 
172  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAcos(PxF64 f) { return ::acos(PxClamp(f,-1.0,1.0)); }
173 
180 
187 
193  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxAtan2(PxF32 x, PxF32 y) { return ::atan2f(x,y); }
194 
200  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF64 PxAtan2(PxF64 x, PxF64 y) { return ::atan2(x,y); }
201 
203  PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(PxF32 f) { return intrinsics::isFinite(f); }
204 
206  PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(PxF64 f) { return intrinsics::isFinite(f); }
207 
209 
211 
213 
214  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxSign(PxF32 a) { return physx::intrinsics::sign(a); }
215 
216  PX_CUDA_CALLABLE PX_FORCE_INLINE PxF32 PxPow(PxF32 x,PxF32 y) { return ::powf(x,y); }
217 
219 
220 #ifndef PX_DOXYGEN
221 } // namespace physx
222 #endif
223 
225 #endif // PX_FOUNDATION_PX_MATH_H


Copyright © 2008-2015 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com