From: Logan Capaldo Date: 2006-05-07T03:45:49+09:00 Subject: Re: What do you say to log2 to Math module? On May 6, 2006, at 2:39 PM, M. Edward (Ed) Borasky wrote: > Am I missing something here? In any programming language, define the > constant > > Multiplier = 1.0/logtoanybase(2) > > Then > > log2(x) = Multiplier*logtoanybase(x) > > You have to compute the Multiplier *once*. My guess is that most > implementations of other languages compute logs to only one base, > probably the natural (base e) log, and compute logs to all other bases > by doing this multiplication every time you call them -- or worse, not > pre-computing the Multiplier and doing a divide every time, which > takes > longer and is less accurate. > > I'm sure they do, he would just like to avoid typing module Math Log2Multiplier = 1.0 / self.log(2.0) def self.log2(x) self.log(x) * Log2Multiplier end end everytime he writes a new program > > Minkoo Seo wrote: >> Hi list. >> >> I'm using ruby for my research purpose, and as everyone knows >> computer science is all about log function whose base is 2. >> >> Unfortunately, Math module does not contain log2 though it has >> log10. What do you think about adding log2 to Math? >> >> Yes, I know that adding log2 is way so simple because I can >> open Math module and add log2 method, but I've had to that ALWAYS. >> >> Sincerely, >> Minkoo Seo >> > > -- > M. Edward (Ed) Borasky > > http://linuxcapacityplanning.com > >