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


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


描述

這個java.lang.StrictMath.ulp(double d) 方法返回參數的 ulp 的大小。 double 值的 ulp 是此浮點值與大小上次大的 double 值之間的正距離。對於非 NaN x,ulp(-x) == ulp(x).它包括這些情況 -

  • 如果參數為NaN,則結果為NaN。
  • 如果參數為正無窮大或負無窮大,則結果為正無窮大。
  • 如果參數為正零或負零,則結果為 Double.MIN_VALUE。
  • 如果參數為 ±Double.MAX_VALUE,則結果等於 2971

聲明

以下是聲明java.lang.StrictMath.ulp()方法

public static double ulp(double d)

參數

d- 這是要返回其 ulp 的浮點值。

返回值

此方法返回參數的 ulp 的大小。

異常

NA

示例

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

package com.tutorialspoint;

import java.lang.*;

public class StrictMathDemo {

   public static void main(String[] args) {

      double d1 = 5.5 , d2 = -2.9, d3 = 0.0;
     
      // returns the size of an ulp of the argument
      double ulpValue = StrictMath.ulp(d1); 
      System.out.println("Size of ulp of " + d1 + " = " + ulpValue);
    
      ulpValue = StrictMath.ulp(d2); 
      System.out.println("Size of ulp of " + d2 + " = " + ulpValue);
    
      ulpValue = StrictMath.ulp(d3); 
      System.out.println("Size of ulp of " + d3 + " = " + ulpValue);
   }
}

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

Size of ulp of 5.5 = 8.881784197001252E-16
Size of ulp of -2.9 = 4.440892098500626E-16
Size of ulp of 0.0 = 4.9E-324

相關用法


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