一、基本概念

log: 表示对数,与指数相反。例如:
我们读作log以3为底,9的对数。具体计算方式是3的2次方为9,及以3为底9的对数就是2。
lg: 10为底的对数,叫作常用对数。
ln: 以无理数e(e=2.71828…)为底的对数,叫作自然对数

对数是对求幂的逆运算,正如除法是乘法的倒数,反之亦然。 这意味着一个数字的对数是必须产生另一个固定数字(基数)的指数。 在简单的情况下,乘数中的对数计数因子。更一般来说,乘幂允许将任何正实数提高到任何实际功率,总是产生正的结果,因此可以对于b不等于1的任何两个正实数b和x计算对数。

如果a的x次方等于N(a>0,且a不等于1),那么数x叫做以a为底N的对数(logarithm),记作x=logₐN。其中,a叫做对数的底数,N叫做真数。

二、javaAPI

1.求lg

java.lang.Math @Contract(pure = true)
public static double log10(double a)Returns the base 10 logarithm of a double value.
返回以10为底的对数
Special cases:
If the argument is NaN or less than zero, then the result is NaN.
如果参数是NaN或者小于0的数据,则返回NaN
If the argument is positive infinity, then the result is positive infinity.
如果参数是正无群大,返回正无群大
If the argument is positive zero or negative zero, then the result is negative infinity.
如果参数为正零或负零,则结果为负无穷大。
If the argument is equal to 10n for integer n, then the result is n.
如果整数n的参数等于10n,则结果为n。
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.
计算结果必须在精确结果的1ulp范围内。结果必须是半单调的。

2.求ln

java.lang.Math @Contract(pure = true)
public static double log(double a)Returns the natural logarithm (base e) of a double value.
返回double类型的自然对数(以e为底)。
Special cases:
If the argument is NaN or less than zero, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is positive zero or negative zero, then the result is negative infinity.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.Params:
a – a value
Returns:
the value ln a, the natural logarithm of a.
值ln a,a的自然对数。
External annotations:
@org.jetbrains.annotations.Contract(pure = true)

3.求ln(x+1)

java.lang.Math @Contract(pure = true)
public static double log1p(double x)Returns the natural logarithm of the sum of the argument and 1. Note that for small values x, the result of log1p(x) is much closer to the true result of ln(1 + x) than the floating-point evaluation of log(1.0+x).
返回参数和1之和的自然对数。注意,对于小值x,log1p(x)的结果比log(1.0+x)的浮点求值更接近ln(1+x)的真实结果。Special cases:
If the argument is NaN or less than -1, then the result is NaN.
If the argument is positive infinity, then the result is positive infinity.
If the argument is negative one, then the result is negative infinity.
If the argument is zero, then the result is a zero with the same sign as the argument.
The computed result must be within 1 ulp of the exact result. Results must be semi-monotonic.Params:
x – a value
Returns:
the value ln(x + 1), the natural log of x + 1ln(x + 1),x+1的自然对数
Since:
1.5
External annotations:
@org.jetbrains.annotations.Contract(pure = true)

4.求任意底数的对数
实现原理:换底公式

static public double log(double value, int base){return Math.log(value) / Math.log(base);
}

5.代码示例

public static void main(String[] args) {System.out.println("Math.log==>"+Math.log(-1));System.out.println("Double.NaN==>"+Double.NaN);System.out.println("Math.log10(10)==>"+Math.log10(10));System.out.println("Math.log1p(9)==>"+Math.log1p(9));System.out.println("Math.log(10)==>"+Math.log(10));System.out.println("log2 8==>"+log(8,2));System.out.println("log5 125==>"+log(125, 5));}

运行结果

Math.log==>NaN
Double.NaN==>NaN
Math.log10(10)==>1.0
Math.log1p(9)==>2.302585092994046
Math.log(10)==>2.302585092994046
log2 8==>3.0
log5 125==>3.0000000000000004

三、Mysql函数

Name Description
LN() Return the natural logarithm of the argument
LOG() Return the natural logarithm of the first argument
LOG10() Return the base-10 logarithm of the argument
LOG2() Return the base-2 logarithm of the argument

