NetBSD Problem Report #59264
From www@netbsd.org Mon Apr 7 00:46:20 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
client-signature RSA-PSS (2048 bits) client-digest SHA256)
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id AFEC01A9239
for <gnats-bugs@gnats.NetBSD.org>; Mon, 7 Apr 2025 00:46:20 +0000 (UTC)
Message-Id: <20250407004619.346451A923C@mollari.NetBSD.org>
Date: Mon, 7 Apr 2025 00:46:19 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: t_strtod:strtod_gherman_bug test is failing
X-Send-Pr-Version: www-1.0
>Number: 59264
>Category: port-vax
>Synopsis: t_strtod:strtod_gherman_bug test is failing
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: port-vax-maintainer
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Apr 07 00:50:00 +0000 2025
>Last-Modified: Mon Apr 07 02:30:02 +0000 2025
>Originator: Taylor R Campbell
>Release: current
>Organization:
The VaxBSD Floating-point Halfway House
>Environment:
>Description:
Termination reason
FAILED: 1 checks failed; see output for more details
Standard error stream
*** Check failed: /tmp/build/2025.04.04.21.52.19-vax/src/tests/lib/libc/stdlib/t_strtod.c:334: d != 0x1.d34fd8378ea83p+0: d=1.82544=0xe.9a7ec1bc7541cp-3
https://releng.netbsd.org/b5reports/vax/2025/2025.04.04.21.52.19/test.html#lib_libc_stdlib_t_strtod_strtod_gherman_bug
Relevant information about the bug in parsing the decimal notation for a number verrrrrrrrrrry close to halfway between two binary floating-point numbers:
https://www.exploringbinary.com/a-bug-in-the-bigcomp-function-of-david-gays-strtod/
https://web.archive.org/web/20241212101326/https://www.exploringbinary.com/a-bug-in-the-bigcomp-function-of-david-gays-strtod/
The notation is confusing because printf on VAX uses 0xe as the leading hex digit instead of 0x1, but once you shift it, you see the result is off by a single bit in the least significant place:
Expected: 0x1.d34fd8378ea830p+0
VAXctual: 0x1.d34fd8378ea838p+0
^
Before the Geza Herman bug fix chronicled at https://www.exploringbinary.com/a-bug-in-the-bigcomp-function-of-david-gays-strtod/, strtod would erroneously return 0x1.d34fd8378ea84p+0 _in IEEE 754 binary64 arithmetic_.
But IEEE 754 binary64 arithmetic uses 53-bit precision, whereas VAX D (double) arithmetic uses 56-bit precision.
I used Sollya and MIT Scheme to verify that the answer we compute on VAX is correct:
;;; Sollya, with 1000-bit floating-point approximation
> prec=1000;
The precision has been set to 1000 bits.
> display = hexadecimal;
Display mode is hexadecimal numbers.
> round(1.8254370818746402660437411213933955878019332885742187, double, RN);
Warning: Rounding occurred when converting the constant "1.8254370818746402660437411213933955878019332885742187" to floating-point with 1000 bits.
If safe computation is needed, try to increase the precision.
0x1.d34fd8378ea83p0
> round(1.8254370818746402660437411213933955878019332885742187, 53, RN);
Warning: Rounding occurred when converting the constant "1.8254370818746402660437411213933955878019332885742187" to floating-point with 1000 bits.
If safe computation is needed, try to increase the precision.
0x1.d34fd8378ea83p0
> round(1.8254370818746402660437411213933955878019332885742187, 56, RN);
Warning: Rounding occurred when converting the constant "1.8254370818746402660437411213933955878019332885742187" to floating-point with 1000 bits.
If safe computation is needed, try to increase the precision.
0x1.d34fd8378ea838p0
;;; MIT Scheme, entirely with arbitrary-precision bignum integer arithmetic -- note that we start with a leading 1 bit, so the inner shift is by p-1 (p=53 for binary64, p=56 for VAX D), not by p; then the outer shift is to adjust the leading hexadecimal digit to match.
(number->string (* 16 (round (* #e1.8254370818746402660437411213933955878019332885742187 (expt 2 52)))) #x10)
;Value: "1d34fd8378ea830"
(number->string (* 2 (round (* #e1.8254370818746402660437411213933955878019332885742187 (expt 2 55)))) #x10)
;Value: "1d34fd8378ea838"
>How-To-Repeat:
cd /usr/tests/lib/libc/stdlib
atf-run t_strtod | atf-report
>Fix:
#if DBL_MANT_DIG == 53
ATF_CHECK_EQ_MSG(d, 0x1.d34fd8378ea83p+0, "d=%g=%a", d, d);
#elif DBL_MANT_DIG == 56
ATF_CHECK_EQ_MSG(d, 0x1.d34fd8378ea838p+0, "d=%g=%a", d, d);
#else
# error Fill in the correct answer for this machine's DBL_MANT_DIG!
#endif
>Release-Note:
>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59264 CVS commit: src/tests/lib/libc/stdlib
Date: Mon, 7 Apr 2025 02:23:22 +0000
Module Name: src
Committed By: riastradh
Date: Mon Apr 7 02:23:21 UTC 2025
Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c
Log Message:
tests/lib/libc/stdlib/t_strtod: Adapt strtod_gherman_bug to VAX.
PR port-vax/59264: t_strtod:strtod_gherman_bug test is failing
To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/tests/lib/libc/stdlib/t_strtod.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/59264 CVS commit: src/tests/lib/libc/stdlib
Date: Mon, 7 Apr 2025 02:28:01 +0000
Module Name: src
Committed By: riastradh
Date: Mon Apr 7 02:28:01 UTC 2025
Modified Files:
src/tests/lib/libc/stdlib: t_strtod.c
Log Message:
tests/lib/libc/stdlib/t_strtod: Fix strtod_gherman_bug build on VAX.
A typo (DBL_MANG_DIG) excluded this whole block, so my attempts to
compile-test it failed to find the build errors. Oops!
PR port-vax/59264: t_strtod:strtod_gherman_bug test is failing
To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/tests/lib/libc/stdlib/t_strtod.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.