Skip to content

Commit

Permalink
Fixed Range.size to use proper floating point tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
dabroz committed Nov 24, 2016
1 parent a8b8abb commit 72ed7ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/mruby.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
#endif

#include "mrbconf.h"

#ifdef MRB_USE_FLOAT
#define MRB_FLOAT_EPSILON FLT_EPSILON
#else
#define MRB_FLOAT_EPSILON DBL_EPSILON
#endif

#include "mruby/common.h"
#include <mruby/value.h>
#include <mruby/gc.h>
Expand Down
2 changes: 1 addition & 1 deletion mrbgems/mruby-range-ext/src/range.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ mrb_range_size(mrb_state *mrb, mrb_value range)
}
if (num_p) {
mrb_float n = end_f - beg_f;
mrb_float err = (fabs(beg_f) + fabs(end_f) + fabs(end_f-beg_f)) * DBL_EPSILON;
mrb_float err = (fabs(beg_f) + fabs(end_f) + fabs(end_f-beg_f)) * MRB_FLOAT_EPSILON;

if (err>0.5) err=0.5;
if (excl) {
Expand Down

0 comments on commit 72ed7ee

Please sign in to comment.