参考链接:https://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_log

1.LN(X)

Returns the natural logarithm of X; that is, the base-e logarithm of X. If X is less than or equal to 0.0E0, the function returns NULL and a warning “Invalid argument for logarithm” is reported.
返回X的自然对数,即X的e底对数。如果X小于或等于0.0E0,则函数返回空值,并报告警告“对数参数无效”mysql> SELECT LN(2);-> 0.69314718055995
mysql> SELECT LN(-2);-> NULLThis function is synonymous with LOG(X). The inverse of this function is the EXP() function.
此函数与LOG(X)同义此函数的逆函数是EXP()函数。

2.LOG(X), LOG(B,X)

If called with one parameter, this function returns the natural logarithm of X. If X is less than or equal to 0.0E0, the function returns NULL and a warning “Invalid argument for logarithm” is reported.
如果使用一个参数调用,则此函数返回X的自然对数。如果X小于或等于0.0E0,则此函数返回空值,并报告警告“对数参数无效”。
The inverse of this function (when called with a single argument) is the EXP() function.
此函数的逆函数(使用单个参数调用时)是EXP()函数。mysql> SELECT LOG(2);-> 0.69314718055995
mysql> SELECT LOG(-2);-> NULLIf called with two parameters, this function returns the logarithm of X to the base B. If X is less than or equal to 0, or if B is less than or equal to 1, then NULL is returned.
如果使用两个参数调用,则此函数将X的对数返回到基数B。如果X小于或等于0,或者如果B小于或等于1,则返回NULL。mysql> SELECT LOG(2,65536);-> 16
mysql> SELECT LOG(10,100);-> 2
mysql> SELECT LOG(1,100);-> NULLLOG(B,X) is equivalent to LOG(X) / LOG(B).
LOG(B,X)相当于LOG(X)/LOG(B)。

3.LOG2(X)

Returns the base-2 logarithm of X. If X is less than or equal to 0.0E0, the function returns NULL and a warning “Invalid argument for logarithm” is reported.
返回X的以2为底的对数。如果X小于或等于0.0E0,则函数返回空值,并报告警告“对数参数无效”。mysql> SELECT LOG2(65536);-> 16
mysql> SELECT LOG2(-100);-> NULLLOG2() is useful for finding out how many bits a number requires for storage. This function is equivalent to the expression LOG(X) / LOG(2).
LOG2()有助于找出一个数字存储需要多少位。此函数相当于表达式LOG(X)/LOG(2)。

4.LOG10(X)

Returns the base-10 logarithm of X. If X is less than or equal to 0.0E0, the function returns NULL and a warning “Invalid argument for logarithm” is reported.
返回X的以10为底的对数。如果X小于或等于0.0E0,则函数返回空值,并报告警告“对数参数无效”。mysql> SELECT LOG10(2);-> 0.30102999566398
mysql> SELECT LOG10(100);-> 2
mysql> SELECT LOG10(-100);-> NULLLOG10(X) is equivalent to LOG(10,X).
LOG10(X)相当于LOG(10,X)

参考文档:
1.java8API
2.mysql官方文档:https://dev.mysql.com/doc/refman/5.7/en/mathematical-functions.html#function_log

