Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Float#**
(::Complex) -> ::Complex
(::Numeric) -> ::Float
self ** other → numeric
numeric.c
View on GitHub ↗
VALUE
rb_float_pow(VALUE x, VALUE y)
{
double dx, dy;
if (y == INT2FIX(2)) {
dx = RFLOAT_VALUE(x);
return DBL2NUM(dx * dx);
}
else if (FIXNUM_P(y)) {
dx = RFLOAT_VALUE(x);
dy = (double)FIX2LONG(y);
}
else if (RB_BIGNUM_TYPE_P(y)) {
dx = RFLOAT_VALUE(x);
dy = rb_big2dbl(y);
}
else if (RB_FLOAT_TYPE_P(y)) {
dx = RFLOAT_VALUE(x);
dy = RFLOAT_VALUE(y);
if (dx < 0 && dy != round(dy))
return rb_dbl_complex_new_polar_pi(pow(-dx, dy), dy);
}
else {
return rb_num_coerce_bin(x, y, idPow);
}
return DBL2NUM(pow(dx, dy));
}
Raises self to the power of other:
Example
f = 3.14 f ** 2 # => 9.8596 f ** -2 # => 0.1014239928597509 f ** 2.1 # => 11.054834900588839 f ** Rational(2, 1) # => 9.8596 f ** Complex(2, 0) # => (9.8596+0i)