1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

use particlar macros

* bignum.c: use particlar macros for positive/negative conditions.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53831 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-02-15 05:09:59 +00:00
parent 73e29d2cf1
commit 174be80027

View file

@ -2978,7 +2978,7 @@ static VALUE
bignew_1(VALUE klass, size_t len, int sign) bignew_1(VALUE klass, size_t len, int sign)
{ {
NEWOBJ_OF(big, struct RBignum, klass, T_BIGNUM | (RGENGC_WB_PROTECTED_BIGNUM ? FL_WB_PROTECTED : 0)); NEWOBJ_OF(big, struct RBignum, klass, T_BIGNUM | (RGENGC_WB_PROTECTED_BIGNUM ? FL_WB_PROTECTED : 0));
BIGNUM_SET_SIGN(big, sign?1:0); BIGNUM_SET_SIGN(big, sign);
if (len <= BIGNUM_EMBED_LEN_MAX) { if (len <= BIGNUM_EMBED_LEN_MAX) {
RBASIC(big)->flags |= BIGNUM_EMBED_FLAG; RBASIC(big)->flags |= BIGNUM_EMBED_FLAG;
BIGNUM_SET_LEN(big, len); BIGNUM_SET_LEN(big, len);
@ -3174,7 +3174,7 @@ rb_int2big(SIGNED_VALUE n)
} }
big = rb_uint2big(u); big = rb_uint2big(u);
if (neg) { if (neg) {
BIGNUM_SET_SIGN(big, 0); BIGNUM_SET_NEGATIVE_SIGN(big);
} }
return big; return big;
} }
@ -4346,7 +4346,7 @@ rb_ll2big(LONG_LONG n)
} }
big = rb_ull2big(u); big = rb_ull2big(u);
if (neg) { if (neg) {
BIGNUM_SET_SIGN(big, 0); BIGNUM_SET_NEGATIVE_SIGN(big);
} }
return big; return big;
} }
@ -4401,7 +4401,7 @@ rb_int128t2big(int128_t n)
} }
big = rb_uint128t2big(u); big = rb_uint128t2big(u);
if (neg) { if (neg) {
BIGNUM_SET_SIGN(big, 0); BIGNUM_SET_NEGATIVE_SIGN(big);
} }
return big; return big;
} }
@ -5199,7 +5199,7 @@ big2dbl(VALUE x)
} }
} }
} }
if (!BIGNUM_SIGN(x)) d = -d; if (BIGNUM_NEGATIVE_P(x)) d = -d;
return d; return d;
} }
@ -6316,7 +6316,7 @@ rb_big_pow(VALUE x, VALUE y)
if (y == INT2FIX(0)) return INT2FIX(1); if (y == INT2FIX(0)) return INT2FIX(1);
if (RB_FLOAT_TYPE_P(y)) { if (RB_FLOAT_TYPE_P(y)) {
d = RFLOAT_VALUE(y); d = RFLOAT_VALUE(y);
if ((!BIGNUM_SIGN(x) && !BIGZEROP(x)) && d != round(d)) if ((BIGNUM_NEGATIVE_P(x) && !BIGZEROP(x)) && d != round(d))
return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y); return rb_funcall(rb_complex_raw1(x), rb_intern("**"), 1, y);
} }
else if (RB_BIGNUM_TYPE_P(y)) { else if (RB_BIGNUM_TYPE_P(y)) {
@ -6800,7 +6800,7 @@ rb_big_aref(VALUE x, VALUE y)
BDIGIT bit; BDIGIT bit;
if (RB_BIGNUM_TYPE_P(y)) { if (RB_BIGNUM_TYPE_P(y)) {
if (!BIGNUM_SIGN(y)) if (BIGNUM_NEGATIVE_P(y))
return INT2FIX(0); return INT2FIX(0);
bigtrunc(y); bigtrunc(y);
if (BIGSIZE(y) > sizeof(size_t)) { if (BIGSIZE(y) > sizeof(size_t)) {
@ -6893,9 +6893,9 @@ rb_big_coerce(VALUE x, VALUE y)
static VALUE static VALUE
rb_big_abs(VALUE x) rb_big_abs(VALUE x)
{ {
if (!BIGNUM_SIGN(x)) { if (BIGNUM_NEGATIVE_P(x)) {
x = rb_big_clone(x); x = rb_big_clone(x);
BIGNUM_SET_SIGN(x, 1); BIGNUM_SET_POSITIVE_SIGN(x);
} }
return x; return x;
} }