From 335d35cbc99484a55059db82e4a8170ced45ffe0 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 6 Apr 2024 18:47:10 +0800 Subject: [PATCH] some fix --- include/pocketpy/common.h | 2 -- include/pocketpy/linalg.h | 2 +- src/modules.cpp | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/pocketpy/common.h b/include/pocketpy/common.h index 2eefa336..29c80f3a 100644 --- a/include/pocketpy/common.h +++ b/include/pocketpy/common.h @@ -84,7 +84,6 @@ struct NumberTraits<4> { using int_t = int32_t; static constexpr int_t kMaxSmallInt = (1 << 28) - 1; static constexpr int_t kMinSmallInt = is_negative_shift_well_defined() ? -(1 << 28) : 0; - static constexpr float_t kEpsilon = (float_t)1e-4; }; template <> @@ -92,7 +91,6 @@ struct NumberTraits<8> { using int_t = int64_t; static constexpr int_t kMaxSmallInt = (1ll << 60) - 1; static constexpr int_t kMinSmallInt = is_negative_shift_well_defined() ? -(1ll << 60) : 0; - static constexpr float_t kEpsilon = (float_t)1e-8; }; using Number = NumberTraits; diff --git a/include/pocketpy/linalg.h b/include/pocketpy/linalg.h index ad93e556..6879466b 100644 --- a/include/pocketpy/linalg.h +++ b/include/pocketpy/linalg.h @@ -4,7 +4,7 @@ namespace pkpy{ -inline bool isclose(float a, float b){ return std::fabs(a - b) <= NumberTraits<4>::kEpsilon; } +inline bool isclose(float a, float b){ return std::fabs(a - b) < 1e-5; } struct Vec2{ PY_CLASS(Vec2, linalg, vec2) diff --git a/src/modules.cpp b/src/modules.cpp index a1bb445f..e7d1cb3f 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -166,7 +166,7 @@ void add_module_math(VM* vm){ vm->bind_func<2>(mod, "isclose", [](VM* vm, ArgsView args) { f64 a = CAST_F(args[0]); f64 b = CAST_F(args[1]); - return VAR(std::fabs(a - b) <= Number::kEpsilon); + return VAR(std::fabs(a - b) < 1e-9); }); vm->bind_func<1>(mod, "exp", PK_LAMBDA(VAR(std::exp(CAST_F(args[0])))));