RFA: Fix signbit() for 16-bit targets

Nick Clifton nickc@redhat.com
Tue May 12 21:11:00 GMT 2015

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 ?


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);
 __signbitf (float x)
-  unsigned int w;
+  __uint32_t w;
-  return (w & 0x80000000);
+  return (w & 0x80000000) != 0;
 __signbitd (double x)
-  unsigned int msw;
+  __uint32_t msw;
   GET_HIGH_WORD(msw, x);
-  return (msw & 0x80000000);
+  return (msw & 0x80000000) != 0;

More information about the Newlib mailing list