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

前端 未结 8 740
说谎
说谎 2020-12-28 11:35

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

8条回答
  •  一个人的身影
    2020-12-28 12:35

    bc does not directly gives the logarithm in other than except or in other ways, using bc, we can calculate only ln(x). So, to get any other base logarithm, it is wise to remember some identities. The basic one is -

    log base 10 (x) = log base e (x) / log base e (10)
    

    Here I am giving you some examples of different base logarithms -

    totan@Home-Computer ~ $ bc -l
    bc 1.06.95
    Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
    This is free software with ABSOLUTELY NO WARRANTY.
    For details type `warranty'. 
    
    l(8)/l(2)
    3.00000000000000000002
    
    l(1000)/l(10)
    3.00000000000000000000
    
    l(100000)/l(100)
    2.50000000000000000000
    
    l(100000)/l(10)
    5.00000000000000000001
    
    l(81)/l(3)
    4.00000000000000000001
    
    l(64)/l(4)
    3.00000000000000000000
    
    quit()
    totan@Home-Computer ~ $ 
    

    Hope this helps you.

提交回复
热议问题