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
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
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>
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
Dear Siddhesh,
> This is Akila's first submission. Paul, could you please commit for him?
sure, done. Thank you Akila for your contribution!
Paul
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
>
@@ -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; \
})