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))
135 if (recur)
return Qtrue;
204 if (recur)
return Qtrue;
275 (*func) (
v,
arg, 0, 0, 0);
281 (*func) (
v,
arg, 0, 0, 0);
439 if (i + unit < i)
break;
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++) {
943 if (c > 0 || (c == 0 &&
EXCL(range)))
982 if (c == 0)
return Qnil;
1022 long beg,
end, origbeg, origend;
1041 if (err == 0 || err == 2) {
1058 origbeg, excl ?
"." :
"", origend);
1171 if (
r_le(beg, val)) {
1195 if (b <= v && v < e)
return Qtrue;
1196 if (!
EXCL(range) && v == e)
return Qtrue;
1229 if (
r_le(beg, val)) {
1339 #define rb_intern(str) rb_intern_const(str)
1351 "begin",
"end",
"excl",
NULL);
#define RB_TYPE_P(obj, type)
static int is_integer_p(VALUE v)
const char * rb_obj_classname(VALUE)
static VALUE range_max(VALUE range)
static VALUE range_dumper(VALUE range)
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
static VALUE range_include(VALUE range, VALUE val)
SSL_METHOD *(* func)(void)
static int linear_object_p(VALUE obj)
RUBY_EXTERN VALUE rb_cTime
static VALUE range_bsearch(VALUE range)
static VALUE range_loader(VALUE range, VALUE obj)
static void range_modify(VALUE range)
VALUE rb_ary_last(int argc, VALUE *argv, VALUE ary)
VALUE rb_ary_push(VALUE ary, VALUE item)
static VALUE inspect_range(VALUE range, VALUE dummy, int recur)
void rb_raise(VALUE exc, const char *fmt,...)
#define RETURN_ENUMERATOR(obj, argc, argv)
void rb_include_module(VALUE klass, VALUE module)
#define RGENGC_WB_PROTECTED_OBJECT
static VALUE range_to_s(VALUE range)
int rb_cmpint(VALUE val, VALUE a, VALUE b)
VALUE rb_ivar_get(VALUE, ID)
VALUE rb_equal(VALUE, VALUE)
static void range_each_func(VALUE range, rb_block_call_func *func, VALUE arg)
void rb_name_error(ID id, const char *fmt,...)
st_index_t rb_hash_start(st_index_t)
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
static VALUE recursive_eql(VALUE range, VALUE obj, int recur)
static VALUE range_eql(VALUE range, VALUE obj)
static VALUE range_size(VALUE range)
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)
static VALUE range_enum_size(VALUE range, VALUE args, VALUE eobj)
#define RARRAY_AREF(a, i)
VALUE ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
int ruby_float_step(VALUE from, VALUE to, VALUE step, int excl)
static VALUE range_initialize(int argc, VALUE *argv, VALUE range)
VALUE rb_check_to_integer(VALUE, const char *)
VALUE rb_call_super(int, const VALUE *)
static VALUE range_step_size(VALUE range, VALUE args, VALUE eobj)
VALUE rb_struct_define_without_accessor(const char *, VALUE, rb_alloc_func_t,...)
#define range(low, item, hi)
#define BSEARCH_CHECK(val)
static VALUE range_first(int argc, VALUE *argv, VALUE range)
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
VALUE rb_obj_as_string(VALUE)
RUBY_EXTERN VALUE rb_cInteger
static VALUE range_check(VALUE *args)
static VALUE range_min(VALUE range)
static VALUE range_hash(VALUE range)
VALUE rb_range_new(VALUE, VALUE, int)
rb_block_call(enumerable, id_each, 0, 0, chunk_ii, arg)
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)
static int discrete_object_p(VALUE obj)
#define RANGE_SET_END(r, v)
#define RANGE_SET_EXCL(r, v)
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
static VALUE recursive_equal(VALUE range, VALUE obj, int recur)
#define NEWOBJ_OF(obj, type, klass, flags)
VALUE rb_str_cat(VALUE, const char *, long)
static VALUE range_end(VALUE range)
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
static VALUE range_inspect(VALUE range)
static int r_lt(VALUE a, VALUE b)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
static VALUE range_begin(VALUE range)
static VALUE range_last(int argc, VALUE *argv, VALUE range)
VALUE rb_exec_recursive_paired(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE, VALUE)
RUBY_EXTERN VALUE rb_cObject
int rb_respond_to(VALUE, ID)
static VALUE range_alloc(VALUE klass)
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
rb_ivar_set(yielder, id_memo, LONG2NUM(++count))
static VALUE range_each(VALUE range)
VALUE rb_range_beg_len(VALUE, long *, long *, long, int)
VALUE rb_obj_alloc(VALUE)
VALUE rb_str_intern(VALUE)
static VALUE range_eqq(VALUE range, VALUE val)
#define SPECIAL_CONST_P(x)
static VALUE range_eq(VALUE range, VALUE obj)
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
VALUE rb_struct_init_copy(VALUE copy, VALUE s)
VALUE rb_check_string_type(VALUE)
static int r_le(VALUE a, VALUE b)
RUBY_EXTERN VALUE rb_cRange
static VALUE range_cover(VALUE range, VALUE val)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
#define RANGE_SET_BEG(r, v)
RUBY_EXTERN VALUE rb_cNumeric
static VALUE range_failed(void)
VALUE rb_struct_alloc_noinit(VALUE)
#define rb_hash_uint(h, i)