factor/native/arithmetic.c

94 lines
1.4 KiB
C
Raw Normal View History

2004-07-28 19:02:24 -04:00
#include "factor.h"
2004-12-18 20:24:46 -05:00
void primitive_arithmetic_type(void)
{
2004-12-18 20:24:46 -05:00
CELL obj1 = dpeek();
CELL obj2 = get(ds - CELLS);
2004-10-01 22:46:12 -04:00
CELL type1 = type_of(obj1);
CELL type2 = type_of(obj2);
2004-09-19 00:57:33 -04:00
CELL type;
2004-12-18 20:24:46 -05:00
switch(type2)
{
case FIXNUM_TYPE:
2004-12-18 20:24:46 -05:00
switch(type1)
{
case BIGNUM_TYPE:
put(ds - CELLS,tag_object(to_bignum(obj2)));
break;
case FLOAT_TYPE:
put(ds - CELLS,tag_object(make_float(to_float((obj2)))));
break;
}
type = type1;
2004-09-19 00:57:33 -04:00
break;
case BIGNUM_TYPE:
2004-12-18 20:24:46 -05:00
switch(type1)
{
case FIXNUM_TYPE:
2004-12-18 20:24:46 -05:00
drepl(tag_object(to_bignum(obj1)));
type = type2;
break;
case FLOAT_TYPE:
put(ds - CELLS,tag_object(make_float(to_float((obj2)))));
2004-09-19 00:57:33 -04:00
type = type1;
break;
default:
2004-12-18 20:24:46 -05:00
type = type1;
2004-09-19 00:57:33 -04:00
break;
}
2004-09-19 17:39:28 -04:00
break;
case RATIO_TYPE:
2004-12-18 20:24:46 -05:00
switch(type1)
{
case FIXNUM_TYPE:
case BIGNUM_TYPE:
2004-12-18 20:24:46 -05:00
type = type2;
break;
case FLOAT_TYPE:
put(ds - CELLS,tag_object(make_float(to_float((obj2)))));
2004-09-19 00:57:33 -04:00
type = type1;
break;
default:
2004-12-18 20:24:46 -05:00
type = type1;
2004-09-19 00:57:33 -04:00
break;
}
2004-09-19 17:39:28 -04:00
break;
case FLOAT_TYPE:
2004-12-18 20:24:46 -05:00
switch(type1)
{
case FIXNUM_TYPE:
case BIGNUM_TYPE:
case RATIO_TYPE:
2004-12-18 20:24:46 -05:00
drepl(tag_object(make_float(to_float(obj1))));
type = type2;
2004-09-19 00:57:33 -04:00
break;
default:
2004-12-18 20:24:46 -05:00
type = type1;
2004-09-19 00:57:33 -04:00
break;
}
2004-09-19 17:39:28 -04:00
break;
case COMPLEX_TYPE:
2004-12-18 20:24:46 -05:00
switch(type1)
{
case FIXNUM_TYPE:
case BIGNUM_TYPE:
case RATIO_TYPE:
case FLOAT_TYPE:
2004-12-18 20:24:46 -05:00
type = type2;
2004-09-19 00:57:33 -04:00
break;
default:
2004-12-18 20:24:46 -05:00
type = type1;
2004-09-19 00:57:33 -04:00
break;
}
2004-09-19 17:39:28 -04:00
break;
default:
2004-12-18 20:24:46 -05:00
type = type2;
2004-09-19 00:57:33 -04:00
break;
}
2004-10-01 22:46:12 -04:00
2004-12-18 20:24:46 -05:00
dpush(tag_fixnum(type));
2004-09-19 00:33:40 -04:00
}