Add a few utils. Start converting tabs to spaces.
This commit is contained in:
parent
78b55e1e37
commit
e848645e88
@ -7,6 +7,11 @@
|
||||
#include <nvcore/Debug.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <limits.h> // INT_MAX
|
||||
|
||||
#if NV_OS_WIN32
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
// Function linkage
|
||||
#if NVMATH_SHARED
|
||||
@ -92,10 +97,6 @@ inline float asinf_assert(const float f)
|
||||
#define asin asin_assert
|
||||
#define asinf asinf_assert
|
||||
|
||||
#if NV_OS_WIN32
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
namespace nv
|
||||
{
|
||||
inline float toRadian(float degree) { return degree * (PI / 180.0f); }
|
||||
@ -148,6 +149,12 @@ inline uint log2(uint i)
|
||||
return value;
|
||||
}
|
||||
|
||||
inline float log2f(float x)
|
||||
{
|
||||
nvCheck(x >= 0);
|
||||
return logf(x) / logf(2.0f);
|
||||
}
|
||||
|
||||
inline float lerp(float f0, float f1, float t)
|
||||
{
|
||||
const float s = 1.0f - t;
|
||||
@ -159,6 +166,31 @@ inline float square(float f)
|
||||
return f * f;
|
||||
}
|
||||
|
||||
// @@ Float to int conversions to be optimized at some point. See:
|
||||
// http://cbloomrants.blogspot.com/2009/01/01-17-09-float-to-int.html
|
||||
// http://www.stereopsis.com/sree/fpu2006.html
|
||||
// http://assemblyrequired.crashworks.org/2009/01/12/why-you-should-never-cast-floats-to-ints/
|
||||
// http://chrishecker.com/Miscellaneous_Technical_Articles#Floating_Point
|
||||
inline int iround(float f)
|
||||
{
|
||||
return int(f);
|
||||
}
|
||||
|
||||
inline int ifloor(float f)
|
||||
{
|
||||
return int(floorf(f));
|
||||
}
|
||||
|
||||
inline int iceil(float f)
|
||||
{
|
||||
return int(ceilf(f));
|
||||
}
|
||||
|
||||
inline float frac(float f)
|
||||
{
|
||||
return f - floor(f);
|
||||
}
|
||||
|
||||
} // nv
|
||||
|
||||
#endif // NV_MATH_H
|
||||
|
Loading…
Reference in New Issue
Block a user