當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.lang.StrictMath.IEEEremainder()用法及代碼示例


描述

這個java.lang.StrictMath.IEEEremainder() 方法計算兩個參數的餘數運算。

餘數在數學上等於f1 - f2 × 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 時,此方法返回餘數。

異常

NA

示例

下麵的例子展示了 java.lang.StrictMath.IEEEremainder() 方法的用法。

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      double d1 = 102.20d , d2 = 32.29d;
   
      // returns the remainder
      double retval = StrictMath.IEEEremainder(d1, d2);
      System.out.println(" remainder = " + retval);

      /* if the first argument is finite and the second argument is infinite, 
         then the result is the same as the first argument */
      d1 = 30.12d;
      d2 = (1.0)/(0.0);
      retval = StrictMath.IEEEremainder(d1, d2);
      System.out.println(" remainder = " + retval);
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果 -

remainder = 5.330000000000005
remainder = 30.12

相關用法


注:本文由純淨天空篩選整理自 Java.lang.StrictMath.IEEEremainder() Method Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。