Java Math IEEEremainder() Method
Last Updated :
12 May, 2025
The IEEEremainder() method in Java is a part of the java.lang.Math class. This method calculates the remainder operation on two arguments based on the IEEE 754 standard, which is different from the regular modulus "%" operator.
Usage of IEEEremainder() Method
The method calculates the remainder using the below formula:
remainder = dividend - (divisor × n)
The remainder value is mathematically equal to dividend - (divisor × n), where n is the mathematical integer closest to the exact mathematical value of the quotient dividend / divisor, and if two mathematical integers are equally close to dividend / divisor, then n is the integer that is even.
Syntax of IEEEremainder() Method
public static double Math.IEEEremainder(double dividend, double divisor)
- Parameters:
- dividend: The number to be divided.
- divisor: The number by which the dividend is divided.
- Returns: It returns the IEEE 754 remainder. If the result is zero, it has the same sign as the dividend.
For Special Cases:
- If the remainder is zero, its sign is the same as the sign of the first argument.
- If either argument is NaN, or the first argument is infinite, or the second argument is positive zero or negative zero, then the result is NaN.
- If the first argument is finite and the second argument is infinite, then the result is the same as the first argument.
Examples of Java Math IEEEremainder() Method
Example 1: In this example, we will see the working of IEEEremainder() method.
Java
// Java program to demonstrate
// Math.IEEEremainder() with standard input
import java.lang.Math;
public class Geeks {
public static void main(String[] args) {
double dividend = 31.34;
double divisor = 2.2;
System.out.println("Result: "
+ Math.IEEEremainder(dividend, divisor));
}
}
OutputResult: 0.5399999999999974
Example 2: In this example, we will see how IEEEremainder() method handles negative values and zero.
Java
// Java program demonstrating how IEEEremainder
// handles negative values and zero
import java.lang.Math;
public class Geeks {
public static void main(String[] args) {
double x = -21.0;
double y = 7.0;
System.out.println("Result: " + Math.IEEEremainder(x, y));
}
}
Example 3: In this example, we will see how IEEEremainder() method handles edge cases.
Java
// Java program to show results with
// infinity and NaN inputs
import java.lang.Math;
public class Geeks {
public static void main(String[] args) {
double inf = Double.POSITIVE_INFINITY;
double zero = 0.0;
double finite = -2.34;
double large = Double.POSITIVE_INFINITY;
System.out.println("Infinity / 0 = "
+ Math.IEEEremainder(inf, zero));
System.out.println("Finite / Infinity = "
+ Math.IEEEremainder(finite, large));
}
}
OutputInfinity / 0 = NaN
Finite / Infinity = -2.34