[BugFix] Fix two minus signs when the result is INT256_MIN (backport #62512) (#62528)

Signed-off-by: stephen <stephen5217@163.com>
Co-authored-by: stephen <91597003+stephen-shelby@users.noreply.github.com>
This commit is contained in:
mergify[bot] 2025-09-02 10:02:19 +08:00 committed by GitHub
parent 23079e240e
commit a3553f320d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -165,6 +165,12 @@ public:
T abs_value = value;
if (value < 0) {
// Special handling for INT256_MIN to avoid double negative signs
if constexpr (std::is_same_v<ST, int256_t>) {
if (value == INT256_MIN) {
return "-57896044618658097711785492504343953926634992332820282019728792003956564819968";
}
}
abs_value = -value;
str_decimal[len++] = '-';
}

View File

@ -22,7 +22,7 @@ select cast(power_250 * 16 + 723700557733226221397318656304299424082937404160253
-- !result
select cast((-(power_250 * 16 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602495) - 1) as string) from powers_of_2;
-- result:
--57896044618658097711785492504343953926634992332820282019728792003956564819968
-57896044618658097711785492504343953926634992332820282019728792003956564819968
-- !result
select cast(power_250 * 16 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602495 + 1 as string) from powers_of_2;
-- result:
@ -58,7 +58,7 @@ select cast((-(power_250 * 16 + 723700557733226221397318656304299424082937404160
-- !result
select cast((-(power_250 * 16 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602495) - 1) * 1 as string) from powers_of_2;
-- result:
--57896044618658097711785492504343953926634992332820282019728792003956564819968
-57896044618658097711785492504343953926634992332820282019728792003956564819968
-- !result
select cast((-(power_250 * 16 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602496 + 7237005577332262213973186563042994240829374041602535252466099000494570602495) - 1) * -1 as string) from powers_of_2;
-- result:
@ -121,7 +121,6 @@ CREATE TABLE test_decimal_multiply_overflow (
d38_0 DECIMAL(38, 0) -- Maximum 38-digit decimal number
) PROPERTIES("replication_num"="1");
-- result:
--57896044618658097711785492504343953926634992332820282019728792003956564819968
-- !result
INSERT INTO test_decimal_multiply_overflow VALUES
(1, 'Small values',