ln, lg, log在C中的应用

在C语言中定义的函数和数学上定义的函数有所区别:C语言中只定义的两个函数:
(1)y=log(double x)
(2)y=log10(double x)
第(1)个代表数学式中的ln,第(2)个代表数学式中的 lg;而数学上要求loga(b) (a不为e和10),可用换底公式表示为log(b)/log(a)(或者 log10(b)/log10(a))。注意一点的是要包含头文件math.h

函数为:

extern _ARMABI double log(double /*x*/);
/* computes the natural logarithm of x. A domain error occurs if the */
/* argument is negative, and -HUGE_VAL is returned. A range error occurs */
/* if the argument is zero. */
/* Returns: the natural logarithm. */
/*          if range error; -HUGE_VAL is returned. */
extern _ARMABI double log10(double /*x*/);
/* computes the base-ten logarithm of x. A domain error occurs if the */
/* argument is negative. A range error occurs if the argument is zero. */
/* Returns: the base-ten logarithm. */

备注:有时候keil中即使包含math.h头文件在使用依然会出现错误数据的情况(计算为异常0值);则需要在要调用改数学函数文件中包含:
extern _ARMABI double log(double /x/);
extern _ARMABI double log10(double /x/);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值