diff --git a/core/types.rs b/core/types.rs index 6bddb0b2b..8e428aa55 100644 --- a/core/types.rs +++ b/core/types.rs @@ -706,8 +706,12 @@ impl PartialOrd for Value { fn partial_cmp(&self, other: &Self) -> Option { 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) } diff --git a/testing/compare.test b/testing/compare.test index 54633c93d..dd09ffb92 100644 --- a/testing/compare.test +++ b/testing/compare.test @@ -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 -} \ No newline at end of file +} + +# 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; +} {} \ No newline at end of file