PATCH -- Fix degree trignometric functions

Fritz Reese fritzoreese@gmail.com
Fri Mar 27 23:36:15 GMT 2020


On Fri, Mar 6, 2020 at 6:18 PM Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
[...]
> TL;DR version.
>
>   Fix the simplification and handling of the degree trigonometric functions.
>   This includes fixing a number of ICEs.  See PR 93871.

An updated version of the patch is attached. Regression tests (and new
test cases) are pending.

Changes since Steve's patch of note:

* libgfortran/intrinsics/trigd.c now indirectly includes trigd.inc
(formerly trigd_inc.c) through trigd_lib.inc. trigd.inc is now written
using GMP/MPFR functions, so that the same file can be included from
the front-end for simplification. The GMP/MPFR functions are
pre-processed into native code by trigd_lib.inc. This ensures that
both the FE and the library are using the same code for resolving
these functions, preventing future maintenance woes.

* TAND(90, 270) returns +Infinity and -Infinity, instead of NaN. This
is compatible with behavior of (at least some) DEC compilers.

* COTAN[D] are implemented as -TAN[D](x + 90 degrees) rather than 1 /
COTAN[D] for speed and to avoid singularities (though the new
implementation of TAND allows 1 / TAND to return zero when TAND
returns infinity).

* SMALL thresholds and signs of some specific values are corrected.
For REAL(10) and REAL(16), the SMALL threshold for SIND(x) = D2R(x) is
eliminated, since there would be loss of precision. The other
thresholds achieve COSD(x) = 1 and SIND(x) = D2R(x) without loss of
precision.

ChangeLogs are below. I will post an update soon after I perform
regression tests, which include some new tests which I will add.

gcc/fortran/ChangeLog:

        PR fortran/93871

        * gfortran.h (GFC_ISYM_ACOSD, GFC_ISYM_ASIND, GFC_ISYM_ATAN2D,
        GFC_ISYM_ATAND, GFC_ISYM_COSD, GFC_ISYM_COTAND, GFC_ISYM_SIND,
        GFC_ISYM_TAND): New.
        * intrinsic.c (add_functions): Remove check for flag_dec_math.
        Give degree trig functions simplification and name resolution
        functions (e.g, gfc_simplify_atrigd () and gfc_resolve_atrigd ()).
        (do_simplify): Remove special casing of degree trig functions.
        * intrinsic.h (gfc_simplify_acosd, gfc_simplify_asind,
        gfc_simplify_atand, gfc_simplify_cosd, gfc_simplify_cotand,
        gfc_simplify_sind, gfc_simplify_tand, gfc_resolve_trigd2): Add new
        prototypes.
        (gfc_simplify_atrigd, gfc_simplify_trigd, gfc_resolve_cotan,
        resolve_atrigd): Remove prototypes of deleted functions.
        * iresolve.c (is_trig_resolved, copy_replace_function_shallow,
        gfc_resolve_cotan, get_radians, get_degrees, resolve_trig_call,
        gfc_resolve_atrigd, gfc_resolve_atan2d): Delete functions.
        (gfc_resolve_trigd, gfc_resolve_trigd2): Resolve to library functions.
        * simplify.c (rad2deg, deg2rad, gfc_simplify_acosd, gfc_simplify_asind,
        gfc_simplify_atand, gfc_simplify_atan2d, gfc_simplify_cosd,
        gfc_simplify_sind, gfc_simplify_tand, gfc_simplify_cotand): New
        functions.
        (gfc_simplify_atan2): Fix error message.
        (simplify_trig_call, gfc_simplify_trigd, gfc_simplify_atrigd,
        radians_f): Delete functions.
        * trans-intrinsic.c: Add LIB_FUNCTION decls for sind, cosd, tand.
        (rad2deg, gfc_conv_intrinsic_atrigd, gfc_conv_intrinsic_cotan,
        gfc_conv_intrinsic_cotand, gfc_conv_intrinsic_atan2d): New functions.
        (gfc_conv_intrinsic_function): Handle ACOSD, ASIND, ATAND, COTAN,
        COTAND, ATAN2D.
        * trigd_fe.inc: New file. Included by simplify.c to implement
        simplify_sind, simplify_cosd, simplify_tand with code common to the
        libgfortran implementation.

libgfortran/ChangeLog:

        PR fortran/93871
        * Makefile.am, Makefile.in: New make rule for intrinsics/trigd.c.
        * gfortran.map: New routines for {sind, cosd, tand}X{r4, r8, r10, r16}.
        * intrinsics/trigd.c, intrinsics/trigd_lib.inc, intrinsics/trigd.inc:
        New files. Defines native degree-valued trig functions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trigd_v3.patch
Type: text/x-patch
Size: 70319 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20200327/c98fc558/attachment-0001.bin>


More information about the Gcc-patches mailing list