[gnumeric] Fix QUARTILE.EXC and PERCENTILE.EXC for datasets of one value



commit 5986b848843713734434429203bc9476d3daedc1
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date:   Fri Jul 3 14:15:53 2015 -0600

    Fix QUARTILE.EXC and PERCENTILE.EXC for datasets of one value
    
    2015-07-03  Andreas J. Guelzow <aguelzow pyrshep ca>
    
        * functions.c (help_quartile_exc): avoid division by 0
        (gnumeric_percentile_exc): ditto

 plugins/fn-stat/ChangeLog   |    5 +++++
 plugins/fn-stat/functions.c |   38 ++++++++++++++++++++++----------------
 2 files changed, 27 insertions(+), 16 deletions(-)
---
diff --git a/plugins/fn-stat/ChangeLog b/plugins/fn-stat/ChangeLog
index 435f77f..ff514d8 100644
--- a/plugins/fn-stat/ChangeLog
+++ b/plugins/fn-stat/ChangeLog
@@ -1,3 +1,8 @@
+2015-07-03  Andreas J. Guelzow <aguelzow pyrshep ca>
+
+       * functions.c (help_quartile_exc): avoid division by 0
+       (gnumeric_percentile_exc): ditto
+
 2015-06-30  Morten Welinder  <terra gnome org>
 
        * functions.c (gnumeric_growth): Fix check for no results.  Fixes
diff --git a/plugins/fn-stat/functions.c b/plugins/fn-stat/functions.c
index 0223c94..d0e28da 100644
--- a/plugins/fn-stat/functions.c
+++ b/plugins/fn-stat/functions.c
@@ -3094,14 +3094,17 @@ gnumeric_percentile_exc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
                                     COLLECT_SORT,
                                     &n, &result);
        if (!result) {
-               gnm_float p = value_get_as_float (argv[1]);
-               gnm_float res;
-               gnm_float fr = (p * (n + 1) - 1)/(n-1);
-
-               if (gnm_range_fractile_inter_sorted (data, n, &res, fr))
+               if (n > 1) {
+                       gnm_float p = value_get_as_float (argv[1]);
+                       gnm_float res;
+                       gnm_float fr = (p * (n + 1) - 1)/(n-1);
+                       
+                       if (gnm_range_fractile_inter_sorted (data, n, &res, fr))
+                               result = value_new_error_NUM (ei->pos);
+                       else
+                               result = value_new_float (res);
+               } else
                        result = value_new_error_NUM (ei->pos);
-               else
-                       result = value_new_float (res);
        }
 
        g_free (data);
@@ -3180,16 +3183,19 @@ gnumeric_quartile_exc (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
                                     COLLECT_SORT,
                                     &n, &result);
        if (!result) {
-               gnm_float q = gnm_fake_floor (value_get_as_float (argv[1]));
-               gnm_float res;
-               gnm_float fr = ((q / 4.0) * (n + 1) - 1)/(n-1);
-
-               if (gnm_range_fractile_inter_sorted (data, n, &res, fr))
-                       result = value_new_error_NUM (ei->pos);
-               else
-                       result = value_new_float (res);
+               if (n > 1) {
+                       gnm_float q = gnm_fake_floor (value_get_as_float (argv[1]));
+                       gnm_float res;
+                       gnm_float fr = ((q / 4.0) * (n + 1) - 1)/(n-1);
+                       
+                       if (gnm_range_fractile_inter_sorted (data, n, &res, fr))
+                               result = value_new_error_NUM (ei->pos);
+                       else
+                               result = value_new_float (res);
+               } else
+                       result = value_new_error_NUM (ei->pos); 
        }
-
+       
        g_free (data);
        return result;
 }


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