java.lang.Math.IEEEremainder()方法按照IEEE 754标准的规定计算两个自变量的余数运算。该余数在数学上等于f1-f2 xn,其中n是最接近整数精确数学值的数学整数。商f1 /f2,并且如果两个数学整数均相等地接近f1 /f2,则n是偶数。注意:
如果余数为零,则其符号与第一个参数的符号相同。
如果任一自变量为NaN,或第一个自变量为无限,或第二个自变量为正零或负零,则结果为NaN。
如果第一个参数是有限的而第二个参数是无限的,则结果与第一个参数相同。
用法:
public static double IEEEremainder(double dividend, double divisor)
Parameter:
dividend:the dividend.
divisor:the divisor.
Return:
This method returns the remainder when dividend is divided by divisor.
例子1:显示java.lang.Math.IEEEremainder()方法的用法。
// Java program to demonstrate working
// of java.lang.Math.IEEEremainder() method
import java.lang.Math;
class Gfg {
// driver code
public static void main(String args[])
{
double did1 = 31.34;
double dis1 = 2.2;
System.out.println(Math.IEEEremainder(did1, dis1));
double did2 = -21.0;
double dis2 = 7.0;
// Sign of did2 is negative, Output is negative zero
System.out.println(Math.IEEEremainder(did2, dis2));
double did3 = 1.0 / 0;
double dis3 = 0.0;
// First argument is infinity and Second argument is zero
// Output NaN
System.out.println(Math.IEEEremainder(did3, dis3));
double did4 = -2.34;
double dis4 = 1.0 / 0;
// First argument finite and Second argument is infinity
// Output first argument
System.out.println(Math.IEEEremainder(did4, dis4));
}
}
输出:
0.5399999999999974
-0.0
NaN
-2.34