COMMON: Fix UB shifting negative integers

Compilers optimise these back into shifts on architectures where
shifts of negative integers work the same as mul/div, so this
solves the UB without actually causing any performance issue.
This commit is contained in:
Colin Snover 2017-11-20 10:22:40 -06:00
parent 9a36870e78
commit 02614f2f1a

View file

@ -46,7 +46,7 @@ typedef int32 frac_t;
inline frac_t doubleToFrac(double value) { return (frac_t)(value * FRAC_ONE); }
inline double fracToDouble(frac_t value) { return ((double)value) / FRAC_ONE; }
inline frac_t intToFrac(int16 value) { return value << FRAC_BITS; }
inline int16 fracToInt(frac_t value) { return value >> FRAC_BITS; }
inline frac_t intToFrac(int16 value) { return value * (1 << FRAC_BITS); }
inline int16 fracToInt(frac_t value) { return value / (1 << FRAC_BITS); }
#endif