xsd_schema/types/equality.rs
1//! Value-space equality helpers shared across validators and XPath.
2//!
3//! These implement XSD §3.3.6.1 (Value Equality) for numeric types, where
4//! `NaN == NaN` and `+0 == -0`. The rule differs from Rust's `PartialEq` for
5//! `f32`/`f64` (where `NaN != NaN`), so comparisons that need XSD semantics
6//! must go through these functions.
7//!
8//! Duration equality is *not* here: XPath's `durations_equal` (cross-type
9//! zero-duration check, §14.4 fn:distinct-values) and the validators'
10//! `duration_eq` (signed total-months / day-time-seconds, §3.3.6.1) solve
11//! different problems despite similar names.
12
13/// Value-space equality for `xs:float` — NaN equals NaN, `+0 == -0`.
14pub fn float_eq(a: f32, b: f32) -> bool {
15 if a.is_nan() && b.is_nan() {
16 return true;
17 }
18 a == b
19}
20
21/// Value-space equality for `xs:double` — NaN equals NaN, `+0 == -0`.
22pub fn double_eq(a: f64, b: f64) -> bool {
23 if a.is_nan() && b.is_nan() {
24 return true;
25 }
26 a == b
27}