numeric.c: optimize float ** 2
case by fastpath
It would be a relatively frequent case. It is still slower than `float * float` because `*` has a dedicated VM instruction (opt_mult), though.
This commit is contained in:
parent
95ac235537
commit
42abad2464
@ -1309,7 +1309,11 @@ VALUE
|
|||||||
rb_float_pow(VALUE x, VALUE y)
|
rb_float_pow(VALUE x, VALUE y)
|
||||||
{
|
{
|
||||||
double dx, dy;
|
double dx, dy;
|
||||||
if (RB_TYPE_P(y, T_FIXNUM)) {
|
if (y == INT2FIX(2)) {
|
||||||
|
dx = RFLOAT_VALUE(x);
|
||||||
|
return DBL2NUM(dx * dx);
|
||||||
|
}
|
||||||
|
else if (RB_TYPE_P(y, T_FIXNUM)) {
|
||||||
dx = RFLOAT_VALUE(x);
|
dx = RFLOAT_VALUE(x);
|
||||||
dy = (double)FIX2LONG(y);
|
dy = (double)FIX2LONG(y);
|
||||||
}
|
}
|
||||||
|
@ -305,6 +305,7 @@ class TestFloat < Test::Unit::TestCase
|
|||||||
assert_equal(1.0, 1.0 ** (2**32))
|
assert_equal(1.0, 1.0 ** (2**32))
|
||||||
assert_equal(1.0, 1.0 ** 1.0)
|
assert_equal(1.0, 1.0 ** 1.0)
|
||||||
assert_raise(TypeError) { 1.0 ** nil }
|
assert_raise(TypeError) { 1.0 ** nil }
|
||||||
|
assert_equal(9.0, 3.0 ** 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_eql
|
def test_eql
|
||||||
|
Loading…
x
Reference in New Issue
Block a user