In C#, IEEERemainder(Single) is a MathF class method which is used to return the remainder resulting from the division of a specified number by another specified number.
Syntax: public static float IEEERemainder (float x, float y);
x: It is the dividend of type System.Single.
y: It is the divisor of type System.Single.
Return Type: This method returns a number equal to x – (y Q), where Q is the quotient of x / y rounded to the nearest integer of type System.Single.
- If x / y falls halfway between two integers, the even integer is returned.
- If x – (y Q) is zero, the value Positive Zero is returned if x is positive, or Negative Zero if y is negative.
- If y = 0, NaN is returned.
Difference Between IEEERemainder and Remainder Operator: Both are used to returns the remainder after division but the formulas they use are different. The formula for the IEEERemainder method is:
IEEERemainder = dividend - (divisor * MathF.Round(dividend / divisor))
And the formula for the remainder operator is:
Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * (MathF.Floor(MathF.Abs(dividend) / MathF.Abs(divisor))))) * MathF.Sign(dividend)
IEEERemainder Remainder Operator 0 / 1 = 0 0 -4 / 8 = -4 -4 1 / 0 = NaN NaN -1 / 0 = NaN NaN 175 / 6 = 1 1 784.52 / 124 = 40.52002 40.52002 92.267 / 3.259 = 1.014997 1.014997