Java StrictMath nextDown()方法

Java StrictMath nextDown()方法

nextDown(double num)

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

语法

public static double nextDown(double num)

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

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

例子 :
输入: num = 7.16
输出:7.159999999999999

以下程序说明了nextDown()方法。

程序1 :

// Java program 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 为负无穷大时,它返回负无穷大。当参数为0时,结果为Float.MIN_VALUE。nextDown()方法等同于nextAfter( num, Float.NEGATIVE_INFINITY ),但nextDown()的运行速度比其等同的nextAfter调用快。

语法

public static float nextDown( _float num_ )

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

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

例子 :

输入: num = 1.2f
输出:1.1999999

以下程序说明了Java.lang.StrictMath.nextDown()方法。

程序1 :

// Java program 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

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程