Commit 97eadaac authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder
Browse files

Simplify using value_get_as_checked_bool.

2006-01-09  Morten Welinder  <terra@gnome.org>

	* functions.c (func_coup): Simplify using
	value_get_as_checked_bool.

2006-01-09  Morten Welinder  <terra@gnome.org>

	* functions.c (gnumeric_expondist): Simplify.
	(gnumeric_binomdist): Ditto.
	(gnumeric_cauchy): Ditto.
	(gnumeric_weibull): Ditto.
	(gnumeric_normdist): Ditto.
	(gnumeric_hypgeomdist): Fix "cuml" option parsing.
	(gnumeric_gammadist): Ditto.

2006-01-09  Morten Welinder  <terra@gnome.org>

	* functions.c (gnumeric_fixed): Use value_get_as_checked_bool.
parent d2c9d528
2006-01-09 Morten Welinder <terra@gnome.org>
* functions.c (func_coup): Simplify using
value_get_as_checked_bool.
2005-11-14 Jody Goldberg <jody@gnome.org>
* Release 1.6.1
......
......@@ -278,15 +278,13 @@ func_coup (FunctionEvalInfo *ei, GnmValue const * const *argv,
{
GDate settlement, maturity;
GnmCouponConvention conv;
gboolean err = FALSE;
conv.freq = value_get_as_int (argv[2]);
conv.basis = argv[3] ? value_get_as_int (argv[3]) : BASIS_MSRB_30_360;
conv.eom = argv[4] ? value_get_as_bool (argv[4], &err) : TRUE;
conv.eom = argv[4] ? value_get_as_checked_bool (argv[4]) : TRUE;
conv.date_conv = workbook_date_conv (ei->pos->sheet->workbook);
if (err ||
!datetime_value_to_g (&settlement, argv[0], conv.date_conv) ||
if (!datetime_value_to_g (&settlement, argv[0], conv.date_conv) ||
!datetime_value_to_g (&maturity, argv[1], conv.date_conv))
return value_new_error_VALUE (ei->pos);
......
......@@ -840,7 +840,7 @@ gnumeric_indirect (FunctionEvalInfo *ei, GnmValue const * const *args)
char const *text = value_peek_string (args[0]);
GnmExprConventions const *convs = gnm_expr_conventions_default;
if (args[1] && !value_get_as_bool (args[1], NULL))
if (args[1] && !value_get_as_checked_bool (args[1]))
convs = gnm_expr_conventions_r1c1;
expr = gnm_expr_parse_str (text,
......
2006-01-09 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_expondist): Simplify.
(gnumeric_binomdist): Ditto.
(gnumeric_cauchy): Ditto.
(gnumeric_weibull): Ditto.
(gnumeric_normdist): Ditto.
(gnumeric_hypgeomdist): Fix "cum" option parsing.
(gnumeric_gammadist): Ditto.
2005-11-14 Jody Goldberg <jody@gnome.org>
* Release 1.6.1
......
......@@ -529,12 +529,9 @@ static GnmFuncHelp const help_negbinomdist[] = {
static GnmValue *
gnumeric_negbinomdist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int x, r;
gnm_float p;
x = value_get_as_int (argv[0]);
r = value_get_as_int (argv[1]);
p = value_get_as_float (argv[2]);
int x = value_get_as_int (argv[0]);
int r = value_get_as_int (argv[1]);
gnm_float p = value_get_as_float (argv[2]);
if ((x + r - 1) <= 0 || p < 0 || p > 1)
return value_new_error_NUM (ei->pos);
......@@ -1145,20 +1142,13 @@ static GnmFuncHelp const help_expondist[] = {
static GnmValue *
gnumeric_expondist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x, y;
int cuml;
gboolean err;
x = value_get_as_float (argv[0]);
y = value_get_as_float (argv[1]);
gnm_float x = value_get_as_float (argv[0]);
gnm_float y = value_get_as_float (argv[1]);
gboolean cuml = value_get_as_checked_bool (argv[2]);
if (x < 0.0 || y <= 0.0)
return value_new_error_NUM (ei->pos);
cuml = value_get_as_bool (argv[2], &err);
if (err)
return value_new_error_VALUE (ei->pos);
if (cuml)
return value_new_float (pexp (x, 1 / y, TRUE, FALSE));
else
......@@ -1277,17 +1267,14 @@ static GnmFuncHelp const help_gammadist[] = {
static GnmValue *
gnumeric_gammadist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x, alpha, beta;
int cum;
x = value_get_as_float (argv[0]);
alpha = value_get_as_float (argv[1]);
beta = value_get_as_float (argv[2]);
gnm_float x = value_get_as_float (argv[0]);
gnm_float alpha = value_get_as_float (argv[1]);
gnm_float beta = value_get_as_float (argv[2]);
gboolean cum = value_get_as_checked_bool (argv[3]);
if (x < 0 || alpha <= 0 || beta <= 0)
return value_new_error_NUM (ei->pos);
cum = value_get_as_int (argv[3]);
if (cum)
return value_new_float (pgamma (x, alpha, beta, TRUE, FALSE));
else
......@@ -1359,11 +1346,8 @@ static GnmFuncHelp const help_chidist[] = {
static GnmValue *
gnumeric_chidist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x;
int dof;
x = value_get_as_float (argv[0]);
dof = value_get_as_int (argv[1]);
gnm_float x = value_get_as_float (argv[0]);
int dof = value_get_as_int (argv[1]);
if (dof < 1)
return value_new_error_NUM (ei->pos);
......@@ -1396,11 +1380,8 @@ static GnmFuncHelp const help_chiinv[] = {
static GnmValue *
gnumeric_chiinv (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p;
int dof;
p = value_get_as_float (argv[0]);
dof = value_get_as_int (argv[1]);
gnm_float p = value_get_as_float (argv[0]);
int dof = value_get_as_int (argv[1]);
if (p < 0 || p > 1 || dof < 1)
return value_new_error_NUM (ei->pos);
......@@ -1667,12 +1648,9 @@ static GnmFuncHelp const help_tdist[] = {
static GnmValue *
gnumeric_tdist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x;
int dof, tails;
x = value_get_as_float (argv[0]);
dof = value_get_as_int (argv[1]);
tails = value_get_as_int (argv[2]);
gnm_float x = value_get_as_float (argv[0]);
int dof = value_get_as_int (argv[1]);
int tails = value_get_as_int (argv[2]);
if (dof < 1 || (tails != 1 && tails != 2))
return value_new_error_NUM (ei->pos);
......@@ -1706,11 +1684,8 @@ static GnmFuncHelp const help_tinv[] = {
static GnmValue *
gnumeric_tinv (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p;
int dof;
p = value_get_as_float (argv[0]);
dof = value_get_as_int (argv[1]);
gnm_float p = value_get_as_float (argv[0]);
int dof = value_get_as_int (argv[1]);
if (p < 0 || p > 1 || dof < 1)
return value_new_error_NUM (ei->pos);
......@@ -1745,12 +1720,9 @@ static GnmFuncHelp const help_fdist[] = {
static GnmValue *
gnumeric_fdist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x;
int dof1, dof2;
x = value_get_as_float (argv[0]);
dof1 = value_get_as_int (argv[1]);
dof2 = value_get_as_int (argv[2]);
gnm_float x = value_get_as_float (argv[0]);
int dof1 = value_get_as_int (argv[1]);
int dof2 = value_get_as_int (argv[2]);
if (x < 0 || dof1 < 1 || dof2 < 1)
return value_new_error_NUM (ei->pos);
......@@ -1929,12 +1901,9 @@ static GnmFuncHelp const help_finv[] = {
static GnmValue *
gnumeric_finv (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p;
int dof1, dof2;
p = value_get_as_float (argv[0]);
dof1 = value_get_as_int (argv[1]);
dof2 = value_get_as_int (argv[2]);
gnm_float p = value_get_as_float (argv[0]);
int dof1 = value_get_as_int (argv[1]);
int dof2 = value_get_as_int (argv[2]);
if (p < 0 || p > 1 || dof1 < 1 || dof2 < 1)
return value_new_error_NUM (ei->pos);
......@@ -1973,16 +1942,12 @@ static GnmFuncHelp const help_binomdist[] = {
static GnmValue *
gnumeric_binomdist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int n, trials, cuml;
gboolean err;
gnm_float p;
int n = value_get_as_int (argv[0]);
int trials = value_get_as_int (argv[1]);
gnm_float p = value_get_as_float (argv[2]);
gboolean cuml = value_get_as_checked_bool (argv[3]);
n = value_get_as_int (argv[0]);
trials = value_get_as_int (argv[1]);
p = value_get_as_float (argv[2]);
cuml = value_get_as_bool (argv[3], &err);
if (n < 0 || trials < 0 || p < 0 || p > 1 || n > trials || err)
if (n < 0 || trials < 0 || p < 0 || p > 1 || n > trials)
return value_new_error_NUM (ei->pos);
if (cuml)
......@@ -2018,16 +1983,11 @@ gnumeric_cauchy (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x = value_get_as_float (argv[0]);
gnm_float a = value_get_as_float (argv[1]);
int cuml;
gboolean err;
gboolean cuml = value_get_as_checked_bool (argv[2]);
if (a < 0)
return value_new_error_NUM (ei->pos);
cuml = value_get_as_bool (argv[2], &err);
if (err)
return value_new_error_VALUE (ei->pos);
if (cuml)
return value_new_float (pcauchy (x, 0, a, FALSE, FALSE));
else
......@@ -2064,12 +2024,9 @@ static GnmFuncHelp const help_critbinom[] = {
static GnmValue *
gnumeric_critbinom (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int trials;
gnm_float p, alpha;
trials = value_get_as_int (argv[0]);
p = value_get_as_float (argv[1]);
alpha = value_get_as_float (argv[2]);
int trials = value_get_as_int (argv[0]);
gnm_float p = value_get_as_float (argv[1]);
gnm_float alpha = value_get_as_float (argv[2]);
if (trials < 0 || p < 0 || p > 1 || alpha < 0 || alpha > 1)
return value_new_error_NUM (ei->pos);
......@@ -2104,10 +2061,8 @@ static GnmFuncHelp const help_permut[] = {
static GnmValue *
gnumeric_permut (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int n, k;
n = value_get_as_int (argv[0]);
k = value_get_as_int (argv[1]);
int n = value_get_as_int (argv[0]);
int k = value_get_as_int (argv[1]);
if (0 <= k && k <= n)
return value_new_float (permut (n, k));
......@@ -2151,7 +2106,7 @@ gnumeric_hypgeomdist (FunctionEvalInfo *ei, GnmValue const * const *argv)
int n = value_get_as_int (argv[1]);
int M = value_get_as_int (argv[2]);
int N = value_get_as_int (argv[3]);
gboolean cum = argv[4] ? value_get_as_int (argv[4]) : FALSE;
gboolean cum = argv[4] ? value_get_as_checked_bool (argv[4]) : FALSE;
if (x < 0 || n < 0 || M < 0 || N < 0 || x > M || n > N)
return value_new_error_NUM (ei->pos);
......@@ -2265,21 +2220,14 @@ static GnmFuncHelp const help_weibull[] = {
static GnmValue *
gnumeric_weibull (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x, alpha, beta;
int cuml;
gboolean err;
x = value_get_as_float (argv[0]);
alpha = value_get_as_float (argv[1]);
beta = value_get_as_float (argv[2]);
gnm_float x = value_get_as_float (argv[0]);
gnm_float alpha = value_get_as_float (argv[1]);
gnm_float beta = value_get_as_float (argv[2]);
gboolean cuml = value_get_as_checked_bool (argv[3]);
if (x < 0 || alpha <= 0 || beta <= 0)
return value_new_error_NUM (ei->pos);
cuml = value_get_as_bool (argv[3], &err);
if (err)
return value_new_error_VALUE (ei->pos);
if (cuml)
return value_new_float (pweibull (x, alpha, beta, TRUE, FALSE));
else
......@@ -2318,21 +2266,14 @@ static GnmFuncHelp const help_normdist[] = {
static GnmValue *
gnumeric_normdist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float x, mean, stddev;
int cuml;
gboolean err;
x = value_get_as_float (argv[0]);
mean = value_get_as_float (argv[1]);
stddev = value_get_as_float (argv[2]);
gnm_float x = value_get_as_float (argv[0]);
gnm_float mean = value_get_as_float (argv[1]);
gnm_float stddev = value_get_as_float (argv[2]);
gboolean cuml = value_get_as_checked_bool (argv[3]);
if (stddev <= 0)
return value_new_error_NUM (ei->pos);
cuml = value_get_as_bool (argv[3], &err);
if (err)
return value_new_error_VALUE (ei->pos);
if (cuml)
return value_new_float (pnorm (x, mean, stddev, TRUE, FALSE));
else
......@@ -2367,11 +2308,9 @@ static GnmFuncHelp const help_norminv[] = {
static GnmValue *
gnumeric_norminv (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float p, mean, stddev;
p = value_get_as_float (argv[0]);
mean = value_get_as_float (argv[1]);
stddev = value_get_as_float (argv[2]);
gnm_float p = value_get_as_float (argv[0]);
gnm_float mean = value_get_as_float (argv[1]);
gnm_float stddev = value_get_as_float (argv[2]);
if (p < 0 || p > 1 || stddev <= 0)
return value_new_error_NUM (ei->pos);
......@@ -2595,15 +2534,11 @@ static GnmFuncHelp const help_poisson[] = {
static GnmValue *
gnumeric_poisson (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float mean;
int x, cuml;
gboolean err;
x = value_get_as_int (argv[0]);
mean = value_get_as_float (argv[1]);
cuml = value_get_as_bool (argv[2], &err);
gnm_float x = value_get_as_int (argv[0]);
gnm_float mean = value_get_as_float (argv[1]);
gboolean cuml = value_get_as_checked_bool (argv[2]);
if (x < 0 || mean <= 0 || err)
if (x < 0 || mean <= 0)
return value_new_error_NUM (ei->pos);
if (cuml)
......@@ -5650,9 +5585,9 @@ static GnmFuncHelp const help_geomdist[] = {
static GnmValue *
gnumeric_geomdist (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
int k = value_get_as_int (argv[0]);
int k = value_get_as_int (argv[0]);
gnm_float p = value_get_as_float (argv[1]);
gboolean cum = value_get_as_int (argv[2]);
gboolean cum = value_get_as_checked_bool (argv[2]);
if (p < 0 || p > 1 || k < 0 || (cum != TRUE && cum != FALSE))
return value_new_error_NUM (ei->pos);
......@@ -5932,7 +5867,7 @@ const GnmFuncDescriptor stat_functions[] = {
help_binomdist, gnumeric_binomdist, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
{ "cauchy", "fff", N_("x,a,cum"), help_cauchy,
{ "cauchy", "ffb", N_("x,a,cum"), help_cauchy,
gnumeric_cauchy, NULL, NULL, NULL, NULL,
GNM_FUNC_SIMPLE, GNM_FUNC_IMPL_STATUS_COMPLETE, GNM_FUNC_TEST_STATUS_BASIC },
......
2006-01-09 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_fixed): Use value_get_as_checked_bool.
2006-01-06 Morten Welinder <terra@gnome.org>
* functions.c (gnumeric_char): Plug leak. Handle crazy input
......
......@@ -641,17 +641,10 @@ gnumeric_fixed (FunctionEvalInfo *ei, GnmValue const * const *argv)
{
gnm_float num = value_get_as_float (argv[0]);
gnm_float decimals = argv[1] ? value_get_as_float (argv[1]) : 2.0;
gboolean commas = TRUE;
gboolean commas = argv[2] ? value_get_as_checked_bool (argv[2]) : TRUE;
GONumberFormat fmt;
GString *str;
if (argv[2] != NULL) {
gboolean err;
commas = !value_get_as_bool (argv[2], &err);
if (err)
return value_new_error_VALUE (ei->pos);
}
decimals = gnm_fake_trunc (decimals);
if (decimals >= 128)
return value_new_error_VALUE (ei->pos);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment