Open Centril opened 3 months ago
Note that {f32,f64}::total_cmp
, aka IEEE 754-2008 totalOrder:
decorum::FloatOrd
and FloatEq
are implemented relatively slowly with branches in an external dependency.0.xxx * 2^n
, where a normalized float is always in the format 1.xxx * 2^n
. Denormalized floats may occur naturally as a result of arithmetic on values very close to 0, but they are generally sketchy and unsupported anyways, which is reasonable because they can only appear at the limit of the float type's precision. Because of this misbehavior, totalOrder is technically a distinct ordering from {f32,f64}::partial_cmp
, but this is unlikely to matter in practice.(a.total_cmp(b) == Ordering::Equal) <=> (a.to_bits() == b.to_bits())
.
Currently,
AlgebraicValue::F32/F64
usesdecorum::Total<f32>
andTotal<f64>
as a way to getOrd
andPartialEq
implementations for floats. TheOrd
impl eventually usesdecorum::FloatOrd
anddecorum::FloatEq
. ForFloatEq
, this eventually results in callingto_canonical_bits
, which is implemented here. As explained in theFloatOrd
andFloatEq
docs, one of their properties is that they treat allNaN
s as equal. These semantics for floats are used forAlgebraicValue
,eq_bsatn
, and ineq_to_pv
.Meanwhile, the
spacetimedb_table::eq
implementation compares bytes directly, which is ostensibly compatible with the{f32, f64}::total_cmp
methods, which behave according to thetotalOrd
predicate defined by IEEE 754 FP standard, and unlike the behavior ofFloatOrd
.We thus have an inconsistency in our implementation and should pick one. For performance, it seems like
total_cmp
would be the winner, as it allows us to keep comparing bytes directly for VLOs.