From 056d59e862a11c9f841a08fbbdfd1a805b098f29 Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 11 Apr 2020 22:43:32 -0700 Subject: MathLib: improved FastFloat implementation --- Common/interface/BasicMath.hpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/BasicMath.hpp b/Common/interface/BasicMath.hpp index 757244e1..25e99240 100644 --- a/Common/interface/BasicMath.hpp +++ b/Common/interface/BasicMath.hpp @@ -1942,13 +1942,32 @@ inline Uint32 F4Color_To_RGBA8Unorm(const float4& f4Color) return RGBA8U; } +template +struct _FastFloatIntermediateType +{ +}; + +template <> +struct _FastFloatIntermediateType +{ + // All floats that have fractional part are representable as 32-bit int + using Type = Int32; +}; + +template <> +struct _FastFloatIntermediateType +{ + // All doubles that have fractional part are representable as 64-bit int + using Type = Int64; +}; // At least on MSVC std::floor is an actual function call into ucrtbase.dll. -// For floats/doubles that fit into Int64 representable range we can do much better. +// All floats/doubles that have fractional parts also fit into integer +// representable range, so we can do much better. template T FastFloor(T x) { - auto i = static_cast(x); + auto i = static_cast::Type>(x); auto flr = static_cast(i); // x flr floor(x) flr <= x // +1.0 -> 1.0 1.0 true -- cgit v1.2.3