[gnumeric] Complex: improve error handling for complex functions.



commit b6ce9b5bebc01e7a2fa12bce8ba79e6249b88db5
Author: Morten Welinder <terra gnome org>
Date:   Sun May 2 15:38:33 2010 -0400

    Complex: improve error handling for complex functions.

 ChangeLog                      |    5 +++++
 NEWS                           |    1 +
 plugins/fn-complex/ChangeLog   |    4 ++++
 plugins/fn-complex/functions.c |    4 +++-
 src/complex.h                  |   19 +++++++++++++++++++
 5 files changed, 32 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fa6d52a..62c7fdc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-05-02  Morten Welinder  <terra gnome org>
+
+	* src/complex.h (complex_invalid, complex_invalid_p): New
+	functions.
+
 2010-05-01  Morten Welinder  <terra gnome org>
 
 	* src/complex.c (complex_from_string): Reject invalid strings like
diff --git a/NEWS b/NEWS
index 1b0d8eb..b4b6db1 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ Morten:
 	* Fix auto-filter problem.  [#383400]
 	* Fix advanced-filter problem with multiple criteria.  [#164169]
 	* Fix problem parsing comples numbers.
+	* Improve error handle for complex functions.
 
 --------------------------------------------------------------------------
 Gnumeric 1.10.2
diff --git a/plugins/fn-complex/ChangeLog b/plugins/fn-complex/ChangeLog
index 74f95e4..b009049 100644
--- a/plugins/fn-complex/ChangeLog
+++ b/plugins/fn-complex/ChangeLog
@@ -1,3 +1,7 @@
+2010-05-02  Morten Welinder  <terra gnome org>
+
+	* functions.c (value_new_complex): Handle errors better.
+
 2010-04-16  Morten Welinder <terra gnome org>
 
 	* Release 1.10.2
diff --git a/plugins/fn-complex/functions.c b/plugins/fn-complex/functions.c
index 5057a3e..97ce119 100644
--- a/plugins/fn-complex/functions.c
+++ b/plugins/fn-complex/functions.c
@@ -64,7 +64,9 @@ value_get_as_complex (GnmValue const *val, complex_t *res, char *imunit)
 static GnmValue *
 value_new_complex (complex_t const *c, char imunit)
 {
-	if (complex_real_p (c))
+	if (complex_invalid_p (c))
+		return value_new_error_NUM (NULL);
+	else if (complex_real_p (c))
 		return value_new_float (c->re);
 	else {
 		char f[5 + 4 * sizeof (int) + sizeof (GNM_FORMAT_g)];
diff --git a/src/complex.h b/src/complex.h
index b679a5d..ba3e0fe 100644
--- a/src/complex.h
+++ b/src/complex.h
@@ -60,6 +60,16 @@ GNUMERIC_COMPLEX_PROTO (void complex_init (complex_t *dst, gnm_float re, gnm_flo
 
 /* ------------------------------------------------------------------------- */
 
+GNUMERIC_COMPLEX_PROTO (void complex_invalid (complex_t *dst))
+#ifdef GNUMERIC_COMPLEX_BODY
+{
+	dst->re = gnm_nan;
+	dst->im = gnm_nan;
+}
+#endif
+
+/* ------------------------------------------------------------------------- */
+
 GNUMERIC_COMPLEX_PROTO (void complex_real (complex_t *dst, gnm_float re))
 #ifdef GNUMERIC_COMPLEX_BODY
 {
@@ -79,6 +89,15 @@ GNUMERIC_COMPLEX_PROTO (int complex_real_p (complex_t const *src))
 
 /* ------------------------------------------------------------------------- */
 
+GNUMERIC_COMPLEX_PROTO (int complex_invalid_p (complex_t const *src))
+#ifdef GNUMERIC_COMPLEX_BODY
+{
+	return !(gnm_finite (src->re) && gnm_finite (src->im));
+}
+#endif
+
+/* ------------------------------------------------------------------------- */
+
 GNUMERIC_COMPLEX_PROTO (int complex_zero_p (complex_t const *src))
 #ifdef GNUMERIC_COMPLEX_BODY
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]