git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15834 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2008-03-24 13:34:13 +00:00
Родитель 9bfc01ea17
Коммит 76865ca0ec
2 изменённых файлов: 110 добавлений и 110 удалений

110
complex.c
Просмотреть файл

@ -68,53 +68,53 @@ m_##n(VALUE x, VALUE y)\
inline static VALUE inline static VALUE
f_add(VALUE x, VALUE y) f_add(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(y) == 0) if (FIX2LONG(y) == 0)
_r = x; r = x;
else else
_r = rb_funcall(x, '+', 1, y); r = rb_funcall(x, '+', 1, y);
} else if (FIXNUM_P(x)) { } else if (FIXNUM_P(x)) {
if (FIX2LONG(x) == 0) if (FIX2LONG(x) == 0)
_r = y; r = y;
else else
_r = rb_funcall(x, '+', 1, y); r = rb_funcall(x, '+', 1, y);
} else } else
_r = rb_funcall(x, '+', 1, y); r = rb_funcall(x, '+', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_div(VALUE x, VALUE y) f_div(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y) && FIX2LONG(y) == 1) if (FIXNUM_P(y) && FIX2LONG(y) == 1)
_r = x; r = x;
else else
_r = rb_funcall(x, '/', 1, y); r = rb_funcall(x, '/', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_gt_p(VALUE x, VALUE y) f_gt_p(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) if (FIXNUM_P(x) && FIXNUM_P(y))
_r = f_boolcast(FIX2LONG(x) > FIX2LONG(y)); r = f_boolcast(FIX2LONG(x) > FIX2LONG(y));
else else
_r = rb_funcall(x, '>', 1, y); r = rb_funcall(x, '>', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_lt_p(VALUE x, VALUE y) f_lt_p(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) if (FIXNUM_P(x) && FIXNUM_P(y))
_r = f_boolcast(FIX2LONG(x) < FIX2LONG(y)); r = f_boolcast(FIX2LONG(x) < FIX2LONG(y));
else else
_r = rb_funcall(x, '<', 1, y); r = rb_funcall(x, '<', 1, y);
return _r; return r;
} }
binop(mod, '%') binop(mod, '%')
@ -122,46 +122,46 @@ binop(mod, '%')
inline static VALUE inline static VALUE
f_mul(VALUE x, VALUE y) f_mul(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
long _iy = FIX2LONG(y); long _iy = FIX2LONG(y);
if (_iy == 0) { if (_iy == 0) {
if (TYPE(x) == T_FLOAT) if (TYPE(x) == T_FLOAT)
_r = rb_float_new(0.0); r = rb_float_new(0.0);
else else
_r = ZERO; r = ZERO;
} else if (_iy == 1) } else if (_iy == 1)
_r = x; r = x;
else else
_r = rb_funcall(x, '*', 1, y); r = rb_funcall(x, '*', 1, y);
} else if (FIXNUM_P(x)) { } else if (FIXNUM_P(x)) {
long _ix = FIX2LONG(x); long _ix = FIX2LONG(x);
if (_ix == 0) { if (_ix == 0) {
if (TYPE(y) == T_FLOAT) if (TYPE(y) == T_FLOAT)
_r = rb_float_new(0.0); r = rb_float_new(0.0);
else else
_r = ZERO; r = ZERO;
} else if (_ix == 1) } else if (_ix == 1)
_r = y; r = y;
else else
_r = rb_funcall(x, '*', 1, y); r = rb_funcall(x, '*', 1, y);
} else } else
_r = rb_funcall(x, '*', 1, y); r = rb_funcall(x, '*', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_sub(VALUE x, VALUE y) f_sub(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(y) == 0) if (FIX2LONG(y) == 0)
_r = x; r = x;
else else
_r = rb_funcall(x, '-', 1, y); r = rb_funcall(x, '-', 1, y);
} else } else
_r = rb_funcall(x, '-', 1, y); r = rb_funcall(x, '-', 1, y);
return _r; return r;
} }
binop(xor, '^') binop(xor, '^')
@ -187,17 +187,17 @@ fun1(truncate)
inline static VALUE inline static VALUE
f_cmp(VALUE x, VALUE y) f_cmp(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) { if (FIXNUM_P(x) && FIXNUM_P(y)) {
long c = FIX2LONG(x) - FIX2LONG(y); long c = FIX2LONG(x) - FIX2LONG(y);
if (c > 0) if (c > 0)
c = 1; c = 1;
else if (c < 0) else if (c < 0)
c = -1; c = -1;
_r = INT2FIX(c); r = INT2FIX(c);
} else } else
_r = rb_funcall(x, id_cmp, 1, y); r = rb_funcall(x, id_cmp, 1, y);
return _r; return r;
} }
fun2(coerce) fun2(coerce)
@ -206,12 +206,12 @@ fun2(divmod)
inline static VALUE inline static VALUE
f_equal_p(VALUE x, VALUE y) f_equal_p(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) if (FIXNUM_P(x) && FIXNUM_P(y))
_r = f_boolcast(FIX2LONG(x) == FIX2LONG(y)); r = f_boolcast(FIX2LONG(x) == FIX2LONG(y));
else else
_r = rb_funcall(x, id_equal_p, 1, y); r = rb_funcall(x, id_equal_p, 1, y);
return _r; return r;
} }
fun2(expt) fun2(expt)
@ -221,34 +221,34 @@ fun2(quo)
inline static VALUE inline static VALUE
f_negative_p(VALUE x) f_negative_p(VALUE x)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x)) if (FIXNUM_P(x))
_r = f_boolcast(FIX2LONG(x) < 0); r = f_boolcast(FIX2LONG(x) < 0);
else else
_r = rb_funcall(x, '<', 1, ZERO); r = rb_funcall(x, '<', 1, ZERO);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_zero_p(VALUE x) f_zero_p(VALUE x)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x)) if (FIXNUM_P(x))
_r = f_boolcast(FIX2LONG(x) == 0); r = f_boolcast(FIX2LONG(x) == 0);
else else
_r = rb_funcall(x, id_equal_p, 1, ZERO); r = rb_funcall(x, id_equal_p, 1, ZERO);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_one_p(VALUE x) f_one_p(VALUE x)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x)) if (FIXNUM_P(x))
_r = f_boolcast(FIX2LONG(x) == 1); r = f_boolcast(FIX2LONG(x) == 1);
else else
_r = rb_funcall(x, id_equal_p, 1, ONE); r = rb_funcall(x, id_equal_p, 1, ONE);
return _r; return r;
} }
inline static VALUE inline static VALUE

