This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
RFA: Fix signbit() for 16-bit targets
- From: Nick Clifton <nickc at redhat dot com>
- To: newlib at sourceware dot org
- Date: Tue, 12 May 2015 11:05:39 +0100
- Subject: RFA: Fix signbit() for 16-bit targets
- Authentication-results: sourceware.org; auth=none
Hi Jeff, Hi Corinna,
The signbit() functions in s_signbit.c are broken for targets that use
16-bit integers. Firstly the GET_*_WORD macros expect to place their
result into a __uint32_t type, but they are being given an int type.
Secondly the result of the functions is an int, so just extracting the
sign bit via a mask is insufficient, as the result will be truncated
to 16-bits.
The patch below takes care of these problems. Tested with no
regressions on an rl78-elf toolchain.
OK to apply ?
Cheers
Nick
newlib/ChangeLog
2015-05-12 Nick Clifton <nickc@redhat.com>
* libm/common/s_signbit.c (__signbitf): Fix for 16-bit targets.
(__signbitd): Likewise.
diff --git a/newlib/libm/common/s_signbit.c b/newlib/libm/common/s_signbit.c
index 746ab46..6ea714d 100644
--- a/newlib/libm/common/s_signbit.c
+++ b/newlib/libm/common/s_signbit.c
@@ -41,19 +41,19 @@ int __signbitd (double x);
int
__signbitf (float x)
{
- unsigned int w;
+ __uint32_t w;
GET_FLOAT_WORD(w,x);
- return (w & 0x80000000);
+ return (w & 0x80000000) != 0;
}
int
__signbitd (double x)
{
- unsigned int msw;
+ __uint32_t msw;
GET_HIGH_WORD(msw, x);
- return (msw & 0x80000000);
+ return (msw & 0x80000000) != 0;
}