From 420218dfb5ce6af1fabb848cf422b6d956ebc431 Mon Sep 17 00:00:00 2001 From: guoxu <13910754971@163.com> Date: Thu, 18 Dec 2025 16:04:28 +0800 Subject: [PATCH] [fix][libexpr] Fix issue about decimal eq and ne. --- src/types/decimal/decimal.h | 47 ++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/types/decimal/decimal.h b/src/types/decimal/decimal.h index 390755b..0fd05d9 100644 --- a/src/types/decimal/decimal.h +++ b/src/types/decimal/decimal.h @@ -219,7 +219,14 @@ class Decimal { * @return */ bool operator==(const Decimal &dec) const { - return v == dec.getMpf(); + const mpf_class& mpf1 = mpf_class(toString()); + const mpf_class& mpf2 = mpf_class(dec.toString()); + + int ret = cmp(mpf1, mpf2); + if(ret == 0) { + return true; + } + return false; } /** @@ -228,7 +235,7 @@ class Decimal { * @return */ bool operator!=(const Decimal &dec) const { - return v != dec.getMpf(); + return !(*this == dec); } /** @@ -237,7 +244,14 @@ class Decimal { * @return */ bool operator<(const Decimal &dec) const { - return v < dec.getMpf(); + const mpf_class& mpf1 = mpf_class(toString()); + const mpf_class& mpf2 = mpf_class(dec.toString()); + + int ret = cmp(mpf1, mpf2); + if(ret < 0) { + return true; + } + return false; } /** @@ -246,7 +260,14 @@ class Decimal { * @return */ bool operator<=(const Decimal &dec) const { - return v <= dec.getMpf(); + const mpf_class& mpf1 = mpf_class(toString()); + const mpf_class& mpf2 = mpf_class(dec.toString()); + + int ret = cmp(mpf1, mpf2); + if(ret <= 0) { + return true; + } + return false; } /** @@ -255,7 +276,14 @@ class Decimal { * @return */ bool operator>(const Decimal &dec) const { - return v > dec.getMpf();; + const mpf_class& mpf1 = mpf_class(toString()); + const mpf_class& mpf2 = mpf_class(dec.toString()); + + int ret = cmp(mpf1, mpf2); + if(ret > 0) { + return true; + } + return false; } /** @@ -264,7 +292,14 @@ class Decimal { * @return */ bool operator>=(const Decimal &dec) const { - return v >= dec.getMpf(); + const mpf_class& mpf1 = mpf_class(toString()); + const mpf_class& mpf2 = mpf_class(dec.toString()); + + int ret = cmp(mpf1, mpf2); + if(ret >= 0) { + return true; + } + return false; } /**