How do I calculate the log of a number using bc?

2019-02-04 00:39发布

This is the first time I am using bc. I want to calculate the log (base 10) of a number. How do I this?

标签: unix bc
7条回答
【Aperson】
2楼-- · 2019-02-04 01:33

the logarithm of x in respect to base b can be computed given any logarithm function to an arbitrary base k -- that's actually pretty cool!

log_b(x) = log_k(x) / log_k(b)

e.g.

log_b(x) = ln(x) / ln(b)

if b=10:

log_10(x) = ln(x) / ln(10)

and -l in bc enables the math library

so that's why this works:

# bc -l
l(100) / l(10)
2.00000000000000000000
查看更多
登录 后发表回答