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



描述

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

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

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

宣告

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

public static double IEEEremainder(double f1, double f2)

引數

  • f1 - 被除數。

  • f2 - 除數。

返回值

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

異常

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

以下示例顯示了 StrictMath IEEEremainder() 方法的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   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("StrictMath.IEEEremainder(" + x + "," + y + ")=" + StrictMath.IEEEremainder(x, y));
   }
}

輸出

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

StrictMath.IEEEremainder(60984.1,-497.99)=229.31999999999744

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

以下示例顯示了 StrictMath IEEEremainder() 方法在零值情況下的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   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("StrictMath.IEEEremainder(" + x + "," + y + ")=" + StrictMath.IEEEremainder(x, y));
   }
}

輸出

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

StrictMath.IEEEremainder(0.0,-0.0)=NaN

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

以下示例顯示了 StrictMath IEEEremainder() 方法在 1 值情況下的使用。

package com.tutorialspoint;

public class StrictMathDemo {

   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("StrictMath.IEEEremainder(" + x + "," + y + ")=" + StrictMath.IEEEremainder(x, y));
   }
}

輸出

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

StrictMath.IEEEremainder(1.0,-1.0)=0.0
java_lang_strictmath.htm
廣告