| www.delorie.com/archives/browse.cgi | search |
| DMARC-Filter: | OpenDMARC Filter v1.4.2 delorie.com 65929xgU1124667 |
| Authentication-Results: | delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com |
| Authentication-Results: | delorie.com; spf=pass smtp.mailfrom=cygwin.com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 delorie.com 65929xgU1124667 |
| Authentication-Results: | delorie.com; |
| dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=BaVhScO3 | |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 37AED4B7A1D0 |
| DKIM-Signature: | v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; |
| s=default; t=1780970998; | |
| bh=AtHcn3/6+WBmaXrqM+FN5ZYo1ldIWWCA1GcPzWbemHc=; | |
| h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: | |
| List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: | |
| From; | |
| b=BaVhScO3SQsrfCVz9XALkI1lPAYj69f8oNV7Biu0VJippXJi5OY5UVeL+7iAlyxsB | |
| YKbTXAM/TmEHUYH1odmfJLyZx9Z68jzAY16BMF8nRNUWPpn10dA5Jdw0W11cFPg9Yj | |
| NlJ5VkYwPP+tInNQ6u2Beyn4Xams652/jfK1MVR4= | |
| X-Original-To: | cygwin AT cygwin DOT com |
| Delivered-To: | cygwin AT cygwin DOT com |
| DMARC-Filter: | OpenDMARC Filter v1.4.2 sourceware.org 8D0D94BA2E25 |
| ARC-Filter: | OpenARC Filter v1.0.0 sourceware.org 8D0D94BA2E25 |
| ARC-Seal: | i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780970974; cv=none; |
| b=lzHCQN1wDw2Q0iG3Jn8LxP4cL21pxhlsxRFe1APT8Lrg5oRtsAUZynmGPxR1Bskyq/ZSZn/XbmU7E6VEGqF+Iwtrij7Qi5nV21caGn6jsY+5WKnHfsH9wOagMHxBap44LYouRLmGB6C1FT5RUePn3ikP67/sLWPRYq3PsxhW0bg= | |
| ARC-Message-Signature: | i=1; a=rsa-sha256; d=sourceware.org; s=key; |
| t=1780970974; c=relaxed/simple; | |
| bh=icqVd0Mutl/o17D/LHbmNsnSCMjJKQTXFGR8i6FyMn8=; | |
| h=DKIM-Signature:Subject:To:From:Message-ID:Date:MIME-Version; | |
| b=ctPzRAx2ZztaNl3nN7DsiSmJqUrVA5e866QiQFzt7RgaGaPEhz/tsmBbRT2Z/FYnfIxTdvmEcfpUYdEm/Uy2PK+o0/C584TxSEwtfem+eXsN9WPeG1YCO+DcdkqABeUdDgrLK50+PkOwUZQ02zqrP2nHoF7ZAut/5wPHMMJ4uzs= | |
| ARC-Authentication-Results: | i=1; sourceware.org; |
| dkim=pass (2048-bit key, unprotected) | |
| header.d=wisemo.com header.i=@wisemo.com header.a=rsa-sha256 header.s=v2016 | |
| header.b=IZEIzMJC | |
| DKIM-Filter: | OpenDKIM Filter v2.11.0 sourceware.org 8D0D94BA2E25 |
| Subject: | Re: log2() is not called for C code, a bug into math.h ? |
| To: | cygwin AT cygwin DOT com |
| References: | <CADt9577cpSu1Ke7xu6mMQgfyfdOg8qFg1YFWRXQ_4NbmJto2Ug AT mail DOT gmail DOT com> |
| <C907B908-9877-431C-B9AA-50F63ABA581C AT unified-streaming DOT com> | |
| <CADt9576meHrk_QGyqrXYZuOky_9uA478+tehwjGg38_R6R9xTA AT mail DOT gmail DOT com> | |
| <1640804308 DOT 295932 DOT 1780787212417 AT connect DOT xfinity DOT com> | |
| <2125010483 DOT 296244 DOT 1780788258493 AT connect DOT xfinity DOT com> | |
| <CADt9576CBtgj9_7tKxfHdZ+X9kUKW-8-f_3J_6j0JXNyGF=hMA AT mail DOT gmail DOT com> | |
| Organization: | WiseMo A/S |
| Message-ID: | <b0b0cad9-2adb-c4b5-8c1f-a9eba7afd979@wisemo.com> |
| Date: | Tue, 9 Jun 2026 04:09:31 +0200 |
| X-Mailer: | Epyrus/2.2.0 |
| MIME-Version: | 1.0 |
| In-Reply-To: | <CADt9576CBtgj9_7tKxfHdZ+X9kUKW-8-f_3J_6j0JXNyGF=hMA@mail.gmail.com> |
| X-BeenThere: | cygwin AT cygwin DOT com |
| X-Mailman-Version: | 2.1.30 |
| List-Id: | General Cygwin discussions and problem reports <cygwin.cygwin.com> |
| List-Unsubscribe: | <https://cygwin.com/mailman/options/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=unsubscribe> | |
| List-Archive: | <https://cygwin.com/pipermail/cygwin/> |
| List-Post: | <mailto:cygwin AT cygwin DOT com> |
| List-Help: | <mailto:cygwin-request AT cygwin DOT com?subject=help> |
| List-Subscribe: | <https://cygwin.com/mailman/listinfo/cygwin>, |
| <mailto:cygwin-request AT cygwin DOT com?subject=subscribe> | |
| From: | Jakob Bohm via Cygwin <cygwin AT cygwin DOT com> |
| Reply-To: | Jakob Bohm <jb-cygwin AT wisemo DOT com> |
| Errors-To: | cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com |
| Sender: | "Cygwin" <cygwin-bounces~archive-cygwin=delorie DOT com AT cygwin DOT com> |
| X-MIME-Autoconverted: | from base64 to 8bit by delorie.com id 65929xgU1124667 |
On 08/06/2026 10:48, Carlo B. via Cygwin wrote:
> 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.
That implementation is not what the OP apparently found in the Cygwin
copy of newlib.
And both implementations are suboptimal for the x86 family, which has
a dedicated singleinstruction log2(double) function named FY2LX in its
floating point hardware, as mentionedduring the January discussion, in
fact the basic floating point x87 instruction set offerslog10() and
ln() only via multiplying log2() by a constant from the FLDLxx
instruction family.
Something like:
#if defined(__x86_64__) || defined(__i386)
double logfuncnam(double v) {
 __asm__(
  "...lines below..." // Put ifndef __x86_64__ around "FWAIT"
  : "=t" (v) : "=t" (v) : "st(7)");
 return v;
}
#endif
; x87 assembler implementations of floating point logarithms
; Initially input is in ST(0) via register calling convention or inlining
; Somehow make sure there is at least one free entry in the ST() stack,
perhaps by
;Â Â Â telling gcc __asm__ that this is needed as shown above
"FWAIT\n\t"Â Â Â Â Â Â // Only needed if 386-, waits for 80x87 ready for new
instruction
"FLDLxx\n\t"Â Â Â Â Â // Different Lxx for log2, ln and log10
                 // This pushes a relevant constant onto the ST() stack
              // Use FLD1 = 1.0 = log2(2) for log2(a)
                 // Use FLDLN2 = ln(2) for ln(a)
                 // Use FLDLG2 = log10(2) for log10(a)
