[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/kspread/functions
From:       Sascha Pfau <MrPeacock () web ! de>
Date:       2007-09-20 18:55:11
Message-ID: 1190314511.889070.22230.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 714855 by pfau:

functions	fixes LOGINV, LOGNORMDIST

 M  +33 -11    statistical.cpp  


--- trunk/koffice/kspread/functions/statistical.cpp #714854:714855
@@ -243,7 +243,7 @@
   f = new Function ("LEGACYNORMSINV", func_normsinv);
   repo->add (f);
   f = new Function ("LOGINV", func_loginv);
-  f->setParamCount (3);
+  f->setParamCount (1,3);
   repo->add (f);
   f = new Function ("LOGNORMDIST", func_lognormdist);
   f->setParamCount (1, 4);
@@ -1502,9 +1502,16 @@
 Value func_loginv (valVector args, ValueCalc *calc, FuncExtra *)
 {
   Value p = args[0];
-  Value m = args[1];
-  Value s = args[2];
 
+  // defaults
+  Value m = Value(0.0);
+  Value s = Value(1.0);
+
+  if ( args.count() > 1)
+    m = args[1];
+  if ( args.count() > 2)
+    s = args[2];
+
   if (calc->lower (p, Value(0)) || calc->greater (p, Value(1)))
     return Value::errorVALUE();
 
@@ -1531,24 +1538,39 @@
 Value func_lognormdist (valVector args, ValueCalc *calc, FuncExtra *)
 {
   // defaults
-  Value mue = Value(0);
+  Value mue   = Value(0);
   Value sigma = Value(1);
   bool kum = true;
 
   Value x = args[0];
   if ( args.count() > 1)
-    Value mue = args[1];
+    mue = args[1];
   if ( args.count() > 2)
-    Value sigma = args[2];
+    sigma = args[2];
   if (args.count() > 3)
     kum = calc->conv()->asInteger (args[3]).asInteger();
 
-  if (!calc->greater (sigma, 0.0) || (!calc->greater (x, 0.0)))
-    return Value::errorVALUE();
+  if ( !kum )
+  {
+    // TODO implement me !!!
+    return Value::errorVALUE();    
 
-  // (ln(x) - mue) / sigma
-  Value Y = calc->div (calc->sub (calc->ln (x), mue), sigma);
-  return calc->add (calc->gauss (Y), 0.5);
+    // check constraints
+    if (!calc->greater (sigma, 0.0) || (!calc->greater (x, 0.0)))
+      return Value::errorVALUE();
+  }
+  else
+  {
+    // non-cumulative
+    
+    // check constraints
+    if ( calc->lower( x, Value(0.0)) )
+      return Value(0.0);
+
+    // (ln(x) - mue) / sigma
+    Value Y = calc->div (calc->sub (calc->ln (x), mue), sigma);
+    return calc->add (calc->gauss (Y), 0.5);
+  }
 }
 
 //
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic