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

Java Basic Tutorial

Contrôle de flux Java

Java tableau

Java orienté objet (I)

Java Programmation orientée objet (II)

Java Programmation orientée objet (III)

Java Exception Handling

Java List

Java Queue (file d'attente)

Java Map Collection

Java Set Collection

Java Entrée/Sortie (I/O)

Reader Java/Writer

Autres sujets de Java

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

Java Math mathematical methods

La méthode tanh() de Java Math retourne la tangente hyperbolique de la valeur spécifiée.

La tangente hyperbolique est égale à(e x -e -x)/(e x + e -x)Où e est le nombre d'Euler. De plus, tanh() = sinh() / cosh()/cos()。

La syntaxe de la méthode tanh() est :

Math.tanh(double value)

paramètre tanh()

  • value - Pour déterminer son angle tangente hyperbolique

Remarque:Cette valeur est généralement exprimée en radians.

La valeur retournée par tanh()

  • RetourneLa valeurtangente hyperbolique

  • Si le paramètreLa valeur NaN, alors il retourne NaN

  • Si le paramètre est +Infini, alors il retourne1.0

  • Si le paramètre est -Infini, alors il retourne-1.0

Remarque:Si le paramètre est zéro, cette méthode retourne zéro et le signe est le même que le paramètre.

Exemple1:Java Math tanh()

class Main {
  public static void main(String[] args) {
    //Création de la variable double
    double value1 = 45.0;
    double value2 = 60.0;
    double value3 = 30.0;
    //Convertir en radians
    value1 = Math.toRadians(value1);
    value2 = Math.toRadians(value2);
    value3 = Math.toRadians(value3);
    //Calculate hyperbolic tangent
    System.out.println(Math.tanh(value1));  // 0.6557942026326724
    System.out.println(Math.tanh(value2));  // 0.7807144353592677
    System.out.println(Math.tanh(value3));  // 0.4804727781564516
  }
}

Dans cet exemple, veuillez noter les expressions suivantes :

Math.tanh(value1)

Ici, nous avons utilisé directement le nom de la classe pour appeler la méthode. C'est parce que tanh() est une méthode statique.

Remarque:Nous avons utiliséMath.toRadians()La méthode convertit toutes les valeurs en radians.

Exemple2:Utiliser sinh() et cosh() pour calculer tanh()

class Main {
  public static void main(String[] args) {
    //Création de la variable double
    double value1 = 45.0;
    double value2 = 60.0;
    double value3 = 30.0;
    //Convertir en radians
    value1 = Math.toRadians(value1);
    value2 = Math.toRadians(value2);
    value3 = Math.toRadians(value3);
    //Calculer la tangente hyperbolique : sinh()/cosh()。
    //Retourne 0.6557942026326724
    System.out.println(Math.sinh(value1)/Math.cosh(value1));
    // Retourne 0.7807144353592677
    System.out.println(Math.sinh(value2)/Math.cosh(value2));
    // Retourne 0.4804727781564516
    System.out.println(Math.sinh(value3)/Math.cosh(value3));
  }
}

Dans cet exemple, veuillez noter les expressions suivantes :

Math.sinh(value1)/Math.cosh(value2)

Ici, nous utilisons sinh()/cosh() calcule la tangente hyperbolique. Comme nous pouvons le voir, les résultats de tanh() et sinh()/cosh() est le même.

Exemple2: tanh() contient 0, NaN et Infinite

class Main {
  public static void main(String[] args) {
    //Création de la variable double
    double value1 = Double.POSITIVE_INFINITY;
    double value2 = Double.NEGATIVE_INFINITY;
    double value3 = Math.sqrt(-5);
    double value4 = 0.0;
    //Convert to radians
    value1 = Math.toRadians(value1);
    value2 = Math.toRadians(value2);
    value3 = Math.toRadians(value3);
    value4 = Math.toRadians(value4);
    //Calculate hyperbolic tangent
    System.out.println(Math.tanh(value1));  // 1.0
    System.out.println(Math.tanh(value2));  // -1.0
    System.out.println(Math.tanh(value3));  // NaN
    System.out.println(Math.tanh(value4));  // 0.0
  }
}

In the above examples,

  • Double.POSITIVE_INFINITY - Implementing positive infinity in Java

  • Double.NEGATIVE_INFINITY - Implementing negative infinity in Java

  • Math.sqrt(-5) - The square root of a negative number is not a number

Note: for positive infinity parameters, the tanh() method returns1.0, for negative infinity parameters, it returns-1.0.

We have usedMath.sqrt()A method to calculate the square root of a number.

Recommended tutorials

Java Math mathematical methods