Просмотреть файл

@ -51,53 +51,53 @@ f_##n(VALUE x, VALUE y)\
inline static VALUE inline static VALUE
f_add(VALUE x, VALUE y) f_add(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(y) == 0) if (FIX2LONG(y) == 0)
_r = x; r = x;
else else
_r = rb_funcall(x, '+', 1, y); r = rb_funcall(x, '+', 1, y);
} else if (FIXNUM_P(x)) { } else if (FIXNUM_P(x)) {
if (FIX2LONG(x) == 0) if (FIX2LONG(x) == 0)
_r = y; r = y;
else else
_r = rb_funcall(x, '+', 1, y); r = rb_funcall(x, '+', 1, y);
} else } else
_r = rb_funcall(x, '+', 1, y); r = rb_funcall(x, '+', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_div(VALUE x, VALUE y) f_div(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y) && FIX2LONG(y) == 1) if (FIXNUM_P(y) && FIX2LONG(y) == 1)
_r = x; r = x;
else else
_r = rb_funcall(x, '/', 1, y); r = rb_funcall(x, '/', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_gt_p(VALUE x, VALUE y) f_gt_p(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) if (FIXNUM_P(x) && FIXNUM_P(y))
_r = f_boolcast(FIX2LONG(x) > FIX2LONG(y)); r = f_boolcast(FIX2LONG(x) > FIX2LONG(y));
else else
_r = rb_funcall(x, '>', 1, y); r = rb_funcall(x, '>', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_lt_p(VALUE x, VALUE y) f_lt_p(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) if (FIXNUM_P(x) && FIXNUM_P(y))
_r = f_boolcast(FIX2LONG(x) < FIX2LONG(y)); r = f_boolcast(FIX2LONG(x) < FIX2LONG(y));
else else
_r = rb_funcall(x, '<', 1, y); r = rb_funcall(x, '<', 1, y);
return _r; return r;
} }
binop(mod, '%') binop(mod, '%')
@ -105,46 +105,46 @@ binop(mod, '%')
inline static VALUE inline static VALUE
f_mul(VALUE x, VALUE y) f_mul(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
long _iy = FIX2LONG(y); long _iy = FIX2LONG(y);
if (_iy == 0) { if (_iy == 0) {
if (TYPE(x) == T_FLOAT) if (TYPE(x) == T_FLOAT)
_r = rb_float_new(0.0); r = rb_float_new(0.0);
else else
_r = ZERO; r = ZERO;
} else if (_iy == 1) } else if (_iy == 1)
_r = x; r = x;
else else
_r = rb_funcall(x, '*', 1, y); r = rb_funcall(x, '*', 1, y);
} else if (FIXNUM_P(x)) { } else if (FIXNUM_P(x)) {
long _ix = FIX2LONG(x); long _ix = FIX2LONG(x);
if (_ix == 0) { if (_ix == 0) {
if (TYPE(y) == T_FLOAT) if (TYPE(y) == T_FLOAT)
_r = rb_float_new(0.0); r = rb_float_new(0.0);
else else
_r = ZERO; r = ZERO;
} else if (_ix == 1) } else if (_ix == 1)
_r = y; r = y;
else else
_r = rb_funcall(x, '*', 1, y); r = rb_funcall(x, '*', 1, y);
} else } else
_r = rb_funcall(x, '*', 1, y); r = rb_funcall(x, '*', 1, y);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_sub(VALUE x, VALUE y) f_sub(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(y)) { if (FIXNUM_P(y)) {
if (FIX2LONG(y) == 0) if (FIX2LONG(y) == 0)
_r = x; r = x;
else else
_r = rb_funcall(x, '-', 1, y); r = rb_funcall(x, '-', 1, y);
} else } else
_r = rb_funcall(x, '-', 1, y); r = rb_funcall(x, '-', 1, y);
return _r; return r;
} }
binop(xor, '^') binop(xor, '^')
@ -160,17 +160,17 @@ fun1(truncate)
inline static VALUE inline static VALUE
f_cmp(VALUE x, VALUE y) f_cmp(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) { if (FIXNUM_P(x) && FIXNUM_P(y)) {
long c = FIX2LONG(x) - FIX2LONG(y); long c = FIX2LONG(x) - FIX2LONG(y);
if (c > 0) if (c > 0)
c = 1; c = 1;
else if (c < 0) else if (c < 0)
c = -1; c = -1;
_r = INT2FIX(c); r = INT2FIX(c);
} else } else
_r = rb_funcall(x, id_cmp, 1, y); r = rb_funcall(x, id_cmp, 1, y);
return _r; return r;
} }
fun2(coerce) fun2(coerce)
@ -178,12 +178,12 @@ fun2(coerce)
inline static VALUE inline static VALUE
f_equal_p(VALUE x, VALUE y) f_equal_p(VALUE x, VALUE y)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x) && FIXNUM_P(y)) if (FIXNUM_P(x) && FIXNUM_P(y))
_r = f_boolcast(FIX2LONG(x) == FIX2LONG(y)); r = f_boolcast(FIX2LONG(x) == FIX2LONG(y));
else else
_r = rb_funcall(x, id_equal_p, 1, y); r = rb_funcall(x, id_equal_p, 1, y);
return _r; return r;
} }
fun2(expt) fun2(expt)
@ -192,34 +192,34 @@ fun2(idiv)
inline static VALUE inline static VALUE
f_negative_p(VALUE x) f_negative_p(VALUE x)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x)) if (FIXNUM_P(x))
_r = f_boolcast(FIX2LONG(x) < 0); r = f_boolcast(FIX2LONG(x) < 0);
else else
_r = rb_funcall(x, '<', 1, ZERO); r = rb_funcall(x, '<', 1, ZERO);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_zero_p(VALUE x) f_zero_p(VALUE x)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x)) if (FIXNUM_P(x))
_r = f_boolcast(FIX2LONG(x) == 0); r = f_boolcast(FIX2LONG(x) == 0);
else else
_r = rb_funcall(x, id_equal_p, 1, ZERO); r = rb_funcall(x, id_equal_p, 1, ZERO);
return _r; return r;
} }
inline static VALUE inline static VALUE
f_one_p(VALUE x) f_one_p(VALUE x)
{ {
VALUE _r; VALUE r;
if (FIXNUM_P(x)) if (FIXNUM_P(x))
_r = f_boolcast(FIX2LONG(x) == 1); r = f_boolcast(FIX2LONG(x) == 1);
else else
_r = rb_funcall(x, id_equal_p, 1, ONE); r = rb_funcall(x, id_equal_p, 1, ONE);
return _r; return r;
} }
inline static VALUE inline static VALUE