当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java StrictMath nextDown()用法及代码示例


nextDown(double num)

nextDown(double num)是Java中StrictMath类的内置方法,用于获取在负无穷大方向上与num相邻的浮点值。当参数为NaN时,结果为NaN。当num为负无穷大时,它将返回负无穷大。当参数为零时,结果为Double.MIN_VALUE。 nextDown()方法等效于nextAfter(num,Double.NEGATIVE_INFINITY),但nextDown()的运行速度比其等效的nextAfter调用快。

用法:

public static double nextDown(double num)

参数:该方法接受一个双精度类型的参数num,它是起始浮点值。


返回值:该方法返回更接近负无穷大的相邻浮点值。

例子:

Input: num = 7.16
Output: 7.159999999999999

以下示例程序旨在说明nextDown()方法:

示例1:

// Java praogram to illustrate the 
// Java.lang.StrictMath.nextDown() Method 
  
import java.lang.*; 
  
public class Geeks { 
    public static void main(String[] args) 
    { 
  
        // Get a double number 
        double num1 = 62.9; 
  
        // Get the floating-point value adjacent to num 
        double nextDown_Value = StrictMath.nextDown(num1); 
  
        // Print the result 
        System.out.println("The Next down value of "
                           + num1 + " = " + nextDown_Value); 
  
        // Get a double number 
        double num2 = 16.6226; 
  
        // Get the floating-point value adjacent to num 
        nextDown_Value = StrictMath.nextDown(num2); 
  
        // Print the result 
        System.out.println("The Next down value of "
                           + num2 + " = " + nextDown_Value); 
  
        // Get a double number 
        double num3 = 0.0; 
  
        // Get the floating-point value adjacent to num 
        nextDown_Value = StrictMath.nextDown(num3); 
  
        // Print the result 
        System.out.println("The Next down value of "
                           + num3 + " = " + nextDown_Value); 
    } 
}
输出:
The Next down value of 62.9 = 62.89999999999999
The Next down value of 16.6226 = 16.622599999999995
The Next down value of 0.0 = -4.9E-324

nextDown(float num)

nextDown(float num)是Java中StrictMath类的内置方法,用于获取在负无穷大方向上与num相邻的浮点值。当参数为NaN时,结果为NaN。当num为负无穷大时,它将返回负无穷大。当参数为零时,结果为Float.MIN_VALUE。 nextDown()方法与nextAfter(num,Float.NEGATIVE_INFINITY)等效,但nextDown()的运行速度比其等效的nextAfter调用快。

用法:

public static float nextDown(float num)

参数:该方法接受一个浮点类型的参数num,它是起始浮点值。

返回值:该方法返回更接近负无穷大的相邻浮点值。

例子:

Input: num = 1.2f
Output: 1.1999999

以下示例程序旨在说明Java.lang.StrictMath.nextDown()方法:

示例1:

// Java praogram to illustrate the 
// Java.lang.StrictMath.nextDown() Method 
  
import java.lang.*; 
  
public class Geeks { 
    public static void main(String[] args) 
    { 
  
        // Get a float number 
        float num1 = 16.622f; 
  
        // Get the floating-point value adjacent to num 
        float nextDown_Value = StrictMath.nextDown(num1); 
  
        // Print the result 
        System.out.println("The Next down value of "
                           + num1 + " = " + nextDown_Value); 
  
        // Get a float number 
        float num2 = 91.11f; 
  
        // Get the floating-point value adjacent to num 
        nextDown_Value = StrictMath.nextDown(num2); 
  
        // Print the result 
        System.out.println("The Next down value of "
                           + num2 + " = " + nextDown_Value); 
  
        // Get a float number 
        float num3 = 0.0f; 
  
        // Get the floating-point value adjacent to num 
        nextDown_Value = StrictMath.nextDown(num3); 
  
        // Print the result 
        System.out.println("The Next down value of "
                           + num3 + " = " + nextDown_Value); 
    } 
}
输出:
The Next down value of 16.622 = 16.621998
The Next down value of 91.11 = 91.10999
The Next down value of 0.0 = -1.4E-45


相关用法


注:本文由纯净天空筛选整理自ankita_chowrasia大神的英文原创作品 StrictMath nextDown() Method in Java。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。