[PATCH, Fortran] Extension: COTAN and degree-valued trig intrinsics with -fdec-math

Joseph Myers joseph@codesourcery.com
Wed Sep 28 01:12:00 GMT 2016


On Mon, 26 Sep 2016, Tobias Burnus wrote:

> Regarding the decimal trigonometric functions, the internet suggests to
> use
>    sin (fmod ((x), 360) * M_PI / 180)
> instead of
>    sin (x * M_PI / 180)
> to yield better results for angles which are larger than +/-360 degrees.

Actually for good results you should reduce to the interval +/-45 degrees 
(which may require swapping which of sin and cos is used, or between 
tangent and cotangent, and then adjusting the sign of the result, 
depending on the quadrant the original argument was in).  Consider e.g. 
cos of an argument close to 90 degrees; subtracting 90 and taking -sin of 
the result converted to radians gives a good result, converting 90 
directly to radians and taking cos of that yields large errors (in ulps) 
for such input.

(Unfortunately MPFR doesn't have sinpi etc., or the variants sinu etc. 
suggested in its TODO file, which would be helpful for implementing these 
functions for constant arguments.)

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Gcc-patches mailing list