logarithm to the base of 2 (binary logarithm), base 10 and base n - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: Chatting and Socializing (https://qb64phoenix.com/forum/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://qb64phoenix.com/forum/forumdisplay.php?fid=2) +--- Thread: logarithm to the base of 2 (binary logarithm), base 10 and base n (/showthread.php?tid=2055) |
logarithm to the base of 2 (binary logarithm), base 10 and base n - BSpinoza - 10-02-2023 As I see, QB64 only knows the logarithm function LOG() to the base e. The following small program calculates the binary logarithm ( logarithm to the base of 2) and the logarithms to the base 10 and n Code: (Select All)
LOG10 is often called LG and LOG is often LN (for natural logarithm). Could these functions be implemented as standard QB64PE functions: _LOG2(), _LOG10(), LOGn(,)? RE: logarithm to the base of 2 (binary logarithm), base 10 and base n - bplus - 10-02-2023 (10-02-2023, 12:18 PM)BSpinoza Wrote: As I see, QB64 only knows the logarithm function LOG() to the base e. Wouldn't it be more efficient to do all other log bases like you did Log2 as it is one less call to User Defined Function. ie 0 calls to user defined function BaseNLog##(BaseN, a) = Log(a)/Log(BaseN) ' which includes Log2(a)'s which I think is in wiki already RE: logarithm to the base of 2 (binary logarithm), base 10 and base n - mnrvovrfc - 10-02-2023 This is actually beyond my realm. I also don't understand why the designers of BASIC used "LOG" for natural logarithm. Obviously they weren't American. -_O_- I saw source code which `LOG()` is used only once: to be wrapped into an user function called `LN()`. Then that `LN()` was called to provide common log, called `L10()`. RE: logarithm to the base of 2 (binary logarithm), base 10 and base n - BSpinoza - 10-03-2023 bplus wrote: Quote:Wouldn't it be more efficient to do all other log bases like you did Log2 as it is one less call to User Defined Function. ie 0 calls to user defined functionI know this and thats right. In some conditions it would make some math formulas less complicate, if you have some special LOG functions, especially the LOG2 and LOG10. This also know the creators of other programming languages, i.e. Python. |