mMathFn.h

Engine/source/math/mMathFn.h

More...

Public Variables

F32(*
m_catmullrom )(F32 t, F32 p0, F32 p1, F32 p2, F32 p3)
F32(*
m_matF_determinant )(const F32 *m)
void(*
m_matF_identity )(F32 *m)
void(*
m_matF_inverse )(F32 *m)
void(*
m_matF_invert_to )(const F32 *m, F32 *d)
void(*
m_matF_normalize )(F32 *m)
void(*
m_matF_scale )(F32 *m, const F32 *p)
void(*
m_matF_set_euler )(const F32 *e, F32 *result)
void(*
m_matF_set_euler_point )(const F32 *e, const F32 *p, F32 *result)
void(*
m_matF_transpose )(F32 *m)
void(*
m_matF_x_box3F )(const F32 *m, F32 *min, F32 *max)
void(*
m_matF_x_matF )(const F32 *a, const F32 *b, F32 *mresult)
void(*
m_matF_x_matF_aligned )(const F32 *a, const F32 *b, F32 *mresult)
void(*
m_matF_x_point4F )(const F32 *m, const F32 *p, F32 *presult)
void(*
m_matF_x_scale_x_planeF )(const F32 *m, const F32 *s, const F32 *p, F32 *presult)
S32(*
m_mulDivS32 )(S32 a, S32 b, S32 c)
U32(*
m_mulDivU32 )(S32 a, S32 b, U32 c)
void(*
m_point2D_normalize_f )(F64 *p, F64 len)
void(*
m_point2F_normalize_f )(F32 *p, F32 len)
void(*
m_point3D_interpolate )(const F64 *from, const F64 *to, F64 factor, F64 *result)
void(*
m_point3D_normalize_f )(F64 *p, F64 len)
void(*
m_point3F_bulk_dot )(const F32 *refVector, const F32 *dotPoints, const U32 numPoints, const U32 pointStride, F32 *output)
void(*
m_point3F_bulk_dot_indexed )(const F32 *refVector, const F32 *dotPoints, const U32 numPoints, const U32 pointStride, const U32 *pointIndices, F32 *output)
void(*
m_point3F_interpolate )(const F32 *from, const F32 *to, F32 factor, F32 *result)
void(*
m_point3F_normalize_f )(F32 *p, F32 len)
void(*
m_quatF_set_matF )(F32 x, F32 y, F32 z, F32 w, F32 *m)
void(*
m_sincos )(F32 angle, F32 *s, F32 *c)
void(*
m_sincosD )(F64 angle, F64 *s, F64 *c)
U32(*
mSolveCubic )(F32 a, F32 b, F32 c, F32 d, F32 *x)
U32(*
mSolveQuadratic )(F32 a, F32 b, F32 c, F32 *x)
U32(*
mSolveQuartic )(F32 a, F32 b, F32 c, F32 d, F32 e, F32 *x)

Public Functions

m_matF_x_point3F(const F32 * m, const F32 * p, F32 * presult)
m_matF_x_vectorF(const F32 * m, const F32 * v, F32 * vresult)
A
mAlignToMultiple(A val, B mul)
mCatmullrom(F32 t, F32 p0, F32 p1, F32 p2, F32 p3)
mClamp(S32 val, S32 low, S32 high)
mClampF(F32 val, F32 low, F32 high)
mClampToZero(F32 & input)
mClampU(U32 val, U32 low, U32 high)
mCos(const F32 angle)
mCos(const F64 angle)
mFmod(const F32 val, const F32 mod)
bool
mIsEqual(F32 a, F32 b, const F32 epsilon)
bool
bool
bool
mIsZero(const F32 val, const F32 epsilon)
T
mLerp(const T & v1, const T & v2, F32 factor)

Template function for doing a linear interpolation between any two types which implement operators for scalar multiply and addition.

mMulDiv(S32 a, S32 b, S32 c)
mMulDiv(S32 a, S32 b, U32 c)
mRandF(F32 f1, F32 f2)
mRandI(S32 i1, S32 i2)
mSin(const F32 angle)
mSin(const F64 angle)
mSinCos(const F32 angle, F32 & s, F32 & c)
mSinCos(const F64 angle, F64 & s, F64 & c)

Returns the input value squared.

mTan(const F32 angle)
mTan(const F64 angle)
mTanh(const F32 angle)
mTanh(const F64 angle)
mWrap(S32 val, S32 low, S32 high)
mWrapF(F32 val, F32 low, F32 high)

