NetBSD Problem Report #58236
From www@netbsd.org Wed May 8 16:14:24 2024
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))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 0AB6C1A9238
for <gnats-bugs@gnats.NetBSD.org>; Wed, 8 May 2024 16:14:24 +0000 (UTC)
Message-Id: <20240508161422.9E7D61A923B@mollari.NetBSD.org>
Date: Wed, 8 May 2024 16:14:22 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: nexttoward(3) is broken on subnormals
X-Send-Pr-Version: www-1.0
>Number: 58236
>Category: lib
>Synopsis: nexttoward(3) is broken on subnormals
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: lib-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed May 08 16:15:01 +0000 2024
>Closed-Date: Sun Oct 13 20:26:42 +0000 2024
>Last-Modified: Sun Oct 13 20:26:42 +0000 2024
>Originator: Taylor R Campbell
>Release: current, 10, 9, ...
>Organization:
The nexttowarbsd(3) Foundation
>Environment:
>Description:
nexttoward(k*n, INFINITY) should return (k + 1)*n, where n is the smallest positive subnormal and k is any integer below 2^p. But instead it returns (k - 1)*n.
Similarly, nexttoward(k*n, -INFINITY) should return (k - 1)*n, but it returns (k + 1)*n.
>How-To-Repeat:
$ cat test.c
#include <math.h>
#include <stdio.h>
int
main(void)
{
volatile double n = __DBL_DENORM_MIN__;
volatile double d = INFINITY;
printf("123*n goes up to %.0f*n\n", nextafter(123*n, d)/n);
printf("123*n goes down to %.0f*n\n", nextafter(123*n, -d)/n);
fflush(stdout);
return ferror(stdout);
}
$ make test LDLIBS=-lm
cc -O2 -o test test.c -lm
$ ./test
123*n goes up to 124*n
123*n goes down to 122*n
>Fix:
Yes, please!
>Release-Note:
>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/58236 CVS commit: src/tests/lib/libm
Date: Wed, 8 May 2024 17:27:04 +0000
Module Name: src
Committed By: riastradh
Date: Wed May 8 17:27:04 UTC 2024
Modified Files:
src/tests/lib/libm: t_next.c
Log Message:
tests/lib/libm/t_next: Expand substantially.
This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/lib/libm/t_next.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/58236 CVS commit: src
Date: Sat, 11 May 2024 02:07:54 +0000
Module Name: src
Committed By: riastradh
Date: Sat May 11 02:07:54 UTC 2024
Modified Files:
src/lib/libm/src: s_nexttoward.c
src/tests/lib/libm: t_next.c
Log Message:
nexttoward(3): Fix high-word test on small positive subnormals.
By this point in the logic, x can't be zero, so it's either positive
or negative.
The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.
hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.
PR lib/58236
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libm/src/s_nexttoward.c
cvs rdiff -u -r1.5 -r1.6 src/tests/lib/libm/t_next.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: open->needs-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Tue, 23 Jul 2024 21:17:45 +0000
State-Changed-Why:
fixed in HEAD, needs pullup-10 and pullup-9
State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sun, 13 Oct 2024 00:57:20 +0000
State-Changed-Why:
pullup-10 #963 https://releng.netbsd.org/cgi-bin/req-10.cgi?show=963
pullup-9 #1906 https://releng.netbsd.org/cgi-bin/req-9.cgi?show=1906
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/58236 CVS commit: [netbsd-10] src
Date: Sun, 13 Oct 2024 15:05:18 +0000
Module Name: src
Committed By: martin
Date: Sun Oct 13 15:05:18 UTC 2024
Modified Files:
src/distrib/sets/lists/debug [netbsd-10]: mi
src/distrib/sets/lists/tests [netbsd-10]: mi
src/lib/libm/src [netbsd-10]: s_nexttoward.c
src/tests/lib/libm [netbsd-10]: Makefile
Added Files:
src/tests/lib/libm [netbsd-10]: t_next.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #963):
tests/lib/libm/Makefile: revision 1.49
distrib/sets/lists/tests/mi: revision 1.1315
tests/lib/libm/t_next.c: revision 1.1
tests/lib/libm/t_next.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.435
tests/lib/libm/t_next.c: revision 1.3
tests/lib/libm/t_next.c: revision 1.4
tests/lib/libm/t_next.c: revision 1.5
tests/lib/libm/t_next.c: revision 1.6
lib/libm/src/s_nexttoward.c: revision 1.3
tests/lib/libm: Test nextafter/nexttoward and variants.
The tests are fairly trivial but should work without any conditionals
about floating-point formats.
tests/lib/libm/t_next: Disable this test on VAX.
But leave a replacement xfail test that fails unconditionally, to
leave a reminder in the tests of PR 57881: vax libm is missing
various symbols.
tests/lib/libm/t_next: Fix stub on VAX.
Tested building the wrong tree, oops.
tests/lib/libm/t_next: Expand substantially.
This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
tests/lib/libm/t_next: nexttoward works if it's just nextafter.
It's broken on platforms where long double and double aren't the same
and nexttoward isn't an alias for nextafter.
nexttoward(3): Fix high-word test on small positive subnormals.
By this point in the logic, x can't be zero, so it's either positive
or negative.
The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.
hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.
PR lib/58236
To generate a diff of this commit:
cvs rdiff -u -r1.394.2.12 -r1.394.2.13 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.1238.2.14 -r1.1238.2.15 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.2 -r1.2.36.1 src/lib/libm/src/s_nexttoward.c
cvs rdiff -u -r1.48.2.2 -r1.48.2.3 src/tests/lib/libm/Makefile
cvs rdiff -u -r0 -r1.7.4.2 src/tests/lib/libm/t_next.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/58236 CVS commit: [netbsd-9] src
Date: Sun, 13 Oct 2024 15:09:58 +0000
Module Name: src
Committed By: martin
Date: Sun Oct 13 15:09:58 UTC 2024
Modified Files:
src/distrib/sets/lists/debug [netbsd-9]: mi
src/distrib/sets/lists/tests [netbsd-9]: mi
src/lib/libm/src [netbsd-9]: s_nexttoward.c
src/tests/lib/libm [netbsd-9]: Makefile
Added Files:
src/tests/lib/libm [netbsd-9]: t_next.c
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #963):
tests/lib/libm/Makefile: revision 1.49
distrib/sets/lists/tests/mi: revision 1.1315
tests/lib/libm/t_next.c: revision 1.1
tests/lib/libm/t_next.c: revision 1.2
distrib/sets/lists/debug/mi: revision 1.435
tests/lib/libm/t_next.c: revision 1.3
tests/lib/libm/t_next.c: revision 1.4
tests/lib/libm/t_next.c: revision 1.5
tests/lib/libm/t_next.c: revision 1.6
lib/libm/src/s_nexttoward.c: revision 1.3
(all via patch)
tests/lib/libm: Test nextafter/nexttoward and variants.
The tests are fairly trivial but should work without any conditionals
about floating-point formats.
tests/lib/libm/t_next: Disable this test on VAX.
But leave a replacement xfail test that fails unconditionally, to
leave a reminder in the tests of PR 57881: vax libm is missing
various symbols.
tests/lib/libm/t_next: Fix stub on VAX.
Tested building the wrong tree, oops.
tests/lib/libm/t_next: Expand substantially.
This covers many more potential problem areas -- and includes a new
xfail test for PR lib/58236: nexttoward(3) is broken on subnormals.
tests/lib/libm/t_next: nexttoward works if it's just nextafter.
It's broken on platforms where long double and double aren't the same
and nexttoward isn't an alias for nextafter.
nexttoward(3): Fix high-word test on small positive subnormals.
By this point in the logic, x can't be zero, so it's either positive
or negative.
The high word hx, however, can be zero, when x is a small positive
subnormal. This means x is a small positive subnormal, so if x > y
we are computing nextDown, and if x < y we are computing nextUp.
hx is a (signed 32-bit) integer, not a double floating-point number,
so it's a little silly to compare hx > 0.0. But that on its own
isn't enough to trigger the bug because all signed 32-bit integers
can be represented by double on all NetBSD architectures.
PR lib/58236
To generate a diff of this commit:
cvs rdiff -u -r1.285.2.9 -r1.285.2.10 src/distrib/sets/lists/debug/mi
cvs rdiff -u -r1.818.2.7 -r1.818.2.8 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.2 -r1.2.28.1 src/lib/libm/src/s_nexttoward.c
cvs rdiff -u -r1.46 -r1.46.2.1 src/tests/lib/libm/Makefile
cvs rdiff -u -r0 -r1.7.6.2 src/tests/lib/libm/t_next.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
State-Changed-From-To: pending-pullups->closed
State-Changed-By: riastradh@NetBSD.org
State-Changed-When: Sun, 13 Oct 2024 20:26:42 +0000
State-Changed-Why:
fixed in HEAD, pulled up to 9 and 10
>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-2024
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.