📜  Java中的 StrictMath IEEEremainder() 方法

📅  最后修改于: 2022-05-13 01:55:49.670000             🧑  作者: Mango

Java中的 StrictMath IEEEremainder() 方法

Java.lang.StrictMath.IEEEremainder() 是 StrictMath 类的内置方法,用于对 IEEE 754 标准规定的给定两个参数执行余数运算。余数值在数学上等于num1 - num2 * rem  , 其中rem是最接近商的精确数学值的数学整数num1 / num2  ,并且当两个数学整数同样接近num1 / num2  , n 为偶数。它产生了两个特殊的结果:

  • 当余数为零时,其符号与第一个参数的符号相同。
  • 当任一参数为 NaN,或num1为无穷大,或num2为正零或负零时,它返回 NaN。
  • num1为有限且num2为无限时,结果与num1相同。

句法:

public static double IEEEremainder(double num1, double num2)

参数:该方法接受两个参数:

  • num1:这是双精度类型,即被除数。
  • num2这是双精度型的 als,它是除数。

返回值:该方法返回 num1 除以 num2 的余数。
例子 :

Input: 
num1 = 100.61d
num2 = 5.32d

Output: -0.47000000000000597

下面的程序说明了Java.lang.StrictMath.IEEEremainder() 方法:
方案一:

java
// Java program to illustrate the
// Java.lang.StrictMath.IEEEremainder()
import java.lang.*;
 
public class Geeks {
 
    public static void main(String[] args)
    {
 
        double num1 = 5651.51d, num2 = 61.79d;
 
        // It  returns the remainder value
        double remain_val = StrictMath.IEEEremainder(num1, num2);
        System.out.println("Remainder value of "+num1+" & "+num2
                                            +" = " + remain_val);
    }
}


java
// Java program to illustrate the
// Java.lang.StrictMath.IEEEremainder()
import java.lang.*;
 
public class Geeks {
 
    public static void main(String[] args)
    {
        /* Here  num1 is finite and num2 is infinite so
     the result is the same as the num1 */
        double num1 = 70.55d, num2 = (1.0) / (0.0);
 
        double remain_val = StrictMath.IEEEremainder(num1, num2);
        System.out.println("Remainder value of "+num1+" & "+num2
                                            +" = " + remain_val);
    }
}


输出:
Remainder value of 5651.51 & 61.79 = 28.620000000000296

方案二:

Java

// Java program to illustrate the
// Java.lang.StrictMath.IEEEremainder()
import java.lang.*;
 
public class Geeks {
 
    public static void main(String[] args)
    {
        /* Here  num1 is finite and num2 is infinite so
     the result is the same as the num1 */
        double num1 = 70.55d, num2 = (1.0) / (0.0);
 
        double remain_val = StrictMath.IEEEremainder(num1, num2);
        System.out.println("Remainder value of "+num1+" & "+num2
                                            +" = " + remain_val);
    }
}
输出:
Remainder value is = 70.55