Skip to content

Float comparison does not follow IEEE 754 totalOrder for -0.0 vs +0.0 #1951

@yshcz

Description

@yshcz

Apache Iceberg Rust version

0.6.0 (latest version)

Describe the bug

This is a bit pedantic but iceberg-rust uses partial_cmp for float/double comparison in the iceberg_float_cmp function, which treats -0.0 and +0.0 as equal, violating the function's own comments about the expected ordering.

The existing test test_iceberg_float_order uses assert_eq!, which cannot detect ordering differences between -0.0 and +0.0 since underlying f64(or f32) treats them as equal.

Using f64's total_cmp instead would likely fix this.

To Reproduce

#[test]
fn test_negative_zero_less_than_positive_zero() {
    let neg_zero = Datum::float(-0.0);
    let pos_zero = Datum::float(0.0);

    assert_eq!(
        neg_zero.partial_cmp(&pos_zero),
        Some(Ordering::Less),
        "IEEE 754 totalOrder requires -0.0 < +0.0"
    );
}

Current: Some(Ordering::Equal)
Expected: Some(Ordering::Less)

Expected behavior

No response

Willingness to contribute

None

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions