English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
La méthode log() de Math dans Java calcule le logarithme naturel d'une valeur spécifiée (basé sur e) et le retourne.
La syntaxe de la méthode log() est la suivante :
Math.log(double x)
Attention:La méthode log() est une méthode statique. Par conséquent, nous pouvons appeler cette méthode directement en utilisant le nom de la classe Math.
x - Calculer la valeur de son logarithme
Retourne le logarithme naturel de x (c'est-à-dire ln a)
Si le paramètre est NaN ou inférieur à zéro, il renvoie NaN
If the parameter is positive infinity, it returns positive infinity
If the parameter is zero, it returns negative infinity
class Main { public static void main(String[] args) { // Calculate the log of a double-precision value System.out.println(Math.log(9.0)); // 2.1972245773362196 //Calculate the log of zero System.out.println(Math.log(0.0)); // -Infinity //Calculate the log of NaN double nanValue = Math.sqrt(-5.0); System.out.println(Math.log(nanValue)); // NaN //Calculate the log of infinity double infinity = Double.POSITIVE_INFINITY; System.out.println(Math.log(infinity)); // Infinity //Calculate the log of a negative number System.out.println(Math.log(-9.0)); // NaN } }