Skip to content

Commit 432523f

Browse files
authored
fix: hash NaN the way Spark does in hash, xxhash64 and native shuffle (apache#6413)
* refactor: move native -0.0 and NaN handling into one float_semantics module Part of apache#6385. Each native expression that follows one of Spark's float rules carried its own copy of that rule. This moves them onto a new `float_semantics` module in `spark-expr`, with no change in behavior. - `normalize_float`, `canonicalize_nan`, `compare_floats` and `hash_input` are the per-value rules: `NormalizeNaNAndZero`, `Double.equals`, `compareDoubles`, and the `Murmur3Hash`/`XxHash64` input. - `normalize_floats`, `normalize_nested_floats` and `has_float_leaf` normalize arrays. `NormalizeNaNAndZero` and `NormalizeNestedFloats` move into the module, and `NormalizeNaNAndZero::wrap_if_needed` takes over the planner's check in `create_normalized_key_expr`. - `spark_comparator` replaces both `nested_equality` (nested `=` and `IN`) and the comparator local to `array_min`/`array_max`. hll_plus_plus, max_min_by, mode, percentile, array_extrema, array_position, arrays_overlap, nested_comparison, the float hash macros, and the planner's sort keys and range partition bounds now call the module. * Restore hot-loop speed and narrow the float_semantics API - compare_floats uses the if-chain form again, so `.is_eq()` in array_position and percentile compiles to a single comparison. - float_extrema calls new float_lt/float_gt predicates, which compile to the same instructions as the inline tests they replace. The three-way comparison was up to 9x slower in that loop. - spark_equality gives nested `=` and `IN` back the length check that skips comparing the elements of lists of different lengths. - float_semantics is a private module again, re-exporting normalize_floats, canonicalize_nan and the two expressions. - The Parquet variant cast canonicalizes NaN with canonicalize_nan, and gains a test. - Tests share the NaN constants and check the per-value rules in one table, and the max_by doc defers to the module docs. * Return an error, not a panic, for mismatched physical types in the comparator `check_types` compares logical types, so a `Dictionary(_, Float64)` passes as `Float64` and then panicked when `float_comparator` downcast it. The comparator now matches on both sides' types and returns the internal error. `mismatched_types_are_rejected` covers a dictionary on either side, at the top level and inside a list. * fix: hash NaN the way Spark does in hash, xxhash64 and native shuffle Part of apache#6385. Spark hashes a float through doubleToLongBits or floatToIntBits, which canonicalize NaN, so every NaN hashes alike. Comet hashed the raw bits, so `hash(-d)` and `xxhash64(-d)` differed from Spark for a NaN, and on x86-64 so did the hash of every NaN that arithmetic produces. `hash_input` now returns `normalize_float`, which covers `hash`, `xxhash64`, list, struct and dictionary elements, the native shuffle's hash partitioner and `approx_count_distinct`. At the default seed, `xxhash64` handed float arguments to datafusion-spark's `SparkXxhash64`, which also hashes the raw bits, so floats now stay on Comet's kernel. `approx_count_distinct` no longer normalizes floats before hashing, since `xxhash64` now does. * test: cover infinities in hash NaN tests and link the upstream xxhash64 issue Add Infinity and -Infinity rows to the hash fixture, so hash(-d) and hash(-f) show that both infinities keep their own hashes through NaN canonicalization. Link apache/datafusion#25913, the upstream report of SparkXxhash64 hashing a NaN's raw bits, at the gate that keeps floats on Comet's kernel, and list floats among the retained cases in the xxhash64 audit entry. * test: cover maps and nested floats in the hash NaN tests * test: drop the sweep suite's known gap for hash and xxhash64 hash, xxhash64 and the native shuffle's hash partitioner now hash NaN the way Spark does, so the suite requires those cases to match.
1 parent 1d313f5 commit 432523f

9 files changed

Lines changed: 281 additions & 57 deletions

File tree

‎docs/source/contributor-guide/expression-audits/hash_funcs.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@
7070
- Spark 3.5.8 (audited 2026-05-27): baseline. `XxHash64(children, seed) extends HashExpression[Long]`; produces an xxHash64 hash with a configurable Long seed and `LongType` result. Comet routes via `CometXxHash64` to the native `xxhash64` UDF.
7171
- Spark 4.0.1 (audited 2026-05-27): semantics unchanged.
7272
- Spark 4.1.1 (audited 2026-05-27): identical to 4.0.1.
73-
- Upstream (2026-09-15): Comet's native `xxhash64` UDF delegates compatible arguments at Spark's default seed (`42`) to `datafusion-spark::SparkXxhash64`. Differential tests in `native/spark-expr/src/hash_funcs/xxhash64_diff.rs` compare Comet's kernel against `SparkXxhash64` for primitives, both Decimal128 widths, dictionaries, lists, maps, and nested combinations. The Comet kernel is retained for a non-default seed (`SparkXxhash64` hardcodes 42), `Struct` (upstream does not push a parent null mask into children; see #5753), a `Dictionary` nested in a list/map (upstream restarts those hashes from 42), and `Time64`. `murmur3` is unchanged; `create_xxhash64_hashes` remains for `approx_count_distinct` and the fallback path.
73+
- Upstream (2026-09-15): Comet's native `xxhash64` UDF delegates compatible arguments at Spark's default seed (`42`) to `datafusion-spark::SparkXxhash64`. Differential tests in `native/spark-expr/src/hash_funcs/xxhash64_diff.rs` compare Comet's kernel against `SparkXxhash64` for primitives, both Decimal128 widths, dictionaries, lists, maps, and nested combinations, and record where the two differ on a NaN whose bits are not canonical. The Comet kernel is retained for a non-default seed (`SparkXxhash64` hardcodes 42), `Struct` (upstream does not push a parent null mask into children; see #5753), a `Dictionary` nested in a list/map (upstream restarts those hashes from 42), `Time64`, and `Float32`/`Float64`, including values nested in lists and maps (upstream hashes the raw bits of a NaN, where Spark hashes every NaN as the canonical NaN; see [apache/datafusion#25913](https://github.com/apache/datafusion/issues/25913)). `murmur3` is unchanged; `create_xxhash64_hashes` remains for `approx_count_distinct` and the fallback path.
7474

7575
[Spark Expression Support]: ../../user-guide/latest/expressions.md

‎native/spark-expr/src/agg_funcs/hll_plus_plus.rs‎

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
//! Spark-compatible `approx_count_distinct`, a faithful port of Spark's
1919
//! `HyperLogLogPlusPlus` / `HyperLogLogPlusPlusHelper`. Values are hashed with Spark's
20-
//! `XxHash64` (seed 42, floats normalized first) and the registers are stored using the exact
21-
//! same packed-`Long` buffer layout Spark uses (10 six-bit registers per 64-bit word). Keeping
22-
//! the wire format identical means the partial-aggregation state matches Spark's
23-
//! `aggBufferSchema`, and the cardinality estimate uses the same bias-correction tables, so
24-
//! results are bit-identical to Spark.
20+
//! `XxHash64` (seed 42) and the registers are stored using the exact same packed-`Long` buffer
21+
//! layout Spark uses (10 six-bit registers per 64-bit word). Keeping the wire format identical
22+
//! means the partial-aggregation state matches Spark's `aggBufferSchema`, and the cardinality
23+
//! estimate uses the same bias-correction tables, so results are bit-identical to Spark.
2524
2625
use crate::agg_funcs::hll_plus_plus_const::{BIAS_DATA, RAW_ESTIMATE_DATA, THRESHOLDS};
27-
use crate::float_semantics::normalize_floats;
2826
use crate::hash_funcs::create_xxhash64_hashes;
2927
use arrow::array::{Array, ArrayRef, AsArray, BooleanArray, Int64Array};
3028
use arrow::datatypes::{DataType, Field, FieldRef};
@@ -118,14 +116,17 @@ impl AggregateUDFImpl for HllPlusPlus {
118116
}
119117
}
120118

