aboutsummaryrefslogtreecommitdiffstats
path: root/numeric.c
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-02 22:39:22 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-02 22:39:22 +0000
commit4993cf9e24769ad69a6b0c7d26324f3af88b2ef3 (patch)
treec475db76ea3131b463fb7ae656755f22a4379c61 /numeric.c
parent3065dd71e83565a1c21881aa5cd684d7cca16f96 (diff)
downloadruby-4993cf9e24769ad69a6b0c7d26324f3af88b2ef3.tar.gz
Numeral#step should raise TypeError if a non-numeric parameter is given.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'numeric.c')
-rw-r--r--numeric.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/numeric.c b/numeric.c
index 04e2bcbd2e..57b61759c1 100644
--- a/numeric.c
+++ b/numeric.c
@@ -1858,9 +1858,23 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl)
rb_raise(rb_eArgError, "step can't be 0"); \
} \
} \
- if (NIL_P(step)) step = INT2FIX(1); \
+ if (NIL_P(step)) { \
+ step = INT2FIX(1); \
+ } \
+ else { \
+ if (!rb_obj_is_kind_of(step, rb_cNumeric)) { \
+ rb_raise(rb_eTypeError, "step must be numeric"); \
+ } \
+ } \
desc = negative_int_p(step); \
- if (NIL_P(to)) to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY); \
+ if (NIL_P(to)) { \
+ to = desc ? DBL2NUM(-INFINITY) : DBL2NUM(INFINITY); \
+ } \
+ else { \
+ if (!rb_obj_is_kind_of(to, rb_cNumeric)) { \
+ rb_raise(rb_eTypeError, "limit must be numeric"); \
+ } \
+ } \
if (TYPE(to) == T_FLOAT) { \
double f = RFLOAT_VALUE(to); \
inf = isinf(f) && (signbit(f) ? desc : !desc); \