https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93871

--- Comment #27 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Wed, Feb 26, 2020 at 12:58:21PM +0000, thenlich at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93871
> 
> --- Comment #26 from Thomas Henlich <thenlich at gcc dot gnu.org> ---
> Created attachment 47914
>   --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47914&action=edit
> Demonstration of range reduction
> 
> There is a danger of some inaccuracy in the degree trigonometric functions
> (sind, cosd, tand, cotand) because a full period of 360 degrees can not be
> expressed accurately in radians.
> 
> This can be circumvented by using some trigonometric identities to reduce the
> range and also place the inaccurate x range to where |dy/dx|→min, and away 
> from
> y values near zero toward high y values so that the error is mostly cancelled.

I implemented FreeBSD's cosl, sinl, and tanl, did the legwork to produce
all of the sincos family of functions, and have implemented sinpi and
friends for FreeBSD .  I'm well aware of argument reduction and ULPs.  If
you're going to go this route, then you'll need to write functions that
can be called from libgfortran.

My patch rewrites the special handling of degree trig functions to bring
these functions into the general framework that gfortran uses for all other
intrinsic routines (except a few in IEEE_ARITHEMETIC).

> This is a best effort to still be able to use the standard library functions
> but also get an increased accuracy expected from the degree functions.
> 
> Thus:
> 1. Calculate cosd(x) = sind(90 - x)
> 2. Calculate cotand(x) = tand(90 - x)
> 3. Reduce range of sind() argument from (0...360) further to x-360 if it is
> above 270, and to 180-x if it is above 90
> 

(snip)

> $ gf10 -fdec-math -fdefault-real-8 periods.f90 && ./a.exe

Any result that uses -fdefault-real-8 will be ingored by me.
That option should have been removed years ago.  I even posted
a patch that removed it.  It was not well-received.

Reply via email to