// 示例代码:使用 Math.log() 计算自然对数
// Math.log(x) 返回 x 的自然对数(以 e 为底)
let num = 10;
let result = Math.log(num);
console.log(`Math.log(${num}) = ${result}`); // 输出: Math.log(10) = 2.302585092994046
// 如果需要计算其他底数的对数,可以使用换底公式:
// log_b(x) = log_e(x) / log_e(b)
let base = 2;
let logBaseResult = Math.log(num) / Math.log(base);
console.log(`log_${base}(${num}) = ${logBaseResult}`); // 输出: log_2(10) = 3.321928094887362
Math.log(x):返回 x 的自然对数(即以 e 为底的对数)。e(约等于 2.71828)为底的对数。log_b(x) = log_e(x) / log_e(b)。上一篇:js 键值对
下一篇:js 数组首位添加
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站