Merge changes from the witness.
This commit is contained in:
1222
src/nvmath/Half.cpp
1222
src/nvmath/Half.cpp
File diff suppressed because it is too large
Load Diff
@ -1,30 +1,30 @@
|
||||
#pragma once
|
||||
#ifndef NV_MATH_HALF_H
|
||||
#define NV_MATH_HALF_H
|
||||
|
||||
#include "nvmath.h"
|
||||
|
||||
namespace nv {
|
||||
|
||||
uint32 half_to_float( uint16 h );
|
||||
uint16 half_from_float( uint32 f );
|
||||
|
||||
void half_init_tables();
|
||||
|
||||
uint32 fast_half_to_float(uint16 h);
|
||||
|
||||
inline uint16 to_half(float c) {
|
||||
union { float f; uint32 u; } f;
|
||||
f.f = c;
|
||||
return nv::half_from_float( f.u );
|
||||
}
|
||||
|
||||
inline float to_float(uint16 c) {
|
||||
union { float f; uint32 u; } f;
|
||||
f.u = nv::fast_half_to_float( c );
|
||||
return f.f;
|
||||
}
|
||||
|
||||
} // nv namespace
|
||||
|
||||
#endif // NV_MATH_HALF_H
|
||||
#pragma once
|
||||
#ifndef NV_MATH_HALF_H
|
||||
#define NV_MATH_HALF_H
|
||||
|
||||
#include "nvmath.h"
|
||||
|
||||
namespace nv {
|
||||
|
||||
uint32 half_to_float( uint16 h );
|
||||
uint16 half_from_float( uint32 f );
|
||||
|
||||
void half_init_tables();
|
||||
|
||||
uint32 fast_half_to_float(uint16 h);
|
||||
|
||||
inline uint16 to_half(float c) {
|
||||
union { float f; uint32 u; } f;
|
||||
f.f = c;
|
||||
return nv::half_from_float( f.u );
|
||||
}
|
||||
|
||||
inline float to_float(uint16 c) {
|
||||
union { float f; uint32 u; } f;
|
||||
f.u = nv::fast_half_to_float( c );
|
||||
return f.f;
|
||||
}
|
||||
|
||||
} // nv namespace
|
||||
|
||||
#endif // NV_MATH_HALF_H
|
||||
|
2398
src/nvmath/Matrix.h
2398
src/nvmath/Matrix.h
File diff suppressed because it is too large
Load Diff
@ -381,14 +381,14 @@ namespace nv
|
||||
return Vector2(max(a.x, b.x), max(a.y, b.y));
|
||||
}
|
||||
|
||||
inline bool isValid(Vector2::Arg v)
|
||||
inline bool isFinite(Vector2::Arg v)
|
||||
{
|
||||
return isFinite(v.x) && isFinite(v.y);
|
||||
}
|
||||
|
||||
inline Vector2 validate(Vector2::Arg v, Vector2::Arg fallback = Vector2(0.0f))
|
||||
{
|
||||
if (!isValid(v)) return fallback;
|
||||
if (!isFinite(v)) return fallback;
|
||||
Vector2 vf = v;
|
||||
nv::floatCleanup(vf.component, 2);
|
||||
return vf;
|
||||
@ -567,14 +567,14 @@ namespace nv
|
||||
return Vector3(ceilf(v.x), ceilf(v.y), ceilf(v.z));
|
||||
}
|
||||
|
||||
inline bool isValid(Vector3::Arg v)
|
||||
inline bool isFinite(Vector3::Arg v)
|
||||
{
|
||||
return isFinite(v.x) && isFinite(v.y) && isFinite(v.z);
|
||||
}
|
||||
|
||||
inline Vector3 validate(Vector3::Arg v, Vector3::Arg fallback = Vector3(0.0f))
|
||||
{
|
||||
if (!isValid(v)) return fallback;
|
||||
if (!isFinite(v)) return fallback;
|
||||
Vector3 vf = v;
|
||||
nv::floatCleanup(vf.component, 3);
|
||||
return vf;
|
||||
@ -699,14 +699,14 @@ namespace nv
|
||||
return Vector4(max(a.x, b.x), max(a.y, b.y), max(a.z, b.z), max(a.w, b.w));
|
||||
}
|
||||
|
||||
inline bool isValid(Vector4::Arg v)
|
||||
inline bool isFinite(Vector4::Arg v)
|
||||
{
|
||||
return isFinite(v.x) && isFinite(v.y) && isFinite(v.z) && isFinite(v.w);
|
||||
}
|
||||
|
||||
inline Vector4 validate(Vector4::Arg v, Vector4::Arg fallback = Vector4(0.0f))
|
||||
{
|
||||
if (!isValid(v)) return fallback;
|
||||
if (!isFinite(v)) return fallback;
|
||||
Vector4 vf = v;
|
||||
nv::floatCleanup(vf.component, 4);
|
||||
return vf;
|
||||
|
@ -5,14 +5,13 @@
|
||||
#define NV_MATH_H
|
||||
|
||||
#include "nvcore/nvcore.h"
|
||||
#include "nvcore/Debug.h"
|
||||
#include "nvcore/Utils.h" // clamp
|
||||
#include "nvcore/Debug.h" // nvDebugCheck
|
||||
#include "nvcore/Utils.h" // clamp
|
||||
|
||||
#include <math.h>
|
||||
#include <limits.h> // INT_MAX
|
||||
|
||||
#if NV_OS_WIN32 || NV_OS_XBOX
|
||||
#include <float.h>
|
||||
#include <float.h> // finite, isnan
|
||||
#endif
|
||||
|
||||
// Function linkage
|
||||
@ -105,9 +104,12 @@ namespace nv
|
||||
inline float toRadian(float degree) { return degree * (PI / 180.0f); }
|
||||
inline float toDegree(float radian) { return radian * (180.0f / PI); }
|
||||
|
||||
// Robust floating point comparisons:
|
||||
// http://realtimecollisiondetection.net/blog/?p=89
|
||||
inline bool equal(const float f0, const float f1, const float epsilon = NV_EPSILON)
|
||||
{
|
||||
return fabs(f0-f1) <= epsilon;
|
||||
//return fabs(f0-f1) <= epsilon;
|
||||
return fabs(f0-f1) <= epsilon * max(1.0f, fabs(f0), fabs(f1));
|
||||
}
|
||||
|
||||
inline bool isZero(const float f, const float epsilon = NV_EPSILON)
|
||||
|
Reference in New Issue
Block a user