[gnumeric] PERMUTATION: fix handling of argument in the range (-1,0)



commit ecf7f7edee496f2df17b8d7c7e38e546f2c78004
Author: Morten Welinder <terra gnome org>
Date:   Wed Nov 22 21:18:58 2017 -0500

    PERMUTATION: fix handling of argument in the range (-1,0)
    
    Also avoid overflow in some cases.

 NEWS                        |    1 +
 plugins/fn-stat/ChangeLog   |    2 ++
 plugins/fn-stat/functions.c |   12 +++++-------
 3 files changed, 8 insertions(+), 7 deletions(-)
---
diff --git a/NEWS b/NEWS
index 5ecd3fa..e850edf 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ Gnumeric 1.12.37
 Morten:
        * Test suite improvements.
        * Improve format guessing for newly entered formulas.
+       * Improve PERMUTATIONA for unusual arguments.  [#790742]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.36
diff --git a/plugins/fn-stat/ChangeLog b/plugins/fn-stat/ChangeLog
index 186bdc4..82d78dd 100644
--- a/plugins/fn-stat/ChangeLog
+++ b/plugins/fn-stat/ChangeLog
@@ -2,6 +2,8 @@
 
        * functions.c (math_functions): Mark COUNT, COUNTA, PERMUT, and
        PERMUTATIONA as unitless.
+       (gnumeric_permutationa): Be more compatible and about overflow
+       where possible.
 
 2017-11-20  Morten Welinder  <terra gnome org>
 
diff --git a/plugins/fn-stat/functions.c b/plugins/fn-stat/functions.c
index 01b0c84..3aaf0db 100644
--- a/plugins/fn-stat/functions.c
+++ b/plugins/fn-stat/functions.c
@@ -4977,17 +4977,15 @@ static GnmFuncHelp const help_permutationa[] = {
 static GnmValue *
 gnumeric_permutationa (GnmFuncEvalInfo *ei, GnmValue const * const *argv)
 {
-       gnm_float x = value_get_as_float (argv[0]);
-       gnm_float y = value_get_as_float (argv[1]);
-       int ix = (int) x;
-       int iy = (int) y;
+       gnm_float x = gnm_fake_floor (value_get_as_float (argv[0]));
+       gnm_float y = gnm_fake_floor (value_get_as_float (argv[1]));
 
-       if (ix < 0 || iy < 0)
+       if (x < 0 || y < 0)
                return value_new_error_NUM (ei->pos);
-       else if (ix == 0 && iy == 0)
+       else if (y == 0)
                return value_new_float (1);
        else
-               return value_new_float (gnm_pow (ix, iy));
+               return value_new_float (gnm_pow (x, y));
 }
 
 /***************************************************************************/


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