[Bug libgcc/116017] New: libgcc/riscv/softfp: Fix loss of sign when truncating NaN values
keithp at keithp dot com
gcc-bugzilla@gcc.gnu.org
Sat Jul 20 18:45:24 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116017
Bug ID: 116017
Summary: libgcc/riscv/softfp: Fix loss of sign when truncating
NaN values
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: keithp at keithp dot com
Target Milestone: ---
Created attachment 58714
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58714&action=edit
Proposed patch
Using soft float to truncate 128-bit -nan to 64-bit float loses the sign bit.
When _FP_KEEP_NANFRACP is not set, the fraction *and sign* of a NaN value are
discarded in _FP_PACK_SEMIRAW causing this problem.
I'll note that riscv is the only target which doesn't set this value, so it
could also be that the _FP_KEEPNANFRACP code is just broken?
Test application:
#include <stdio.h>
#include <math.h>
int main(void)
{
volatile long double ld;
volatile double d;
ld = (long double) NAN;
ld = -ld;
d = ld;
printf("%a\n", d);
return signbit(d) ? 0 : 1;
}
More information about the Gcc-bugs
mailing list