mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
complex.c: removed redundant conditions
Fixnums can be compared by object values themselves only. Addition/subtraction/mulplication of fixnum 0 do not affect the sign. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62701 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
38b240156c
commit
1e30a7e001
1 changed files with 9 additions and 27 deletions
36
complex.c
36
complex.c
|
@ -70,12 +70,10 @@ f_##n(VALUE x, VALUE y)\
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_add(VALUE x, VALUE y)
|
f_add(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
#ifndef PRESERVE_SIGNEDZERO
|
if (FIXNUM_ZERO_P(y))
|
||||||
if (FIXNUM_P(y) && FIXNUM_ZERO_P(y))
|
|
||||||
return x;
|
return x;
|
||||||
else if (FIXNUM_P(x) && FIXNUM_ZERO_P(x))
|
if (FIXNUM_ZERO_P(x))
|
||||||
return y;
|
return y;
|
||||||
#endif
|
|
||||||
return rb_funcall(x, '+', 1, y);
|
return rb_funcall(x, '+', 1, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,36 +105,20 @@ f_gt_p(VALUE x, VALUE y)
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_mul(VALUE x, VALUE y)
|
f_mul(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
#ifndef PRESERVE_SIGNEDZERO
|
if (FIXNUM_ZERO_P(y) && RB_INTEGER_TYPE_P(x))
|
||||||
if (FIXNUM_P(y)) {
|
return ZERO;
|
||||||
long iy = FIX2LONG(y);
|
if (FIXNUM_ZERO_P(x) && RB_INTEGER_TYPE_P(y))
|
||||||
if (iy == 0) {
|
return ZERO;
|
||||||
if (RB_INTEGER_TYPE_P(x))
|
if (y == ONE) return x;
|
||||||
return ZERO;
|
if (x == ONE) return y;
|
||||||
}
|
|
||||||
else if (iy == 1)
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
else if (FIXNUM_P(x)) {
|
|
||||||
long ix = FIX2LONG(x);
|
|
||||||
if (ix == 0) {
|
|
||||||
if (RB_INTEGER_TYPE_P(y))
|
|
||||||
return ZERO;
|
|
||||||
}
|
|
||||||
else if (ix == 1)
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return rb_funcall(x, '*', 1, y);
|
return rb_funcall(x, '*', 1, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static VALUE
|
inline static VALUE
|
||||||
f_sub(VALUE x, VALUE y)
|
f_sub(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
#ifndef PRESERVE_SIGNEDZERO
|
if (FIXNUM_ZERO_P(y))
|
||||||
if (FIXNUM_P(y) && FIXNUM_ZERO_P(y))
|
|
||||||
return x;
|
return x;
|
||||||
#endif
|
|
||||||
return rb_funcall(x, '-', 1, y);
|
return rb_funcall(x, '-', 1, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue