RFA: patch to fix scaling in ef_hypot.c
Richard Sandiford
rsandifo@redhat.com
Tue Feb 26 06:42:00 GMT 2002
"J. Johnston" <jjohnstn@redhat.com> writes:
> > OK to apply?
>
> Yes. Thanks.
Sorry, it since dawned on me that 2**80 was a bit big. b can be
O(a * 2**-30), so if a was 2**51 and b was 2**21, reducing b by 2**80
would make b 2**-59 (< 2**-50) and both arguments would be scaled up
by 2**80 again. Shouldn't affect the accuracy at all, but a bit silly
all the same.
So, OK to install with an adjustment of 68 instead? Avoids the yo-yo
effect, while still being big enough to avoid overflow.
Tested in the same way as before, with the same results.
Richard
* libm/math/ef_hypot.c: Increasing scale factor to 80.
Index: libm/math/ef_hypot.c
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libm/math/ef_hypot.c,v
retrieving revision 1.5
diff -c -p -d -r1.5 ef_hypot.c
*** libm/math/ef_hypot.c 2001/04/04 13:36:56 1.5
--- libm/math/ef_hypot.c 2002/02/26 14:16:07
***************
*** 41,48 ****
if(FLT_UWORD_IS_INFINITE(hb)) w = b;
return w;
}
! /* scale a and b by 2**-60 */
! ha -= 0x5d800000L; hb -= 0x5d800000L; k += 60;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
--- 41,48 ----
if(FLT_UWORD_IS_INFINITE(hb)) w = b;
return w;
}
! /* scale a and b by 2**-68 */
! ha -= 0x22000000L; hb -= 0x22000000L; k += 68;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
***************
*** 54,63 ****
b *= t1;
a *= t1;
k -= 126;
! } else { /* scale a and b by 2^60 */
! ha += 0x5d800000; /* a *= 2^60 */
! hb += 0x5d800000; /* b *= 2^60 */
! k -= 60;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
--- 54,63 ----
b *= t1;
a *= t1;
k -= 126;
! } else { /* scale a and b by 2^68 */
! ha += 0x22000000; /* a *= 2^68 */
! hb += 0x22000000; /* b *= 2^68 */
! k -= 68;
SET_FLOAT_WORD(a,ha);
SET_FLOAT_WORD(b,hb);
}
More information about the Newlib
mailing list