mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c (rb_big_new, rb_bigzero_p), range.c (rb_range_values):
added for random.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24143 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
eb9bc2d265
commit
5e65d8f433
4 changed files with 40 additions and 7 deletions
|
@ -1,4 +1,7 @@
|
|||
Thu Jul 16 15:00:27 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
Thu Jul 16 15:52:25 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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]
|
||||
|
|
12
bignum.c
12
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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
27
range.c
27
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue