Re: [PATCH] Fix error in float trig. function range reduction

Corinna Vinschen <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
On Mar  3 14:49, Fabian Schriever wrote:
> The single-precision trigonometric functions show rather high errors in
> specific ranges starting at about 30000 radians. For example the sinf
> procedure produces an error of 7626.55 ULP with the input
> 5.195880078125e+04 (0x474AF6CD) (compared with MPFR in 128bit
> precision). For the test we used 100k values evenly spaced in the range
> of [30k, 70k]. The issues are periodic at higher ranges.
> 
> This error was introduced when the double precision range reduction was
> first converted to float. The shift by 8 bits always returns 0 as iq is
> never higher than 255.
> 
> The fix reduces the error of the example above to 0.45 ULP, highest
> error within the test set fell to 1.31 ULP, which is not perfect, but
> still a significant improvement. Testing other previously erroneous
> ranges no longer show particularly large accuracy errors.
> ---
>  newlib/libm/math/kf_rem_pio2.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/newlib/libm/math/kf_rem_pio2.c b/newlib/libm/math/kf_rem_pio2.c
> index 1573ca9f6..3ca7cc20d 100644
> --- a/newlib/libm/math/kf_rem_pio2.c
> +++ b/newlib/libm/math/kf_rem_pio2.c
> @@ -101,7 +101,7 @@ recompute:
>  	    iq[jz-1] -= i<<(8-q0);
>  	    ih = iq[jz-1]>>(7-q0);
>  	} 
> -	else if(q0==0) ih = iq[jz-1]>>8;
> +	else if(q0==0) ih = iq[jz-1]>>7;
>  	else if(z>=(float)0.5) ih=2;
>  
>  	if(ih>0) {	/* q > 0.5 */
> -- 
> 2.24.1.windows.2
> 

Pushed.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEoVYPmneWZnwT6kwF9TYGna5ET6AFAl5ee7gACgkQ9TYGna5E
T6C3PQ//YyinIsrl6VWLRwCK7mtXd7ugIFMfsuvx9nXZU37WSJElzlv9dG2LLOxf
K8cUbaraJpOP17Om6ggHTsaXC/2m1rX8HnSdnK/3p1MIXrX48MhQhgYRSiIyVN9F
0Ac2PcoVvllP/QZbNJ1XwXg0uokjS0HRt64FCs387WBlVrKHbssg1Xcw0ulS/SeF
wqUZfP96EXp++yWoBR2K9e2/c1P9jfvXlE0LazEdLjJyQ8J6vJuviGniL9GJwrR4
BCsVjrnhRO9bYQvemBaYKw7h6lxE24TZlp9GtCXTPTVayS5PQ4AZAGKDysCeHDEy
fZmGVUHfJNso+F3diHh313w36StCrbUyTMuY9+38Iu6KIL2osjjMfrMRCKBNOick
cWrBKaDbhIhoST2QTuyNmErio+LKuDda0kF5Dgg9rcYWKpJJx5Hp5oHbkN3A3jbA
PEmS38PemPgIamxhA/wPDbrWMmMjYLQZUTuvZUC2vGdf+blVEFqn/5SabohoQVpr
rGZ82shGerPRToxarpW1cXjah9eck7mT3JLX1/+Oepl0zOnevPRRxqM08LpaygCK
dzUFoyGIMqNUaLe8/eJjTO1I2hJzb6FE+DJiBM5DpNJguhabmnpw/sHwavAXXskH
sJl6rLU6NXGN45hDVVMbYZ7yIwa+dUyf8XZQtEhLsKJby/msEP4=
=K1Np
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.