public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Fritz Reese <fritzoreese@gmail.com>
To: Tobias Burnus <tobias.burnus@physik.fu-berlin.de>,
		gcc-patches <gcc-patches@gcc.gnu.org>,
	fortran <fortran@gcc.gnu.org>
Subject: Re: [PATCH, Fortran] Extension: COTAN and degree-valued trig intrinsics with -fdec-math
Date: Tue, 27 Sep 2016 11:06:00 -0000	[thread overview]
Message-ID: <CAE4aFAmocYyhqeit=jF_QQtqqLaOipBjRcNnGUH6W5agXLh9og@mail.gmail.com> (raw)
In-Reply-To: <20160926155930.GA24746@physik.fu-berlin.de>

Tobias,

Many thanks for the comments. I will adjust the patch according to
your advice shortly.

- Fritz

On Mon, Sep 26, 2016, 11:59 Tobias Burnus
<tobias.burnus@physik.fu-berlin.de> wrote:
>
> Fritz Reese wrote:
> > Attached is a patch extending the GNU Fortran front-end to support
> > some additional math intrinsics, enabled with a new compile flag
> > -fdec-math. The flag adds the COTAN intrinsic (cotangent), as well as
> > degree versions of all trigonometric intrinsics (SIND, TAND, ACOSD,
> > etc...).
> >
> > +     /* There is no builtin mpc_cot, so compute x = 1 / tan (x).  */
> > +     val = &result->value.complex;
> > +     mpc_tan (*val, *val, GFC_MPC_RND_MODE);
> > +     mpc_div (*val, one, *val, GFC_MPC_RND_MODE);
>
> The internet remarks: TAN(x) for x -> pi/2 goes to +inf or -inf - while
> COTAN(pi/2) == 0. For values near pi/2, using cos(x)/sin(x) should be
> numerically better than 1/tan(x). [Cf. mpfr_sin_cos  and BUILT_IN_SINCOS.]
>
> I am not sure how big the prevision difference really is. A quick test
> showed results which didn't look to bad:
>
> implicit none
> real(8), volatile  :: x
> x = 3.14159265358d0/2.0d0
> print '(g0)', cotan(x), cos(x)/sin(x), cotan(x)-cos(x)/sin(x)
> end
>
> yields:
>
> 0.48965888601467483E-011
> 0.48965888601467475E-011
> 0.80779356694631609E-027
>
> Usint N[1/Tan[314159265358/10^11/2],200], Mathematica shows
>   4.8966192313216916397514812338... * 10^12.
> I am not quite sure whether I should expect that already the 5th digit
> differs from the results above.
>
>
> > mpfr_set_d (tmp, 180.0l, GFC_RND_MODE);
>
> With some fonts the L after 180.0 looks like a one; I was initially
> puzzled why one uses not 180 but 180.01. Hence, I'd prefer an "L" instead
> of an "l".
>
> However, the second argument of mpfr_set_d is a "double" and 180.0 is
> already a double. Hence, one can even completely get rid of the "l".
>
>
>
> 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.
>
>
> Cheers,
>
> Tobias

  reply	other threads:[~2016-09-27 10:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-26 16:11 Tobias Burnus
2016-09-27 11:06 ` Fritz Reese [this message]
2016-09-28  1:12 ` Joseph Myers
  -- strict thread matches above, loose matches on Subject: below --
2016-09-26 14:20 Fritz Reese
2016-09-26 19:08 ` Toon Moene
2016-09-28 19:04 ` Steve Kargl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE4aFAmocYyhqeit=jF_QQtqqLaOipBjRcNnGUH6W5agXLh9og@mail.gmail.com' \
    --to=fritzoreese@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=tobias.burnus@physik.fu-berlin.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).