Advertisement
Advertisement


How to get the base 10 logarithm of a Fixnum in Ruby?


Question

I want to get the base 10 logarithm of a Fixnum using Ruby, but found that n.log or n.log10 are not defined. Math::log is defined but uses a different base than 10.

What is the easiest way to get the base 10 logarithm of a Fixnum?

2008/09/09
1
2
9/9/2008 8:56:23 AM

Accepted Answer

There is

Math::log10 (n)

And there is also a property of logarithms that logx(y) = log(y)/log(x)

2018/05/18
9
5/18/2018 9:09:29 AM

Reading the documentation for module Math the answer is really obvious:

Math::log10(n) 

This gives the base 10 logarithm of n.

2008/09/09

Math.log10(numeric) => float returns base 10 log

2008/09/09

Source: https://stackoverflow.com/questions/51420
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]