standards/83845: [ patch ] add log2() and log2f() support for
libm
David Schultz
das at FreeBSD.ORG
Thu Jul 21 18:10:21 GMT 2005
The following reply was made to PR standards/83845; it has been noted by GNATS.
From: David Schultz <das at FreeBSD.ORG>
To: Roman Bogorodskiy <bogorodskiy at gmail.com>
Cc: FreeBSD-gnats-submit at FreeBSD.ORG
Subject: Re: standards/83845: [ patch ] add log2() and log2f() support for libm
Date: Thu, 21 Jul 2005 14:07:08 -0400
On Thu, Jul 21, 2005, Roman Bogorodskiy wrote:
> Add e_log2.c and e_log2f.c files based on e_log.c and e_logf.c
> respectively which adds support of C99 funtions log2() and log2f().
>
> The idea is simple:
>
> log(N) to base A is equal to logN/logA, that way, log2(x) = log(x)/log(2).
> So after some simplifications and deviding result by precalculated value of
> log(2) we can compute the value of the logarithm of argument x to base 2.
Though this seems like a reasonable approach, it leads to
significant rounding errors since it requires dividing an inexact
result (ln(x) rounded to 52 bits) by another inexact quantity
(ln(2) rounded to 52 bits). For instance, I suspect that if you
computed log2(2), log2(4), log2(8), log2(16), ... using your
implementation, the results would not always be exact.
Technically speaking I don't think they are required to be exact,
but common sense suggests that they ought to be.
A more minor objection is that log2() can be computed more quickly
than log(), but this impelementation does it less quickly. This
isn't such a big deal, though; I'm more concerned about the
problem that accuracy guarantees will be significantly weaker than
for other routines in libm.
--David
More information about the freebsd-standards
mailing list