Java Math IEEEremainder()

The syntax of the IEEEremainder() method is:

Math.IEEEremainder(double x, double y)

Note: The IEEEremainder() method is a static method. Hence, we can call the method directly using the class name Math.


IEEEremainder() Parameters

  • x - the dividend which is divided by y
  • y - the divisor which divides x

IEEEremainder() Return Values

  • returns the remainder according to IEEE 754 standard

Example 1: Java Math.IEEEremainder()


Difference between Math.IEEEremainder() and % Operator

The remainder returned by both the Math.IEEEremainder() method and % operator is equal to arg1 - arg2 * n. However, the value of n is different.

  • IEEEremainder() - n is closest integer to arg1/arg2. And, if arg1/arg2 returns a value in between two integers, n is even integer (i.e for result 1.5, n = 2).
  • % operator - n is the integer part of arg1/arg2 (for result 1.5, n = 1).

In the above example, we can see that the remainder values returned by IEEEremainder() method and the % operator are different. It is because,

For Math.IEEEremainder()

   arg1/arg2
=> 1.8

   // for IEEEremainder()
   n = 2
   arg - arg2 * n
=> 9.0 - 5.0 * 2.0
=> -1.0

For % operator

   arg1/arg2
=> 1.8

   // for % operator
   n = 1
   arg1 - arg2 * n
=> 9.0 - 5.0 * 1.0
=> 4.0