"FWAIT\n\t" Â Â Â Â Â // Only needed if 386-, waits for 80x87 ready for new
instruction
"FXCH ST(1)\n\t"Â // Put constant in ST(1), input in ST(0)
"FWAIT\n\t"Â Â Â Â Â Â // Only needed if 386-, waits for 80x87 ready for new
instruction
"FYL2X\n\t"Â Â Â Â Â Â // replace ST(0) and ST(1) by ST(1)*log2(ST(0))
"FWAIT\n\t"Â Â Â Â Â Â // Optional: Pass exception (such as zero #Z or negative
                 //  #IA arg) from FPU to CPU on Pentium and later
                 //  On 386 and older, it is enough to do nothing and
                 //  let the exception interrupt the CPU later. An FWAIT
         //  here would just waste time by halting the CPU
while the
                 //  x87 chip calculates the logarithm.
; logarithm is now in ST(0) for return
; ln() Machine code for 486+ is thus               D9 ED //   D9 C9
//Â Â Â D9 F1
; log10() Machine code for all x86 chips is thus 9B D9 EC // 9B D9 C9 //
9B D9 F1
The SSE instruction set seems to require using the x87 instruction
for logarithm anyway.
Enjoy
Jakob
--
Jakob Bohm, CIO, Partner, WiseMo A/S. https://www.wisemo.com
Transformervej 29, 2860 Søborg, Denmark. Direct +45 31 13 16 10
This public discussion message is non-binding and may contain errors.
WiseMo - Remote Service Management for PCs, Phones and Embedded
--
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |