Re: Log2 seems inefficient

Paul Zimmermann via Cygwin <[email protected]>
Newsgroups gmane.os.cygwin
Message-ID <[email protected]>
       Hi,

> With default settings the worst case error in nearest rounding mode is 0.547 ULP 
> with inlined fma and fma contraction.
> It uses a 1 KB lookup table,
> ...
> Note that the math.h header defines log2(x) to be log(x)/Ln2, this is
> not changed, so the new code is only used if that macro is suppressed."
>
> Paul Zimmerman regularly posts library math function comparisons on the newlib 
> and comparable library mailing lists, available at:
> 
> 	https://members.loria.fr/PZimmermann/papers/accuracy.pdf
> 
> that should give you an idea of the current state of the functions, if he is 
> even aware of the issue.

indeed, the known worst case error for Newlib log2 is 2.06 ulp:

log2 0 -1 0x1.68d778f076021p+0 [2] [2.06] 2.05526 2.055255219183752
libm gives 0x1.fb1b88680e7adp-2
mpfr gives 0x1.fb1b88680e7abp-2

The 0.547 value above could match the GNU libc worst error:

log2 0 -1 0x1.1406d79e1b574p+0 [1] [0.548] 0.547538 0.5475371438132311
libm gives 0x1.bd16a11d3404ep-4
mpfr gives 0x1.bd16a11d3404fp-4

If your goal is accuracy, you can try the CORE-MATH implementation:

https://gitlab.inria.fr/core-math/core-math/-/blob/master/src/binary64/log2/log2.c

It takes 19 cycles on average on an Intel(R) Core(TM) i7-8700, and is
correctly rounded (for any rounding mode).

Paul



-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.