mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #3277 from dabroz/feature-float-tolerance
Fixed float tolerance in tests when MRB_USE_FLOAT is set
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -94,6 +94,12 @@ mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose)
|
||||
mrb_define_const(mrb, mrbtest, "FIXNUM_MIN", mrb_fixnum_value(MRB_INT_MIN));
|
||||
mrb_define_const(mrb, mrbtest, "FIXNUM_BIT", mrb_fixnum_value(MRB_INT_BIT));
|
||||
|
||||
#ifdef MRB_USE_FLOAT
|
||||
mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-6));
|
||||
#else
|
||||
mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-12));
|
||||
#endif
|
||||
|
||||
if (verbose) {
|
||||
mrb_gv_set(mrb, mrb_intern_lit(mrb, "$mrbtest_verbose"), mrb_true_value());
|
||||
}
|
||||
|
||||
+1
-1
@@ -232,7 +232,7 @@ end
|
||||
##
|
||||
# Performs fuzzy check for equality on methods returning floats
|
||||
def check_float(a, b)
|
||||
tolerance = 1e-12
|
||||
tolerance = Mrbtest::FLOAT_TOLERANCE
|
||||
a = a.to_f
|
||||
b = b.to_f
|
||||
if a.finite? and b.finite?
|
||||
|
||||
Reference in New Issue
Block a user