When comes Javascript Math.log1p() in use?

// Section 1 - 19 : Changing base
// Using NodeJS

// Using a function
console.log(`Logbase 2, for 32 equals to ${Math.log2(32)}`) // 5

// LOGx(n), doesn't exist.
// Reaclulation using base 10
let a = 2
let x = 64
console.log(`LOGa(x) = LOG10(${x}) / LOG10(${a}) = ${Math.log10(x) / Math.log10(a)}`) // 6
console.log(`LOGa(x) = LOG2(${x}) / LOG2(${a}) = ${Math.log2(x) / Math.log2(a)}`) // 6

// Javascript has also a LOG1p
//   (method) Math.log1p(x: number): number
//   Returns the natural logarithm of 1 + x.
//   @param x — A numeric expression.

console.log(`Math.log1p(0) = ${Math.log1p(0)}`) // 0
console.log(`Math.log1p(1) = ${Math.log1p(1)}`) // 0.6931471805599453
console.log(`Math.log1p(2) = ${Math.log1p(2)}`) // 1.0986122886681096
console.log(`Math.log1p(10) = ${Math.log1p(10)}`) // 2.3978952727983707

Privacy & Terms