Commit 54be9059 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Ok, people _are_ reading this, :-)

1999-06-25  Morten Welinder  <terra@diku.dk>

	* src/fn-eng.c (eng_functions_init): Extend impower to handle two
 	complex numbers.
	(eng_functions_init): Prepare for besseli and besselk.  Docs
 	please.

	* src/mathfunc.c (dweibull, pweibull, ppois, dpois, dexp, pexp,
 	dbinom, pbinom, qbinom, besseli, besselk): New functions.

	* src/fn-stat.c: Use new mathfuncs.
	(gnumeric_kurt): Use range function.
	(gnumeric_kurtp): New function.
	(gnumeric_skewp): New function.

	* src/mathfunc.c (range_skew_est): Rename from range_skew.
	(range_skew_pop): New function.
	(range_kurtosis_m3_est): New function.
	(range_kurtosis_m3_pop): New function.

	* src/fn-math.c (gnumeric_gcd): Cleanup and fix.
parent 82f545e4
Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-eng.c (eng_functions_init): Extend impower to handle two
complex numbers.
(eng_functions_init): Prepare for besseli and besselk. Docs
please.
* src/mathfunc.c (dweibull, pweibull, ppois, dpois, dexp, pexp,
dbinom, pbinom, qbinom, besseli, besselk): New functions.
* src/fn-stat.c (gnumeric_kurt): Use range function.
* src/fn-stat.c: Use new mathfuncs.
(gnumeric_kurt): Use range function.
(gnumeric_kurtp): New function.
(gnumeric_skewp): New function.
......@@ -9,8 +18,6 @@ Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
(range_kurtosis_m3_est): New function.
(range_kurtosis_m3_pop): New function.
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_gcd): Cleanup and fix.
1999-06-24 Michael Meeks <michael@edenproject.org>
......
Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-eng.c (eng_functions_init): Extend impower to handle two
complex numbers.
(eng_functions_init): Prepare for besseli and besselk. Docs
please.
* src/mathfunc.c (dweibull, pweibull, ppois, dpois, dexp, pexp,
dbinom, pbinom, qbinom, besseli, besselk): New functions.
* src/fn-stat.c (gnumeric_kurt): Use range function.
* src/fn-stat.c: Use new mathfuncs.
(gnumeric_kurt): Use range function.
(gnumeric_kurtp): New function.
(gnumeric_skewp): New function.
......@@ -9,8 +18,6 @@ Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
(range_kurtosis_m3_est): New function.
(range_kurtosis_m3_pop): New function.
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_gcd): Cleanup and fix.
1999-06-24 Michael Meeks <michael@edenproject.org>
......
Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-eng.c (eng_functions_init): Extend impower to handle two
complex numbers.
(eng_functions_init): Prepare for besseli and besselk. Docs
please.
* src/mathfunc.c (dweibull, pweibull, ppois, dpois, dexp, pexp,
dbinom, pbinom, qbinom, besseli, besselk): New functions.
* src/fn-stat.c (gnumeric_kurt): Use range function.
* src/fn-stat.c: Use new mathfuncs.
(gnumeric_kurt): Use range function.
(gnumeric_kurtp): New function.
(gnumeric_skewp): New function.
......@@ -9,8 +18,6 @@ Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
(range_kurtosis_m3_est): New function.
(range_kurtosis_m3_pop): New function.
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_gcd): Cleanup and fix.
1999-06-24 Michael Meeks <michael@edenproject.org>
......
Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-eng.c (eng_functions_init): Extend impower to handle two
complex numbers.
(eng_functions_init): Prepare for besseli and besselk. Docs
please.
* src/mathfunc.c (dweibull, pweibull, ppois, dpois, dexp, pexp,
dbinom, pbinom, qbinom, besseli, besselk): New functions.
* src/fn-stat.c (gnumeric_kurt): Use range function.
* src/fn-stat.c: Use new mathfuncs.
(gnumeric_kurt): Use range function.
(gnumeric_kurtp): New function.
(gnumeric_skewp): New function.
......@@ -9,8 +18,6 @@ Fri Jun 25 12:56:37 1999 Morten Welinder <welinder@rentec.com>
(range_kurtosis_m3_est): New function.
(range_kurtosis_m3_pop): New function.
1999-06-25 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_gcd): Cleanup and fix.
1999-06-24 Michael Meeks <michael@edenproject.org>
......
......@@ -381,13 +381,13 @@ static char *help_besselj = {
"@DESCRIPTION="
"The BESSELJ function returns the bessel function with "
"x is where the function is evaluated. "
"y is the order of the bessel function, if non-integer it is "
"@x is where the function is evaluated. "
"@y is the order of the bessel function, if non-integer it is "
"truncated."
"\n"
"if x or n are not numeric a #VALUE! error is returned."
"if n < 0 a #NUM! error is returned."
"If @x or @y are not numeric a #VALUE! error is returned. "
"If @y < 0 a #NUM! error is returned."
"\n"
"@SEEALSO=BESSELJ,BESSELK,BESSELY")
};
......@@ -395,14 +395,12 @@ static char *help_besselj = {
static Value *
gnumeric_besselj (FunctionEvalInfo *ei, Value **argv)
{
int y;
if (argv[0]->type != VALUE_INTEGER &&
argv[1]->type != VALUE_INTEGER &&
argv[0]->type != VALUE_FLOAT &&
argv[1]->type != VALUE_FLOAT)
return function_error (ei, gnumeric_err_VALUE);
int x, y;
if ((y=value_get_as_int(argv[1]))<0)
x = value_get_as_int (argv[0]);
y = value_get_as_int (argv[1]);
if (y<0)
return function_error (ei, gnumeric_err_NUM);
return value_new_float (jn (y, value_get_as_float (argv [0])));
......@@ -1598,78 +1596,86 @@ void eng_functions_init()
{
FunctionCategory *cat = function_get_category (_("Engineering"));
function_add_args (cat, "bessely", "ff", "xnum,ynum", &help_bessely,
gnumeric_bessely);
#if 0
function_add_args (cat, "besseli", "ff", "xnum,ynum", &help_besseli,
gnumeric_besseli);
#endif
function_add_args (cat, "besselj", "ff", "xnum,ynum", &help_besselj,
gnumeric_besselj);
gnumeric_besselj);
#if 0
function_add_args (cat, "besselk", "ff", "xnum,ynum", &help_besselk,
gnumeric_besselk);
#endif
function_add_args (cat, "bessely", "ff", "xnum,ynum", &help_bessely,
gnumeric_bessely);
function_add_args (cat, "bin2dec", "?", "number", &help_bin2dec,
gnumeric_bin2dec);
gnumeric_bin2dec);
function_add_args (cat, "bin2hex", "?|f", "xnum,ynum", &help_bin2hex,
gnumeric_bin2hex);
gnumeric_bin2hex);
function_add_args (cat, "bin2oct", "?|f", "xnum,ynum", &help_bin2oct,
gnumeric_bin2oct);
gnumeric_bin2oct);
function_add_args (cat, "complex", "ff|s", "real,im[,suffix]", &help_complex,
gnumeric_complex);
gnumeric_complex);
function_add_args (cat, "convert", "fss", "number,from_unit,to_unit", &help_convert,
gnumeric_convert);
gnumeric_convert);
function_add_args (cat, "dec2bin", "?|f", "xnum,ynum", &help_dec2bin,
gnumeric_dec2bin);
gnumeric_dec2bin);
function_add_args (cat, "dec2oct", "?|f", "xnum,ynum", &help_dec2oct,
gnumeric_dec2oct);
gnumeric_dec2oct);
function_add_args (cat, "dec2hex", "?|f", "xnum,ynum", &help_dec2hex,
gnumeric_dec2hex);
gnumeric_dec2hex);
function_add_args (cat, "delta", "f|f", "xnum,ynum", &help_delta,
gnumeric_delta);
gnumeric_delta);
function_add_args (cat, "erf", "f|f", "lower,upper", &help_erf,
gnumeric_erf );
gnumeric_erf );
function_add_args (cat, "erfc", "f", "number", &help_erfc,
gnumeric_erfc);
gnumeric_erfc);
function_add_args (cat, "gestep", "f|f", "xnum,ynum", &help_gestep,
gnumeric_gestep);
gnumeric_gestep);
function_add_args (cat, "hex2bin", "?|f", "xnum,ynum", &help_hex2bin,
gnumeric_hex2bin);
gnumeric_hex2bin);
function_add_args (cat, "hex2dec", "?", "number", &help_hex2dec,
gnumeric_hex2dec);
gnumeric_hex2dec);
function_add_args (cat, "hex2oct", "?|f", "xnum,ynum", &help_hex2oct,
gnumeric_hex2oct);
gnumeric_hex2oct);
function_add_args (cat, "imabs", "?", "inumber", &help_imabs,
gnumeric_imabs);
gnumeric_imabs);
function_add_args (cat, "imaginary", "?", "inumber", &help_imaginary,
gnumeric_imaginary);
gnumeric_imaginary);
function_add_args (cat, "imargument", "?", "inumber", &help_imargument,
gnumeric_imargument);
gnumeric_imargument);
function_add_args (cat, "imconjugate", "?", "inumber", &help_imconjugate,
gnumeric_imconjugate);
gnumeric_imconjugate);
function_add_args (cat, "imcos", "?", "inumber", &help_imcos,
gnumeric_imcos);
gnumeric_imcos);
function_add_args (cat, "imdiv", "??", "inumber,inumber", &help_imdiv,
gnumeric_imdiv);
gnumeric_imdiv);
function_add_args (cat, "imexp", "?", "inumber", &help_imexp,
gnumeric_imexp);
gnumeric_imexp);
function_add_args (cat, "imln", "?", "inumber", &help_imln,
gnumeric_imln);
gnumeric_imln);
function_add_args (cat, "imlog10", "?", "inumber", &help_imlog10,
gnumeric_imlog10);
gnumeric_imlog10);
function_add_args (cat, "imlog2", "?", "inumber", &help_imlog2,
gnumeric_imlog2);
function_add_args (cat, "impower", "?f", "inumber,number", &help_impower,
gnumeric_impower);
gnumeric_imlog2);
function_add_args (cat, "impower", "??", "inumber,inumber", &help_impower,
gnumeric_impower);
function_add_nodes (cat, "improduct", "??", "inumber,inumber", &help_improduct,
gnumeric_improduct);
gnumeric_improduct);
function_add_args (cat, "imreal", "?", "inumber", &help_imreal,
gnumeric_imreal);
gnumeric_imreal);
function_add_args (cat, "imsin", "?", "inumber", &help_imsin,
gnumeric_imsin);
gnumeric_imsin);
function_add_args (cat, "imsqrt", "?", "inumber", &help_imsqrt,
gnumeric_imsqrt);
gnumeric_imsqrt);
function_add_args (cat, "imsub", "??", "inumber,inumber", &help_imsub,
gnumeric_imsub);
gnumeric_imsub);
function_add_nodes (cat, "imsum", "??", "inumber,inumber", &help_imsum,
gnumeric_imsum);
gnumeric_imsum);
function_add_args (cat, "oct2bin", "?|f", "xnum,ynum", &help_oct2bin,
gnumeric_oct2bin);
gnumeric_oct2bin);
function_add_args (cat, "oct2dec", "?", "number", &help_oct2dec,
gnumeric_oct2dec);
gnumeric_oct2dec);
function_add_args (cat, "oct2hex", "?|f", "xnum,ynum", &help_oct2hex,
gnumeric_oct2hex);
gnumeric_oct2hex);
}
......@@ -540,7 +540,7 @@ gnumeric_negbinomdist (FunctionEvalInfo *ei, Value **argv)
r = value_get_as_int (argv [1]);
p = value_get_as_float (argv[2]);
if ((x + r -1) <= 0 || p < 0 || p > 1)
if ((x + r - 1) <= 0 || p < 0 || p > 1)
return function_error (ei, gnumeric_err_NUM);
return value_new_float (combin (x+r-1, r-1) * pow (p, r) * pow (1-p, x));
......@@ -1036,15 +1036,13 @@ gnumeric_expondist (FunctionEvalInfo *ei, Value **argv)
return function_error (ei, gnumeric_err_NUM);
cuml = value_get_as_bool (argv[2], &err);
if (err)
return function_error (ei, gnumeric_err_VALUE);
if (cuml){
return value_new_float (-expm1(-y*x));
} else {
return value_new_float (y*exp(-y*x));
}
if (cuml)
return value_new_float (pexp (x, 1 / y));
else
return value_new_float (dexp (x, 1 / y));
}
static char *help_gammaln = {
......@@ -1207,7 +1205,7 @@ static char *help_chitest = {
"@DESCRIPTION="
"The CHITEST function returns the test for independence of "
"chi-squared distribution. "
"chi-squared distribution."
"\n"
"@actual_range is a range that contains the observed data points. "
"@theoretical_range is a range that contains the expected values "
......@@ -1576,17 +1574,10 @@ gnumeric_binomdist (FunctionEvalInfo *ei, Value **argv)
if (n<0 || trials<0 || p<0 || p>1 || n>trials || err)
return function_error (ei, gnumeric_err_NUM);
if (cuml){
float_t v=0;
int x;
for (x=0; x<=n; x++)
v += (combin(trials, x) * pow(p, x) *
pow(1-p, trials-x));
return value_new_float (v);
} else
return value_new_float (combin(trials, n) * pow(p, n) *
pow(1-p, trials-n));
if (cuml)
return value_new_float (pbinom (n, trials, p));
else
return value_new_float (dbinom (n, trials, p));
}
static char *help_critbinom = {
......@@ -1614,11 +1605,6 @@ gnumeric_critbinom (FunctionEvalInfo *ei, Value **argv)
float_t p, alpha, sum;
int x;
if (!VALUE_IS_NUMBER(argv[0]) ||
!VALUE_IS_NUMBER(argv[1]) ||
!VALUE_IS_NUMBER(argv[2]))
return function_error (ei, gnumeric_err_VALUE);
trials = value_get_as_int (argv [0]);
p = value_get_as_float (argv[1]);
alpha = value_get_as_float (argv[2]);
......@@ -1626,10 +1612,7 @@ gnumeric_critbinom (FunctionEvalInfo *ei, Value **argv)
if (trials<0 || p<0 || p>1 || alpha<0 || alpha>1)
return function_error (ei, gnumeric_err_NUM);
sum = 0;
for (x=0; sum<alpha; x++)
sum += (combin(trials, x) * pow(p, x) * pow(1-p, trials-x));
return value_new_int (x-1);
return value_new_float (qbinom (alpha, trials, p));
}
static char *help_permut = {
......@@ -1641,7 +1624,6 @@ static char *help_permut = {
"@n is the number of objects, @k is the number of objects in each "
"permutation."
"\n"
"if n or k is non-integer PERMUT returns #VALUE! error. "
"if n = 0 PERMUT returns #NUM! error. "
"if n < k PERMUT returns #NUM! error."
"\n"
......@@ -1653,17 +1635,13 @@ gnumeric_permut (FunctionEvalInfo *ei, Value **argv)
{
int n, k;
if (argv[0]->type != VALUE_INTEGER ||
argv[1]->type != VALUE_INTEGER)
return function_error (ei, gnumeric_err_VALUE);
n = value_get_as_int (argv [0]);
k = value_get_as_int (argv [1]);
if (n<k || n==0)
if (0 <= k && k <= n)
return value_new_float (fact (n) / fact (n-k));
else
return function_error (ei, gnumeric_err_NUM);
return value_new_float (fact(n) / fact(n-k));
}
static char *help_hypgeomdist = {
......@@ -1688,11 +1666,6 @@ gnumeric_hypgeomdist (FunctionEvalInfo *ei, Value **argv)
{
int x, n, M, N;
if (!VALUE_IS_NUMBER(argv[0]) ||
!VALUE_IS_NUMBER(argv[1]) ||
!VALUE_IS_NUMBER(argv[2]))
return function_error (ei, gnumeric_err_VALUE);
x = value_get_as_int (argv [0]);
n = value_get_as_int (argv [1]);
M = value_get_as_int (argv [2]);
......@@ -1726,11 +1699,6 @@ gnumeric_confidence (FunctionEvalInfo *ei, Value **argv)
float_t x, stddev;
int size;
if (!VALUE_IS_NUMBER(argv[0]) ||
!VALUE_IS_NUMBER(argv[1]) ||
!VALUE_IS_NUMBER(argv[2]))
return function_error (ei, gnumeric_err_VALUE);
x = value_get_as_float (argv [0]);
stddev = value_get_as_float (argv [1]);
size = value_get_as_int (argv [2]);
......@@ -1769,6 +1737,8 @@ gnumeric_standardize (FunctionEvalInfo *ei, Value **argv)
if (stddev == 0)
return function_error (ei, gnumeric_err_DIV0);
else if (stddev < 0)
return function_error (ei, gnumeric_err_NUM);
return value_new_float ((x-mean) / stddev);
}
......@@ -1793,7 +1763,7 @@ static Value *
gnumeric_weibull (FunctionEvalInfo *ei, Value **argv)
{
float_t x, alpha, beta;
int cuml, err=0;
int cuml, err;
x = value_get_as_float (argv [0]);
alpha = value_get_as_float (argv [1]);
......@@ -1803,15 +1773,13 @@ gnumeric_weibull (FunctionEvalInfo *ei, Value **argv)
return function_error (ei, gnumeric_err_NUM);
cuml = value_get_as_bool (argv[3], &err);
if (err)
return function_error (ei, gnumeric_err_VALUE);
if (cuml)
return value_new_float (1.0 - exp(-pow(x/beta, alpha)));
return value_new_float (pweibull (x, alpha, beta));
else
return value_new_float ((alpha/pow(beta, alpha)*
pow(x, alpha-1)*exp(-pow(x/beta, alpha))));
return value_new_float (dweibull (x, alpha, beta));
}
static char *help_normdist = {
......@@ -1843,7 +1811,6 @@ gnumeric_normdist (FunctionEvalInfo *ei, Value **argv)
return function_error (ei, gnumeric_err_DIV0);
cuml = value_get_as_bool (argv[3], &err);
if (err)
return function_error (ei, gnumeric_err_VALUE);
......@@ -2044,17 +2011,10 @@ gnumeric_poisson (FunctionEvalInfo *ei, Value **argv)
if (x<=0 || mean <=0 || err)
return function_error (ei, gnumeric_err_NUM);
if (cuml) {
int k;
float_t sum = 0;
for (k=0; k<=x; k++)
sum += exp(-mean)*pow(mean,k) / exp (lgamma (k + 1));
return value_new_float (sum);
} else
return value_new_float (exp(-mean)*pow(mean,x) /
exp (lgamma (x + 1)));
if (cuml)
return value_new_float (ppois (x, mean));
else
return value_new_float (dpois (x, mean));
}
static char *help_pearson = {
......
......@@ -381,13 +381,13 @@ static char *help_besselj = {
"@DESCRIPTION="
"The BESSELJ function returns the bessel function with "
"x is where the function is evaluated. "
"y is the order of the bessel function, if non-integer it is "
"@x is where the function is evaluated. "
"@y is the order of the bessel function, if non-integer it is "
"truncated."
"\n"
"if x or n are not numeric a #VALUE! error is returned."
"if n < 0 a #NUM! error is returned."
"If @x or @y are not numeric a #VALUE! error is returned. "
"If @y < 0 a #NUM! error is returned."
"\n"
"@SEEALSO=BESSELJ,BESSELK,BESSELY")
};
......@@ -395,14 +395,12 @@ static char *help_besselj = {
static Value *
gnumeric_besselj (FunctionEvalInfo *ei, Value **argv)
{
int y;
if (argv[0]->type != VALUE_INTEGER &&
argv[1]->type != VALUE_INTEGER &&
argv[0]->type != VALUE_FLOAT &&
argv[1]->type != VALUE_FLOAT)
return function_error (ei, gnumeric_err_VALUE);
int x, y;
if ((y=value_get_as_int(argv[1]))<0)
x = value_get_as_int (argv[0]);
y = value_get_as_int (argv[1]);
if (y<0)
return function_error (ei, gnumeric_err_NUM);
return value_new_float (jn (y, value_get_as_float (argv [0])));
......@@ -1598,78 +1596,86 @@ void eng_functions_init()
{
FunctionCategory *cat = function_get_category (_("Engineering"));
function_add_args (cat, "bessely", "ff", "xnum,ynum", &help_bessely,
gnumeric_bessely);
#if 0
function_add_args (cat, "besseli", "ff", "xnum,ynum", &help_besseli,
gnumeric_besseli);
#endif
function_add_args (cat, "besselj", "ff", "xnum,ynum", &help_besselj,
gnumeric_besselj);
gnumeric_besselj);
#if 0
function_add_args (cat, "besselk", "ff", "xnum,ynum", &help_besselk,
gnumeric_besselk);
#endif
function_add_args (cat, "bessely", "ff", "xnum,ynum", &help_bessely,
gnumeric_bessely);
function_add_args (cat, "bin2dec", "?", "number", &help_bin2dec,
gnumeric_bin2dec);
gnumeric_bin2dec);
function_add_args (cat, "bin2hex", "?|f", "xnum,ynum", &help_bin2hex,
gnumeric_bin2hex);
gnumeric_bin2hex);
function_add_args (cat, "bin2oct", "?|f", "xnum,ynum", &help_bin2oct,
gnumeric_bin2oct);
gnumeric_bin2oct);
function_add_args (cat, "complex", "ff|s", "real,im[,suffix]", &help_complex,
gnumeric_complex);
gnumeric_complex);
function_add_args (cat, "convert", "fss", "number,from_unit,to_unit", &help_convert,
gnumeric_convert);
gnumeric_convert);
function_add_args (cat, "dec2bin", "?|f", "xnum,ynum", &help_dec2bin,
gnumeric_dec2bin);
gnumeric_dec2bin);
function_add_args (cat, "dec2oct", "?|f", "xnum,ynum", &help_dec2oct,
gnumeric_dec2oct);
gnumeric_dec2oct);
function_add_args (cat, "dec2hex", "?|f", "xnum,ynum", &help_dec2hex,
gnumeric_dec2hex);
gnumeric_dec2hex);
function_add_args (cat, "delta", "f|f", "xnum,ynum", &help_delta,
gnumeric_delta);
gnumeric_delta);
function_add_args (cat, "erf", "f|f", "lower,upper", &help_erf,
gnumeric_erf );
gnumeric_erf );
function_add_args (cat, "erfc", "f", "number", &help_erfc,
gnumeric_erfc);
gnumeric_erfc);
function_add_args (cat, "gestep", "f|f", "xnum,ynum", &help_gestep,
gnumeric_gestep);
gnumeric_gestep);
function_add_args (cat, "hex2bin", "?|f", "xnum,ynum", &help_hex2bin,
gnumeric_hex2bin);
gnumeric_hex2bin);
function_add_args (cat, "hex2dec", "?", "number", &help_hex2dec,
gnumeric_hex2dec);
gnumeric_hex2dec);
function_add_args (cat, "hex2oct", "?|f", "xnum,ynum", &help_hex2oct,
gnumeric_hex2oct);
gnumeric_hex2oct);
function_add_args (cat, "imabs", "?", "inumber", &help_imabs,
gnumeric_imabs);
gnumeric_imabs);
function_add_args (cat, "imaginary", "?", "inumber", &help_imaginary,
gnumeric_imaginary);
gnumeric_imaginary);
function_add_args (cat, "imargument", "?", "inumber", &help_imargument,
gnumeric_imargument);
gnumeric_imargument);
function_add_args (cat, "imconjugate", "?", "inumber", &help_imconjugate,
gnumeric_imconjugate);
gnumeric_imconjugate);
function_add_args (cat, "imcos", "?", "inumber", &help_imcos,
gnumeric_imcos);
gnumeric_imcos);
function_add_args (cat, "imdiv", "??", "inumber,inumber", &help_imdiv,
gnumeric_imdiv);
gnumeric_imdiv);
function_add_args (cat, "imexp", "?", "inumber", &help_imexp,
gnumeric_imexp);
gnumeric_imexp);
function_add_args (cat, "imln", "?", "inumber", &help_imln,
gnumeric_imln);
gnumeric_imln);
function_add_args (cat, "imlog10", "?", "inumber", &help_imlog10,
gnumeric_imlog10);
gnumeric_imlog10);
function_add_args (cat, "imlog2", "?", "inumber", &help_imlog2,
gnumeric_imlog2);
function_add_args (cat, "impower", "?f", "inumber,number", &help_impower,
gnumeric_impower);
gnumeric_imlog2);
function_add_args (cat, "impower", "??", "inumber,inumber", &help_impower,
gnumeric_impower);
function_add_nodes (cat, "improduct", "??", "inumber,inumber", &help_improduct,
gnumeric_improduct);
gnumeric_improduct);
function_add_args (cat, "imreal", "?", "inumber", &help_imreal,
gnumeric_imreal);
gnumeric_imreal);
function_add_args (cat, "imsin", "?", "inumber", &help_imsin,
gnumeric_imsin);
gnumeric_imsin);
function_add_args (cat, "imsqrt", "?", "inumber", &help_imsqrt,
gnumeric_imsqrt);
gnumeric_imsqrt);
function_add_args (cat, "imsub", "??", "inumber,inumber", &help_imsub,
gnumeric_imsub);
gnumeric_imsub);
function_add_nodes (cat, "imsum", "??", "inumber,inumber", &help_imsum,
gnumeric_imsum);
gnumeric_imsum);
function_add_args (cat, "oct2bin", "?|f", "xnum,ynum", &help_oct2bin,
gnumeric_oct2bin);
gnumeric_oct2bin);
function_add_args (cat, "oct2dec", "?", "number", &help_oct2dec,
gnumeric_oct2dec);
gnumeric_oct2dec);
function_add_args (cat, "oct2hex", "?|f", "xnum,ynum", &help_oct2hex,
gnumeric_oct2hex);
gnumeric_oct2hex);
}
......@@ -540,7 +540,7 @@ gnumeric_negbinomdist (FunctionEvalInfo *ei, Value **argv)
r = value_get_as_int (argv [1]);
p = value_get_as_float (argv[2]);
if ((x + r -1) <= 0 || p < 0 || p > 1)
if ((x + r - 1) <= 0 || p < 0 || p > 1)
return function_error (ei, gnumeric_err_NUM);
return value_new_float (combin (x+r-1, r-1) * pow (p, r) * pow (1-p, x));
......@@ -1036,15 +1036,13 @@ gnumeric_expondist (FunctionEvalInfo *ei, Value **argv)
return function_error (ei, gnumeric_err_NUM);
cuml = value_get_as_bool (argv[2], &err);
if (err)
return function_error (ei, gnumeric_err_VALUE);
if (cuml){
return value_new_float (-expm1(-y*x));
} else {
return value_new_float (y*exp(-y*x));
}
if (cuml)
return value_new_float (pexp (x, 1 / y));
else
return value_new_float (dexp (x, 1 / y));
}
static char *help_gammaln = {
......@@ -1207,7 +1205,7 @@ static char *help_chitest = {
"@DESCRIPTION="
"The CHITEST function returns the test for independence of "
"chi-squared distribution. "
"chi-squared distribution."
"\n"
"@actual_range is a range that contains the observed data points. "
"@theoretical_range is a range that contains the expected values "
......@@ -1576,17 +1574,10 @@ gnumeric_binomdist (FunctionEvalInfo *ei, Value **argv)
if (n<0 || trials<0 || p<0 || p>1 || n>trials || err)
return function_error (ei, gnumeric_err_NUM);
if (cuml){
float_t v=0;
int x;
for (x=0; x<=n; x++)
v += (combin(trials, x) * pow(p, x) *
pow(1-p, trials-x));
return value_new_float (v);
} else
return value_new_float (combin(trials, n) * pow(p, n) *
pow(1-p, trials-n));
if (cuml)
return value_new_float (pbinom (n, trials, p));
else
return value_new_float (dbinom (n, trials, p));
}
static char *help_critbinom = {
......@@ -1614,11 +1605,6 @@ gnumeric_critbinom (FunctionEvalInfo *ei, Value **argv)
float_t p, alpha, sum;
int x;
if (!VALUE_IS_NUMBER(argv[0]) ||
!VALUE_IS_NUMBER(argv[1]) ||
!VALUE_IS_NUMBER(argv[2]))
return function_error (ei, gnumeric_err_VALUE);
trials = value_get_as_int (argv [0]);
p = value_get_as_float (argv[1]);
alpha = value_get_as_float (argv[2]);
......@@ -1626,10 +1612,7 @@ gnumeric_critbinom (FunctionEvalInfo *ei, Value **argv)
if (trials<0 || p<0 || p>1 || alpha<0 || alpha>1)
return function_error (ei, gnumeric_err_NUM);
sum = 0;
for (x=0; sum<alpha; x++)
sum += (combin(trials, x) * pow(p, x) * pow(1-p, trials-x));
return value_new_int (x-1);
return value_new_float (qbinom (alpha, trials, p));
}
static char *help_permut = {
......@@ -1641,7 +1624,6 @@ static char *help_permut = {
"@n is the number of objects, @k is the number of objects in each "
"permutation."
"\n"
"if n or k is non-integer PERMUT returns #VALUE! error. "
"if n = 0 PERMUT returns #NUM! error. "
"if n < k PERMUT returns #NUM! error."
"\n"
......@@ -1653,17 +1635,13 @@ gnumeric_permut (FunctionEvalInfo *ei, Value **argv)
{
int n, k;
if (argv[0]->type != VALUE_INTEGER ||
argv[1]->type != VALUE_INTEGER)
return function_error (ei, gnumeric_err_VALUE);
n = value_get_as_int (argv [0]);
k = value_get_as_int (argv [1]);