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: needs-pullups
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed May 08 16:15:01 +0000 2024
>Closed-Date:
>Last-Modified: Tue Jul 23 21:17:45 +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
>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.