Java Math log () metode aprēķina norādītās vērtības dabisko logaritmu (bāze e) un to atgriež.
Metodes sintakse log()
ir šāda:
Math.log(double x)
Šeit log()
ir statiska metode. Tādējādi mēs tieši izsaucam metodi, izmantojot klases nosaukumu Math
.
log () parametri
- x - vērtība, kuras logaritms jāaprēķina
log () Atgriezt vērtības
- atgriež x (ti
ln a
) naturālo logaritmu - atgriež NaN, ja arguments ir NaN vai mazāks par nulli
- atgriež pozitīvu bezgalību, ja arguments ir pozitīvs bezgalība
- atgriež negatīvu bezgalību, ja arguments ir nulle
Piemērs: 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 ) )
Ieteicamā apmācība
- Java Math.log10 ()
- Java Math.log1p ()