sysdeps: Simplify sin Taylor Series calculation

Message ID 20211212183503.9332-1-akilawelihinda@ucla.edu
State Committed
Commit 3b1402b3fc3a9ff228c2b721a67f0fef430a82fd
Headers
Series sysdeps: Simplify sin Taylor Series calculation |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Akila Welihinda Dec. 12, 2021, 6:35 p.m. UTC
  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 <akilawelihinda@ucla.edu>
---
 sysdeps/ieee754/dbl-64/s_sin.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Paul Zimmermann Dec. 13, 2021, 9:53 a.m. UTC | #1
Dear Akila,

thank you for the new version, this seems good to me.

Do you have commit access?

Best regards,
Paul Zimmermann

> From: Akila Welihinda <akilawelihinda@ucla.edu>
> Date: Sun, 12 Dec 2021 10:35:03 -0800
> Cc: Akila Welihinda <akilawelihinda@ucla.edu>
> 
> 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 <akilawelihinda@ucla.edu>
> ---
>  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;									      \
>  })
>  
> -- 
> 2.30.1 (Apple Git-130)

Reviewed-by: Paul Zimmermann <Paul.Zimmermann@inria.fr>
  
Siddhesh Poyarekar Dec. 13, 2021, 2:08 p.m. UTC | #2
On 12/13/21 15:23, Paul Zimmermann wrote:
>         Dear Akila,
> 
> thank you for the new version, this seems good to me.
> 
> Do you have commit access?
> 

This is Akila's first submission.  Paul, could you please commit for him?

Thanks,
Siddhesh
  
Paul Zimmermann Dec. 13, 2021, 2:31 p.m. UTC | #3
Dear Siddhesh,

> This is Akila's first submission.  Paul, could you please commit for him?

sure, done. Thank you Akila for your contribution!

Paul
  
Akila Welihinda Dec. 13, 2021, 4:58 p.m. UTC | #4
Thank you Paul and Siddhesh for the review!

On Mon, Dec 13, 2021 at 6:32 AM Paul Zimmermann <Paul.Zimmermann@inria.fr>
wrote:

>        Dear Siddhesh,
>
> > This is Akila's first submission.  Paul, could you please commit for him?
>
> sure, done. Thank you Akila for your contribution!
>
> Paul
>
  

Patch

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;									      \
 })