diff options
author | Chris Robinson <[email protected]> | 2019-09-12 17:45:06 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-09-12 17:45:06 -0700 |
commit | 5f862a5b49412ef2690a271ed240d5a6fc881b37 (patch) | |
tree | 6d71d22a3a31775ab554494cbb47bfff7598b540 /common/alnumeric.h | |
parent | 5ca8796d6ab804841be2724ecb3daa134eb23c39 (diff) |
Clean up sample converter implicit conversions
Diffstat (limited to 'common/alnumeric.h')
-rw-r--r-- | common/alnumeric.h | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/common/alnumeric.h b/common/alnumeric.h index 0a05f4bf..94ea2ee0 100644 --- a/common/alnumeric.h +++ b/common/alnumeric.h @@ -216,6 +216,8 @@ inline int fastf2i(float f) noexcept return static_cast<int>(f); #endif } +inline unsigned int fastf2u(float f) noexcept +{ return static_cast<unsigned int>(fastf2i(f)); } /** Converts float-to-int using standard behavior (truncation). */ inline int float2int(float f) noexcept @@ -254,34 +256,34 @@ inline int float2int(float f) noexcept inline int double2int(double d) noexcept { #if defined(HAVE_SSE_INTRINSICS) - return _mm_cvttsd_si32(_mm_set_sd(d)); + return _mm_cvttsd_si32(_mm_set_sd(d)); #elif ((defined(__GNUC__) || defined(__clang__)) && (defined(__i386__) || defined(__x86_64__)) && \ !defined(__SSE2_MATH__)) || (defined(_MSC_VER) && defined(_M_IX86_FP) && _M_IX86_FP < 2) - int sign, shift; - int64_t mant; - union { - double d; - int64_t i64; - } conv; + int sign, shift; + int64_t mant; + union { + double d; + int64_t i64; + } conv; - conv.d = d; - sign = (conv.i64 >> 63) | 1; - shift = ((conv.i64 >> 52) & 0x7ff) - (1023 + 52); + conv.d = d; + sign = (conv.i64 >> 63) | 1; + shift = ((conv.i64 >> 52) & 0x7ff) - (1023 + 52); - /* Over/underflow */ - if UNLIKELY(shift >= 63 || shift < -52) - return 0; + /* Over/underflow */ + if UNLIKELY(shift >= 63 || shift < -52) + return 0; - mant = (conv.i64 & 0xfffffffffffff_i64) | 0x10000000000000_i64; - if LIKELY(shift < 0) - return (int)(mant >> -shift) * sign; - return (int)(mant << shift) * sign; + mant = (conv.i64 & 0xfffffffffffff_i64) | 0x10000000000000_i64; + if LIKELY(shift < 0) + return (int)(mant >> -shift) * sign; + return (int)(mant << shift) * sign; #else - return static_cast<int>(d); + return static_cast<int>(d); #endif } |