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)
91 91
#endif
92 92

  
93 93
#ifndef RRATIONAL_ZERO_P
94
# define RRATIONAL_ZERO_P(x) (FIXNUM_P(RRATIONAL(x)->num) && \
95
			      FIX2LONG(RRATIONAL(x)->num) == 0)
94
# define RRATIONAL_ZERO_P(x) (FIXNUM_P(rb_rational_num(x)) && \
95
			      FIX2LONG(rb_rational_num(x)) == 0)
96 96
#endif
97 97

  
98 98
#ifndef RRATIONAL_NEGATIVE_P
......
239 239
	if (prec < 0) goto unable_to_coerce_without_prec;
240 240

  
241 241
	if (orig == Qundef ? (orig = v, 1) : orig != v) {
242
	    num = RRATIONAL(v)->num;
242
	    num = rb_rational_num(v);
243 243
	    pv = GetVpValueWithPrec(num, -1, must);
244 244
	    if (pv == NULL) goto SomeOneMayDoIt;
245 245

  
246
	    v = BigDecimal_div2(ToValue(pv), RRATIONAL(v)->den, LONG2NUM(prec));
246
	    v = BigDecimal_div2(ToValue(pv), rb_rational_den(v), LONG2NUM(prec));
247 247
	    goto again;
248 248
	}
249 249

  
......
2118 2118
	return Qfalse;
2119 2119

  
2120 2120
      case T_RATIONAL:
2121
	num = RRATIONAL(x)->num;
2121
	num = rb_rational_num(x);
2122 2122
	return FIXNUM_P(num) && FIX2LONG(num) == 0;
2123 2123

  
2124 2124
      default:
......
2141 2141
	return Qfalse;
2142 2142

  
2143 2143
      case T_RATIONAL:
2144
	num = RRATIONAL(x)->num;
2145
	den = RRATIONAL(x)->den;
2144
	num = rb_rational_num(x);
2145
	den = rb_rational_den(x);
2146 2146
	return FIXNUM_P(den) && FIX2LONG(den) == 1 &&
2147 2147
	       FIXNUM_P(num) && FIX2LONG(num) == 1;
2148 2148

  
......
2248 2248
	break;
2249 2249

  
2250 2250
      case T_RATIONAL:
2251
	if (is_zero(RRATIONAL(vexp)->num)) {
2251
	if (is_zero(rb_rational_num(vexp))) {
2252 2252
	    if (is_positive(vexp)) {
2253 2253
		vexp = INT2FIX(0);
2254 2254
		goto retry;
2255 2255
	    }
2256 2256
	}
2257
	else if (is_one(RRATIONAL(vexp)->den)) {
2258
	    vexp = RRATIONAL(vexp)->num;
2257
	else if (is_one(rb_rational_den(vexp))) {
2258
	    vexp = rb_rational_num(vexp);
2259 2259
	    goto retry;
2260 2260
	}
2261 2261
	exp = GetVpValueWithPrec(vexp, n, 1);
ext/date/date_core.c (working copy)
114 114
	return Qfalse;
115 115
      case T_RATIONAL:
116 116
	{
117
	    VALUE num = RRATIONAL(x)->num;
117
	    VALUE num = rb_rational_num(x);
118 118
	    return f_boolcast(FIXNUM_P(num) && FIX2LONG(num) == 0);
119 119
	}
120 120
    }
......
305 305
canon(VALUE x)
306 306
{
307 307
    if (TYPE(x) == T_RATIONAL) {
308
	VALUE den = RRATIONAL(x)->den;
308
	VALUE den = rb_rational_den(x);
309 309
	if (FIXNUM_P(den) && FIX2LONG(den) == 1)
310
	    return RRATIONAL(x)->num;
310
	    return rb_rational_num(x);
311 311
    }
312 312
    return x;
313 313
}
......
2396 2396
		return 1;
2397 2397
	    }
