Commit 32cf65a4 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa
Browse files

Detects integer over/under flow.

1999-03-14  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/fn-math.c (callback_function_sum): Detects integer
	over/under flow.

	* src/expr.c (eval_expr): Add integer overflow code for addition
	and substraction.
parent a0bc506c
1999-03-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Detects integer
over/under flow.
* src/expr.c (eval_expr): Add integer overflow code for addition
and substraction.
* src/cell.c (cell_set_format): Call cell_render_value and
cell_queue_redraw calls here.
* src/expr.c (bigger_prec): When decoding left-to-right apply
parentheses if the two priorities are equal.
......
1999-03-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Detects integer
over/under flow.
* src/expr.c (eval_expr): Add integer overflow code for addition
and substraction.
* src/cell.c (cell_set_format): Call cell_render_value and
cell_queue_redraw calls here.
* src/expr.c (bigger_prec): When decoding left-to-right apply
parentheses if the two priorities are equal.
......
1999-03-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Detects integer
over/under flow.
* src/expr.c (eval_expr): Add integer overflow code for addition
and substraction.
* src/cell.c (cell_set_format): Call cell_render_value and
cell_queue_redraw calls here.
* src/expr.c (bigger_prec): When decoding left-to-right apply
parentheses if the two priorities are equal.
......
1999-03-14 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/fn-math.c (callback_function_sum): Detects integer
over/under flow.
* src/expr.c (eval_expr): Add integer overflow code for addition
and substraction.
* src/cell.c (cell_set_format): Call cell_render_value and
cell_queue_redraw calls here.
* src/expr.c (bigger_prec): When decoding left-to-right apply
parentheses if the two priorities are equal.
......
......@@ -1020,9 +1020,32 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
switch (value->type){
case VALUE_INTEGER:
if (result->type == VALUE_INTEGER)
result->v.v_int += value->v.v_int;
else
if (result->type == VALUE_INTEGER){
if ((result->v.v_int > 0) && (value->v.v_int > 0)){
int sum = result->v.v_int + value->v.v_int;
if (sum < result->v.v_int){
double n = result->v.v_int + value->v.v_int;
result->type = VALUE_FLOAT;
result->v.v_float = n;
} else
result->v.v_int = sum;
} else if ((result->v.v_int < 0) && (value->v.v_int < 0)){
int sum = result->v.v_int + value->v.v_int;
if (sum > result->v.v_int){
double n = result->v.v_int + value->v.v_int;
result->type = VALUE_FLOAT;
result->v.v_float = n;
} else {
result->v.v_int = sum;
}
} else {
result->v.v_int += value->v.v_int;
}
} else
result->v.v_float += value->v.v_int;
break;
......
......@@ -796,16 +796,43 @@ eval_expr (void *asheet, ExprTree *tree, int eval_col, int eval_row, char **erro
res = g_new (Value, 1);
if (a->type == VALUE_INTEGER && b->type == VALUE_INTEGER){
int ia = a->v.v_int;
int ib = b->v.v_int;
res->type = VALUE_INTEGER;
switch (tree->oper){
case OPER_ADD:
res->v.v_int = a->v.v_int + b->v.v_int;
break;
case OPER_SUB:
res->v.v_int = a->v.v_int - b->v.v_int;
case OPER_ADD: {
int sum;
if (tree->oper == OPER_SUB){
int t = ia;
ia = ib;
ib = -t;
}
sum = ia + ib;
if ((ia > 0) && (ib > 0)){
if (sum < ia){
res->type = VALUE_FLOAT;
res->v.v_float = ((double)ia) + ib;
} else
res->v.v_int = sum;
} else if ((ia < 0) && (ib < 0)){
if (sum > ia){
res->type = VALUE_FLOAT;
res->v.v_float = ((double)ia) + ib;
} else
res->v.v_int = sum;
} else
res->v.v_int = sum;
break;
}
case OPER_MULT:
res->v.v_int = a->v.v_int * b->v.v_int;
......
......@@ -1020,9 +1020,32 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
switch (value->type){
case VALUE_INTEGER:
if (result->type == VALUE_INTEGER)
result->v.v_int += value->v.v_int;
else
if (result->type == VALUE_INTEGER){
if ((result->v.v_int > 0) && (value->v.v_int > 0)){
int sum = result->v.v_int + value->v.v_int;
if (sum < result->v.v_int){
double n = result->v.v_int + value->v.v_int;
result->type = VALUE_FLOAT;
result->v.v_float = n;
} else
result->v.v_int = sum;
} else if ((result->v.v_int < 0) && (value->v.v_int < 0)){
int sum = result->v.v_int + value->v.v_int;
if (sum > result->v.v_int){
double n = result->v.v_int + value->v.v_int;
result->type = VALUE_FLOAT;
result->v.v_float = n;
} else {
result->v.v_int = sum;
}
} else {
result->v.v_int += value->v.v_int;
}
} else
result->v.v_float += value->v.v_int;
break;
......
......@@ -1020,9 +1020,32 @@ callback_function_sum (Sheet *sheet, Value *value, char **error_string, void *cl
switch (value->type){
case VALUE_INTEGER:
if (result->type == VALUE_INTEGER)
result->v.v_int += value->v.v_int;
else
if (result->type == VALUE_INTEGER){
if ((result->v.v_int > 0) && (value->v.v_int > 0)){
int sum = result->v.v_int + value->v.v_int;
if (sum < result->v.v_int){
double n = result->v.v_int + value->v.v_int;
result->type = VALUE_FLOAT;
result->v.v_float = n;
} else
result->v.v_int = sum;
} else if ((result->v.v_int < 0) && (value->v.v_int < 0)){
int sum = result->v.v_int + value->v.v_int;
if (sum > result->v.v_int){
double n = result->v.v_int + value->v.v_int;
result->type = VALUE_FLOAT;
result->v.v_float = n;
} else {
result->v.v_int = sum;
}
} else {
result->v.v_int += value->v.v_int;
}
} else
result->v.v_float += value->v.v_int;
break;
......
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