121-
/// Hash a value column with Spark's `XxHash64` (seed 42), normalizing floats first, reusing
122-
/// `buf` as scratch to avoid a per-batch allocation. The buffer is re-seeded (not just cleared)
123-
/// because `create_xxhash64_hashes` folds each value into the existing seed.
119+
/// Hash a value column with Spark's `XxHash64` (seed 42), reusing `buf` as scratch to avoid a
120+
/// per-batch allocation. The buffer is re-seeded (not just cleared) because
121+
/// `create_xxhash64_hashes` folds each value into the existing seed.
122+
///
123+
/// Spark runs float inputs through `NormalizeFloatingNumbers` before hashing, but
124+
/// `create_xxhash64_hashes` already hashes `-0.0` as `0.0` and every NaN as the canonical NaN, so
125+
/// the result is the same without a separate pass.
124126
fn hash_values_into(array: &ArrayRef, buf: &mut Vec<u64>) -> Result<()> {
125-
let normalized = normalize_floats(array);
126127
buf.clear();
127-
buf.resize(normalized.len(), HASH_SEED);
128-
create_xxhash64_hashes(&[normalized], buf)?;
128+
buf.resize(array.len(), HASH_SEED);
129+
create_xxhash64_hashes(&[Arc::clone(array)], buf)?;
129130
Ok(())
130131
}
131132