对数log ln lg 的java实现和mysql实现相关推荐

  1. c语言中怎么将lg换成ln,lg和ln的换算(ln和log怎么转化)

    lgx=lnx/ln10 lg=log10 由于在数学对数计算时,以10为底的对数非常常见,为了书写方便,提高书写效率,就简化为lg,省掉了中间的o和底数10.类似的还有ln,自然对数,是以e=2.. ...

  2. eclipse报错:An error has occurred. See error log for more details. java.lang.NullPointerException

    eclipse一直不停的报错: An error has occurred. See error log for more details. java.lang.NullPointerExceptio ...

  3. Java高效率复习-MySQL上篇[MySQL]

    前言 本文章是用于总结尚硅谷MySQL教学视频的记录文章,主要用于复习,非商用 原视频连接:https://www.bilibili.com/video/BV1iq4y1u7vj/?p=21& ...

  4. Java项目:酒店管理系统(java+SSM+jsp+mysql+maven)

    源码获取:博客首页 "资源" 里下载! 主要技术:java springmvc  mybatis   mysql  tomcat js   jauery  jsp   log4j等 ...

  5. Java监听mysql的binlog详解(mysql-binlog-connector)

    Java监听mysql的binlog详解(mysql-binlog-connector) 1. 需求概述 2. 技术选型 3. 方案设计 3.环境准备 3.1 查看是否开启binlog 3.2 mys ...

  6. 基于javaweb的零食商城系统(java+ssm+jsp+mysql+easyui)

    基于javaweb的零食商城系统(java+ssm+jsp+mysql+easyui) 运行环境 Java≥8.MySQL≥5.7.Tomcat≥8 开发工具 eclipse/idea/myeclip ...

  7. 基于javaweb的医院分诊挂号住院管理系统(java+springboot+freemarker+mysql)

    基于javaweb的医院分诊挂号住院管理系统(java+springboot+freemarker+mysql) 运行环境 Java≥8.MySQL≥5.7 开发工具 eclipse/idea/mye ...

  8. 基于javaweb+springboot的医院分诊挂号住院管理系统(java+SpringBoot+FreeMarker+Mysql)

    基于javaweb+springboot的医院分诊挂号住院管理系统(java+SpringBoot+FreeMarker+Mysql) 主要实现了从挂号预约到分诊住院出诊等一些列医院基本操作流程的全部 ...

  9. 基于javaweb+springboot的物流快递在线寄查快递系统(java+SpringBoot+FreeMarker+Mysql)

    基于javaweb+springboot的物流快递在线寄查快递系统(java+SpringBoot+FreeMarker+Mysql) 超级管理员:系统管理.用户管理.网点管理.运输点管理.快递员管理 ...

  10. 基于javaweb的酒店管理系统(java+ssm+jsp+mysql)

    基于javaweb的酒店管理系统(java+ssm+jsp+mysql) 运行环境 Java≥8.MySQL≥5.7.Tomcat≥8 开发工具 eclipse/idea/myeclipse/sts等 ...

最新文章

  1. CPU和内存之间——地址映射(理解很重要)
  2. 新版linux安装旧软件下载,Linux下载安装各种版本的firefox
  3. 3.6.6 码点与代码单元
  4. 部署在SAP ABAP服务器上的SAP UI5应用,resource root的计算逻辑
  5. 《NoSQL权威指南》导读
  6. C/C++信息隐写术(一)之认识文件结构
  7. 码农的自我修炼之路-----BST
  8. 图解Linux内核:内核启动(1)从Bootloader到内核代码
  9. android与ios图片类型转换,ios11图片转换工具
  10. node怎么解析vue代码_vue中node_modules中第三方模块的修改使用详解
  11. 关于全局低级键盘hook的记录(WH_KEYBOARD_LL)
  12. matlab基于瑞利信道,基于matlab的瑞利信道仿真.docx
  13. AMI编码规则与HDB3编码规则详解
  14. Ubuntu 修改鼠标中键功能
  15. 【NYNU 1151】轻羽飞扬 数塔DP
  16. python火车票分析_通过python splinter分析12306网站
  17. 一套牛逼哄哄的开源的监控系统(附源码)
  18. 《中文文本信息抽取模型与方法研究》5:基于论元结构的事件要素及其角色识别
  19. MySQL审计插件使用和对比
  20. 【有奖众测】快服务开发者俱乐部第一期来咯!

热门文章

  1. 苹果iOS申请个人开发者账号注册教程
  2. 矩阵乘法Java实现
  3. 时间管理之番茄工作法
  4. 利用pandas进行简单数据分析——医院销售数据分析案例
  5. PPT如何制作?掌握这几个思维,就可快捷设计制作PPT了
  6. Win10环境下VS2003安装教程
  7. 机器人控制框架行为树py_trees <一、行为树介绍>
  8. px4讲解(一)历史起源
  9. 外架小横杆外露长度规范要求_外架小横杆外露长度
  10. MindManager 2020免费序列号激活下载及怎样运用思维导图进行头脑风暴教程