3 void primitive_fixnump(void)
5 check_non_empty(env.dt);
6 env.dt = tag_boolean(TAG(env.dt) == FIXNUM_TYPE);
9 void primitive_not(void)
11 type_check(FIXNUM_TYPE,env.dt);
12 env.dt = RETAG(UNTAG(~env.dt),FIXNUM_TYPE);
15 FIXNUM to_fixnum(CELL tagged)
19 switch(type_of(tagged))
22 return untag_fixnum_fast(tagged);
24 return bignum_to_fixnum(tagged);
26 r = (RATIO*)UNTAG(tagged);
27 return to_fixnum(divint(r->numerator,r->denominator));
29 type_error(FIXNUM_TYPE,tagged);
30 return -1; /* can't happen */
34 void primitive_to_fixnum(void)
36 env.dt = tag_fixnum(to_fixnum(env.dt));
39 CELL number_eq_fixnum(CELL x, CELL y)
41 return tag_boolean(x == y);
44 CELL add_fixnum(CELL x, CELL y)
46 CELL_TO_INTEGER(untag_fixnum_fast(x) + untag_fixnum_fast(y));
49 CELL subtract_fixnum(CELL x, CELL y)
51 CELL_TO_INTEGER(untag_fixnum_fast(x) - untag_fixnum_fast(y));
54 CELL multiply_fixnum(CELL x, CELL y)
56 BIGNUM_2_TO_INTEGER((BIGNUM_2)untag_fixnum_fast(x)
57 * (BIGNUM_2)untag_fixnum_fast(y));
60 CELL divint_fixnum(CELL x, CELL y)
62 /* division takes common factor of 8 out. */
63 return tag_fixnum(x / y);
66 CELL divmod_fixnum(CELL x, CELL y)
69 /* division takes common factor of 8 out. */
70 dpush(tag_fixnum(q.quot));
74 CELL mod_fixnum(CELL x, CELL y)
79 FIXNUM gcd_fixnum(FIXNUM x, FIXNUM y)
106 CELL divide_fixnum(CELL x, CELL y)
108 FIXNUM _x = untag_fixnum_fast(x);
109 FIXNUM _y = untag_fixnum_fast(y);
122 FIXNUM gcd = gcd_fixnum(_x,_y);
130 return tag_fixnum(_x);
132 return tag_ratio(ratio(tag_fixnum(_x),tag_fixnum(_y)));
135 CELL and_fixnum(CELL x, CELL y)
140 CELL or_fixnum(CELL x, CELL y)
145 CELL xor_fixnum(CELL x, CELL y)
150 CELL shiftleft_fixnum(CELL x, CELL y)
152 BIGNUM_2_TO_INTEGER((BIGNUM_2)untag_fixnum_fast(x)
153 << (BIGNUM_2)untag_fixnum_fast(y));
156 CELL shiftright_fixnum(CELL x, CELL y)
158 BIGNUM_2_TO_INTEGER((BIGNUM_2)untag_fixnum_fast(x)
159 >> (BIGNUM_2)untag_fixnum_fast(y));
162 CELL less_fixnum(CELL x, CELL y)
164 return tag_boolean((FIXNUM)x < (FIXNUM)y);
167 CELL lesseq_fixnum(CELL x, CELL y)
169 return tag_boolean((FIXNUM)x <= (FIXNUM)y);
172 CELL greater_fixnum(CELL x, CELL y)
174 return tag_boolean((FIXNUM)x > (FIXNUM)y);
177 CELL greatereq_fixnum(CELL x, CELL y)
179 return tag_boolean((FIXNUM)x >= (FIXNUM)y);