java math.log2_Java Math log()用法及代码示例

java.lang.Math.log()方法返回双精度值的自然对数(以e为底)作为参数。有多种情况:

如果参数为NaN或小于零,则结果为NaN。

如果参数为正无穷大,则结果为正无穷大。

如果参数为正零或负零,则结果为负无穷大。

用法:

public static double log(double a)

参数:

a:User input

返回:

This method returns the value ln a.

例:展示java.lang.Math.log()方法的用法。

// Java program to demonstrate working

// of java.lang.Math.log() method

import java.lang.Math;

class Gfg {

// driver code

public static void main(String args[])

{

double a = -2.55;

double b = 1.0 / 0;

double c = 0, d = 145.256;

// negative integer as argument, output NAN

System.out.println(Math.log(a));

// positive infinity as argument, output Infinity

System.out.println(Math.log(b));

// positive zero as argument, output -Infinity

System.out.println(Math.log(c));

// positive double as argument

System.out.println(Math.log(d));

}

}

输出:

NaN

Infinity

-Infinity

4.978497702968366

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值