[gnumeric] fn-r: minor improvement for r.psnorm's right-tail version.



commit e760e8432bdc44e16255828ea3ce38a698cef223
Author: Morten Welinder <terra gnome org>
Date:   Thu Apr 4 15:09:22 2013 -0400

    fn-r: minor improvement for r.psnorm's right-tail version.

 plugins/fn-r/ChangeLog |    1 +
 plugins/fn-r/extra.c   |    9 ++++-----
 2 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/plugins/fn-r/ChangeLog b/plugins/fn-r/ChangeLog
index f18192f..ced672b 100644
--- a/plugins/fn-r/ChangeLog
+++ b/plugins/fn-r/ChangeLog
@@ -1,6 +1,7 @@
 2013-04-04  Morten Welinder  <terra gnome org>
 
        * extra.c (pst): Implement.
+       (psnorm): Improve right-tail accuracy a bit.
 
 2013-03-09  Morten Welinder <terra gnome org>
 
diff --git a/plugins/fn-r/extra.c b/plugins/fn-r/extra.c
index 9a50c3f..1eb94e9 100644
--- a/plugins/fn-r/extra.c
+++ b/plugins/fn-r/extra.c
@@ -145,15 +145,14 @@ dsnorm (gnm_float x, gnm_float shape, gnm_float location, gnm_float scale, gbool
 gnm_float
 psnorm (gnm_float x, gnm_float shape, gnm_float location, gnm_float scale, gboolean lower_tail, gboolean 
log_p)
 {
-       gnm_float result;
+       gnm_float result, a, b;
 
        if (shape == 0.)
                return pnorm (x, location, scale, lower_tail, log_p);
 
-       result = pnorm (x, location, scale, TRUE, FALSE) - 2 * gnm_owent ((x - location)/scale, shape);
-
-       if (!lower_tail)
-               result = 1. - result;
+       a = pnorm (x, location, scale, lower_tail, FALSE);
+       b = 2 * gnm_owent ((x - location) / scale, shape);
+       result = lower_tail ? a - b : a + b;
 
        if (log_p)
                return gnm_log (result);


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