[PATCH] hypotf fails for denormal inputs

Bob Wilson bwilson@tensilica.com
Mon Aug 1 19:09:00 GMT 2005

The hypotf function in newlib gives incorrect results for denormal input values. 
  The problem occurs when the values are scaled by 2^126 because the scaling 
value is incorrectly specified without the exponent bias.  The test program 
below will demonstrate the problem -- without the patch, the value returned by 
hypotf will be zero.

(I noticed that other small but non-denormal values are scaled by 2^68 by adding 
68 to the exponent, in which case the exponent bias is not included.  For the 
denorm case, the value must be multiplied so the result will be normalized. 
Presumably someone overlooked this distinction and forgot to add the exponent 
bias for the denorm case.)

#include <math.h>
unsigned int ta = 0x80000002;
main ()
   float a = *(float *)&ta;
   float c = hypotf(a, a);
   float d = hypot(a, a);
   printf("a = %e hypotf(a,a) = %e hypot(a,a) = %e\n", a, c, d);

2005-08-01  Bob Wilson  <bob.wilson@acm.org>

         * libm/math/ef_hypot.c (__ieee754_hypotf): Add missing exponent bias
         to the value for 2^126.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hypotf-denorm.patch
Type: text/x-patch
Size: 533 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20050801/44f6d664/attachment.bin>

More information about the Newlib mailing list