[prev in list] [next in list] [prev in thread] [next in thread]
List: koffice-devel
Subject: KSpread - Better Precision with NORMINV, ...
From: Martin Eitzenberger <m.eitzenberger () unix ! net>
Date: 2004-03-24 10:07:33
Message-ID: 200403241107.33290 () proxima ! psiplus ! at
[Download RAW message or body]
Hi!
I created a better gaussinv (base for NORMINV and some other statistical
functions) for OpenOffice based on the A241 Algorythm and the way Gnumeric
did it (but a little bit differently implemented) ... Because KSpread has
currently the same precision problems like OOo with some of these statistic
functions...
I hope this is usefull for you!
(PS: I'm not subscribed to this mailinglist, so please reply directly to
me ;-) )
Have Fun!
Martin
["gaussinv.c" (text/x-csrc)]
/*
Alternative gaussinv-Implementation for OpenOffice.org Calc
By Martin Eitzenberger <m.eitzenberger@unix.net>
Inspired by Gnumeric's qnorm
Licensed under the terms of the
GNU Lesser General Public License Version 2.1
*/
#include <stdio.h>
#include <math.h>
double gaussinv(double x);
int main(int argc,char**argv)
{
double result,sigma,mue,x;
x=(double)0.975;
mue=0;
sigma=1;
/* Test Norminv, as implemented in OpenOffice Calc */
result=gaussinv(x)*sigma+mue;
printf("Result: %0.20f\n",result);
}
double gaussinv(double x)
{
double q,t,z;
q=x-0.5;
if(fabs(q)<=.425)
{
t=0.180625-q*q;
z=
q*
(
(
(
(
(
(
(
t*2509.0809287301226727+33430.575583588128105
)
*t+67265.770927008700853
)
*t+45921.953931549871457
)
*t+13731.693765509461125
)
*t+1971.5909503065514427
)
*t+133.14166789178437745
)
*t+3.387132872796366608
)
/
(
(
(
(
(
(
(
t*5226.495278852854561+28729.085735721942674
)
*t+39307.89580009271061
)
*t+21213.794301586595867
)
*t+5394.1960214247511077
)
*t+687.1870074920579083
)
*t+42.313330701600911252
)
*t+1.0
);
}
else
{
if(q>0) t=1-x;
else t=x;
t=sqrt(-log(t));
if(t<=5.0)
{
t+=-1.6;
z=
(
(
(
(
(
(
(
t*7.7454501427834140764e-4+0.0227238449892691845833
)
*t+0.24178072517745061177
)
*t+1.27045825245236838258
)
*t+3.64784832476320460504
)
*t+5.7694972214606914055
)
*t+4.6303378461565452959
)
*t+1.42343711074968357734
)
/
(
(
(
(
(
(
(
t*1.05075007164441684324e-9+5.475938084995344946e-4
)
*t+0.0151986665636164571966
)
*t+0.14810397642748007459
)
*t+0.68976733498510000455
)
*t+1.6763848301838038494
)
*t+2.05319162663775882187
)
*t+1.0
);
}
else
{
t+=-5.0;
z=
(
(
(
(
(
(
(
t*2.01033439929228813265e-7+2.71155556874348757815e-5
)
*t+0.0012426609473880784386
)
*t+0.026532189526576123093
)
*t+0.29656057182850489123
)
*t+1.7848265399172913358
)
*t+5.4637849111641143699
)
*t+6.6579046435011037772
)
/
(
(
(
(
(
(
(
t*2.04426310338993978564e-15+1.4215117583164458887e-7
)
*t+1.8463183175100546818e-5
)
*t+7.868691311456132591e-4
)
*t+0.0148753612908506148525
)
*t+0.13692988092273580531
)
*t+0.59983220655588793769
)
*t+1.0
);
}
if(q<0.0) z=-z;
}
return z;
}
_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic