From patchwork Sun Dec 12 18:35:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akila Welihinda X-Patchwork-Id: 48850 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A50B03857803 for ; Sun, 12 Dec 2021 18:35:45 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from Akilas-MacBook-Pro.local (047-224-207-180.res.spectrum.com [47.224.207.180]) by sourceware.org (Postfix) with ESMTP id 8BA193858419 for ; Sun, 12 Dec 2021 18:35:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8BA193858419 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ucla.edu Authentication-Results: sourceware.org; spf=none smtp.mailfrom=Akilas-MacBook-Pro.local Received: by Akilas-MacBook-Pro.local (Postfix, from userid 501) id AD62CE65116; Sun, 12 Dec 2021 10:35:31 -0800 (PST) From: Akila Welihinda To: libc-alpha@sourceware.org Subject: [PATCH] sysdeps: Simplify sin Taylor Series calculation Date: Sun, 12 Dec 2021 10:35:03 -0800 Message-Id: <20211212183503.9332-1-akilawelihinda@ucla.edu> X-Mailer: git-send-email 2.30.1 (Apple Git-130) In-Reply-To: <20211211180214.5692-1-akilawelihinda@ucla.edu> References: <20211211180214.5692-1-akilawelihinda@ucla.edu> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KHOP_HELO_FCRDNS, NO_DNS_FOR_FROM, PDS_RDNS_DYNAMIC_FP, RDNS_DYNAMIC, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Akila Welihinda Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" The macro TAYLOR_SIN adds the term `-0.5*da*a^2 + da` in hopes of regaining some precision as a function of da. However the comment says we add the term `-0.5*da*a^2 + 0.5*da` which is different. This fix updates the comment to reflect the code and also simplifies the calculation by replacing `a` with `x` because they always have the same value. Signed-off-by: Akila Welihinda Reviewed-by: Paul Zimmermann --- sysdeps/ieee754/dbl-64/s_sin.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sysdeps/ieee754/dbl-64/s_sin.c b/sysdeps/ieee754/dbl-64/s_sin.c index 7d89e3dfc2..a412c3642d 100644 --- a/sysdeps/ieee754/dbl-64/s_sin.c +++ b/sysdeps/ieee754/dbl-64/s_sin.c @@ -51,16 +51,16 @@ #define POLYNOMIAL(xx) (POLYNOMIAL2 (xx) + s1) /* The computed polynomial is a variation of the Taylor series expansion for - sin(a): + sin(x): - a - a^3/3! + a^5/5! - a^7/7! + a^9/9! + (1 - a^2) * da / 2 + x - x^3/3! + x^5/5! - x^7/7! + x^9/9! - dx*x^2/2 + dx The constants s1, s2, s3, etc. are pre-computed values of 1/3!, 1/5! and so on. The result is returned to LHS. */ -#define TAYLOR_SIN(xx, a, da) \ +#define TAYLOR_SIN(xx, x, dx) \ ({ \ - double t = ((POLYNOMIAL (xx) * (a) - 0.5 * (da)) * (xx) + (da)); \ - double res = (a) + t; \ + double t = ((POLYNOMIAL (xx) * (x) - 0.5 * (dx)) * (xx) + (dx)); \ + double res = (x) + t; \ res; \ })