From 63e2ec6715416088e04e17ef3594eb849c78e0d2 Mon Sep 17 00:00:00 2001 From: Shimenkov Mikhail Date: Thu, 8 May 2025 21:23:44 +0300 Subject: [PATCH] Revert floating point comparison with epsilon Signed-off-by: Shimenkov Mikhail Change-Id: Iaac4e9d9882f9c97d5ad7c9abc65748a27bea980 --- .../ets/constantExpressionLowering.cpp | 24 ------------------- .../lowering/ets/constantExpressionLowering.h | 2 -- 2 files changed, 26 deletions(-) diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 19cb3b3fd..131b83984 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -461,31 +461,7 @@ static bool PerformRelationOperation(InputType left, InputType right, lexer::Tok } case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: case lexer::TokenType::PUNCTUATOR_EQUAL: { - if constexpr (std::is_same_v) { - // Compare floating point numbers in two steps: - // 1. With fixed epsilon - // 2. with adaptive epsilon - // Minimal possible difference between two float values - // For float (IEEE-754 binary32) it is 2^(-23) and its bit representation is 0x34000000. - static auto epsilon = bit_cast(FLOAT_BIT_REPRESENTATION); - if (std::fabs(left - right) <= epsilon) { - return true; - } - return std::fabs(left - right) <= epsilon * std::fmax(std::fabs(left), std::fabs(right)); - } else if constexpr (std::is_same_v) { - // Compare floating point numbers in two steps: - // 1. With fixed epsilon - // 2. with adaptive epsilon - // Minimal possible difference between two double values - // For double (IEEE-754 binary64) it is 2^(-52) and its bit representation is 0x3cb0000000000000. - static auto epsilon = bit_cast(DOUBLE_BIT_REPRESENTATION); - if (std::fabs(left - right) <= epsilon) { - return true; - } - return std::fabs(left - right) <= epsilon * std::fmax(std::fabs(left), std::fabs(right)); - } else { return left == right; - } } case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: { diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.h b/ets2panda/compiler/lowering/ets/constantExpressionLowering.h index 4b4b67b7f..ae0645eeb 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.h +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.h @@ -20,8 +20,6 @@ namespace ark::es2panda::compiler { -constexpr static uint64_t FLOAT_BIT_REPRESENTATION = 0x34000000; -constexpr static uint64_t DOUBLE_BIT_REPRESENTATION = 0x3cb0000000000000; constexpr static char32_t MAX_CHAR = 0xFFFF; enum class TypeRank { -- Gitee