summaryrefslogtreecommitdiff
path: root/enumerator.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 01:52:39 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 01:52:39 +0000
commit3a083985a471ca3d8429146f9f18dead6747c203 (patch)
tree90f05d31fb7a12e953dab7ff32e8554605c504d3 /enumerator.c
parenta3b92a5d926cc9ec5d7f730e54eaa1aabe783a1f (diff)
avoid division by zero
* cvt(): use signbit() instead of 1/d < 0 * w_float(): ditto * ruby_float_step_size(): unit==0 check shall be prior to divisions * arith_seq_float_step_size(): ditto * rb_big_divide(): same as r65642 * fix_divide(): ditto * rb_big_fdiv_double(): ditto * fix_fdiv_double(): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65751 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/enumerator.c b/enumerator.c
index 466e064..274583a 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -2790,15 +2790,16 @@ static double
arith_seq_float_step_size(double beg, double end, double step, int excl)
{
double const epsilon = DBL_EPSILON;
- double n = (end - beg) / step;
- double err = (fabs(beg) + fabs(end) + fabs(end - beg)) / fabs(step) * epsilon;
+ double n, err;
- if (isinf(step)) {
- return step > 0 ? beg <= end : beg >= end;
- }
if (step == 0) {
return HUGE_VAL;
}
+ n = (end - beg) / step;
+ err = (fabs(beg) + fabs(end) + fabs(end - beg)) / fabs(step) * epsilon;
+ if (isinf(step)) {
+ return step > 0 ? beg <= end : beg >= end;
+ }
if (err > 0.5) err = 0.5;
if (excl) {
if (n <= 0) return 0;