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