Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Complex#==
(untyped) -> bool
self == other → true or false
complex.c
View on GitHub ↗
static VALUE
nucomp_eqeq_p(VALUE self, VALUE other)
{
if (RB_TYPE_P(other, T_COMPLEX)) {
get_dat2(self, other);
return RBOOL(f_eqeq_p(adat->real, bdat->real) &&
f_eqeq_p(adat->imag, bdat->imag));
}
if (k_numeric_p(other) && f_real_p(other)) {
get_dat1(self);
return RBOOL(f_eqeq_p(dat->real, other) && f_zero_p(dat->imag));
}
return RBOOL(f_eqeq_p(other, self));
}
Returns whether both self.real == other.real and self.imag == other.imag:
Example
Complex.rect(2, 3) == Complex.rect(2.0, 3.0) # => true