14#include "internal/compar.h"
15#include "internal/error.h"
16#include "internal/vm.h"
22rb_cmp(VALUE x, VALUE y)
33 classname = rb_inspect(y);
36 classname = rb_obj_class(y);
38 rb_raise(rb_eArgError,
"comparison of %"PRIsVALUE
" with %"PRIsVALUE
" failed",
39 rb_obj_class(x), classname);
43invcmp_recursive(VALUE x, VALUE y,
int recursive)
45 if (recursive)
return Qnil;
50rb_invcmp(VALUE x, VALUE y)
63cmp_eq_recursive(VALUE arg1, VALUE arg2,
int recursive)
65 if (recursive)
return Qnil;
66 return rb_cmp(arg1, arg2);
79cmp_equal(VALUE x, VALUE y)
82 if (x == y)
return Qtrue;
91cmpint(VALUE x, VALUE y)
105cmp_gt(VALUE x, VALUE y)
107 return RBOOL(cmpint(x, y) > 0);
119cmp_ge(VALUE x, VALUE y)
121 return RBOOL(cmpint(x, y) >= 0);
133cmp_lt(VALUE x, VALUE y)
135 return RBOOL(cmpint(x, y) < 0);
147cmp_le(VALUE x, VALUE y)
149 return RBOOL(cmpint(x, y) <= 0);
168cmp_between(VALUE x, VALUE min, VALUE max)
170 if (cmpint(x, min) < 0)
return Qfalse;
171 if (cmpint(x, max) > 0)
return Qfalse;
218cmp_clamp(
int argc, VALUE *argv, VALUE x)
226 rb_raise(rb_eTypeError,
"wrong argument type %s (expected Range)",
227 rb_builtin_class_name(range));
230 if (excl)
rb_raise(rb_eArgError,
"cannot clamp with an exclusive range");
233 if (!
NIL_P(min) && !
NIL_P(max) && cmpint(min, max) > 0) {
234 rb_raise(rb_eArgError,
"min argument must be smaller than max argument");
239 if (c == 0)
return x;
240 if (c < 0)
return min;
244 if (c > 0)
return max;
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.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
#define Qundef
Old name of RUBY_Qundef.
#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.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
VALUE rb_mComparable
Comparable module.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
int rb_cmpint(VALUE val, VALUE a, VALUE b)
Canonicalises the passed val, which is the return value of a <=> b, into C's {-1, 0,...
void rb_cmperr(VALUE a, VALUE b)
Raises "comparison failed" error.
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...