What is Math.IEEEremainder() in Java?
IEEEremainder() is a static method that returns the answer by performing the remainder operation on two parameters as approved by the IEEE-754 Standard.
In math, the value of the remainder can be calculated by subtracting the divisor (num2) from dividend (num1) and then multiplying the answer by n. This is represented as (num1-num2) * n where n is an integer that is nearest to the exact value of quotient num1/num2.
If two numbers are equal to the exact value then we will consider the even one as the value of n. Its sign will be the same as the sign of the first parameter if the remainder will be zero.
Syntax
static double IEEEremainder(double num1, double num2)
Parameters
Both parameter values are of primitive datatype double.
num1: dividendnum2: divisor
Return value
This method will return the quotient of dividend and divisor, hence it returns the answer of f1/f2.
- If any parameter is
NaNor the first one is infinite or the first one isnegativeorpositivezero, then the result or output will beNaN. - If the parameter is finite and the other one is infinite, then the result will be the same as the first parameter.
Example
In the code below, we take two double-type variables named num1 and num2 (dividend and divisor). Both values contain the positive values so we can get the output regarding the remainder of num1/num2 using the Math.IEEEremainder(num1,num2) method.
Then we have the variable dvd2 with a negative value and num2 with a positive one. The output will be negative.
num3 is infinite (means value/0) and num3 is zero. The result will be NaN. We have two more variables named num4 and num5. num4 has finite value and num5 has infinite value so the output will be the first value or value of num4. The code uses four print statements to generate four different outputs.
// import Math library (Optional Step)import java.lang.Math;class EdPresso {public static void main(String args[]){// both are positive decimal numbersdouble num1 = 23.20;double num2 = 1.4;System.out.println(Math.IEEEremainder(num1,num2));// dvd2 is negative so result will be negativenum1 = -21.0;num2 = 8.0;System.out.println(Math.IEEEremainder(num1,num2));// first parameter is infinite and other is zero, so result is NaNnum1 = 2.0 / 0;num2 = 0.0;System.out.println(Math.IEEEremainder(num1,num2));//First parameter is finite and second one is infinite, output is first parameter.num1 = -3.56;num2 = 2.0 / 0;System.out.println(Math.IEEEremainder(num1,num2));}}