[PATCH 2/5] Use fabs(x) instead of branching on signedness of input to sin and cos

Manfred mx2927@gmail.com
Tue Aug 23 20:53:00 GMT 2016



On 08/23/2016 08:22 PM, Siddhesh Poyarekar wrote:

> @@ -181,10 +181,7 @@ do_cos_slow (mynumber u, double x, double dx, double eps, double *corp)
>    cor = cor + ((cs - y) - e1 * x1);
>    res = y + cor;
>    cor = (y - res) + cor;
> -  if (cor > 0)
> -    cor = 1.0005 * cor + eps;
> -  else
> -    cor = 1.0005 * cor - eps;
> +  cor = 1.0005 * cor + ((cor > 0) ? eps : -eps);
>    *corp = cor;
>    return res;

If eps is known to be >=0 then
 > +  cor = 1.0005 * cor + ((cor > 0) ? eps : -eps);
might be written as
cor = 1.0005 * cor + copysign(eps, cor);

Similarly to fabs(), copysign() avoids a branch - or a potential one 
from the ternary.



More information about the Libc-alpha mailing list