From: Morton Goldberg Date: 2007-02-08T14:00:28+09:00 Subject: Re: Adding Math.log2 and Math.logn to the core library. On Feb 7, 2007, at 9:00 PM, Eric I. wrote: > On Feb 7, 7:08 pm, Morton Goldberg wrote: >> Well, I can find examples with the base first or second. Perhaps for >> Ruby it would most idiomatic to define log as follows >> >> def Math.log(x, b=Math::E); ... ; end >> >> as the core method with log10 and log2 handled (for performance) as >> special cases within this method. Given that, I would still want Math >> to implement log10 and log2 methods for convenience. > > Math.log calls the log in the standard math library, which I suspect > implements the natural log calculation pretty efficiently. If you > make the second parameter the base, you'll either have to check it > against Math::E and treat it as a special case or do two log > calculations for the natural log case. I don't like either of those > options. If there's too much of a performance penalty for this, I would have no problem with the general case being implemented under a different name, and I would suggest "logb" -- that is, def Math.logb(x, b=Math::E); ... ; end My main point is that I think the general case should default its base to Math::E. If we were to end up with Math.log (alias Math.ln), Math.log10, Math.log2, and Math.logb (the general case) that would be fine. Regards, Morton