From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73057 invoked by alias); 27 Sep 2016 10:58:49 -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 72976 invoked by uid 89); 27 Sep 2016 10:58:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:2216, burnus, Burnus, sind X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-oi0-f49.google.com Received: from mail-oi0-f49.google.com (HELO mail-oi0-f49.google.com) (209.85.218.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 27 Sep 2016 10:58:38 +0000 Received: by mail-oi0-f49.google.com with SMTP id t83so10601972oie.3; Tue, 27 Sep 2016 03:58:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=G0F23CMgwq/5mn3NWuSXRusHb1M1HLN5QJbqGieFnL8=; b=aLxG0wI/wNeoFFbOmFLh9Mj8TGcU+PaQqZYDOGBKChTyjHmtwxa9098Ycfk2rl+Jr1 deG3NfGkm4YlLNX5RlIUEBbTNlg6h5HRdnYHbfwrq5J6aRQUMRl1yn+gxjcjKv4OxPjz EmbV6KzHj9gzrRc89bQgcmauIgK6D4DbDcNbQLLbuKhlgqEuUlBvRa1vY0CG2v2juNzT Gm8p9ZXCR2f6AHaYvah1nJ/GwZo//2iGlnMJDSqS9lA1uWewipzKQG8FOnn43T7x/RZ7 vSdBxdhXpdL39UUNYBy78J5kCQFZzcuw1lEJ8ZLIigElMUHuIQnKkg5C8b3V8cS72Wum goGA== X-Gm-Message-State: AA6/9Rm+jspQ+XmvJTAFdDOASfVlTC2aRrNTgZLWuQVYxaITnPqtTwF/x1m/NYCxqtFOi9cQ5V38zmieZTeTnw== X-Received: by 10.202.81.194 with SMTP id f185mr20986487oib.161.1474973916522; Tue, 27 Sep 2016 03:58:36 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.80.166 with HTTP; Tue, 27 Sep 2016 03:58:35 -0700 (PDT) In-Reply-To: <20160926155930.GA24746@physik.fu-berlin.de> References: <20160926155930.GA24746@physik.fu-berlin.de> From: Fritz Reese Date: Tue, 27 Sep 2016 11:06:00 -0000 Message-ID: Subject: Re: [PATCH, Fortran] Extension: COTAN and degree-valued trig intrinsics with -fdec-math To: Tobias Burnus , gcc-patches , fortran Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2016-09/txt/msg01935.txt.bz2 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 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