This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, Fortran] Extension: COTAN and degree-valued trig intrinsics with -fdec-math
- From: Joseph Myers <joseph at codesourcery dot com>
- To: Tobias Burnus <tobias dot burnus at physik dot fu-berlin dot de>
- Cc: Fritz Reese <fritzoreese at gmail dot com>, <gcc-patches at gcc dot gnu dot org>, <fortran at gcc dot gnu dot org>
- Date: Tue, 27 Sep 2016 23:09:43 +0000
- Subject: Re: [PATCH, Fortran] Extension: COTAN and degree-valued trig intrinsics with -fdec-math
- Authentication-results: sourceware.org; auth=none
- References: <20160926155930.GA24746@physik.fu-berlin.de>
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