From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 35620 invoked by alias); 26 Sep 2016 15:59:39 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 35592 invoked by uid 89); 26 Sep 2016 15:59:38 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.2 required=5.0 tests=AWL,BAYES_50,FAKE_REPLY_C,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=sind, 1800, degrees, 5th X-HELO: outpost19.zedat.fu-berlin.de Received: from outpost19.zedat.fu-berlin.de (HELO outpost19.zedat.fu-berlin.de) (130.133.4.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 26 Sep 2016 15:59:37 +0000 Received: from relay1.zedat.fu-berlin.de ([130.133.4.67]) by outpost.zedat.fu-berlin.de (Exim 4.85) with esmtps (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (envelope-from ) id <1boYJb-000xKl-5U>; Mon, 26 Sep 2016 17:59:35 +0200 Received: from mx.physik.fu-berlin.de ([160.45.64.218]) by relay1.zedat.fu-berlin.de (Exim 4.85) with esmtps (TLSv1.2:DHE-RSA-AES128-SHA:128) (envelope-from ) id <1boYJb-003cSx-24>; Mon, 26 Sep 2016 17:59:35 +0200 Received: from login2.physik.fu-berlin.de ([160.45.66.208]) by mx.physik.fu-berlin.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1boYJW-0001WV-RB; Mon, 26 Sep 2016 17:59:30 +0200 Received: from tburnus by login2.physik.fu-berlin.de with local (Exim 4.84 #3 (Debian)) id 1boYJW-0006lW-PB; Mon, 26 Sep 2016 17:59:30 +0200 Date: Mon, 26 Sep 2016 16:11:00 -0000 From: Tobias Burnus To: Fritz Reese , gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: Re: [PATCH, Fortran] Extension: COTAN and degree-valued trig intrinsics with -fdec-math Message-ID: <20160926155930.GA24746@physik.fu-berlin.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2016-09/txt/msg01856.txt.bz2 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