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

Joseph Myers joseph@codesourcery.com
Tue Aug 23 23:05:00 GMT 2016


On Tue, 23 Aug 2016, Manfred wrote:

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

That should be __copysign for namespace reasons (though they should 
generally do the same thing because of inlines in math_private.h).

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Libc-alpha mailing list