English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Tutoriel de base Java

Java contrôle de flux

Java tableau

Java orienté objet (I)

Java orienté objet (II)

Java orienté objet (III)

Gestion des exceptions Java

Java Liste (List)

Java Queue (file d'attente)

Java Map collectif

Java Set collectif

Java entrée/sortie (I/O)

Reader Java/Writer

Autres sujets Java

Utilisation et exemple de la méthode Java Math nextDown()

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.

Paramètre de nextDown()

  • start -Pour retourner le nombre d'origine adjacent

Remarque: Le type de données de start peut être float ou double.

Valeur de retour de nextDown()

  • 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).

Exemple : Java Math.nextDown()

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.

Recommended tutorials

Java Math mathematical methods