Maintainer fix-up: compare clearly different numbers directly, skipping the 15-digit text round trip on the sort/lookup hot path
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
0f21244e9e
commit
11ef0e6b04
|
|
@ -311,6 +311,11 @@ pub fn compare_numbers(a: f64, b: f64) -> Ordering {
|
|||
if a == b {
|
||||
return Ordering::Equal;
|
||||
}
|
||||
// Numbers further apart than the 15th digit can't round together, and rounding keeps their
|
||||
// order: skip the text round trip (this is on the sort and lookup hot path).
|
||||
if (a - b).abs() > a.abs().max(b.abs()) * 1e-13 {
|
||||
return a.partial_cmp(&b).unwrap_or(Ordering::Equal);
|
||||
}
|
||||
round15(a).partial_cmp(&round15(b)).unwrap_or(Ordering::Equal)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue