www.delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2026/01/19/21:50:50

DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 60K2onjk497253
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 60K2onjk497253
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=IQj1hmhL
X-Recipient: archive-cygwin AT delorie DOT com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E0FD4BBCDF9
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
s=default; t=1768877449;
bh=5rtH0tKC9j43/xPjSTzU1PTxyImTTjkxiBtFiokg530=;
h=Date:To:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:
List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
From;
b=IQj1hmhLRxKb/okxT/T/Fd2G/tPBAbJnLWNfOJVL4ZUfp9Q6F6mXxJEApFw1a0Tpc
aKNn0kDRGbdGzk5Ru3Uge1NuhLyyBM5UI0r7gv4YUX0ZCHhvaO8PYlblHflUo0hnIR
v9jlxzy2PQeCxmjrfMUb7ux7JxusXpDULf0cVQxQ=
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E024B4BA9003
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E024B4BA9003
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1768877399; cv=none;
b=YO/0h6b5f2Vymv5LCg4th13tH6TkHBbNBxJRJJB2fqamULooMXImp+HH3EAVxh2dbreVYoSps89I0HKP2U5o9EQvTly78lYkhJSdgzfKZ0GWJOWfOSh6OgEJ6/KeJ10NbLXtMp690UPMl2aCJjJnbfKK/PmkCV70UMQ96fnZ6xc=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
t=1768877399; c=relaxed/simple;
bh=zEm98BUg+20hV7MNkdfn8OntNcH8tmi8sCsYkHd5PYM=;
h=DKIM-Signature:Date:From:To:Message-ID:Subject:MIME-Version;
b=TqTRn0kgGe/YaKqL+7+3gMAZlVjiaF1NUw4dNSald1wkDMZvGwaV1VhmPtsg0mNON4wxR7iXUNJuEfshj9irBwITSuuUVVHLuNl91IOTOmQ31JDg1bXYub4IWia9+QkOqTZjYqwV+xDPHdP2f+UmhtSPjHZD0qhAG4yLDr4ctb0=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E024B4BA9003
Date: Mon, 19 Jan 2026 18:49:56 -0800 (PST)
To: Paul Zimmermann <Paul DOT Zimmermann AT inria DOT fr>,
Paul Zimmermann via Cygwin <cygwin AT cygwin DOT com>
Message-ID: <335671721.621101.1768877396354@connect.xfinity.com>
In-Reply-To: <p9u0ikcyugor.fsf@araignee.loria.fr>
References: <226987210 DOT 591128 DOT 1768766440723 AT connect DOT xfinity DOT com>
<3c56778a-870c-4bae-a855-6b96392870c8 AT SystematicSW DOT ab DOT ca>
<p9u0ikcyugor DOT fsf AT araignee DOT loria DOT fr>
Subject: Re: Log2 seems inefficient
MIME-Version: 1.0
X-Priority: 3
Importance: Normal
X-Mailer: Open-Xchange Mailer v7.10.6-Rev83
X-Originating-IP: ::ffff:50.47.202.14
X-Originating-Port: 23214
X-Originating-Client: open-xchange-appsuite
X-CMAE-Envelope: MS4xfDf8ygFCU7cWxZRYohVxlt1GPwf3AJPfWu15aYgMewUyiHqaf6RtmpfVTrL+iesLjrcYS55V9eEvykZRg9VbglTXkcq0q23CrC4hB5QXHRjoTKqsbaFk
gD1NWCpXdL0GLP1IqH7hImokCx0tOp9BOeNDM6ofQ7PkJ88eXYF+JfXn8Ae8ohitF6mF5gopBqXDdPFGiHOF41CHTizD80u8eGweuxlct5Nb4M1cO1KLjbKc
RC0QaEm4KIlzPsPOz3QMwQ==
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: KENNON J CONRAD via Cygwin <cygwin AT cygwin DOT com>
Reply-To: KENNON J CONRAD <kennonconrad AT comcast DOT net>
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>

Thank you, Paul.  It looks like it would be worth a try as the current log2 implementation from Cygwin is clearly not optimal for either speed or accuracy.  This may be a stupid question, but what would be the easiest way to incorporate this into open source software?  Should I rename the function and copy the (slightly modified) source code into the distribution?

Best Regards,

Kennon

 
> On 01/19/2026 12:53 AM PST Paul Zimmermann via Cygwin <cygwin AT cygwin DOT com> wrote:
> 
>  
> 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

-- 
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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019