This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] hypotf fails for denormal inputs


Patch checked in.  Thanks.

-- Jeff J.

On Mon, 1 Aug 2005, Bob Wilson wrote:

> 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.
> 
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]