Subject: Re: lib/32861: frexp returns incorrect value for small floating-point
To: None <lib-bug-people@netbsd.org, gnats-admin@netbsd.org,>
From: Matthias Drochner <M.Drochner@fz-juelich.de>
List: netbsd-bugs
Date: 02/17/2006 17:15:04
The following reply was made to PR lib/32861; it has been noted by GNATS.

From: Matthias Drochner <M.Drochner@fz-juelich.de>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Subject: Re: lib/32861: frexp returns incorrect value for small floating-point 
 values
Date: Fri, 17 Feb 2006 18:14:16 +0100

 fxcoudert@gcc.gnu.org said:
 > $ gcc b.c -lm && ./a.out
 > frexp(4.94066e-324, &e) = 0.5: 0.5 * 2^-1022 = 4.94066e-324 
 
 For some historic reason there is an implementation of frexp()
 in libc. That one is broken for denormalized numbers.
 The sources for a working one are present in the fdlibm originating
 from Sun; enabling it is as easy as:
 
 
 Index: Makefile
 ===================================================================
 RCS file: /cvsroot/src/lib/libm/Makefile,v
 retrieving revision 1.71
 diff -u -r1.71 Makefile
 --- Makefile    17 Jan 2006 13:16:08 -0000      1.71
 +++ Makefile    17 Feb 2006 16:46:02 -0000
 @@ -137,7 +137,7 @@
         w_pow.c w_powf.c w_remainder.c w_remainderf.c w_scalb.c w_scalbf.c \
         w_sinh.c w_sinhf.c w_sqrt.c w_sqrtf.c \
         lrint.c lrintf.c llrint.c llrintf.c lround.c lroundf.c llround.c \
 -       llroundf.c
 +       llroundf.c s_frexp.c
 
  # math routines for non-IEEE architectures.
  NOIEEE_SRCS = n_asincos.c n_acosh.c n_asinh.c n_atan.c n_atanh.c n_cosh.c \
 
 
 I'm just telling this as a quick hack and for testing; a fix I'd call clean
 would involve:
 1. add the function to libm
 2. bump libm's library minor number
 3. fix distribution file lists for (2)
 4. move the libc implementation to the "compat" area
 5. move the manpage source to libm, fix the "LIBRARY" section
 
 Since (2) and (3) are relatively expensive, I wouldn't
 do it just for frexp(), but check other candidates before (most
 notably  fabs()).
 
 best regards
 Matthias