use sqlite_int_float_compare

This commit is contained in:
Pavan-Nambi
2025-09-08 16:26:37 +05:30
parent b7c43cf293
commit d757a330ee
2 changed files with 25 additions and 3 deletions

View File

@@ -706,8 +706,12 @@ impl PartialOrd<Value> for Value {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
match (self, other) {
(Self::Integer(int_left), Self::Integer(int_right)) => int_left.partial_cmp(int_right),
(Self::Float(float), Self::Integer(int)) => Some(int_float_cmp(*int, *float).reverse()),
(Self::Integer(int), Self::Float(float)) => Some(int_float_cmp(*int, *float)),
(Self::Float(float), Self::Integer(int)) => {
Some(sqlite_int_float_compare(*int, *float).reverse())
}
(Self::Integer(int), Self::Float(float)) => {
Some(sqlite_int_float_compare(*int, *float))
}
(Self::Float(float_left), Self::Float(float_right)) => {
float_left.partial_cmp(float_right)
}

View File

@@ -253,4 +253,22 @@ foreach {testname lhs rhs ans} {
text-text-2 'a' 'a' 0
} {
do_execsql_test compare-is-not-$testname "SELECT $lhs is not $rhs" $::ans
}
}
# github-issue: 2957.
do_execsql_test compare-int-float-setup {
CREATE TABLE t1(i INTEGER);
INSERT INTO t1 VALUES (0), (-1), (1);
} {}
do_execsql_test compare-int-float-lte-negative-zero {
SELECT i FROM t1 WHERE i <= -0.0 ORDER BY i;
} {-1 0}
do_execsql_test compare-int-float-lt-negative-zero {
SELECT i FROM t1 WHERE i < -0.0 ORDER BY i;
} {-1}
do_execsql_test compare-int-float-cleanup {
DROP TABLE t1;
} {}