Java - StrictMath ulp(double x) 方法



描述

Java StrictMath ulp(double d) 方法返回参数的 ulp 的大小。双精度值的 ulp 是该浮点值与下一个较大大小的双精度值之间的正距离。请注意,对于非 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 的大小

异常

示例:获取正双精度值的 ulp

以下示例显示了对正双精度值使用 StrictMath ulp() 方法。

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a double number
      double x = 45.0;

      // print the radian for this double
      System.out.println("StrictMath.ulp(" + x + ")=" + StrictMath.ulp(x));
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果 -

StrictMath.ulp(45.0)=7.105427357601002E-15

示例:获取负双精度值的 ulp

以下示例显示了使用 StrictMath ulp() 方法获取负双精度值的 ulp。

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a double number
      double x = -45.0;

      // print the radian for this double
      System.out.println("StrictMath.ulp(" + x + ")=" + StrictMath.ulp(x));
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果 -

StrictMath.ulp(-45.0)=7.105427357601002E-15

示例:获取零双精度值的 ulp

以下示例显示了使用 StrictMath ulp() 方法获取零双精度值的 ulp。

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a double number
      double x = 0.0;

      // print the radian for this double
      System.out.println("StrictMath.ulp(" + x + ")=" + StrictMath.ulp(x));
   }
}

输出

让我们编译并运行上述程序,这将产生以下结果 -

StrictMath.ulp(0.0)=4.9E-324
java_lang_strictmath.htm
广告

© . All rights reserved.