Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

Macros | Functions | Variables
range.c File Reference
`#include "internal.h"`
`#include "id.h"`
`#include <assert.h>`
`#include <math.h>`

Go to the source code of this file.

## Macros
#define | id_cmp idCmp
#define | id_succ idSucc
#define | RANGE_SET_BEG(r, v) (RSTRUCT_SET(r, 0, v))
#define | RANGE_SET_END(r, v) (RSTRUCT_SET(r, 1, v))
#define | RANGE_SET_EXCL(r, v) (RSTRUCT_SET(r, 2, v))
#define | RBOOL(v) ((v) ? Qtrue : Qfalse)
#define | EXCL(r) RTEST(RANGE_EXCL(r))
#define | BSEARCH_CHECK(expr)
#define | BSEARCH(conv)
#define | rb_intern(str) rb_intern_const(str)

## Functions
VALUE | rb_range_new (VALUE beg, VALUE end, int exclude_end)
int | rb_range_values (VALUE range, VALUE *begp, VALUE *endp, int *exclp)
VALUE | rb_range_beg_len (VALUE range, long *begp, long *lenp, long len, int err)
void | Init_Range (void)

## Variables
VALUE | rb_cRange

## Macro Definition Documentation

## ◆ BSEARCH

#define BSEARCH | ( |  | conv | ) |

Value:
do { \
RETURN_ENUMERATOR(range, 0, 0); \
if (EXCL(range)) high--; \
org_high = high; \
while (low < high) { \
mid = ((high < 0) == (low < 0)) ? low + ((high - low) / 2) \
: (low < -high) ? -((-1 - low - high)/2 + 1) : (low + high) / 2; \
BSEARCH_CHECK(conv(mid)); \
if (smaller) { \
high = mid; \
} \
else { \
low = mid + 1; \
} \
} \
if (low == org_high) { \
BSEARCH_CHECK(conv(low)); \
if (!smaller) return Qnil; \
} \
return satisfied; \
} while (0)

## ◆ BSEARCH_CHECK

#define BSEARCH_CHECK | ( |  | expr | ) |

Value:
do { \
VALUE val = (expr); \
VALUE v = rb_yield(val); \
if (FIXNUM_P(v)) { \
if (v == INT2FIX(0)) return val; \
smaller = (SIGNED_VALUE)v < 0; \
} \
else if (v == Qtrue) { \
satisfied = val; \
smaller = 1; \
} \
else if (v == Qfalse || v == Qnil) { \
smaller = 0; \
} \
else if (rb_obj_is_kind_of(v, rb_cNumeric)) { \
int cmp = rb_cmpint(rb_funcall(v, id_cmp, 1, INT2FIX(0)), v, INT2FIX(0)); \
if (!cmp) return val; \
smaller = cmp < 0; \
} \
else { \
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE \
" (must be numeric, true, false or nil)", \
rb_obj_class(v)); \
} \
} while (0)

## ◆ EXCL

#define EXCL | ( |  | r | ) | RTEST(RANGE_EXCL(r))

Definition at line 33 of file range.c.

## ◆ id_cmp

#define id_cmp idCmp

Definition at line 23 of file range.c.

## ◆ id_succ

#define id_succ idSucc

Definition at line 24 of file range.c.

## ◆ RANGE_SET_BEG

#define RANGE_SET_BEG | ( |  | r,
|  |  | v
| ) |  | (RSTRUCT_SET(r, 0, v))

Definition at line 28 of file range.c.

## ◆ RANGE_SET_END

#define RANGE_SET_END | ( |  | r,
|  |  | v
| ) |  | (RSTRUCT_SET(r, 1, v))

Definition at line 29 of file range.c.

## ◆ RANGE_SET_EXCL

#define RANGE_SET_EXCL | ( |  | r,
|  |  | v
| ) |  | (RSTRUCT_SET(r, 2, v))

Definition at line 30 of file range.c.

## ◆ rb_intern

#define rb_intern | ( |  | str | ) | rb_intern_const(str)

## ◆ RBOOL

#define RBOOL | ( |  | v | ) | ((v) ? Qtrue : Qfalse)

Definition at line 31 of file range.c.

## Function Documentation

## ◆ Init_Range()

void Init_Range | ( | void |  | ) |

Definition at line 1750 of file range.c.

## ◆ rb_range_beg_len()

VALUE rb_range_beg_len | ( | VALUE | range,
|  | long * | begp,
|  | long * | lenp,
|  | long | len,
|  | int | err
| ) |  |

Definition at line 1273 of file range.c.

References err, len, NIL_P, NUM2LONG, Qfalse, Qnil, Qtrue, range, rb_eRangeError, rb_raise(), and rb_range_values().

Referenced by rb_ary_aref1().

## ◆ rb_range_new()

VALUE rb_range_new | ( | VALUE | beg,
|  | VALUE | end,
|  | int | exclude_end
| ) |  |

Definition at line 52 of file range.c.

References range, rb_cRange, and rb_obj_alloc().

## ◆ rb_range_values()

int rb_range_values | ( | VALUE | range,
|  | VALUE * | begp,
|  | VALUE * | endp,
|  | int * | exclp
| ) |  |

Definition at line 1243 of file range.c.

References EXCL, Qfalse, range, RANGE_BEG, RANGE_END, rb_cArithSeq, rb_check_funcall(), rb_cRange, rb_obj_is_kind_of(), and RTEST.

Referenced by rb_range_beg_len().

range
#define range(low, item, hi)
Definition: date_strftime.c:21
id_cmp
#define id_cmp
Definition: range.c:23
rb_cNumeric
RUBY_EXTERN VALUE rb_cNumeric
Definition: ruby.h:2037
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
SIGNED_VALUE
#define SIGNED_VALUE
Definition: ruby.h:104
else
else
Definition: rb_mjit_min_header-2.7.0.h:13246
Qfalse
#define Qfalse
Definition: ruby.h:467
rb_cmpint
#define rb_cmpint(cmp, a, b)
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
EXCL
#define EXCL(r)
Definition: range.c:33
v
int VALUE v
Definition: rb_mjit_min_header-2.7.0.h:12332
if
if((ID)(DISPID) nameid !=nameid)
Definition: win32ole.c:357
rb_obj_class
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
Definition: object.c:217
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:922
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:396
rb_funcall
#define rb_funcall(recv, mid, argc,...)
Definition: rb_mjit_min_header-2.7.0.h:6585
Qtrue
#define Qtrue
Definition: ruby.h:468
rb_yield
VALUE rb_yield(VALUE)
Definition: vm_eval.c:1237
Qnil
#define Qnil
Definition: ruby.h:469
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
Definition: object.c:692