Hello, actually, we have to say that the source code of log2() into newlib:
https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libm/common/log2.c;h=e48c16cf8014b5ba4b3a89af261f54472d643f65;hb=HEAD and the source code of log2() into glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/ieee754/dbl-64/e_log2.c;h=872cebddd8b4283edd2e653167035c0fd527f3ea;hb=HEAD are identical, so we can assume that this code is correct and probably the best we can get in terms of speed. However, here the problem is different. Using log() and the property of the logarithms for changing the base is mathematically correct. But here, it is WRONG. Unfortunately, this method doesn't provide the right result because the intrinsic format of IEEE-754 numbers propagates a precision error. Calculating the log2 of 2^1023 is a perfect integer number and it's 1023, not 1023.00000000000011. So, in my opinion that macro MUST be removed and the genuine log2() function must be used instead. Thank you very much for your time. Sincerely, Carlo Bramini. Il giorno dom 7 giu 2026 alle ore 01:24 KENNON J CONRAD <[email protected]> ha scritto: > > Should have written "I found that using log2 directly on my computer was > slower than using log > with the divide". > > > On 06/06/2026 4:06 PM PDT KENNON J CONRAD via Cygwin <[email protected]> > > wrote: > > > > > > Hello Carlo B., > > > > There was another discussion of this issue back in January. Beware, at the > > time I found that > > using log2 directly on my computer was slower than using log2 with the > > divide (by removing the > > same lines you mention in math.h). It seems to me that in a perfect world, > > using log2 should > > be both more accurate and faster than calling log and dividing the result > > by a constant. > > > > Best Regards, > > > > Kennon Conrad > > > > https://cygwin.com/pipermail/cygwin/2026-January/259314.html > > > > > On 06/06/2026 9:53 AM PDT Carlo B. via Cygwin <[email protected]> wrote: > > > > > > > > > Hello, > > > > > > Il Sab 6 Giu 2026, 14:19 Dimitry Andric <[email protected]> ha > > > scritto: > > > > > > > > > > > It's been defined like that since the "import newlib-2000-02-17 > > > > snapshot", > > > > so for 26 years: > > > > > > > > > > > > https://sourceware.org/git/?p=newlib-cygwin.git;a=blob;f=newlib/libc/include/math.h;h=d3f2e99ae4d33596b608225f0349a6d581d265ca;hb=8a0efa53e44919bcf5ccb1d3353618a82afdf8bc#l103 > > > > > > > > My guess is that at the time, there wasn't yet a separate log2() > > > > implementation, so this was an easy way to cover that case. > > > > > > > > > > Thank you very much for the reply. > > > So, do you think that it would be possible to remove those lines from > > > math.h and use the log2() now provided? > > > > > > Sincerely, > > > > > > Carlo Bramini > > > > > > > > > > -Dimitry > > > > > > > > > > > > > > -- > > > 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 > > > > -- > > 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 -- 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

