Commit 2ab0a35d authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Correct error code; fix for b < 0.

2000-01-20  Morten Welinder  <terra@diku.dk>

	* src/functions/fn-math.c (gnumeric_mod): Correct error code; fix
 	for b < 0.
parent 4661eea5
2000-01-20 Morten Welinder <terra@diku.dk>
* src/functions/fn-math.c (gnumeric_mod): Correct error code; fix
for b < 0.
2000-01-20 Morten Welinder <terra@diku.dk>
* src/functions/fn-math.c (gnumeric_power): Correct error code.
......
2000-01-20 Morten Welinder <terra@diku.dk>
* src/functions/fn-math.c (gnumeric_mod): Correct error code; fix
for b < 0.
2000-01-20 Morten Welinder <terra@diku.dk>
* src/functions/fn-math.c (gnumeric_power): Correct error code.
......
......@@ -1202,25 +1202,29 @@ static char *help_mod = {
static Value *
gnumeric_mod (FunctionEvalInfo *ei, Value **argv)
{
int a,b;
int a, b;
a = value_get_as_int (argv[0]);
b = value_get_as_int (argv[1]);
if (b == 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
if (b < 0) {
a = -a;
return value_new_error (ei->pos, gnumeric_err_DIV0);
else if (b > 0) {
if (a >= 0)
return value_new_int (a % b);
else {
int c = (-a) % b;
return value_new_int (c ? b - c : 0);
}
} else {
b = -b;
/* FIXME: check for overflow. */
}
if (a >= 0)
return value_new_int (a % b);
else {
int invres = (-a) % b;
return value_new_int (invres == 0 ? 0 : b - invres);
a = -a;
if (a >= 0)
return value_new_int (-(a % b));
else {
int c = (-a) % b;
return value_new_int (c ? c - b : 0);
}
}
}
......
No preview for this file type
......@@ -1202,25 +1202,29 @@ static char *help_mod = {
static Value *
gnumeric_mod (FunctionEvalInfo *ei, Value **argv)
{
int a,b;
int a, b;
a = value_get_as_int (argv[0]);
b = value_get_as_int (argv[1]);
if (b == 0)
return value_new_error (ei->pos, gnumeric_err_NUM);
if (b < 0) {
a = -a;
return value_new_error (ei->pos, gnumeric_err_DIV0);
else if (b > 0) {
if (a >= 0)
return value_new_int (a % b);
else {
int c = (-a) % b;
return value_new_int (c ? b - c : 0);
}
} else {
b = -b;
/* FIXME: check for overflow. */
}
if (a >= 0)
return value_new_int (a % b);
else {
int invres = (-a) % b;
return value_new_int (invres == 0 ? 0 : b - invres);
a = -a;
if (a >= 0)
return value_new_int (-(a % b));
else {
int c = (-a) % b;
return value_new_int (c ? c - b : 0);
}
}
}
......
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