summaryrefslogtreecommitdiffstats
path: root/vendor/ordered-float
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:56 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:25:56 +0000
commit018c4950b9406055dec02ef0fb52f132e2bb1e2c (patch)
treea835ebdf2088ef88fa681f8fad45f09922c1ae9a /vendor/ordered-float
parentAdding debian version 1.75.0+dfsg1-5. (diff)
downloadrustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.tar.xz
rustc-018c4950b9406055dec02ef0fb52f132e2bb1e2c.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ordered-float')
-rw-r--r--vendor/ordered-float/.cargo-checksum.json2
-rw-r--r--vendor/ordered-float/Cargo.toml28
-rw-r--r--vendor/ordered-float/src/lib.rs84
-rw-r--r--vendor/ordered-float/tests/test.rs26
4 files changed, 99 insertions, 41 deletions
diff --git a/vendor/ordered-float/.cargo-checksum.json b/vendor/ordered-float/.cargo-checksum.json
index 74ee34f4e..cfae2a2ad 100644
--- a/vendor/ordered-float/.cargo-checksum.json
+++ b/vendor/ordered-float/.cargo-checksum.json
@@ -1 +1 @@
-{"files":{"Cargo.toml":"728dacd01b7edba6809fe90552a02eca004b5f024f4931de5174a16b7b52f3db","LICENSE-MIT":"f7715d38a3fa1b4ac97c5729740752505a39cb92ee83ab5b102aeb5eaa7cdea4","README.md":"f38ad2ec742e6c867cf9fca31026a4baf174f03b3b2f89c74dfcead90c28ea35","rustfmt.toml":"d72fafaea8c9695f74c40bc666ada205b935bec3f02488bb33e5994e2831bffb","src/lib.rs":"643a0c9eca2907cba66de750e059d40eec4b9bf29f895644ed1fb7037aeb7704","tests/test.rs":"50e382c96b04271db502138b816a89fd9a0c13501b7a41190e6455323012360b"},"package":"7940cf2ca942593318d07fcf2596cdca60a85c9e7fab408a5e21a4f9dcd40d87"} \ No newline at end of file
+{"files":{"Cargo.toml":"7ce7bb08b51de5ad0b0b94d830d7573fe78f5e7fb72425cdec86a3543ce658e2","LICENSE-MIT":"f7715d38a3fa1b4ac97c5729740752505a39cb92ee83ab5b102aeb5eaa7cdea4","README.md":"f38ad2ec742e6c867cf9fca31026a4baf174f03b3b2f89c74dfcead90c28ea35","rustfmt.toml":"d72fafaea8c9695f74c40bc666ada205b935bec3f02488bb33e5994e2831bffb","src/lib.rs":"7ef19f59e6870da4a3ddb958f2eb976278704f21f68cf6a59507574dbc5e7715","tests/test.rs":"39049fc96151f42aa3c5f8cfff5d40ff62efae234096825a186ecc0abe5bb1ee"},"package":"68f19d67e5a2795c94e73e0bb1cc1a7edeb2e28efd39e2e1c9b7a40c1108b11c"} \ No newline at end of file
diff --git a/vendor/ordered-float/Cargo.toml b/vendor/ordered-float/Cargo.toml
index 08eae8358..853327de7 100644
--- a/vendor/ordered-float/Cargo.toml
+++ b/vendor/ordered-float/Cargo.toml
@@ -12,14 +12,28 @@
[package]
edition = "2018"
name = "ordered-float"
-version = "2.10.0"
-authors = ["Jonathan Reem <jonathan.reem@gmail.com>", "Matt Brubeck <mbrubeck@limpet.net>"]
+version = "2.10.1"
+authors = [
+ "Jonathan Reem <jonathan.reem@gmail.com>",
+ "Matt Brubeck <mbrubeck@limpet.net>",
+]
description = "Wrappers for total ordering on floats"
readme = "README.md"
-keywords = ["no_std", "ord", "f64", "f32", "sort"]
-categories = ["science", "rust-patterns", "no-std"]
+keywords = [
+ "no_std",
+ "ord",
+ "f64",
+ "f32",
+ "sort",
+]
+categories = [
+ "science",
+ "rust-patterns",
+ "no-std",
+]
license = "MIT"
repository = "https://github.com/reem/rust-ordered-float"
+
[dependencies.arbitrary]
version = "1.0.0"
optional = true
@@ -51,10 +65,14 @@ optional = true
version = "1.0"
optional = true
default-features = false
+
[dev-dependencies.serde_test]
version = "1.0"
[features]
default = ["std"]
-randtest = ["rand/std", "rand/std_rng"]
+randtest = [
+ "rand/std",
+ "rand/std_rng",
+]
std = ["num-traits/std"]
diff --git a/vendor/ordered-float/src/lib.rs b/vendor/ordered-float/src/lib.rs
index dc00004bb..7532ce232 100644
--- a/vendor/ordered-float/src/lib.rs
+++ b/vendor/ordered-float/src/lib.rs
@@ -36,7 +36,14 @@ const MAN_MASK: u64 = 0x000fffffffffffffu64;
// canonical raw bit patterns (for hashing)
const CANONICAL_NAN_BITS: u64 = 0x7ff8000000000000u64;
-const CANONICAL_ZERO_BITS: u64 = 0x0u64;
+
+#[inline(always)]
+fn canonicalize_signed_zero<T: Float>(x: T) -> T {
+ // -0.0 + 0.0 == +0.0 under IEEE754 roundTiesToEven rounding mode,
+ // which Rust guarantees. Thus by adding a positive zero we
+ // canonicalize signed zero without any branches in one instruction.
+ x + T::zero()
+}
/// A wrapper around floats providing implementations of `Eq`, `Ord`, and `Hash`.
///
@@ -111,25 +118,43 @@ impl<T: Float> PartialOrd for OrderedFloat<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
+
+ #[inline]
+ fn lt(&self, other: &Self) -> bool {
+ !self.ge(other)
+ }
+
+ #[inline]
+ fn le(&self, other: &Self) -> bool {
+ other.ge(self)
+ }
+
+ #[inline]
+ fn gt(&self, other: &Self) -> bool {
+ !other.ge(self)
+ }
+
+ #[inline]
+ fn ge(&self, other: &Self) -> bool {
+ // We consider all NaNs equal, and NaN is the largest possible
+ // value. Thus if self is NaN we always return true. Otherwise
+ // self >= other is correct. If other is also not NaN it is trivially
+ // correct, and if it is we note that nothing can be greater or
+ // equal to NaN except NaN itself, which we already handled earlier.
+ self.0.is_nan() | (self.0 >= other.0)
+ }
}
impl<T: Float> Ord for OrderedFloat<T> {
+ #[inline]
+ #[allow(clippy::comparison_chain)]
fn cmp(&self, other: &Self) -> Ordering {
- let lhs = &self.0;
- let rhs = &other.0;
- match lhs.partial_cmp(rhs) {
- Some(ordering) => ordering,
- None => {
- if lhs.is_nan() {
- if rhs.is_nan() {
- Ordering::Equal
- } else {
- Ordering::Greater
- }
- } else {
- Ordering::Less
- }
- }
+ if self < other {
+ Ordering::Less
+ } else if self > other {
+ Ordering::Greater
+ } else {
+ Ordering::Equal
}
}
}
@@ -154,12 +179,13 @@ impl<T: Float> PartialEq<T> for OrderedFloat<T> {
impl<T: Float> Hash for OrderedFloat<T> {
fn hash<H: Hasher>(&self, state: &mut H) {
- if self.is_nan() {
- // normalize to one representation of NaN
- hash_float(&T::nan(), state)
+ let bits = if self.is_nan() {
+ CANONICAL_NAN_BITS
} else {
- hash_float(&self.0, state)
- }
+ raw_double_bits(&canonicalize_signed_zero(self.0))
+ };
+
+ bits.hash(state)
}
}
@@ -943,7 +969,8 @@ impl<T: Float> Ord for NotNan<T> {
impl<T: Float> Hash for NotNan<T> {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
- hash_float(&self.0, state)
+ let bits = raw_double_bits(&canonicalize_signed_zero(self.0));
+ bits.hash(state)
}
}
@@ -1267,21 +1294,8 @@ impl From<FloatIsNan> for std::io::Error {
}
#[inline]
-fn hash_float<F: Float, H: Hasher>(f: &F, state: &mut H) {
- raw_double_bits(f).hash(state);
-}
-
-#[inline]
fn raw_double_bits<F: Float>(f: &F) -> u64 {
- if f.is_nan() {
- return CANONICAL_NAN_BITS;
- }
-
let (man, exp, sign) = f.integer_decode();
- if man == 0 {
- return CANONICAL_ZERO_BITS;
- }
-
let exp_u64 = exp as u16 as u64;
let sign_u64 = if sign > 0 { 1u64 } else { 0u64 };
(man & MAN_MASK) | ((exp_u64 << 52) & EXP_MASK) | ((sign_u64 << 63) & SIGN_MASK)
diff --git a/vendor/ordered-float/tests/test.rs b/vendor/ordered-float/tests/test.rs
index 6db950fb2..357db7c4c 100644
--- a/vendor/ordered-float/tests/test.rs
+++ b/vendor/ordered-float/tests/test.rs
@@ -23,6 +23,32 @@ fn not_nan<T: Float>(x: T) -> NotNan<T> {
}
#[test]
+fn test_total_order() {
+ let numberline = [
+ (-f32::INFINITY, 0),
+ (-1.0, 1),
+ (-0.0, 2),
+ (0.0, 2),
+ (1.0, 3),
+ (f32::INFINITY, 4),
+ (f32::NAN, 5),
+ (-f32::NAN, 5),
+ ];
+
+ for &(fi, i) in &numberline {
+ for &(fj, j) in &numberline {
+ assert_eq!(OrderedFloat(fi) < OrderedFloat(fj), i < j);
+ assert_eq!(OrderedFloat(fi) > OrderedFloat(fj), i > j);
+ assert_eq!(OrderedFloat(fi) <= OrderedFloat(fj), i <= j);
+ assert_eq!(OrderedFloat(fi) >= OrderedFloat(fj), i >= j);
+ assert_eq!(OrderedFloat(fi) == OrderedFloat(fj), i == j);
+ assert_eq!(OrderedFloat(fi) != OrderedFloat(fj), i != j);
+ assert_eq!(OrderedFloat(fi).cmp(&OrderedFloat(fj)), i.cmp(&j));
+ }
+ }
+}
+
+#[test]
fn ordered_f32_compare_regular_floats() {
assert_eq!(OrderedFloat(7.0f32).cmp(&OrderedFloat(7.0)), Equal);
assert_eq!(OrderedFloat(8.0f32).cmp(&OrderedFloat(7.0)), Greater);