From 34cf05679c5ce9ee40be6bd4ccace0ec94fcebdf Mon Sep 17 00:00:00 2001 From: Yukihiro Matsumoto Date: Wed, 1 Aug 2012 01:12:09 +0900 Subject: add Math::TOLERANCE --- src/math.c | 28 +++++++++++++++++----------- test/assert.rb | 3 +-- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/math.c b/src/math.c index 519d4f37b..fe10848c3 100644 --- a/src/math.c +++ b/src/math.c @@ -634,18 +634,24 @@ mrb_init_math(mrb_state *mrb) struct RClass *mrb_math; mrb_math = mrb_define_module(mrb, "Math"); - #ifdef M_PI - mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); - #else - mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(atan(1.0)*4.0)); - #endif - - #ifdef M_E - mrb_define_const(mrb, mrb_math, "E", mrb_float_value(M_E)); - #else - mrb_define_const(mrb, mrb_math, "E", mrb_float_value(exp(1.0))); - #endif +#ifdef M_PI + mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(M_PI)); +#else + mrb_define_const(mrb, mrb_math, "PI", mrb_float_value(atan(1.0)*4.0)); +#endif +#ifdef M_E + mrb_define_const(mrb, mrb_math, "E", mrb_float_value(M_E)); +#else + mrb_define_const(mrb, mrb_math, "E", mrb_float_value(exp(1.0))); +#endif + +#ifdef MRB_USE_FLOAT + mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-6)); +#else + mrb_define_const(mrb, mrb_math, "TOLERANCE", mrb_float_value(1e-12)); +#endif + mrb_define_module_function(mrb, mrb_math, "sin", math_sin, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "cos", math_cos, ARGS_REQ(1)); mrb_define_module_function(mrb, mrb_math, "tan", math_tan, ARGS_REQ(1)); diff --git a/test/assert.rb b/test/assert.rb index 9329638c9..89e820a00 100644 --- a/test/assert.rb +++ b/test/assert.rb @@ -81,7 +81,7 @@ end # Performs fuzzy check for equality on methods returning floats # on the basis of the Math::TOLERANCE constant. def check_float(a, b) - tolerance = 1e-12 + tolerance = Math::TOLERANCE a = a.to_f b = b.to_f if a.finite? and b.finite? @@ -90,4 +90,3 @@ def check_float(a, b) true end end - -- cgit v1.2.3