Skip to content

Commit 72ed7ee

Browse files
committed
Fixed Range.size to use proper floating point tolerance
1 parent a8b8abb commit 72ed7ee

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

include/mruby.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@
6464
#endif
6565

6666
#include "mrbconf.h"
67+
68+
#ifdef MRB_USE_FLOAT
69+
#define MRB_FLOAT_EPSILON FLT_EPSILON
70+
#else
71+
#define MRB_FLOAT_EPSILON DBL_EPSILON
72+
#endif
73+
6774
#include "mruby/common.h"
6875
#include <mruby/value.h>
6976
#include <mruby/gc.h>

mrbgems/mruby-range-ext/src/range.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ mrb_range_size(mrb_state *mrb, mrb_value range)
140140
}
141141
if (num_p) {
142142
mrb_float n = end_f - beg_f;
143-
mrb_float err = (fabs(beg_f) + fabs(end_f) + fabs(end_f-beg_f)) * DBL_EPSILON;
143+
mrb_float err = (fabs(beg_f) + fabs(end_f) + fabs(end_f-beg_f)) * MRB_FLOAT_EPSILON;
144144

145145
if (err>0.5) err=0.5;
146146
if (excl) {

0 commit comments

Comments
 (0)