summaryrefslogtreecommitdiff
path: root/numeric.c
diff options
context:
space:
mode:
authorYusuke Endoh <mame@ruby-lang.org>2020-05-12 02:12:06 +0900
committerYusuke Endoh <mame@ruby-lang.org>2020-05-12 02:14:27 +0900
commit42abad2464a78e3ec8a42f85c7bc878233f3ce16 (patch)
treec1aa0dbc813463918e39bf16395c815630ee4b75 /numeric.c
parent95ac235537fc0e46e4c18f1e82cf14d0a98b3b92 (diff)
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.
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/numeric.c b/numeric.c
index 03d8b86a1d..04fd3a24af 100644
--- a/numeric.c
+++ b/numeric.c
@@ -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);
}