[Haskell-cafe] Confused about logBase
Alexey Khudyakov
alexey.skladnoy at gmail.com
Thu Aug 25 19:27:24 UTC 2016
On 25 August 2016 at 00:51, MarLinn via Haskell-Cafe
<haskell-cafe at haskell.org> wrote:
> Hi,
>
> I discovered that in base logBase, the functions representing arbitrary
> logarithms, are defined in terms of two applications of log. log, the
> functions representing the natural logarithm, just pass responsibility on to
> some primitives. That is fine, mathematically speaking. But from an
> implementation standpoint, I wonder why one would do that.
>
> The logarithm that should be the fastest and the most precise one to
> approximate by a cpu should be the one to base two. In fact if one already
> has a floating point representation, it should be almost ridiculously easy
> to compute from the exponent.
>
Speaking of precision. log in any base is a transcendental function
so best we can do is to ensure that approximation differs from true
answer no more that 0.5 ULPs.
Also I don't think log in base 2 would be any more performant than
natural logarithm. Yes calculations for exponent is easy but you still
need to calculate it for mantissa and it's not easier task. And most
of the time natural logarithm is used.
More information about the Haskell-Cafe
mailing list