summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/math.c28
-rw-r--r--test/assert.rb3
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
-