Project

General

Profile

Feature #9513 ยป hide-rational-internal.patch

akr (Akira Tanaka), 02/12/2014 11:51 AM

View differences:

ext/bigdecimal/bigdecimal.c (working copy)
#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
......
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;
}
......
return Qfalse;
case T_RATIONAL:
num = RRATIONAL(x)->num;
num = rb_rational_num(x);
return FIXNUM_P(num) && FIX2LONG(num) == 0;
default:
......
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;
......
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);
ext/date/date_core.c (working copy)
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);
}
}
......
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;
}
......
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);
......
break;
case T_RATIONAL:
{
VALUE den = RRATIONAL(x)->den;
VALUE den = rb_rational_den(x);
return FIXNUM_P(den) && FIX2LONG(den) == 1;
}
break;
......
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;
include/ruby/intern.h (working copy)
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 */
include/ruby/ruby.h (working copy)
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;
......
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
#define RFILE(obj) (R_CAST(RFile)(obj))
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
#define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
#define FL_SINGLETON FL_USER0
internal.h (working copy)
size_t serial;
};
struct RRational {
struct RBasic basic;
const VALUE num;
const VALUE den;
};
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
#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))
/* class.c */
void rb_class_subclass_add(VALUE super, VALUE klass);
void rb_class_remove_from_super_subclasses(VALUE);
rational.c (working copy)
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)
    (1-1/1)