25 #define RANGE_BEG(r) (RSTRUCT(r)->as.ary[0]) 26 #define RANGE_END(r) (RSTRUCT(r)->as.ary[1]) 27 #define RANGE_EXCL(r) (RSTRUCT(r)->as.ary[2]) 28 #define RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v)) 29 #define RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v)) 30 #define RANGE_SET_EXCL(r, v) (RSTRUCT_SET(r, 2, v)) 31 #define RBOOL(v) ((v) ? Qtrue : Qfalse) 33 #define EXCL(r) RTEST(RANGE_EXCL(r)) 99 VALUE beg, end, flags;
275 (*func) (v, arg, 0, 0, 0);
281 (*func) (v, arg, 0, 0, 0);
408 VALUE b, e, step, tmp;
439 if (i + unit < i)
break;
445 VALUE args[2], iter[2];
473 VALUE args[2], iter[2];
497 #if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T) 504 int64_as_double_to_num(int64_t i)
506 union int64_double convert;
518 double_as_int64(
double d)
520 union int64_double convert;
522 return d < 0 ? -convert.i : convert.i;
589 int smaller, satisfied = 0;
605 #define BSEARCH_CHECK(val) \ 607 VALUE v = rb_yield(val); \ 609 if (FIX2INT(v) == 0) return val; \ 610 smaller = FIX2INT(v) < 0; \ 612 else if (v == Qtrue) { \ 616 else if (v == Qfalse || v == Qnil) { \ 619 else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \ 620 int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \ 621 if (!cmp) return val; \ 625 rb_raise(rb_eTypeError, "wrong argument type %s" \ 626 " (must be numeric, true, false or nil)", \ 627 rb_obj_classname(v)); \ 631 #define BSEARCH(conv) \ 633 RETURN_ENUMERATOR(range, 0, 0); \ 634 if (EXCL(range)) high--; \ 636 while (low < high) { \ 637 mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \ 638 : (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \ 639 BSEARCH_CHECK(conv(mid)); \ 647 if (low == org_high) { \ 648 BSEARCH_CHECK(conv(low)); \ 649 if (!smaller) return Qnil; \ 651 if (!satisfied) return Qnil; \ 665 #if SIZEOF_DOUBLE == 8 && defined(HAVE_INT64_T) 669 int64_t mid, org_high;
670 BSEARCH(int64_as_double_to_num);
693 if (!smaller)
return Qnil;
695 if (!satisfied)
return Qnil;
783 for (i =
FIX2LONG(beg); i < lim; i++) {
982 if (c == 0)
return Qnil;
1022 long beg, end, origbeg, origend;
1041 if (
err == 0 ||
err == 2) {
1058 origbeg, excl ?
"." :
"", origend);
1195 if (b <= v && v < e)
return Qtrue;
1339 #define rb_intern(str) rb_intern_const(str) 1351 "begin",
"end",
"excl",
NULL);
static int is_integer_p(VALUE v)
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
static VALUE range_max(VALUE range)
static VALUE range_dumper(VALUE range)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE range_include(VALUE range, VALUE val)
static VALUE each_i(RB_BLOCK_CALL_FUNC_ARGLIST(v, arg))
st_index_t rb_hash_end(st_index_t)
static int linear_object_p(VALUE obj)
static VALUE range_bsearch(VALUE range)
VALUE rb_struct_init_copy(VALUE copy, VALUE s)
static VALUE range_loader(VALUE range, VALUE obj)
static void range_modify(VALUE range)
static VALUE sym_each_i(RB_BLOCK_CALL_FUNC_ARGLIST(v, arg))
VALUE rb_ary_last(int argc, VALUE *argv, VALUE ary)
VALUE rb_struct_alloc_noinit(VALUE)
VALUE rb_ary_push(VALUE ary, VALUE item)
SSL_METHOD *(* func)(void)
static VALUE step_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
static VALUE inspect_range(VALUE range, VALUE dummy, int recur)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_ivar_get(VALUE, ID)
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
void rb_include_module(VALUE klass, VALUE module)
VALUE rb_block_call(VALUE, ID, int, const VALUE *, rb_block_call_func_t, VALUE)
#define RGENGC_WB_PROTECTED_OBJECT
static VALUE range_to_s(VALUE range)
VALUE rb_range_new(VALUE beg, VALUE end, int exclude_end)
VALUE rb_check_to_integer(VALUE, const char *)
int rb_cmpint(VALUE val, VALUE a, VALUE b)
const char * rb_obj_classname(VALUE)
static void range_each_func(VALUE range, rb_block_call_func *func, VALUE arg)
void rb_name_error(ID id, const char *fmt,...)
#define NEWOBJ_OF(obj, type, klass, flags)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
static VALUE recursive_eql(VALUE range, VALUE obj, int recur)
#define RB_TYPE_P(obj, type)
static VALUE range_eql(VALUE range, VALUE obj)
static VALUE range_size(VALUE range)
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
VALUE rb_rescue(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2)
static VALUE range_step(int argc, VALUE *argv, VALUE range)
static VALUE range_initialize_copy(VALUE range, VALUE orig)
int rb_block_given_p(void)
RUBY_EXTERN VALUE rb_cObject
VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE, VALUE)
static VALUE range_enum_size(VALUE range, VALUE args, VALUE eobj)
VALUE rb_obj_as_string(VALUE)
VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
static VALUE range_initialize(int argc, VALUE *argv, VALUE range)
static VALUE first_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, cbarg))
static VALUE range_step_size(VALUE range, VALUE args, VALUE eobj)
#define range(low, item, hi)
#define BSEARCH_CHECK(val)
VALUE rb_obj_alloc(VALUE)
static VALUE range_first(int argc, VALUE *argv, VALUE range)
int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl)
static VALUE range_check(VALUE *args)
static VALUE range_min(VALUE range)
static VALUE range_hash(VALUE range)
static void range_init(VALUE range, VALUE beg, VALUE end, VALUE exclude_end)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
static VALUE range_exclude_end_p(VALUE range)
VALUE rb_ivar_set(VALUE, ID, VALUE)
static int discrete_object_p(VALUE obj)
#define RANGE_SET_END(r, v)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
RUBY_EXTERN VALUE rb_cInteger
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
VALUE rb_call_super(int, const VALUE *)
RUBY_EXTERN VALUE rb_cNumeric
static VALUE sym_step_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
#define RANGE_SET_EXCL(r, v)
int rb_respond_to(VALUE, ID)
VALUE rb_range_beg_len(VALUE range, long *begp, long *lenp, long len, int err)
static VALUE recursive_equal(VALUE range, VALUE obj, int recur)
VALUE rb_equal(VALUE, VALUE)
static VALUE range_end(VALUE range)
static VALUE range_inspect(VALUE range)
static int r_lt(VALUE a, VALUE b)
#define RARRAY_AREF(a, i)
static VALUE range_begin(VALUE range)
static VALUE range_last(int argc, VALUE *argv, VALUE range)
VALUE rb_check_string_type(VALUE)
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
st_index_t rb_hash_uint(st_index_t, st_index_t)
static VALUE range_alloc(VALUE klass)
static unsigned int hash(const char *str, unsigned int len)
#define RETURN_ENUMERATOR(obj, argc, argv)
static VALUE range_each(VALUE range)
VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t,...)
VALUE rb_str_intern(VALUE)
#define SPECIAL_CONST_P(x)
static VALUE range_eqq(VALUE range, VALUE val)
static VALUE range_eq(VALUE range, VALUE obj)
RUBY_EXTERN VALUE rb_cTime
static int r_le(VALUE a, VALUE b)
static VALUE range_cover(VALUE range, VALUE val)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
#define RANGE_SET_BEG(r, v)
static VALUE range_failed(void)
st_index_t rb_hash_start(st_index_t)