summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-01-18 16:16:48 +0900
committerGitHub <[email protected]>2019-01-18 16:16:48 +0900
commit3d32be6f3edefa335b1c93cccfc21dde1f6e1e77 (patch)
tree85ded80c360df6ad1e86b51991e208a59c425058 /src
parent9a2366ded6a3c2ddfc203d9f53b1c377d626c207 (diff)
parent8969edf03b2f4ff8537974c2bd30e9abe2002da6 (diff)
downloadmruby-3d32be6f3edefa335b1c93cccfc21dde1f6e1e77.tar.gz
mruby-3d32be6f3edefa335b1c93cccfc21dde1f6e1e77.zip
Merge pull request #4231 from shuujii/avoid-runtime-eval-for-without-float
Avoid runtime evaluation for `MRB_WITHOUT_FLOAT`
Diffstat (limited to 'src')
-rw-r--r--src/numeric.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/numeric.c b/src/numeric.c
index fc8460300..fa9daf8a7 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -154,6 +154,22 @@ num_div(mrb_state *mrb, mrb_value x)
#endif
}
+static mrb_value
+num_coerce_step_counter(mrb_state *mrb, mrb_value self)
+{
+ mrb_value counter = self, num, step;
+
+ mrb_get_args(mrb, "oo", &num, &step);
+
+#ifndef MRB_WITHOUT_FLOAT
+ if (mrb_float_p(self) || mrb_float_p(num) || mrb_float_p(step)) {
+ counter = mrb_funcall(mrb, counter, "to_f", 0);
+ }
+#endif
+
+ return counter;
+}
+
#ifndef MRB_WITHOUT_FLOAT
/********************************************************************
*
@@ -1542,6 +1558,7 @@ mrb_init_numeric(mrb_state *mrb)
mrb_define_method(mrb, numeric, ">=", num_ge, MRB_ARGS_REQ(1));
mrb_define_method(mrb, numeric, "finite?", num_finite_p, MRB_ARGS_NONE());
mrb_define_method(mrb, numeric, "infinite?",num_infinite_p, MRB_ARGS_NONE());
+ mrb_define_method(mrb, numeric, "__coerce_step_counter", num_coerce_step_counter, MRB_ARGS_REQ(2));
/* Integer Class */
integer = mrb_define_class(mrb, "Integer", numeric); /* 15.2.8 */