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


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。