Posted By

octech on 07/24/08


Tagged

math base log Logarithm


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

holizz
webstic


Logarithm with any base (任意の底を持つ対数)


 / Published in: Ruby
 

URL: http://d.hatena.ne.jp/octech/20080724#1216874092

英語のタイトルが適当な英訳なので、誰かOK/NGを教えてください。

  1. # 任意の底 a を持つ x の対数を計算.
  2. def logA( x, a )
  3. return (Math.log(x)/Math.log(a))
  4. end
  5.  
  6. p logA( 2, 2 ) # => 1.0
  7. p logA( 4, 2 ) # => 2.0

Report this snippet  

You need to login to post a comment.