[goffice] GOQuad: add log function.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goffice] GOQuad: add log function.
- Date: Thu, 5 Dec 2013 16:10:06 +0000 (UTC)
commit 63a34f2f6f88647dfa5a4212f4fb1e2121533a65
Author: Morten Welinder <terra gnome org>
Date: Thu Dec 5 11:09:49 2013 -0500
GOQuad: add log function.
ChangeLog | 7 +++++++
NEWS | 1 +
goffice/math/go-quad.c | 40 +++++++++++++++++++++++++++++++++++++++-
goffice/math/go-quad.h | 4 ++++
tests/test-quad.c | 1 +
5 files changed, 52 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6a329f4..c5abb55 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-12-05 Morten Welinder <terra gnome org>
+
+ * goffice/math/go-quad.c (go_quad_pi): New constant.
+ (go_quad_log): New function.
+
+ * tests/test-quad.c (main): Check value of go_quad_2pi.
+
2013-12-04 Morten Welinder <terra gnome org>
* goffice/math/go-complex.c (go_complex_pow): Fix class over
diff --git a/NEWS b/NEWS
index 0f1107f..be39466 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,7 @@ Jean
Morten:
* Improve complex math.
+ * Add quad precision log function.
--------------------------------------------------------------------------
goffice 0.10.9:
diff --git a/goffice/math/go-quad.c b/goffice/math/go-quad.c
index d16bd6f..87fda74 100644
--- a/goffice/math/go-quad.c
+++ b/goffice/math/go-quad.c
@@ -215,6 +215,12 @@ SUFFIX(go_quad_start) (void)
256.0,
256.0);
+ SUFFIX(go_quad_constant8) ((QUAD *)&SUFFIX(go_quad_2pi),
+ pi_hex_digits,
+ G_N_ELEMENTS (pi_hex_digits),
+ 256.0,
+ 512.0);
+
SUFFIX(go_quad_constant8) ((QUAD *)&SUFFIX(go_quad_e),
e_hex_digits,
G_N_ELEMENTS (e_hex_digits),
@@ -265,9 +271,10 @@ SUFFIX(go_quad_end) (void *state)
g_free (state);
}
-const QUAD SUFFIX(go_quad_zero);
+const QUAD SUFFIX(go_quad_zero) = { 0, 0 };
const QUAD SUFFIX(go_quad_one) = { 1, 0 };
const QUAD SUFFIX(go_quad_pi);
+const QUAD SUFFIX(go_quad_2pi);
const QUAD SUFFIX(go_quad_e);
const QUAD SUFFIX(go_quad_ln2);
const QUAD SUFFIX(go_quad_sqrt2);
@@ -734,3 +741,34 @@ SUFFIX(go_quad_expm1) (QUAD *res, const QUAD *a)
SUFFIX(go_quad_div) (res, &z, &zp1);
}
}
+
+/**
+ * go_quad_log: (skip)
+ **/
+/**
+ * go_quad_logl: (skip)
+ **/
+void
+SUFFIX(go_quad_log) (QUAD *res, const QUAD *a)
+{
+ DOUBLE da = SUFFIX(go_quad_value) (a);
+
+ if (da == 0)
+ SUFFIX(go_quad_init) (res, SUFFIX(go_ninf));
+ else if (da < 0)
+ SUFFIX(go_quad_init) (res, SUFFIX(go_nan));
+ else if (!SUFFIX(go_finite) (da))
+ *res = *a;
+ else {
+ QUAD xi, yi, dx;
+ SUFFIX(go_quad_init) (&xi, SUFFIX(log) (da));
+
+ /* Newton step. */
+ SUFFIX(go_quad_exp) (&yi, NULL, &xi);
+ SUFFIX(go_quad_sub) (&dx, a, &yi);
+ SUFFIX(go_quad_div) (&dx, &dx, &yi);
+ SUFFIX(go_quad_add) (&xi, &xi, &dx);
+
+ *res = xi;
+ }
+}
diff --git a/goffice/math/go-quad.h b/goffice/math/go-quad.h
index 1ffe022..76f40a0 100644
--- a/goffice/math/go-quad.h
+++ b/goffice/math/go-quad.h
@@ -26,6 +26,7 @@ void go_quad_floor (GOQuad *res, const GOQuad *a);
void go_quad_pow (GOQuad *res, double *exp2, const GOQuad *x, const GOQuad *y);
void go_quad_exp (GOQuad *res, double *exp2, const GOQuad *a);
void go_quad_expm1 (GOQuad *res, const GOQuad *a);
+void go_quad_log (GOQuad *res, const GOQuad *a);
void go_quad_mul12 (GOQuad *res, double x, double y);
@@ -36,6 +37,7 @@ void go_quad_constant8 (GOQuad *res, const guint8 *data, gsize n, double base, d
GO_VAR_DECL const GOQuad go_quad_zero;
GO_VAR_DECL const GOQuad go_quad_one;
GO_VAR_DECL const GOQuad go_quad_pi;
+GO_VAR_DECL const GOQuad go_quad_2pi;
GO_VAR_DECL const GOQuad go_quad_e;
GO_VAR_DECL const GOQuad go_quad_ln2;
GO_VAR_DECL const GOQuad go_quad_sqrt2;
@@ -63,6 +65,7 @@ void go_quad_floorl (GOQuadl *res, const GOQuadl *a);
void go_quad_powl (GOQuadl *res, long double *exp2, const GOQuadl *x, const GOQuadl *y);
void go_quad_expl (GOQuadl *res, long double *exp2, const GOQuadl *a);
void go_quad_expm1l (GOQuadl *res, const GOQuadl *a);
+void go_quad_logl (GOQuadl *res, const GOQuadl *a);
void go_quad_mul12l (GOQuadl *res, long double x, long double y);
@@ -74,6 +77,7 @@ void go_quad_constant8l (GOQuadl *res, const guint8 *data, gsize n, long double
GO_VAR_DECL const GOQuadl go_quad_zerol;
GO_VAR_DECL const GOQuadl go_quad_onel;
GO_VAR_DECL const GOQuadl go_quad_pil;
+GO_VAR_DECL const GOQuadl go_quad_2pil;
GO_VAR_DECL const GOQuadl go_quad_el;
GO_VAR_DECL const GOQuadl go_quad_ln2l;
GO_VAR_DECL const GOQuadl go_quad_sqrt2l;
diff --git a/tests/test-quad.c b/tests/test-quad.c
index a8a3a80..7ae5991 100644
--- a/tests/test-quad.c
+++ b/tests/test-quad.c
@@ -224,6 +224,7 @@ main (int argc, char **argv)
g_assert (go_quad_value (&c) == ldexp (1.0, -80));
g_assert (fabs (go_quad_value (&go_quad_pi) - M_PI) < 1e-14);
+ g_assert (fabs (go_quad_value (&go_quad_2pi) - 2 * M_PI) < 1e-14);
g_assert (fabs (go_quad_value (&go_quad_e) - exp(1)) < 1e-14);
g_assert (fabs (go_quad_value (&go_quad_ln2) - log(2)) < 1e-14);
g_assert (go_quad_value (&go_quad_zero) == 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]