Consider how to represent the base. In math, log is often written as log b (n) where the b is a subscript. Although, the b is often left off, there are usually several possible bases.
We could move the base in, or, because it's a number, just place it directly after the "keyword" log? log2(64), log10(1000), loge(10) ... since that last one looks the worst, maybe e is the default base?
Okay, more research, when written as log(n) the base that is implied can change by field of study. So, this is not a great choice. We could implement the log function to take a base as the second parameter as in log(n, b) which is how Ruby implements log.
We can also use ln for natural logarithm (log with base e). And, if function names are identifiers which match a regexp like [a-zA-Z]\w+, then we could have functions log2(n) and log10(n).
So, this combination of functions feels most right:
Consider how to represent the base. In math, log is often written as
log b (n)
where theb
is a subscript. Although, theb
is often left off, there are usually several possible bases.We could move the base in, or, because it's a number, just place it directly after the "keyword" log?
log2(64)
,log10(1000)
,loge(10)
... since that last one looks the worst, maybee
is the default base?Okay, more research, when written as
log(n)
the base that is implied can change by field of study. So, this is not a great choice. We could implement thelog
function to take a base as the second parameter as inlog(n, b)
which is how Ruby implementslog
.We can also use
ln
for natural logarithm (log with basee
). And, if function names are identifiers which match a regexp like[a-zA-Z]\w+
, then we could have functionslog2(n)
andlog10(n)
.So, this combination of functions feels most right:
log(n, b)
- any baseln(n)
- natural loglog2(n)
- base 2log10(n)
- base 10