[goffice] Complex: fix corner case for complex sqrt.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] Complex: fix corner case for complex sqrt.
- Date: Sat, 5 Mar 2016 20:59:17 +0000 (UTC)
commit e5e05ec9f709288ca2f2799438be112972167dfe
Author: Morten Welinder <terra gnome org>
Date: Sat Mar 5 15:58:05 2016 -0500
Complex: fix corner case for complex sqrt.
When the argument is near the nagative real axis, we will get a result
that is near the imaginary axis and thus has a small real part. Getting
the small real part right requires a little extra care.
ChangeLog | 5 +++++
NEWS | 1 +
goffice/math/go-complex.c | 14 ++++++++++++++
3 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 065b038..583ad56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-03-05 Morten Welinder <terra gnome org>
+
+ * goffice/math/go-complex.c (go_complex_sqrt): Fix accuracy of
+ real component when argument is very near the negative real axis.
+
2016-02-23 Morten Welinder <terra gnome org>
* goffice/math/go-complex.c (go_complex_powx): Expose the power
diff --git a/NEWS b/NEWS
index b8e47f6..ebba682 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ goffice 0.10.28:
Morten:
* Configuration fixes.
* Introspection improvements.
+ * Improve go_complex_sqrt.
--------------------------------------------------------------------------
goffice 0.10.27:
diff --git a/goffice/math/go-complex.c b/goffice/math/go-complex.c
index c845483..c9a5f89 100644
--- a/goffice/math/go-complex.c
+++ b/goffice/math/go-complex.c
@@ -271,6 +271,20 @@ SUFFIX(go_complex_div) (COMPLEX *dst, COMPLEX const *a, COMPLEX const *b)
void
SUFFIX(go_complex_sqrt) (COMPLEX *dst, COMPLEX const *src)
{
+ if (src->re < 0 && -src->re > SUFFIX(fabs)(src->im)) {
+ // Near the negative axis we do not want to squeeze
+ // angle/pi against +-1.
+ COMPLEX msrc, r;
+ msrc.re = - src->re;
+ msrc.im = - src->im;
+ SUFFIX(go_complex_sqrt) (&r, &msrc);
+ if (src->im >= 0)
+ SUFFIX(go_complex_init) (dst, 0 - r.im, r.re);
+ else
+ SUFFIX(go_complex_init) (dst, r.im, 0 - r.re);
+ return;
+ }
+
SUFFIX(go_complex_from_polar_pi)
(dst,
SUFFIX(sqrt) (SUFFIX(go_complex_mod) (src)),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]