14#include "internal/compar.h"
15#include "internal/error.h"
16#include "internal/vm.h"
24 return rb_funcallv(x, idCmp, 1, &y);
28cmperr_subject(
VALUE y)
44 VALUE classname = cmperr_subject(y);
45 rb_raise(rb_eArgError,
"comparison of %"PRIsVALUE
" with %"PRIsVALUE
" failed",
50rb_cmperr_reason(
VALUE x,
VALUE y,
const char *reason)
52 VALUE classname = cmperr_subject(y);
53 rb_raise(rb_eArgError,
"comparison of %"PRIsVALUE
" with %"PRIsVALUE
" failed: %s",
58invcmp_recursive(
VALUE x,
VALUE y,
int recursive)
60 if (recursive)
return Qnil;
68 if (NIL_OR_UNDEF_P(invcmp)) {
72 int result = -rb_cmpint(invcmp, x, y);
78cmp_eq_recursive(
VALUE arg1,
VALUE arg2,
int recursive)
80 if (recursive)
return Qnil;
81 return rb_cmp(arg1, arg2);
97 if (x == y)
return Qtrue;
102 return RBOOL(rb_cmpint(c, x, y) == 0);
108 return rb_cmpint(rb_cmp(x, y), x, y);
125 return RBOOL(cmpint(x, y) > 0);
144 return RBOOL(cmpint(x, y) >= 0);
162 return RBOOL(cmpint(x, y) < 0);
181 return RBOOL(cmpint(x, y) <= 0);
202 return RBOOL((cmpint(x, min) >= 0 && cmpint(x, max) <= 0));
262 rb_raise(
rb_eTypeError,
"wrong argument type %s (expected Range)",
263 rb_builtin_class_name(range));
266 if (excl) rb_raise(rb_eArgError,
"cannot clamp with an exclusive range");
269 if (!
NIL_P(min) && !
NIL_P(max) && cmpint(min, max) > 0) {
270 rb_raise(rb_eArgError,
"min argument must be less than or equal to max argument");
275 if (c == 0)
return x;
276 if (c < 0)
return min;
280 if (c > 0)
return max;
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
VALUE rb_define_module(const char *name)
Defines a top-level module.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
#define INT2FIX
Old name of RB_INT2FIX.
#define T_FLOAT
Old name of RUBY_T_FLOAT.
#define SPECIAL_CONST_P
Old name of RB_SPECIAL_CONST_P.
#define Qtrue
Old name of RUBY_Qtrue.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define BUILTIN_TYPE
Old name of RB_BUILTIN_TYPE.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_mComparable
Comparable module.
int rb_range_values(VALUE range, VALUE *begp, VALUE *endp, int *exclp)
Deconstructs a range into its components.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_exec_recursive_paired_outer(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE p, VALUE h)
Identical to rb_exec_recursive_outer(), except it checks for the recursion on the ordered pair of { g...
uintptr_t VALUE
Type that represents a Ruby object.