10-02-2023, 02:29 PM
(10-02-2023, 12:18 PM)BSpinoza Wrote: 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)
DIM AS _FLOAT a, n
a = 22
PRINT log2##(a)
PRINT logn##(22, 2)
PRINT logn##(22, 10)
PRINT log10##(22)
'Function log2: logarithm to the base of 2 (binary logarithm)
FUNCTION log2## (a)
log2## = (LOG(a) / LOG(2))
END FUNCTION
'Function log10: logarithm of a to the base of n
FUNCTION log10## (a)
log10## = (log2##(a) / log2##(10))
END FUNCTION
'Function logn: logarithm of a to the base of n
FUNCTION logn## (a, n)
logn## = (log2##(a) / log2(n))
END FUNCTION
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(,)?
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
b = b + ...