2398 2398
#endif
2399
	    vn = RRATIONAL(vs)->num;
2400
	    vd = RRATIONAL(vs)->den;
2399
	    vn = rb_rational_num(vs);
2400
	    vd = rb_rational_den(vs);
2401 2401

  
2402 2402
	    if (FIXNUM_P(vn) && FIXNUM_P(vd) && (FIX2LONG(vd) == 1))
2403 2403
		n = FIX2LONG(vn);
......
3120 3120
	break;
3121 3121
      case T_RATIONAL:
3122 3122
	{
3123
	    VALUE den = RRATIONAL(x)->den;
3123
	    VALUE den = rb_rational_den(x);
3124 3124
	    return FIXNUM_P(den) && FIX2LONG(den) == 1;
3125 3125
	}
3126 3126
	break;
......
5727 5727
	    int jd, df, s;
5728 5728

  
5729 5729
	    if (wholenum_p(other))
5730
		return d_lite_plus(self, RRATIONAL(other)->num);
5730
		return d_lite_plus(self, rb_rational_num(other));
5731 5731

  
5732 5732
	    if (f_positive_p(other))
5733 5733
		s = +1;
include/ruby/intern.h (working copy)
172 172
VALUE rb_Rational(VALUE, VALUE);
173 173
#define rb_Rational1(x) rb_Rational((x), INT2FIX(1))
174 174
#define rb_Rational2(x,y) rb_Rational((x), (y))
175
VALUE rb_rational_num(VALUE rat);
176
VALUE rb_rational_den(VALUE rat);
175 177
VALUE rb_flt_rationalize_with_prec(VALUE, VALUE);
176 178
VALUE rb_flt_rationalize(VALUE);
177 179
/* complex.c */
include/ruby/ruby.h (working copy)
938 938
    struct rb_io_t *fptr;
939 939
};
940 940

  
941
struct RRational {
942
    struct RBasic basic;
943
    const VALUE num;
944
    const VALUE den;
945
};
946

  
947
#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
948
#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
949

  
950 941
struct RComplex {
951 942
    struct RBasic basic;
952 943
    const VALUE real;
......
1129 1120
#define RSTRUCT(obj) (R_CAST(RStruct)(obj))
1130 1121
#define RBIGNUM(obj) (R_CAST(RBignum)(obj))
1131 1122
#define RFILE(obj)   (R_CAST(RFile)(obj))
1132
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
1133 1123
#define RCOMPLEX(obj) (R_CAST(RComplex)(obj))
1134 1124

  
1135 1125
#define FL_SINGLETON FL_USER0
internal.h (working copy)
305 305
    size_t serial;
306 306
};
307 307

  
308
struct RRational {
309
    struct RBasic basic;
310
    const VALUE num;
311
    const VALUE den;
312
};
313

  
314
#define RRATIONAL(obj) (R_CAST(RRational)(obj))
315

  
316
#define RRATIONAL_SET_NUM(rat, n) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->num,(n))
317
#define RRATIONAL_SET_DEN(rat, d) RB_OBJ_WRITE((rat), &((struct RRational *)(rat))->den,(d))
318

  
308 319
/* class.c */
309 320
void rb_class_subclass_add(VALUE super, VALUE klass);
310 321
void rb_class_remove_from_super_subclasses(VALUE);
rational.c (working copy)
1806 1806
    return nurat_s_convert(2, a, rb_cRational);
1807 1807
}
1808 1808

  
1809
VALUE
1810
rb_rational_num(VALUE rat)
1811
{
1812
    return nurat_numerator(rat);
1813
}
1814

  
1815
VALUE
1816
rb_rational_den(VALUE rat)
1817
{
1818
    return nurat_denominator(rat);
1819
}
1820

  
1809 1821
#define id_numerator rb_intern("numerator")
1810 1822
#define f_numerator(x) rb_funcall((x), id_numerator, 0)
1811 1823