@@ -463,7 +464,7 @@ impl GroupsAccumulator for HllPlusPlusGroupsAccumulator {
463464
#[cfg(test)]
464465
mod tests {
465466
use super::*;
466-
use arrow::array::{Int32Array, StringArray};
467+
use arrow::array::{Float32Array, Float64Array, Int32Array, StringArray};
467468

468469
fn acc(p: usize) -> HllPlusPlusAccumulator {
469470
HllPlusPlusAccumulator::new(p)
@@ -503,6 +504,66 @@ mod tests {
503504
assert_eq!(eval(&mut a), 2);
504505
}
505506

507+
/// Spark counts the two zeros as one value and every NaN as one value.
508+
#[test]
509+
fn floats_fold_negative_zero_and_nan() {
510+
let values: ArrayRef = Arc::new(Float64Array::from(vec![
511+
0.0,
512+
-0.0,
513+
f64::NAN,
514+
f64::from_bits(0xfff8_0000_0000_0000),
515+
f64::from_bits(0x7ff0_0000_0000_0001),
516+
]));
517+
let mut a = acc(9);
518+
a.update_batch(&[values]).unwrap();
519+
assert_eq!(eval(&mut a), 2);
520+
let values: ArrayRef = Arc::new(Float32Array::from(vec![
521+
0.0,
522+
-0.0,
523+
f32::NAN,
524+
f32::from_bits(0xffc0_0000),
525+
]));
526+
let mut a = acc(9);
527+
a.update_batch(&[values]).unwrap();
528+
assert_eq!(eval(&mut a), 2);
529+
}
530+
531+
/// The hash kernel canonicalizes floats inside nested types, so a struct or list holding a
532+
/// negative zero or a non-canonical NaN counts the same as one holding the plain value.
533+
#[test]
534+
fn nested_floats_fold_negative_zero_and_nan() {
535+
use arrow::array::{ListArray, StructArray};
536+
use arrow::buffer::OffsetBuffer;
537+
use arrow::datatypes::Field;
538+
539+
let floats: ArrayRef = Arc::new(Float64Array::from(vec![
540+
0.0,
541+
-0.0,
542+
f64::NAN,
543+
f64::from_bits(0xfff8_0000_0000_0000),
544+
f64::from_bits(0x7ff0_0000_0000_0001),
545+
]));
546+
let field = Arc::new(Field::new("item", DataType::Float64, true));
547+
let nested: Vec<ArrayRef> = vec![
548+
Arc::new(StructArray::new(
549+
vec![Arc::clone(&field)].into(),
550+
vec![Arc::clone(&floats)],
551+
None,
552+
)),
553+
Arc::new(ListArray::new(
554+
field,
555+
OffsetBuffer::from_lengths([1; 5]),
556+
floats,
557+
None,
558+
)),
559+
];
560+
for values in nested {
561+
let mut a = acc(9);
562+
a.update_batch(&[Arc::clone(&values)]).unwrap();
563+
assert_eq!(eval(&mut a), 2, "{}", values.data_type());
564+
}
565+
}
566+
506567
#[test]
507568
fn strings_small_cardinality() {
508569
let mut a = acc(9);

‎native/spark-expr/src/float_semantics/mod.rs‎

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,12 @@ pub fn float_gt<T: Float>(left: T, right: T) -> bool {
120120
left > right || (left.is_nan() && !right.is_nan())
121121
}
122122

123-
/// The value that Spark's `Murmur3Hash` and `XxHash64` hash in place of a float. `-0.0` hashes as
124-
/// `0.0`, so the two zeros hash alike.
125-
///
126-
/// Spark reads the other bits through `doubleToLongBits`, which also canonicalizes NaN. This does
127-
/// not yet, so a NaN whose bits are not canonical hashes differently from Spark (#6385).
123+
/// The value that Spark's `Murmur3Hash` and `XxHash64` hash in place of a float. Spark hashes
124+
/// `-0.0` as `0.0` and reads the other bits through `doubleToLongBits` or `floatToIntBits`, which
125+
/// canonicalize NaN, so this is the same value [`normalize_float`] returns.
128126
#[inline]
129127
pub fn hash_input<T: Float>(v: T) -> T {
130-
if v == T::zero() {
131-
// `-0.0 == 0.0` in IEEE 754, so this catches negative zero as well.
132-
T::zero()
133-
} else {
134-
v
135-
}
128+
normalize_float(v)
136129
}
137130

138131
/// A NaN with the sign bit set, which arithmetic produces on x86-64.
@@ -150,35 +143,26 @@ mod tests {
150143

151144
#[test]
152145
fn per_value_rules() {
153-
// Each row: the input, then what `normalize_float`, `canonicalize_nan` and `hash_input`
154-
// return for it.
146+
// Each row: the input, then what `normalize_float` and `canonicalize_nan` return for it.
147+
// Spark hashes the value `normalize_float` returns.
155148
let rows = [
156-
(-0.0, 0.0, -0.0, 0.0),
157-
(0.0, 0.0, 0.0, 0.0),
158-
(-1.5, -1.5, -1.5, -1.5),
159-
(
160-
f64::NEG_INFINITY,
161-
f64::NEG_INFINITY,
162-
f64::NEG_INFINITY,
163-
f64::NEG_INFINITY,
164-
),
165-
// `hash_input` does not canonicalize NaN yet (#6385).
166-
(NEGATIVE_NAN, f64::NAN, f64::NAN, NEGATIVE_NAN),
167-
(PAYLOAD_NAN, f64::NAN, f64::NAN, PAYLOAD_NAN),
149+
(-0.0, 0.0, -0.0),
150+
(0.0, 0.0, 0.0),
151+
(-1.5, -1.5, -1.5),
152+
(f64::NEG_INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY),
153+
(NEGATIVE_NAN, f64::NAN, f64::NAN),
154+
(PAYLOAD_NAN, f64::NAN, f64::NAN),
168155
];
169-
for (value, normalized, canonical, hashed) in rows {
156+
for (value, normalized, canonical) in rows {
170157
assert_eq!(normalize_float(value).to_bits(), normalized.to_bits());
171158
assert_eq!(canonicalize_nan(value).to_bits(), canonical.to_bits());
172-
assert_eq!(hash_input(value).to_bits(), hashed.to_bits());
159+
assert_eq!(hash_input(value).to_bits(), normalized.to_bits());
173160
}
174-
let rows = [
175-
(-0.0, 0.0, -0.0, 0.0),
176-
(NEGATIVE_NAN_F32, f32::NAN, f32::NAN, NEGATIVE_NAN_F32),
177-
];
178-
for (value, normalized, canonical, hashed) in rows {
161+
let rows = [(-0.0, 0.0, -0.0), (NEGATIVE_NAN_F32, f32::NAN, f32::NAN)];
162+
for (value, normalized, canonical) in rows {
179163
assert_eq!(normalize_float(value).to_bits(), normalized.to_bits());
180164
assert_eq!(canonicalize_nan(value).to_bits(), canonical.to_bits());
181-
assert_eq!(hash_input(value).to_bits(), hashed.to_bits());
165+
assert_eq!(hash_input(value).to_bits(), normalized.to_bits());
182166
}
183167
}
184168

‎native/spark-expr/src/hash_funcs/murmur3.rs‎

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,14 @@ mod tests {
784784
Some(-1.0),
785785
Some(99999999999.99999999999),
786786
Some(-99999999999.99999999999),
787+
// Every NaN hashes as the canonical NaN, whatever its sign or payload.
788+
Some(f32::NAN),
789+
Some(f32::from_bits(0xffc0_0000)),
790+
Some(f32::from_bits(0x7f80_0001)),
787791
],
788792
vec![
789-
0xe434cc39, 0x379fae8f, 0x379fae8f, 0xdc0da8eb, 0xcbdc340f, 0xc0361c86,
793+
0xe434cc39, 0x379fae8f, 0x379fae8f, 0xdc0da8eb, 0xcbdc340f, 0xc0361c86, 0xeb2eb18a,
794+
0xeb2eb18a, 0xeb2eb18a,
790795
],
791796
);
792797
}
@@ -801,13 +806,107 @@ mod tests {
801806
Some(-1.0),
802807
Some(99999999999.99999999999),
803808
Some(-99999999999.99999999999),
809+
// Every NaN hashes as the canonical NaN, whatever its sign or payload.
810+
Some(f64::NAN),
811+
Some(f64::from_bits(0xfff8_0000_0000_0000)),
812+
Some(f64::from_bits(0x7ff0_0000_0000_0001)),
804813
],
805814
vec![
806-
0xe4876492, 0x9c67b85d, 0x9c67b85d, 0x13d81357, 0xb87e1595, 0xa0eef9f9,
815+
0xe4876492, 0x9c67b85d, 0x9c67b85d, 0x13d81357, 0xb87e1595, 0xa0eef9f9, 0xb3a005cf,
816+
0xb3a005cf, 0xb3a005cf,
807817
],
808818
);
809819
}
810820

821+
/// Spark hashes a float through `doubleToLongBits` or `floatToIntBits`, which canonicalize
822+
/// NaN, so a NaN with the sign bit set or with a payload hashes like the canonical NaN inside
823+
/// lists, structs, maps and dictionaries too. Checks both hashes, which expand the same macros.
824+
#[test]
825+
fn test_non_canonical_nan_hashes_like_canonical_nan() {
826+
use crate::hash_funcs::create_xxhash64_hashes;
827+
use arrow::array::{
828+
DictionaryArray, FixedSizeListArray, Int32Array, LargeListArray, ListArray, MapArray,
829+
StructArray,
830+
};
831+
use arrow::buffer::OffsetBuffer;
832+
use arrow::datatypes::{DataType, Field, Fields};
833+
834+
let shapes = |values: ArrayRef| -> Vec<ArrayRef> {
835+
let field = Arc::new(Field::new("item", values.data_type().clone(), true));
836+
// One entry per row, with the float as both the key and the value.
837+
let entry_fields = Fields::from(vec![
838+
Field::new("key", values.data_type().clone(), false),
839+
Field::new("value", values.data_type().clone(), true),
840+
]);
841+
let entries = StructArray::new(
842+
entry_fields.clone(),
843+
vec![Arc::clone(&values), Arc::clone(&values)],
844+
None,
845+
);
846+
vec![
847+
Arc::clone(&values),
848+
Arc::new(ListArray::new(
849+
Arc::clone(&field),
850+
OffsetBuffer::from_lengths([1; 3]),
851+
Arc::clone(&values),
852+
None,
853+
)),
854+
Arc::new(LargeListArray::new(
855+
Arc::clone(&field),
856+
OffsetBuffer::from_lengths([1; 3]),
857+
Arc::clone(&values),
858+
None,
859+
)),
860+
Arc::new(FixedSizeListArray::new(
861+
Arc::clone(&field),
862+
1,
863+
Arc::clone(&values),
864+
None,
865+
)),
866+
Arc::new(StructArray::new(
867+
vec![field].into(),
868+
vec![Arc::clone(&values)],
869+
None,
870+
)),
871+
Arc::new(DictionaryArray::new(
872+
Int32Array::from(vec![0, 1, 2]),
873+
values,
874+
)),
875+
Arc::new(MapArray::new(
876+
Arc::new(Field::new("entries", DataType::Struct(entry_fields), false)),
877+
OffsetBuffer::from_lengths([1; 3]),
878+
entries,
879+
None,
880+
false,
881+
)),
882+
]
883+
};
884+
let canonical64: ArrayRef = Arc::new(Float64Array::from(vec![f64::NAN; 3]));
885+
let other64: ArrayRef = Arc::new(Float64Array::from(vec![
886+
f64::from_bits(0xfff8_0000_0000_0000),
887+
f64::from_bits(0x7ff0_0000_0000_0001),
888+
f64::from_bits(0xfff0_0000_0000_0001),
889+
]));
890+
let canonical32: ArrayRef = Arc::new(Float32Array::from(vec![f32::NAN; 3]));
891+
let other32: ArrayRef = Arc::new(Float32Array::from(vec![
892+
f32::from_bits(0xffc0_0000),
893+
f32::from_bits(0x7f80_0001),
894+
f32::from_bits(0xff80_0001),
895+
]));
896+
for (canonical, other) in [(canonical64, other64), (canonical32, other32)] {
897+
for (canonical, other) in shapes(canonical).into_iter().zip(shapes(other)) {
898+
let (mut expected, mut actual) = (vec![42u32; 3], vec![42u32; 3]);
899+
create_murmur3_hashes(&[Arc::clone(&canonical)], &mut expected).unwrap();
900+
create_murmur3_hashes(&[Arc::clone(&other)], &mut actual).unwrap();
901+
assert_eq!(actual, expected, "murmur3 of {}", other.data_type());
902+
let (mut expected, mut actual) = (vec![42u64; 3], vec![42u64; 3]);
903+
create_xxhash64_hashes(&[canonical], &mut expected).unwrap();
904+
create_xxhash64_hashes(&[Arc::clone(&other)], &mut actual).unwrap();
905+
assert_eq!(actual, expected, "xxhash64 of {}", other.data_type());
906+
}
907+
}
908+
}
909+
811910
#[test]
812911
fn test_str() {
813912
let input = [

‎native/spark-expr/src/hash_funcs/xxhash64.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ const SPARK_DEFAULT_SEED: i64 = 42;
4848
/// mask into children, so hidden values of a NULL struct would affect the hash
4949
/// - a `Dictionary` nested in a list/map: `SparkXxhash64` restarts those hashes from 42
5050
/// - `Time64`, which `SparkXxhash64` does not dispatch
51+
/// - `Float32`/`Float64` (and anything containing one): `SparkXxhash64` hashes the raw bits of a
52+
/// NaN, where Spark hashes every NaN as the canonical NaN
53+
/// (<https://github.com/apache/datafusion/issues/25913>)
5154
pub fn spark_xxhash64(args: &[ColumnarValue]) -> Result<ColumnarValue, DataFusionError> {
5255
let length = args.len();
5356
let seed = &args[length - 1];
@@ -126,7 +129,7 @@ fn invoke_spark_xxhash64(
126129
fn type_compatible_with_spark_xxhash64(dt: &DataType, in_list_or_map: bool) -> bool {
127130
use DataType::*;
128131
match dt {
129-
Boolean | Int8 | Int16 | Int32 | Int64 | Float32 | Float64 => true,
132+
Boolean | Int8 | Int16 | Int32 | Int64 => true,
130133
Utf8 | LargeUtf8 | Binary | LargeBinary | FixedSizeBinary(_) => true,
131134
Date32 | Date64 | Timestamp(_, _) => true,
132135
Decimal128(_, _) => true,
@@ -143,7 +146,8 @@ fn type_compatible_with_spark_xxhash64(dt: &DataType, in_list_or_map: bool) -> b
143146
_ => false,
144147
},
145148
// Struct: `SparkXxhash64` hashes child buffers without applying the parent null
146-
// mask. Time64 is a Comet-only dispatch arm.
149+
// mask. Time64 is a Comet-only dispatch arm. Float32/Float64: `SparkXxhash64` does not
150+
// canonicalize NaN.
147151
_ => false,
148152
}
149153
}
@@ -403,6 +407,10 @@ mod tests {
403407
Some(-1.0),
404408
Some(99999999999.99999999999),
405409
Some(-99999999999.99999999999),
410+
// Every NaN hashes as the canonical NaN, whatever its sign or payload.
411+
Some(f32::NAN),
412+
Some(f32::from_bits(0xffc0_0000)),
413+
Some(f32::from_bits(0x7f80_0001)),
406414
],
407415
vec![
408416
0x9b92689757fcdbd,
@@ -411,6 +419,9 @@ mod tests {
411419
0xa2becc0e61bb3823,
412420
0x8f20ab82d4f3687f,
413421
0xdce4982d97f7ac4,
422+
0x255d1be3831088f8,
423+
0x255d1be3831088f8,
424+
0x255d1be3831088f8,
414425
],
415426
)
416427
}
@@ -425,6 +436,10 @@ mod tests {
425436
Some(-1.0),
426437
Some(99999999999.99999999999),
427438
Some(-99999999999.99999999999),
439+
// Every NaN hashes as the canonical NaN, whatever its sign or payload.
440+
Some(f64::NAN),
441+
Some(f64::from_bits(0xfff8_0000_0000_0000)),
442+
Some(f64::from_bits(0x7ff0_0000_0000_0001)),
428443
],
429444
vec![
430445
0xe1fd6e07fee8ad53,
@@ -433,6 +448,9 @@ mod tests {
433448
0x8cdde022746f8f1f,
434449
0x793c5c88d313eac7,
435450
0xc5e60e7b75d9b232,
451+
0xd4974f72d7833f32,
452+
0xd4974f72d7833f32,
453+
0xd4974f72d7833f32,
436454
],
437455
)
438456
}

0 commit comments

Comments
 (0)