[goffice] Complex: improve ln near unit circle.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Complex: improve ln near unit circle.
- Date: Sat, 5 Mar 2016 23:22:42 +0000 (UTC)
commit ae4a4ec431c7e0790cfb283c23cc400c57ec5e24
Author: Morten Welinder <terra gnome org>
Date: Sat Mar 5 18:21:43 2016 -0500
Complex: improve ln near unit circle.
|z| is about 1, so Re(ln(z)) is around 0. That requires a bit of extra
care.
ChangeLog | 1 +
NEWS | 1 +
goffice/math/go-complex.c | 11 ++++++++---
3 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 102d7b5..0d6761c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,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.
+ (go_complex_ln): Improve accuracy near unit circle.
2016-02-23 Morten Welinder <terra gnome org>
diff --git a/NEWS b/NEWS
index ac85679..b710a6e 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Morten:
* Introspection improvements.
* Improve go_complex_sqrt.
* Improve go_complex_tan.
+ * Improve go_complex_ln.
--------------------------------------------------------------------------
goffice 0.10.27:
diff --git a/goffice/math/go-complex.c b/goffice/math/go-complex.c
index 5f06bb4..32608ea 100644
--- a/goffice/math/go-complex.c
+++ b/goffice/math/go-complex.c
@@ -557,9 +557,14 @@ void SUFFIX(go_complex_exp) (COMPLEX *dst, COMPLEX const *src)
void SUFFIX(go_complex_ln) (COMPLEX *dst, COMPLEX const *src)
{
- SUFFIX(go_complex_init) (dst,
- SUFFIX(log) (SUFFIX(go_complex_mod) (src)),
- SUFFIX(go_complex_angle) (src));
+ DOUBLE x = SUFFIX(fabs) (src->re);
+ DOUBLE y = SUFFIX(fabs) (src->im);
+ DOUBLE lm = x > y
+ ? SUFFIX(log) (x) + 0.5 * SUFFIX(log1p) ((y / x) * (y / x))
+ : SUFFIX(log) (y) + 0.5 * SUFFIX(log1p) ((x / y) * (x / y));
+ DOUBLE a = SUFFIX(go_complex_angle) (src);
+
+ SUFFIX(go_complex_init) (dst, lm, a);
}
/* ------------------------------------------------------------------------- */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]