Java - Math IEEEremainder(double x, double y) 方法



描述

Java Math IEEEremainder(double f1, double f2) 方法根據 IEEE 754 標準返回兩個引數的餘數運算。餘數值在數學上等於 f1 - f2 x n,其中 n 是商 f1/f2 的精確數學值的最近整數,如果兩個數學整數與 f1/f2 的距離相同,則 n 為偶數整數。如果餘數為零,則其符號與第一個引數的符號相同。特殊情況 -

  • 如果任一引數為 NaN,或者第一個引數為無限大,或者第二個引數為正零或負零,則結果為 NaN。

  • 如果第一個引數為有限數,而第二個引數為無限大,則結果與第一個引數相同。

宣告

以下是 java.lang.Math.IEEEremainder() 方法的宣告

public static double IEEEremainder(double f1, double f2)

引數

  • f1 − 被除數。

  • f2 − 除數。

返回值

此方法返回 f1 除以 f2 時的餘數。

異常

根據 IEEE 754 標準獲取兩個數字的餘數示例

以下示例演示了 Math IEEEremainder() 方法的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 60984.1;
      double y = -497.99;
   
      // call IEEEremainder and print the result
      System.out.println("Math.IEEEremainder(" + x + "," + y + ")=" + Math.IEEEremainder(x, y));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果 -

Math.IEEEremainder(60984.1,-497.99)=229.31999999999744

根據 IEEE 754 標準獲取兩個零數字的餘數示例

以下示例演示了 Math IEEEremainder() 方法對零值的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 0.0;
      double y = -0.0;
   
      // call IEEEremainder and print the result
      System.out.println("Math.IEEEremainder(" + x + "," + y + ")=" + Math.IEEEremainder(x, y));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果 -

Math.IEEEremainder(0.0,-0.0)=NaN

根據 IEEE 754 標準獲取兩個一數字的餘數示例

以下示例演示了 Math IEEEremainder() 方法對 1 值的使用。

package com.tutorialspoint;

public class MathDemo {

   public static void main(String[] args) {

      // get two double numbers
      double x = 1.0;
      double y = -1.0;
   
      // call hypot and print the result
      System.out.println("Math.IEEEremainder(" + x + "," + y + ")=" + Math.IEEEremainder(x, y));
   }
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果 -

Math.IEEEremainder(1.0,-1.0)=0.0
java_lang_math.htm
廣告

© . All rights reserved.