Die Java Math log () -Methode berechnet den natürlichen Logarithmus (Basis e) des angegebenen Werts und gibt ihn zurück.
Die Syntax der log()
Methode lautet:
Math.log(double x)
Hier log()
ist eine statische Methode. Daher rufen wir die Methode direkt mit dem Klassennamen auf Math
.
log () Parameter
- x - der Wert, dessen Logarithmus berechnet werden soll
log () Rückgabewerte
- gibt den natürlichen Logarithmus von x zurück (dh
ln a
) - Gibt NaN zurück, wenn das Argument NaN oder kleiner als Null ist
- Gibt eine positive Unendlichkeit zurück, wenn das Argument eine positive Unendlichkeit ist
- Gibt eine negative Unendlichkeit zurück, wenn das Argument Null ist
Beispiel: Java Math.log ()
class Main ( public static void main(String() args) ( // compute log() for double value System.out.println(Math.log(9.0)); // 2.1972245773362196 // compute log() for zero System.out.println(Math.log(0.0)); // -Infinity // compute log() for NaN double nanValue = Math.sqrt(-5.0); System.out.println(Math.log(nanValue)); // NaN // compute log() for infinity double infinity = Double.POSITIVE_INFINITY; System.out.println(Math.log(infinity)); // Infinity // compute log() for negative numbers System.out.println(Math.log(-9.0)); // NaN ) )
Empfohlenes Tutorial
- Java Math.log10 ()
- Java Math.log1p ()