[PATCH] hypotf fails for denormal inputs
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.)
unsigned int ta = 0x80000002;
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 <email@example.com>
* 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...
Size: 533 bytes
Desc: not available
More information about the Newlib