|
|
public static IRubyObject cpu_primitive_add(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
ARITY(1);
GUARD(FIXNUM_P(msg->recv));
OBJECT t1 = stack_pop();
if(FIXNUM_P(t1)) {
RET(fixnum_add(state, msg->recv, t1));
} else if(BIGNUM_P(t1)) {
RET(bignum_add(state, bignum_new(state, N2I(msg->recv)), t1));
} else if(FLOAT_P(t1)) {
OBJECT t2 = float_coerce(state, msg->recv);
RET(float_new(state, FLOAT_TO_DOUBLE(t2) + FLOAT_TO_DOUBLE(t1)));
} else {
FAIL();
}
}
public static IRubyObject cpu_primitive_bignum_add(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
ARITY(1);
GUARD(BIGNUM_P(msg->recv));
OBJECT t1 = stack_pop();
if(BIGNUM_P(t1) || FIXNUM_P(t1)) {
RET(bignum_add(state, msg->recv, t1));
} else if(FLOAT_P(t1)) {
double a = bignum_to_double(state, msg->recv);
RET(float_new(state, a + FLOAT_TO_DOUBLE(t1)));
} else {
FAIL();
}
}
public static IRubyObject cpu_primitive_sub(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
ARITY(1);
GUARD(FIXNUM_P(msg->recv));
OBJECT t1 = stack_pop();
if(FIXNUM_P(t1)) {
RET(fixnum_sub(state, msg->recv, t1));
} else if(BIGNUM_P(t1)) {
RET(bignum_sub(state, bignum_new(state, N2I(msg->recv)), t1));
} else if(FLOAT_P(t1)) {
OBJECT t2 = float_coerce(state, msg->recv);
RET(float_new(state, FLOAT_TO_DOUBLE(t2) - FLOAT_TO_DOUBLE(t1)));
} else {
FAIL();
...
|