mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Correct C FixedMul() off-by-one errors
The FixedMul() C implementation would produce off by one results, causing constant desyncs on 64 bit builds and builds without an ASM implementation of the function. This is fixed by shifting instead of dividing, possibly avoiding rounding errors.
This commit is contained in:
parent
f677746603
commit
2d3ae11d6f
1 changed files with 3 additions and 1 deletions
|
|
@ -33,7 +33,9 @@
|
|||
*/
|
||||
fixed_t FixedMul(fixed_t a, fixed_t b)
|
||||
{
|
||||
return (fixed_t)((((INT64)a * b) ) / FRACUNIT);
|
||||
// Need to cast to unsigned before shifting to avoid undefined behaviour
|
||||
// for negative integers
|
||||
return (fixed_t)(((UINT64)((INT64)a * b)) >> FRACBITS);
|
||||
}
|
||||
|
||||
#endif //__USE_C_FIXEDMUL__
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue