delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2021/06/13/15:20:00

X-Recipient: archive-cygwin AT delorie DOT com
X-Original-To: cygwin AT cygwin DOT com
Delivered-To: cygwin AT cygwin DOT com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8851385BF9C
Authentication-Results: sourceware.org; dmarc=none (p=none dis=none)
header.from=SystematicSw.ab.ca
Authentication-Results: sourceware.org;
spf=none smtp.mailfrom=systematicsw.ab.ca
X-Authority-Analysis: v=2.4 cv=H864f8Ui c=1 sm=1 tr=0 ts=60c65a4c
a=T+ovY1NZ+FAi/xYICV7Bgg==:117 a=T+ovY1NZ+FAi/xYICV7Bgg==:17
a=r77TgQKjGQsHNAKrUKIA:9 a=CCpqsmhAAAAA:8 a=94nOnFI1EgyDtX4ev68A:9
a=QEXdDO2ut3YA:10 a=zb6ZufOp78YA:10 a=WZ2tzKod9SOGMvyo4TUA:9
a=JMNH9X61SiQA:10 a=ul9cdbp4aOFLsgKbc677:22
From: Brian Inglis <Brian DOT Inglis AT SystematicSw DOT ab DOT ca>
Subject: Re: gcc 11.1.0: printf("%.43f\n", 0x1.52f8a8e32e982p-140): printed
value is incorrectly rounded
To: cygwin AT cygwin DOT com
References: <CAL9Mx1uMOz2wfqbMpD_xfA=D9JkpFzVz6AR_DKHK34AvrGOP6w AT mail DOT gmail DOT com>
Organization: Systematic Software
Message-ID: <6879a094-2bfd-dc85-352f-6c6305fe4c9a@SystematicSw.ab.ca>
Date: Sun, 13 Jun 2021 13:19:38 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
MIME-Version: 1.0
In-Reply-To: <CAL9Mx1uMOz2wfqbMpD_xfA=D9JkpFzVz6AR_DKHK34AvrGOP6w@mail.gmail.com>
X-CMAE-Envelope: MS4xfAi2JlLhFRfs547H0I2AYQE2///hUqEU2fg3hl7FgeIKZe59hJknsIUTMuPRF+u8qX5NKTl52oX/oV6jMk/GMuOgxS0nxFgIEHo7J1MU1gp2tQ8sM6xy
eR/8aCyUHoFvQw08EfYrqz1o2SIKgOKUj/VWCnGdZygvjPdDv49R9bq8InwsD4LV/eIb/VHovDs9tTOXn2ZTzxfoxXgD7raCzSM=
X-Spam-Status: No, score=-3487.7 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS,
KAM_LAZY_DOMAIN_SECURITY, KAM_LOTSOFHASH, NICE_REPLY_A,
RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,
RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE,
TXREP autolearn=no autolearn_force=no version=3.4.2
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on
server2.sourceware.org
X-BeenThere: cygwin AT cygwin DOT com
X-Mailman-Version: 2.1.29
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>
Reply-To: cygwin AT cygwin 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>

This is a multi-part message in MIME format.
--------------0C5D12B9F77078B2EE28FB72
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit

On 2021-06-12 14:45, Pavel M via Cygwin wrote:
> Sample code (t903.c):
> #include <stdio.h>
> int main(void)
> {
>      printf("%.43f\n", 0x1.52f8a8e32e982p-140);
>      return 0;
> }
> 
> Invocations:
> # gcc on Windows 10 (Cygwin)
> $ gcc t903.c -Wall -Wextra -std=c11 -pedantic -Wfatal-errors && ./a.exe
> 0.0000000000000000000000000000000000000000010
> 
> $ gcc --version
> gcc (GCC) 11.1.0
> 
> # gcc on Linux
> $ gcc t903.c -Wall -Wextra -std=c11 -pedantic -Wfatal-errors && ./a.exe
> 0.0000000000000000000000000000000000000000009
> 
> # clang on Windows
> $ clang t903.c -Wall -Wextra -std=c11 -ffp-model=strict -pedantic
> -Wfatal-errors && ./a.exe
> 0.0000000000000000000000000000000000000000009
> 
> # cl on Windows
> $ cl t903.c /std:c11 /Za /fp:strict && ./t903.exe
> 0.0000000000000000000000000000000000000000009

See newlib mailing list incorrectly rounded square root thread starting:

	https://sourceware.org/pipermail/newlib/2021/018369.html

As suggested lately, I tried adding -frounding-math

	$ info gcc frounding-math

to see if it makes any difference to your test on gcc 10 and got the 
same result.
It may need to be applied to the library functions to have any useful 
impact.

I also tried Cygwin clang and got the same result.

It may be an accuracy issue or a bug in the underlying newlib printf 
conversion.

I tried fcvtbuf in the attached test program and found it does the 
rounding as expected on Cygwin:

$ gcc -o test-printf-round{,.c} && ./test-printf-round
sgn 0 decpt -42 +0.0000000000000000000000000000000000000000009 
0.0000000000000000000000000000000000000000010

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.
[Data in binary units and prefixes, physical quantities in SI.]


--------------0C5D12B9F77078B2EE28FB72
Content-Type: text/plain; charset=UTF-8;
 name="test-printf-round.c"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="test-printf-round.c"

LyogdGVzdC1wcmludGYtcm91bmQuYyAqLwoKI2RlZmluZSBfUE9TSVhfU09VUkNFCiNkZWZp
bmUgX1hPUEVOX1NPVVJDRQk2MDAKCiNpbmNsdWRlIDxzdGRpby5oPgojaW5jbHVkZSA8c3Rk
bGliLmg+CiNpbmNsdWRlIDxzdHJpbmcuaD4KCgoKI2lmIDAKI2RlZmluZSBWCQkwWDEuNTJm
OGE4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JREVDSU1BTFMsIFYpOwp9Cgo=
--------------0C5D12B9F77078B2EE28FB72
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


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

--------------0C5D12B9F77078B2EE28FB72--

- Raw text -


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