Wes Oldenbeuving
Wes Oldenbeuving

Reputation: 416

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

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?

Upvotes: 3

Views: 2946

Answers (3)

Slartibartfast
Slartibartfast

Reputation: 8805

There is

Math::log10 (n)

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

Upvotes: 10

Gishu
Gishu

Reputation: 136633

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

Upvotes: 0

Wes Oldenbeuving
Wes Oldenbeuving

Reputation: 416

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

Math::log10(n) 

This gives the base 10 logarithm of n.

Upvotes: 2

Related Questions