factor/native/arithmetic.c

81 lines
1.5 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)
{
2005-03-03 20:43:55 -05:00
CELL obj1 = dpeek(), obj2 = get(ds - CELLS);
CELL type1 = TAG(obj1), type2 = TAG(obj2);
2004-09-19 00:57:33 -04:00
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_bignum(to_bignum(obj2)));
2004-12-18 20:24:46 -05:00
break;
case FLOAT_TYPE:
put(ds - CELLS,tag_float(to_float((obj2))));
2004-12-18 20:24:46 -05:00
break;
}
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(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:
drepl(tag_bignum(to_bignum(obj1)));
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(type2));
2004-12-18 20:24:46 -05:00
break;
case FLOAT_TYPE:
put(ds - CELLS,tag_float(to_float((obj2))));
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(type1));
2004-09-19 00:57:33 -04:00
break;
default:
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(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)
{
2005-03-03 20:43:55 -05:00
case FIXNUM_TYPE: case BIGNUM_TYPE:
dpush(tag_fixnum(type2));
2004-12-18 20:24:46 -05:00
break;
case FLOAT_TYPE:
put(ds - CELLS,tag_float(to_float((obj2))));
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(type1));
2004-09-19 00:57:33 -04:00
break;
default:
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(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)
{
2005-03-03 20:43:55 -05:00
case FIXNUM_TYPE: case BIGNUM_TYPE: case RATIO_TYPE:
drepl(tag_float(to_float(obj1)));
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(type2));
2004-09-19 00:57:33 -04:00
break;
default:
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(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)
{
2005-03-03 20:43:55 -05:00
case FIXNUM_TYPE: case BIGNUM_TYPE: case RATIO_TYPE: case FLOAT_TYPE:
dpush(tag_fixnum(type2));
2004-09-19 00:57:33 -04:00
break;
default:
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(type1));
2004-09-19 00:57:33 -04:00
break;
}
2004-09-19 17:39:28 -04:00
break;
default:
2005-03-03 20:43:55 -05:00
dpush(tag_fixnum(type2));
2004-09-19 00:57:33 -04:00
break;
}
2004-09-19 00:33:40 -04:00
}