Detailed Description

Public Variables

F32(* m_catmullrom )(F32 t, F32 p0, F32 p1, F32 p2, F32 p3)
void(* m_matF_affineInverse )(F32 *m)
F32(* m_matF_determinant )(const F32 *m)
void(* m_matF_identity )(F32 *m)
void(* m_matF_inverse )(F32 *m)
void(* m_matF_invert_to )(const F32 *m, F32 *d)
void(* m_matF_normalize )(F32 *m)
void(* m_matF_scale )(F32 *m, const F32 *p)
void(* m_matF_set_euler )(const F32 *e, F32 *result)
void(* m_matF_set_euler_point )(const F32 *e, const F32 *p, F32 *result)
void(* m_matF_transpose )(F32 *m)
void(* m_matF_x_box3F )(const F32 *m, F32 *min, F32 *max)
void(* m_matF_x_matF )(const F32 *a, const F32 *b, F32 *mresult)
void(* m_matF_x_matF_aligned )(const F32 *a, const F32 *b, F32 *mresult)
void(* m_matF_x_point4F )(const F32 *m, const F32 *p, F32 *presult)
void(* m_matF_x_scale_x_planeF )(const F32 *m, const F32 *s, const F32 *p, F32 *presult)
S32(* m_mulDivS32 )(S32 a, S32 b, S32 c)
U32(* m_mulDivU32 )(S32 a, S32 b, U32 c)
void(* m_point2D_normalize )(F64 *p)
void(* m_point2D_normalize_f )(F64 *p, F64 len)
void(* m_point2F_normalize )(F32 *p)
void(* m_point2F_normalize_f )(F32 *p, F32 len)
void(* m_point3D_interpolate )(const F64 *from, const F64 *to, F64 factor, F64 *result)
void(* m_point3D_normalize )(F64 *p)
void(* m_point3D_normalize_f )(F64 *p, F64 len)
void(* m_point3F_bulk_dot )(const F32 *refVector, const F32 *dotPoints, const U32 numPoints, const U32 pointStride, F32 *output)
void(* m_point3F_bulk_dot_indexed )(const F32 *refVector, const F32 *dotPoints, const U32 numPoints, const U32 pointStride, const U32 *pointIndices, F32 *output)
void(* m_point3F_interpolate )(const F32 *from, const F32 *to, F32 factor, F32 *result)
void(* m_point3F_normalize )(F32 *p)
void(* m_point3F_normalize_f )(F32 *p, F32 len)
void(* m_quatF_set_matF )(F32 x, F32 y, F32 z, F32 w, F32 *m)
void(* m_sincos )(F32 angle, F32 *s, F32 *c)
void(* m_sincosD )(F64 angle, F64 *s, F64 *c)
U32(* mSolveCubic )(F32 a, F32 b, F32 c, F32 d, F32 *x)
U32(* mSolveQuadratic )(F32 a, F32 b, F32 c, F32 *x)
U32(* mSolveQuartic )(F32 a, F32 b, F32 c, F32 d, F32 e, F32 *x)

Public Functions

m_matF_x_point3F(const F32 * m, const F32 * p, F32 * presult)

m_matF_x_vectorF(const F32 * m, const F32 * v, F32 * vresult)

mAbs(const S32 val)

mAcos(const F32 val)

mAcos(const F64 val)

mAlignToMultiple(A val, B mul)

mAsin(const F32 val)

mAsin(const F64 val)

mAtan(const F32 x)

mAtan(const F64 x)

mAtan2(const F32 y, const F32 x)

mAtan2(const F64 x, const F64 y)

MathConsoleInit()

mCatmullrom(F32 t, F32 p0, F32 p1, F32 p2, F32 p3)

mCeil(const F32 val)

mCeilD(const F64 val)

mClamp(S32 val, S32 low, S32 high)

mClampF(F32 val, F32 low, F32 high)

mClampToZero(F32 & input)

mClampU(U32 val, U32 low, U32 high)

mCos(const F32 angle)

mCos(const F64 angle)

mDegToRad(F32 d)

mDegToRad(F64 d)

mExp(const F32 val)

mFabs(const F32 val)

mFabs(const F64 val)

mFabsD(const F64 val)

mFloor(const F32 val)

mFloorD(const F64 val)

