[goffice] Complex: improve tan.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Complex: improve tan.
- Date: Sat, 5 Mar 2016 23:11:39 +0000 (UTC)
commit e623ffea22b99336b64e10440480606b64e81e5a
Author: Morten Welinder <terra gnome org>
Date: Sat Mar 5 18:11:40 2016 -0500
Complex: improve tan.
ChangeLog | 1 +
NEWS | 1 +
goffice/math/go-complex.c | 30 ++++++++++++++++++++++++------
3 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 583ad56..102d7b5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
* goffice/math/go-complex.c (go_complex_sqrt): Fix accuracy of
real component when argument is very near the negative real axis.
+ (go_complex_tan): Improve accuracy.
2016-02-23 Morten Welinder <terra gnome org>
diff --git a/NEWS b/NEWS
index ebba682..ac85679 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Morten:
* Configuration fixes.
* Introspection improvements.
* Improve go_complex_sqrt.
+ * Improve go_complex_tan.
--------------------------------------------------------------------------
goffice 0.10.27:
diff --git a/goffice/math/go-complex.c b/goffice/math/go-complex.c
index c9a5f89..5f06bb4 100644
--- a/goffice/math/go-complex.c
+++ b/goffice/math/go-complex.c
@@ -564,7 +564,7 @@ void SUFFIX(go_complex_ln) (COMPLEX *dst, COMPLEX const *src)
/* ------------------------------------------------------------------------- */
-void SUFFIX(go_complex_sin) ( COMPLEX *dst, COMPLEX const *src)
+void SUFFIX(go_complex_sin) (COMPLEX *dst, COMPLEX const *src)
{
SUFFIX(go_complex_init) (dst,
SUFFIX(sin) (src->re) * SUFFIX(cosh) (src->im),
@@ -573,7 +573,7 @@ void SUFFIX(go_complex_sin) ( COMPLEX *dst, COMPLEX const *src)
/* ------------------------------------------------------------------------- */
-void SUFFIX(go_complex_cos) (COMPLEX *dst, COMPLEX const *src)
+void SUFFIX(go_complex_cos) (COMPLEX *dst, COMPLEX const *src)
{
SUFFIX(go_complex_init) (dst,
SUFFIX(cos) (src->re) * SUFFIX(cosh) (src->im),
@@ -584,11 +584,29 @@ void SUFFIX(go_complex_cos) (COMPLEX *dst, COMPLEX const *src)
void SUFFIX(go_complex_tan) (COMPLEX *dst, COMPLEX const *src)
{
- COMPLEX s, c;
+ DOUBLE R = src->re, I = src->im;
+ DOUBLE sr = SUFFIX(sin) (R);
+ DOUBLE cr = SUFFIX(cos) (R);
- SUFFIX(go_complex_sin) (&s, src);
- SUFFIX(go_complex_cos) (&c, src);
- SUFFIX(go_complex_div) (dst, &s, &c);
+ // Code here inspired by gsl, but doesn't follow it.
+
+ if (SUFFIX(fabs) (I) < 1) {
+ DOUBLE shi = SUFFIX(sinh) (I);
+ DOUBLE D = cr * cr + shi * shi;
+
+ SUFFIX(go_complex_init) (dst,
+ sr * cr / D,
+ 0.5 * SUFFIX(sinh) (2 * I) / D);
+ } else {
+ DOUBLE u = SUFFIX(exp) (-SUFFIX(fabs)(I));
+ DOUBLE C = 2 * u / (1 - u * u);
+ DOUBLE S = C * C;
+ DOUBLE D = 1 + cr * cr * S;
+ DOUBLE T = 1.0 / SUFFIX(tanh) (SUFFIX(fabs) (I));
+ SUFFIX(go_complex_init) (dst,
+ sr * cr * S / D,
+ (I < 0 ? -T : T) / D);
+ }
}
/* ------------------------------------------------------------------------- */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]