English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math nextUp() método devuelve el número adyacente al infinito positivo del parámetro especificado.
Es decir, si el parámetro es6.7entonces, el número adyacente en la dirección del infinito positivo6.7Por6.700000000000001。
La sintaxis del método nextUp() es:
Math.nextUp(start)
Atención:El método nextUp() es un método estático. Por lo tanto, podemos llamar directamente al método utilizando el nombre de la clase Math.
start -Devuelve el número de inicio adyacente
Atención:El tipo de datos de start puede ser float o double.
Devuelve el número adyacente al infinito positivo de start
Si start es NaN, se devuelve NaN
Si start es infinito positivo, se devuelve infinito positivo
Atención:nextUp() método es equivalente aMath.nextAfter(start,Double.POSITIVE_INFINITY)。
class Main { public static void main(String[] args) { // float parámetro float start1 = 7.9f; System.out.println(Math.nextUp(start1)); // 7.9000006 // double parámetro double start2 = 7.9; System.out.println(Math.nextUp(start2)); // 7.900000000000001 //正无穷大 double infinity = Double.POSITIVE_INFINITY; System.out.println(infinity); // Infinity // NaN double nan = Math.sqrt(-5); System.out.println(Math.nextUp(nan)); // NaN } }
在这里,我们使用了Java Math.sqrt(-5)方法来计算-5的平方根。由于负数的平方根不是数字,因此Math.nextUp(nan) 返回 NaN。
Double.POSITIVE_INFINITY是Double类的一个字段,它使我们可以在程序中实现无穷大。