mFmod(const F32 val, const F32 mod)

mFmodD(const F64 val, const F64 mod)

mIsEqual(F32 a, F32 b, const F32 epsilon)

mIsInf_F(const F32 x)

mIsNaN_F(const F32 x)

mIsZero(const F32 val, const F32 epsilon)

mLerp(const T & v1, const T & v2, F32 factor)

Template function for doing a linear interpolation between any two types which implement operators for scalar multiply and addition.

mLog(const F32 val)

mLog(const F64 val)

mLog2(const F32 val)

mLog2(const F64 val)

mMax(const F32 x, const F32 y)

mMin(const F32 x, const F32 y)

mMulDiv(S32 a, S32 b, S32 c)

mMulDiv(S32 a, S32 b, U32 c)

mPow(const F32 x, const F32 y)

mPow(const F64 x, const F64 y)

mRadToDeg(F32 r)

mRadToDeg(F64 r)

mRandF()

mRandF(F32 f1, F32 f2)

mRandI(S32 i1, S32 i2)

mRound(const F32 val)

mRound(const F32 val, const S32 n)

mRoundToNearest(const F32 val)

mSign(const F32 n)

mSin(const F32 angle)

mSin(const F64 angle)

mSinCos(const F32 angle, F32 & s, F32 & c)

mSinCos(const F64 angle, F64 & s, F64 & c)

mSqrt(const F32 val)

mSqrt(const F64 val)

mSqrtD(const F64 val)

mSquared(F32 n)

Returns the input value squared.

mSquared(F64 n)

mTan(const F32 angle)

mTan(const F64 angle)

mTanh(const F32 angle)

mTanh(const F64 angle)

mWrap(S32 val, S32 low, S32 high)

mWrapF(F32 val, F32 low, F32 high)

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _MMATHFN_H_
 25#define _MMATHFN_H_
 26
 27#include <math.h>
 28#include <stdlib.h>
 29#include <limits>
 30
 31#ifndef _MCONSTANTS_H_
 32#include "math/mConstants.h"
 33#endif
 34#ifndef _PLATFORMASSERT_H_
 35#include "platform/platformAssert.h"
 36#endif
 37
 38
 39extern void MathConsoleInit();
 40
 41//--------------------------------------
 42// Installable Library Prototypes
 43extern S32  (*m_mulDivS32)(S32 a, S32 b, S32 c);
 44extern U32  (*m_mulDivU32)(S32 a, S32 b, U32 c);
 45
 46extern F32  (*m_catmullrom)(F32 t, F32 p0, F32 p1, F32 p2, F32 p3);
 47
 48extern void (*m_sincos)( F32 angle, F32 *s, F32 *c );
 49extern void (*m_sincosD)( F64 angle, F64 *s, F64 *c );
 50
 51extern void (*m_point2F_normalize)(F32 *p);
 52extern void (*m_point2F_normalize_f)(F32 *p, F32 len);
 53extern void (*m_point2D_normalize)(F64 *p);
 54extern void (*m_point2D_normalize_f)(F64 *p, F64 len);
 55extern void (*m_point3F_normalize)(F32 *p);
 56extern void (*m_point3F_normalize_f)(F32 *p, F32 len);
 57extern void (*m_point3F_interpolate)(const F32 *from, const F32 *to, F32 factor, F32 *result);
 58
 59extern void (*m_point3D_normalize)(F64 *p);
 60extern void (*m_point3D_normalize_f)(F64 *p, F64 len);
 61extern void (*m_point3D_interpolate)(const F64 *from, const F64 *to, F64 factor, F64 *result);
 62
 63extern void (*m_point3F_bulk_dot)(const F32* refVector,
 64                                  const F32* dotPoints,
 65                                  const U32  numPoints,
 66                                  const U32  pointStride,
 67                                  F32*       output);
 68extern void (*m_point3F_bulk_dot_indexed)(const F32* refVector,
 69                                          const F32* dotPoints,
 70                                          const U32  numPoints,
 71                                          const U32  pointStride,
 72                                          const U32* pointIndices,
 73                                          F32*       output);
 74
 75extern void (*m_quatF_set_matF)( F32 x, F32 y, F32 z, F32 w, F32* m );
 76
 77extern void (*m_matF_set_euler)(const F32 *e, F32 *result);
 78extern void (*m_matF_set_euler_point)(const F32 *e, const F32 *p, F32 *result);
 79extern void (*m_matF_identity)(F32 *m);
 80extern void (*m_matF_inverse)(F32 *m);
 81extern void (*m_matF_invert_to)(const F32 *m, F32 *d);
 82extern void (*m_matF_affineInverse)(F32 *m);
 83extern void (*m_matF_transpose)(F32 *m);
 84extern void (*m_matF_scale)(F32 *m,const F32* p);
 85extern void (*m_matF_normalize)(F32 *m);
 86extern F32  (*m_matF_determinant)(const F32 *m);
 87extern void (*m_matF_x_matF)(const F32 *a, const F32 *b, F32 *mresult);
 88extern void (*m_matF_x_matF_aligned)(const F32 *a, const F32 *b, F32 *mresult);
 89// extern void (*m_matF_x_point3F)(const F32 *m, const F32 *p, F32 *presult);
 90// extern void (*m_matF_x_vectorF)(const F32 *m, const F32 *v, F32 *vresult);
 91extern void (*m_matF_x_point4F)(const F32 *m, const F32 *p, F32 *presult);
 92extern void (*m_matF_x_scale_x_planeF)(const F32 *m, const F32* s, const F32 *p, F32 *presult);
 93extern void (*m_matF_x_box3F)(const F32 *m, F32 *min, F32 *max);
 94
 95// Note that x must point to at least 4 values for quartics, and 3 for cubics
 96extern U32 (*mSolveQuadratic)(F32 a, F32 b, F32 c, F32* x);
 97extern U32 (*mSolveCubic)(F32 a, F32 b, F32 c, F32 d, F32* x);
 98extern U32 (*mSolveQuartic)(F32 a, F32 b, F32 c, F32 d, F32 e, F32* x);
 99
