English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math mathematical methods
La méthode Java Math nextDown() retourne un nombre adjacent à la direction de l'infini négatif du paramètre spécifié.
C'est-à-dire, si le paramètre est6.7alors, le nombre adjacent dans la direction de l'infini négatif6.7Pour6.699999999999999.
La syntaxe de la méthode nextDown() est :
Math.nextDown(start)
Remarque: nextDown() est une méthode statique. Par conséquent, nous pouvons appeler cette méthode directement via le nom de la classe Math.
start -Pour retourner le nombre d'origine adjacent
Remarque: Le type de données de start peut être float ou double.
Retourne le nombre adjacent à start négatif et négatif infini
Si start est NaN, retourne NaN
Si start est infini négatif, retourne infini négatif
Remarque: nextDown() équivaut àMath.nextAfter(start, Double.Negative_INFINITY).
class Main { public static void main(String[] args) { // float paramètre float start1 = 7.9f; System.out.println(Math.nextDown(start1)); // 7.8999996 // double paramètre double start2 = 7.9; System.out.println(Math.nextDown(start2)); // 7.8999999999999995 //Positive infinity double infinity = Double.NEGATIVE_INFINITY; System.out.println(Math.nextDown(infinity)); // -Infinity // NaN double nan = Math.sqrt(-5); System.out.println(Math.nextDown(nan)); // NaN } }
Here, we useJava Math.sqrt(-5)method to calculate-5theSquare root. Since the square root of a negative number is not a number, Math.nextDown(nan) returnsNaN.
Double.NEGATIVE_INFINITY is a field of the Double class that allows us to implement infinity in our programs.