Project

General

Profile

Feature #10594 » num_clamp.c

0x0dea (D.E. Akers), 06/30/2015 02:18 AM

 
static VALUE
num_clamp(VALUE num, VALUE obj)
{
VALUE begp, endp;
int exclp;

if (!rb_range_values(obj, &begp, &endp, &exclp)) {
rb_raise(rb_eArgError, "argument must be a Range");
}

if (exclp) endp = rb_funcall(endp, rb_intern("pred"), 0);
if (rb_funcall(num, idLT, 1, begp)) {
return begp;
} else if (rb_funcall(num, idGT, 1, endp)) {
return endp;
}

return num;
}
(1-1/2)