add Math::TOLERANCE

This commit is contained in:
Yukihiro Matsumoto
2012-08-01 01:12:09 +09:00
parent cde3c35666
commit 34cf05679c
2 changed files with 18 additions and 13 deletions
+17 -11
View File
@@ -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));
+1 -2
View File
@@ -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