Java Math IEEEremainder() Method
The IEEEremainder() method of Math class calculates the remainder as prescribed by the IEEE754 standard. This method simply returns the remainder when f1 (dividend) is divided by f2 (divisor).
Syntax:
public static double IEEEremainder (double f1, double f2)
Parameters:
The parameters ‘f1’ and ‘f2’ represent the dividend and the divisor.
Return Value:
The IEEEremainder () method returns the remainder when first argument is divided by second argument.
Special cases of the IEEEremainder() method are as follows:
- It returns the result same as the first argument, if the second argument is infinite.
- It returns NaN , if either argument is NaN or first argument is infinite or second argument is positive or zero.
Example 1:
public class JavaMathIEEEremainderExample1 { public static void main(String[] args) { double a = 40; double b = 12; //returns the remainder when a is divided by b System.out.println("Remainder : "+Math.IEEEremainder(a,b)); } }
Output:
Remainder : 4.0
Example 2:
public class JavaMathIEEEremainderExample2 { public static void main(String[] args) { double a = 40; double b = 2/0.0d; //returns the result same as the first argument, if the second argument is infinite System.out.println("Remainder : "+Math.IEEEremainder(a,b)); } }
Output:
Remainder : 40.0
Example 3:
public class JavaMathIEEEremainderExample3 { public static void main(String[] args) { double a = 0.0d/0.0d; double b = 2/0.0d; //It returns NaN , if either argument is NaN System.out.println("Remainder : "+Math.IEEEremainder(a,b)); } }
Output:
Remainder : NaN
Example 4:
public class JavaMathIEEEremainderExample4 { public static void main(String[] args) { double a = 45; double b = 0.0d; //It returns NaN , if second argument is zero System.out.println("Remainder : "+Math.IEEEremainder(a,b)); } }
Output:
Remainder : NaN