зеркало из https://github.com/github/ruby.git
* include/ruby/ruby.h: Hide Rational internal.
(RRational): Moved to internal.h (RRATIONAL): Ditto. (RRATIONAL_SET_NUM): Moved to rational.c. (RRATIONAL_SET_DEN): Ditto. * rational.c (rb_rational_num): New function. (rb_rational_den): Ditto. * include/ruby/intern.h (rb_rational_num): Declared. (rb_rational_den): Ditto. * ext/bigdecimal/bigdecimal.c: Follow the above change. * ext/date/date_core.c: Ditto. [ruby-core:60665] [Feature #9513] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
fb8f7259c3
Коммит
e56d2c385a
20
ChangeLog
20
ChangeLog
|
@ -1,3 +1,23 @@
|
|||
Sun May 18 01:21:23 2014 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* include/ruby/ruby.h: Hide Rational internal.
|
||||
(RRational): Moved to internal.h
|
||||
(RRATIONAL): Ditto.
|
||||
(RRATIONAL_SET_NUM): Moved to rational.c.
|
||||
(RRATIONAL_SET_DEN): Ditto.
|
||||
|
||||
* rational.c (rb_rational_num): New function.
|
||||
(rb_rational_den): Ditto.
|
||||
|
||||
* include/ruby/intern.h (rb_rational_num): Declared.
|
||||
(rb_rational_den): Ditto.
|
||||
|
||||
* ext/bigdecimal/bigdecimal.c: Follow the above change.
|
||||
|
||||
* ext/date/date_core.c: Ditto.
|
||||
|
||||
[ruby-core:60665] [Feature #9513]
|
||||
|
||||
Sat May 17 17:04:32 2014 Shota Fukumori <her@sorah.jp>
|
||||
|
||||
* NEWS: Add news about removal of lib/test/**/*.rb.
|
||||
|
|
3
NEWS
3
NEWS
|
@ -133,6 +133,9 @@ with all sufficient information, see the ChangeLog file.
|
|||
* struct RBignum is hidden. [Feature #6083]
|
||||
Use rb_integer_pack and rb_integer_unpack instead.
|
||||
|
||||
* struct RRational is hidden. [Feature #9513]
|
||||
Use rb_rational_num and rb_rational_den instead.
|
||||
|
||||
* rb_big_new and rb_big_resize takes a size_t instead of long.
|
||||
|
||||
* rb_num2long returns a long instead of SIGNED_VALUE.
|
||||
|
|
|
@ -87,8 +87,8 @@ static ID id_eq;
|
|||
#endif
|
||||
|
||||
#ifndef RRATIONAL_ZERO_P
|
||||
# define RRATIONAL_ZERO_P(x) (FIXNUM_P(RRATIONAL(x)->num) && \
|
||||
FIX2LONG(RRATIONAL(x)->num) == 0)
|
||||
# define RRATIONAL_ZERO_P(x) (FIXNUM_P(rb_rational_num(x)) && \
|
||||
FIX2LONG(rb_rational_num(x)) == 0)
|
||||
#endif
|
||||
|
||||
#ifndef RRATIONAL_NEGATIVE_P
|
||||
|
@ -235,11 +235,11 @@ again:
|
|||
if (prec < 0) goto unable_to_coerce_without_prec;
|
||||
|
||||
if (orig == Qundef ? (orig = v, 1) : orig != v) {
|
||||
num = RRATIONAL(v)->num;
|
||||
num = rb_rational_num(v);
|
||||
pv = GetVpValueWithPrec(num, -1, must);
|
||||
if (pv == NULL) goto SomeOneMayDoIt;
|
||||
|
||||
v = BigDecimal_div2(ToValue(pv), RRATIONAL(v)->den, LONG2NUM(prec));
|
||||
v = BigDecimal_div2(ToValue(pv), rb_rational_den(v), LONG2NUM(prec));
|
||||
goto again;
|
||||
}
|
||||
|
||||
|
@ -2114,7 +2114,7 @@ is_zero(VALUE x)
|
|||
return Qfalse;
|
||||
|
||||
case T_RATIONAL:
|
||||
num = RRATIONAL(x)->num;
|
||||
num = rb_rational_num(x);
|
||||
return FIXNUM_P(num) && FIX2LONG(num) == 0;
|
||||
|
||||
default:
|
||||
|
@ -2137,8 +2137,8 @@ is_one(VALUE x)
|
|||
return Qfalse;
|
||||
|
||||
case T_RATIONAL:
|
||||
num = RRATIONAL(x)->num;
|
||||
den = RRATIONAL(x)->den;
|
||||
num = rb_rational_num(x);
|
||||
den = rb_rational_den(x);
|
||||
return FIXNUM_P(den) && FIX2LONG(den) == 1 &&
|
||||
FIXNUM_P(num) && FIX2LONG(num) == 1;
|
||||
|
||||
|
@ -2244,14 +2244,14 @@ BigDecimal_power(int argc, VALUE*argv, VALUE self)
|
|||
break;
|
||||
|
||||
case T_RATIONAL:
|
||||
if (is_zero(RRATIONAL(vexp)->num)) {
|
||||
if (is_zero(rb_rational_num(vexp))) {
|
||||
if (is_positive(vexp)) {
|
||||
vexp = INT2FIX(0);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
else if (is_one(RRATIONAL(vexp)->den)) {
|
||||
vexp = RRATIONAL(vexp)->num;
|
||||
else if (is_one(rb_rational_den(vexp))) {
|
||||
vexp = rb_rational_num(vexp);
|
||||
goto retry;
|
||||
}
|
||||
exp = GetVpValueWithPrec(vexp, n, 1);
|
||||
|
|
|
@ -114,7 +114,7 @@ f_zero_p(VALUE x)
|
|||
return Qfalse;
|
||||
case T_RATIONAL:
|
||||
{
|
||||
VALUE num = RRATIONAL(x)->num;
|
||||
VALUE num = rb_rational_num(x);
|
||||
return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 0);
|
||||
}
|
||||
}
|
||||
|
@ -305,9 +305,9 @@ inline static VALUE
|
|||
canon(VALUE x)
|
||||
{
|
||||
if (TYPE(x) == T_RATIONAL) {
|
||||
VALUE den = RRATIONAL(x)->den;
|
||||
VALUE den = rb_rational_den(x);
|
||||
if (FIXNUM_P(den) && FIX2LONG(den) == 1)
|
||||
return RRATIONAL(x)->num;
|
||||
return rb_rational_num(x);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
@ -2373,8 +2373,8 @@ offset_to_sec(VALUE vof, int *rof)
|
|||
return 1;
|
||||
}
|
||||
#endif
|
||||
vn = RRATIONAL(vs)->num;
|
||||
vd = RRATIONAL(vs)->den;
|
||||
vn = rb_rational_num(vs);
|
||||
vd = rb_rational_den(vs);
|
||||
|
||||
if (FIXNUM_P(vn) && FIXNUM_P(vd) && (FIX2LONG(vd) == 1))
|
||||
n = FIX2LONG(vn);
|
||||
|
@ -3097,7 +3097,7 @@ wholenum_p(VALUE x)
|
|||
break;
|
||||
case T_RATIONAL:
|
||||
{
|
||||
VALUE den = RRATIONAL(x)->den;
|
||||
VALUE den = rb_rational_den(x);
|
||||
return FIXNUM_P(den) && FIX2LONG(den) == 1;
|
||||
}
|
||||
break;
|
||||
|
@ -5707,7 +5707,7 @@ d_lite_plus(VALUE self, VALUE other)
|
|||
int jd, df, s;
|
||||
|
||||
if (wholenum_p(other))
|
||||
return d_lite_plus(self, RRATIONAL(other)->num);
|
||||
return d_lite_plus(self, rb_rational_num(other));
|
||||
|
||||
if (f_positive_p(other))
|
||||
s = +1;
|
||||
|
|
|
@ -168,6 +168,8 @@ VALUE rb_rational_new(VALUE, VALUE);
|
|||
VALUE rb_Rational(VALUE, VALUE);
|
||||
#define rb_Rational1(x) rb_Rational((x), INT2FIX(1))
|
||||
#define rb_Rational2(x,y) rb_Rational((x), (y))
|
||||
VALUE rb_rational_num(VALUE rat);
|
||||
VALUE rb_rational_den(VALUE rat);
|
||||
VALUE rb_flt_rationalize_with_prec(VALUE, VALUE);
|
||||
VALUE rb_flt_rationalize(VALUE);
|
||||
/* complex.c */
|
||||
|
|
|
@ -943,15 +943,6 @@ struct RFile {
|
|||
struct rb_io_t *fptr;
|
||||
};
|
||||
|
||||
struct RRational {
|
||||
struct RBasic basic;
|
||||
const VALUE num;
|
||||
const VALUE den;
|
||||
};
|
||||
|
||||
#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
|
||||
#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
|
||||
|
||||
struct RComplex {
|
||||
struct RBasic basic;
|
||||
const VALUE real;
|
||||
|
@ -1101,7 +1092,6 @@ struct RStruct {
|
|||
#define RTYPEDDATA(obj) (R_CAST(RTypedData)(obj))
|
||||
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
|
||||
#define RFILE(obj) (R_CAST(RFile)(obj))
|
||||
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
|
||||
#define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
|
||||
#define RSYMBOL(obj) (R_CAST(RSymbol)(obj))
|
||||
|
||||
|
|
|
@ -404,6 +404,14 @@ struct RBignum {
|
|||
|
||||
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
|
||||
|
||||
struct RRational {
|
||||
struct RBasic basic;
|
||||
const VALUE num;
|
||||
const VALUE den;
|
||||
};
|
||||
|
||||
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
|
||||
|
||||
/* class.c */
|
||||
void rb_class_subclass_add(VALUE super, VALUE klass);
|
||||
void rb_class_remove_from_super_subclasses(VALUE);
|
||||
|
|
15
rational.c
15
rational.c
|
@ -404,6 +404,9 @@ f_lcm(VALUE x, VALUE y)
|
|||
adat = ((struct RRational *)(x));\
|
||||
bdat = ((struct RRational *)(y))
|
||||
|
||||
#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
|
||||
#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
|
||||
|
||||
inline static VALUE
|
||||
nurat_s_new_internal(VALUE klass, VALUE num, VALUE den)
|
||||
{
|
||||
|
@ -1775,6 +1778,18 @@ rb_Rational(VALUE x, VALUE y)
|
|||
return nurat_s_convert(2, a, rb_cRational);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_rational_num(VALUE rat)
|
||||
{
|
||||
return nurat_numerator(rat);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_rational_den(VALUE rat)
|
||||
{
|
||||
return nurat_denominator(rat);
|
||||
}
|
||||
|
||||
#define id_numerator rb_intern("numerator")
|
||||
#define f_numerator(x) rb_funcall((x), id_numerator, 0)
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче