Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Float#<=
(::Numeric) -> bool
self <= other → true or false
numeric.c
View on GitHub ↗
static VALUE
flo_le(VALUE x, VALUE y)
{
double a, b;
a = RFLOAT_VALUE(x);
if (RB_INTEGER_TYPE_P(y)) {
VALUE rel = rb_integer_float_cmp(y, x);
if (FIXNUM_P(rel))
return RBOOL(-FIX2LONG(rel) <= 0);
return Qfalse;
}
else if (RB_FLOAT_TYPE_P(y)) {
b = RFLOAT_VALUE(y);
#if MSC_VERSION_BEFORE(1300)
if (isnan(b)) return Qfalse;
#endif
}
else {
return rb_num_coerce_relop(x, y, idLE);
}
#if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse;
#endif
return RBOOL(a <= b);
}
Returns true if self is numerically less than or equal to other:
Example
2.0 <= 3 # => true 2.0 <= 3.0 # => true 2.0 <= Rational(3, 1) # => true 2.0 <= 2.0 # => true 2.0 <= 1.0 # => false
Float::NAN <= Float::NAN returns an implementation-dependent value.