IEEE 754 specifies that x % Infinity should return x, for the % operator it returns NaN, for math.fmod it does it correctly.
IEEE 754 also specified that remainder(x, y) should be the remainder of x / y rounded to the nearest half even; for some reason -1 % 4 returns 4 instead of -1 as round(-1 / 4) is 0 and -1 - 0 is -1. math.fmod does it correctly?
Love2D Lua
Code: Select all
print(-1 % 5) -- 4
print(math.fmod(-1, 5)) -- -1
print(2 % math.huge) -- nan
print(math.fmod(2, math.huge)) -- 2
Code: Select all
Console.WriteLine(Math.IEEERemainder(-1.0, 5.0)) // -1.0
Console.WriteLine(Math.IEEERemainder(2.0, Double.PositiveInfinity)) // 2.0