зеркало из https://github.com/github/ruby.git
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:
Родитель
95ac235537
Коммит
42abad2464
|
@ -1309,7 +1309,11 @@ VALUE
|
|||
rb_float_pow(VALUE x, VALUE y)
|
||||
{
|
||||
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);
|
||||
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 ** 1.0)
|
||||
assert_raise(TypeError) { 1.0 ** nil }
|
||||
assert_equal(9.0, 3.0 ** 2)
|
||||
end
|
||||
|
||||
def test_eql
|
||||
|
|
Загрузка…
Ссылка в новой задаче