End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Float#<
self < other → true or false
numeric.c
View on GitHub ↗
static VALUE
flo_lt(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, '<');
}
#if MSC_VERSION_BEFORE(1300)
if (isnan(a)) return Qfalse;
#endif
return RBOOL(a < b);
}
Returns true if self is numerically less than other:
Example
2.0 < 3 # => true 2.0 < 3.0 # => true 2.0 < Rational(3, 1) # => true 2.0 < 2.0 # => false
Float::NAN < Float::NAN returns an implementation-dependent value.