diff --git a/ChangeLog b/ChangeLog index ce1aaeac7a..abf3ec3c30 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Thu Jul 16 15:00:27 2009 Nobuyoshi Nakada +Thu Jul 16 15:52:25 2009 Nobuyoshi Nakada + + * bignum.c (rb_big_new, rb_bigzero_p), range.c (rb_range_values): + added for random.c. * random.c (rb_random_t): objectified. [EXPERIMENTAL] [ruby-dev:30954] diff --git a/bignum.c b/bignum.c index d2f5ea3040..f2853ebe7b 100644 --- a/bignum.c +++ b/bignum.c @@ -52,6 +52,12 @@ bigzero_p(VALUE x) return 1; } +int +rb_bigzero_p(VALUE x) +{ + return BIGZEROP(x); +} + int rb_cmpint(VALUE val, VALUE a, VALUE b) { @@ -142,6 +148,12 @@ bignew_1(VALUE klass, long len, int sign) #define bignew(len,sign) bignew_1(rb_cBignum,len,sign) +VALUE +rb_big_new(long len, int sign) +{ + return bignew(len, sign != 0); +} + VALUE rb_big_clone(VALUE x) { diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 09e71e9193..7375442b41 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -75,6 +75,8 @@ VALUE rb_ary_cmp(VALUE, VALUE); VALUE rb_ary_replace(VALUE copy, VALUE orig); VALUE rb_get_values_at(VALUE, long, int, VALUE*, VALUE(*)(VALUE,long)); /* bignum.c */ +VALUE rb_big_new(long, int); +int rb_bigzero_p(VALUE x); VALUE rb_big_clone(VALUE); void rb_big_2comp(VALUE); VALUE rb_big_norm(VALUE); @@ -520,6 +522,7 @@ VALUE rb_detach_process(rb_pid_t pid); /* range.c */ VALUE rb_range_new(VALUE, VALUE, int); VALUE rb_range_beg_len(VALUE, long*, long*, long, int); +int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp); /* random.c */ unsigned long rb_genrand_int32(void); double rb_genrand_real(void); diff --git a/range.c b/range.c index 0d25a37d55..ce2df63100 100644 --- a/range.c +++ b/range.c @@ -601,12 +601,11 @@ range_max(VALUE range) } } - -VALUE -rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) +int +rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp) { VALUE b, e; - long beg, end, excl; + int excl; if (rb_obj_is_kind_of(range, rb_cRange)) { b = RANGE_BEG(range); @@ -620,9 +619,25 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) e = rb_funcall(range, id_end, 0); excl = RTEST(rb_funcall(range, rb_intern("exclude_end?"), 0)); } + *begp = b; + *endp = e; + *exclp = excl; + return Qtrue; +} + +VALUE +rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) +{ + long beg, end, origbeg, origend; + VALUE b, e; + int excl; + + if (!rb_range_values(range, &b, &e, &excl)) + return Qfalse; beg = NUM2LONG(b); end = NUM2LONG(e); - + origbeg = beg; + origend = end; if (beg < 0) { beg += len; if (beg < 0) @@ -649,7 +664,7 @@ rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err) out_of_range: if (err) { rb_raise(rb_eRangeError, "%ld..%s%ld out of range", - NUM2LONG(b), excl ? "." : "", NUM2LONG(e)); + origbeg, excl ? "." : "", origend); } return Qnil; }