100extern S32 mRandI(S32 i1, S32 i2); // random # from i1 to i2 inclusive
101extern F32 mRandF(F32 f1, F32 f2); // random # from f1 to f2 inclusive
102extern F32 mRandF();               // random # from 0.0 to 1.0 inclusive
103
104
105inline void m_matF_x_point3F(const F32 *m, const F32 *p, F32 *presult)
106{
107   AssertFatal(p != presult, "Error, aliasing matrix mul pointers not allowed here!");
108   
109#ifdef TORQUE_COMPILER_GCC
110   const F32   p0 = p[0], p1 = p[1], p2 = p[2];
111   const F32   m0 = m[0], m1 = m[1], m2 = m[2];
112   const F32   m3 = m[3], m4 = m[4], m5 = m[5];
113   const F32   m6 = m[6], m7 = m[7], m8 = m[8];
114   const F32   m9 = m[9], m10 = m[10], m11 = m[11];
115   
116   presult[0] = m0*p0 + m1*p1 + m2*p2  + m3;
117   presult[1] = m4*p0 + m5*p1 + m6*p2  + m7;
118   presult[2] = m8*p0 + m9*p1 + m10*p2 + m11;
119#else
120   presult[0] = m[0]*p[0] + m[1]*p[1] + m[2]*p[2]  + m[3];
121   presult[1] = m[4]*p[0] + m[5]*p[1] + m[6]*p[2]  + m[7];
122   presult[2] = m[8]*p[0] + m[9]*p[1] + m[10]*p[2] + m[11];
123#endif
124}
125
126
127//--------------------------------------
128inline void m_matF_x_vectorF(const F32 *m, const F32 *v, F32 *vresult)
129{
130   AssertFatal(v != vresult, "Error, aliasing matrix mul pointers not allowed here!");
131
132#ifdef TORQUE_COMPILER_GCC
133   const F32   v0 = v[0], v1 = v[1], v2 = v[2];
134   const F32   m0 = m[0], m1 = m[1], m2 = m[2];
135   const F32   m4 = m[4], m5 = m[5], m6 = m[6];
136   const F32   m8 = m[8], m9 = m[9], m10 = m[10];
137   
138   vresult[0] = m0*v0 + m1*v1 + m2*v2;
139   vresult[1] = m4*v0 + m5*v1 + m6*v2;
140   vresult[2] = m8*v0 + m9*v1 + m10*v2;
141#else
142   vresult[0] = m[0]*v[0] + m[1]*v[1] + m[2]*v[2];
143   vresult[1] = m[4]*v[0] + m[5]*v[1] + m[6]*v[2];
144   vresult[2] = m[8]*v[0] + m[9]*v[1] + m[10]*v[2];
145#endif
146}
147
148
149//--------------------------------------
150// Inlines
151
152inline bool mIsEqual( F32 a, F32 b, const F32 epsilon = __EQUAL_CONST_F )
153{
154   F32 diff = a - b;
155   return diff > -epsilon && diff < epsilon; 
156}
157
158inline bool mIsZero(const F32 val, const F32 epsilon = __EQUAL_CONST_F )
159{
160   return (val > -epsilon) && (val < epsilon);
161}
162
163inline F32 mClampToZero(F32& input)
164{
165   if (input < __EQUAL_CONST_F && input > -__EQUAL_CONST_F)
166      input = 0.0f;
167
168   return input;
169}
170
171
172inline F32 mMax(const F32 x, const F32 y)
173{
174   if (x > y)
175      return x;
176   return y;
177}
178
179inline F32 mMin(const F32 x, const F32 y)
180{
181   if (x < y)
182      return x;
183   return y;
184}
185
186inline F32 mFloor(const F32 val)
187{
188   return (F32) floor(val);
189}
190
191inline F32 mCeil(const F32 val)
192{
193   return (F32) ceil(val);
194}
195
196inline F32 mFabs(const F32 val)
197{
198   return (F32) fabs(val);
199}
200
201inline F64 mFabs(const F64 val)
202{
203   return fabs(val);
204}
205
206inline F32 mFmod(const F32 val, const F32 mod)
207{
208   return fmod(val, mod);
209}
210
211inline S32 mRound(const F32 val)  
212{  
213   return (S32)floor(val + 0.5f);  
214}  
215      
216inline F32 mRound(const F32 val, const S32 n)  
217{  
218   S32 place = (S32) pow(10.0f, n);  
219      
220   return mFloor((val*place)+0.5)/place;  
221}  
222
223inline S32 mAbs(const S32 val)
224{
225   return abs(val);
226}
227
228inline F32 mRoundToNearest( const F32 val )
229{
230   return mFloor( val + .5f );
231}
232
233inline S32 mClamp(S32 val, S32 low, S32 high)
234{
235   return getMax(getMin(val, high), low);
236}
237
238inline U32 mClampU(U32 val, U32 low, U32 high)
239{
240   return getMax(getMin(val, high), low);
241}
242
243inline F32 mClampF(F32 val, F32 low, F32 high)
244{
245   return (F32) getMax(getMin(val, high), low);
246}
247
248inline S32 mWrap(S32 val, S32 low, S32 high)
249{
250   int len = high - low;
251   return low + (val >= 0 ? val % len : -val % len ? len - (-val % len) : 0);
252
253}
254
255inline F32 mWrapF(F32 val, F32 low, F32 high)
256{
257   F32 t = fmod(val - low, high - low);
258   return t < 0 ? t + high : t + low;
259}
260
261/// Template function for doing a linear interpolation between any two
262/// types which implement operators for scalar multiply and addition.
263template <typename T>
264inline T mLerp( const T &v1, const T &v2, F32 factor )
265{
266   return ( v1 * ( 1.0f - factor ) ) + ( v2 * factor );
267}
268
269inline S32 mMulDiv(S32 a, S32 b, S32 c)
270{
271   return m_mulDivS32(a, b, c);
272}
273
274inline U32 mMulDiv(S32 a, S32 b, U32 c)
275{
276   return m_mulDivU32(a, b, c);
277}
278
279inline F32 mSin(const F32 angle)
280{
281   return (F32) sin(angle);
282}
283
284inline F32 mCos(const F32 angle)
285{
286   return (F32) cos(angle);
287}
288
289inline F32 mTan(const F32 angle)
290{
291   return (F32) tan(angle);
292}
293
294inline F32 mAsin(const F32 val)
295{
296   return (F32) asin(val);
297}
298
299inline F32 mAcos(const F32 val)
300{
301   return (F32) acos(val);
302}
303
304inline F32 mAtan( const F32 x )
305{
306   return (F32) atan( x );
307}
308
309inline F32 mAtan2(const F32 y, const F32 x)
310{
311   return (F32)atan2(y, x);
312}
313
314inline void mSinCos(const F32 angle, F32 &s, F32 &c)
315{
316   m_sincos( angle, &s, &c );
317}
318
319inline F32 mTanh(const F32 angle)
320{
321   return (F32) tanh(angle);
322}
323
324inline F32 mSqrt(const F32 val)
325{
326   return (F32) sqrt(val);
327}
328
329inline F64 mSqrt(const F64 val)
330{
331   return (F64) sqrt(val);
332}
333
334inline F32 mPow(const F32 x, const F32 y)
335{
336   return (F32) pow(x, y);
337}
338
339inline F32 mLog(const F32 val)
340{
341   return (F32) log(val);
342}
343
344inline F32 mLog2(const F32 val)
345{
346   return (F32) log2(val);
347}
348
349inline F32 mExp(const F32 val)
350{
351   return (F32) exp(val);
352}
353
354inline F64 mSin(const F64 angle)
355{
356   return (F64) sin(angle);
357}
358
359inline F64 mCos(const F64 angle)
360{
361   return (F64) cos(angle);
362}
363
364inline F64 mTan(const F64 angle)
365{
366   return (F64) tan(angle);
367}
368
369inline F64 mAsin(const F64 val)
370{
371   return (F64) asin(val);
372}
373
374inline F64 mAcos(const F64 val)
375{
376   return (F64) acos(val);
377}
378
379inline F64 mAtan( const F64 x )
380{
381   return (F64) atan( x );
382}
383
384inline F64 mAtan2(const F64 x, const F64 y)
385{
386   return (F64) atan2(x, y);
387}
388
389inline void mSinCos(const F64 angle, F64 &s, F64 &c)
390{
391   m_sincosD( angle, &s, &c );
392}
393
394inline F64 mTanh(const F64 angle)
395{
396   return (F64) tanh(angle);
397}
398
399inline F64 mPow(const F64 x, const F64 y)
400{
401   return (F64) pow(x, y);
402}
403
404inline F64 mLog(const F64 val)
405{
406   return (F64) log(val);
407}
408
409inline F64 mLog2(const F64 val)
410{
411   return (F64) log2(val);
412}
413
414inline F32 mCatmullrom(F32 t, F32 p0, F32 p1, F32 p2, F32 p3)
415{
416   return m_catmullrom(t, p0, p1, p2, p3);
417}
418
419
420inline F64 mFabsD(const F64 val)
421{
422   return (F64) fabs(val);
423}
424
425inline F64 mFmodD(const F64 val, const F64 mod)
426{
427   return (F64) fmod(val, mod);
428}
429
430inline F64 mSqrtD(const F64 val)
431{
432   return (F64) sqrt(val);
433}
434
435inline F64 mFloorD(const F64 val)
436{
437   return (F64) floor(val);
438}
439
440inline F64 mCeilD(const F64 val)
441{
442   return (F64) ceil(val);
443}
444
445///
446template< typename A, typename B >
447inline A mAlignToMultiple( A val, B mul )
448{
449   A rem = val % mul;
450   return ( rem ? val + mul - rem : val );
451}
452
453//--------------------------------------
454inline F32 mDegToRad(F32 d)
455{
456   return((d * M_PI_F) / 180.0f);
457}
458
459inline F32 mRadToDeg(F32 r)
460{
461   return((r * 180.0f) / M_PI_F);
462}
463
464inline F64 mDegToRad(F64 d)
465{
466   return (d * M_PI) / 180.0;
467}
468
469inline F64 mRadToDeg(F64 r)
470{
471   return (r * 180.0) / M_PI;
472}
473
474//------------------------------------------------------------------------------
475
476inline bool mIsNaN_F( const F32 x )
477{
478   // If x is a floating point variable, then (x != x) will be TRUE if x has the value NaN. 
479   // This is only going to work if the compiler is IEEE 748 compliant.
480   //
481   // Tested and working on VC2k5
482   return ( x != x );
483}
484
485inline bool mIsInf_F( const F32 x )
486{
487   return ( x == std::numeric_limits< F32 >::infinity() );
488}
489
490inline F32 mSign( const F32 n )
491{
492   if ( n > 0.0f )
493      return 1.0f;
494   if ( n < 0.0f )
495      return -1.0f;
496
497   return 0.0f;
498}
499
500/// Returns the input value squared.
501inline F32 mSquared( F32 n )
502{
503   return n * n;
504}
505
506/// @copydoc mSquaredF
507inline F64 mSquared( F64 n )
508{
509   return n * n;
510}
511
512
513#endif //_MMATHFN_H_
514