Java Math log1p () metode atgriež norādītās vērtības un 1 summas naturālo logaritmu (bāze e).
Metodes sintakse log1p()
ir šāda:
Math.log1p(double x)
Šeit log1p()
ir statiska metode. Tādējādi mēs tieši izsaucam metodi, izmantojot klases nosaukumu Math
.
log1p () parametri
Metode log1p () aizņem vienu parametru.
- x - vērtība, kuras logaritms jāaprēķina
log1p () atgriešanās vērtības
- atgriež x + 1 naturālo logaritmu
- atgriež NaN, ja x ir NaN vai mazāks par -1
- atgriež pozitīvu bezgalību, ja x ir pozitīva bezgalība
- atgriež nulli, ja x ir nulle
1. piemērs: Java Math.log1p ()
class Main ( public static void main(String() args) ( // log1p() for double value System.out.println(Math.log1p(9.0)); // 2.302585092994046 // log1p() for zero System.out.println(Math.log1p(0.0)); // 0.0 // log1p() for NaN // square root of negative number is NaN double nanValue = Math.sqrt(-5.0); System.out.println(Math.log1p(nanValue)); // NaN // log1p() for infinity double infinity = Double.POSITIVE_INFINITY; System.out.println(Math.log1p(infinity)); // Infinity // log1p() for negative numbers System.out.println(Math.log(-9.0)); // NaN ) )
Iepriekš minētajā piemērā ievērojiet izteicienu
Math.log1p(Math.pow(10, 3))
Šeit Math.pow(10, 3)
atgriež 10 3 . Lai uzzinātu vairāk, apmeklējiet Java Math.pow ().
Piezīme : Mēs izmantojām metodi Math.sqrt (), lai aprēķinātu kvadrātsakni no -5. Negatīvā skaitļa kvadrātsakne nav skaitlis.
2. piemērs: Math.log1p () un Math.log ()
class Main ( public static void main(String() args) ( double a = 9.0; // log1p() for double value System.out.println(Math.log1p(a)); // 2.302585092994046 // Compute log() for a + 1 a = a + 1; System.out.println(Math.log(a)); // 2.302585092994046 // Here you can see log1p(x) == log(x + 1) ) )
Ieteicamās konsultācijas:
- Java Math.log ()
- Java Math.log10 ()