[gnumeric] GCD: fix handling of zeros.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] GCD: fix handling of zeros.
- Date: Wed, 13 Jan 2010 17:12:52 +0000 (UTC)
commit bd906d433aff5f8542c25a0df39f46bfd8dae705
Author: Morten Welinder <terra gnome org>
Date: Wed Jan 13 12:12:34 2010 -0500
GCD: fix handling of zeros.
NEWS | 3 +++
plugins/fn-math/ChangeLog | 5 +++++
plugins/fn-math/functions.c | 9 +++++----
3 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index 6223446..f5755ab 100644
--- a/NEWS
+++ b/NEWS
@@ -44,6 +44,9 @@ Jody:
* More win32 build fixes (xslt for libgda & poppler).
* Fix pango test harness.
+Morten:
+ * Fix GCD border case. [#606870]
+
--------------------------------------------------------------------------
Gnumeric 1.9.17
diff --git a/plugins/fn-math/ChangeLog b/plugins/fn-math/ChangeLog
index 4325086..36f700f 100644
--- a/plugins/fn-math/ChangeLog
+++ b/plugins/fn-math/ChangeLog
@@ -1,3 +1,8 @@
+2010-01-13 Morten Welinder <terra gnome org>
+
+ * functions.c (range_gcd): Handle GCD(2,0)=2 as Excel, but err on
+ GCD(0,0).
+
2009-12-23 Andreas J. Guelzow <aguelzow pyrshep ca>
* functions.c (compare_doubles): rename to
diff --git a/plugins/fn-math/functions.c b/plugins/fn-math/functions.c
index 21823cc..7bd2778 100644
--- a/plugins/fn-math/functions.c
+++ b/plugins/fn-math/functions.c
@@ -70,9 +70,6 @@ static const gnm_float gnm_gcd_max = 1 / GNM_EPSILON;
static gnm_float
gnm_gcd (gnm_float a, gnm_float b)
{
- g_return_val_if_fail (a > 0 && a <= gnm_gcd_max, -1);
- g_return_val_if_fail (b > 0 && b <= gnm_gcd_max, -1);
-
while (b > 0.5) {
gnm_float r = gnm_fmod (a, b);
a = b;
@@ -90,11 +87,15 @@ range_gcd (gnm_float const *xs, int n, gnm_float *res)
for (i = 0; i < n; i++) {
gnm_float thisx = gnm_fake_floor (xs[i]);
- if (thisx <= 0 || thisx > gnm_gcd_max)
+ if (thisx < 0 || thisx > gnm_gcd_max)
return 1;
else
gcd_so_far = gnm_gcd (thisx, gcd_so_far);
}
+
+ if (gcd_so_far == 0)
+ return 1;
+
*res = gcd_so_far;
return 0;
} else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]