Auto merge of #93397 - joshtriplett:sort-floats, r=Amanieu · rust-lang/rust@ed793d8 (original) (raw)
`@@ -4101,6 +4101,66 @@ impl<T, const N: usize> [[T; N]] {
`
4101
4101
`}
`
4102
4102
`}
`
4103
4103
``
``
4104
`+
#[cfg(not(bootstrap))]
`
``
4105
`+
#[cfg(not(test))]
`
``
4106
`+
impl [f32] {
`
``
4107
`+
/// Sorts the slice of floats.
`
``
4108
`+
///
`
``
4109
`+
/// This sort is in-place (i.e. does not allocate), O(n * log(n)) worst-case, and uses
`
``
4110
`` +
/// the ordering defined by [f32::total_cmp
].
``
``
4111
`+
///
`
``
4112
`+
/// # Current implementation
`
``
4113
`+
///
`
``
4114
`` +
/// This uses the same sorting algorithm as sort_unstable_by
.
``
``
4115
`+
///
`
``
4116
`+
/// # Examples
`
``
4117
`+
///
`
``
4118
/// ```
``
4119
`+
/// #![feature(sort_floats)]
`
``
4120
`+
/// let mut v = [2.6, -5e-8, f32::NAN, 8.29, f32::INFINITY, -1.0, 0.0, -f32::INFINITY, -0.0];
`
``
4121
`+
///
`
``
4122
`+
/// v.sort_floats();
`
``
4123
`+
/// let sorted = [-f32::INFINITY, -1.0, -5e-8, -0.0, 0.0, 2.6, 8.29, f32::INFINITY, f32::NAN];
`
``
4124
`+
/// assert_eq!(&v[..8], &sorted[..8]);
`
``
4125
`+
/// assert!(v[8].is_nan());
`
``
4126
/// ```
``
4127
`+
#[unstable(feature = "sort_floats", issue = "93396")]
`
``
4128
`+
#[inline]
`
``
4129
`+
pub fn sort_floats(&mut self) {
`
``
4130
`+
self.sort_unstable_by(f32::total_cmp);
`
``
4131
`+
}
`
``
4132
`+
}
`
``
4133
+
``
4134
`+
#[cfg(not(bootstrap))]
`
``
4135
`+
#[cfg(not(test))]
`
``
4136
`+
impl [f64] {
`
``
4137
`+
/// Sorts the slice of floats.
`
``
4138
`+
///
`
``
4139
`+
/// This sort is in-place (i.e. does not allocate), O(n * log(n)) worst-case, and uses
`
``
4140
`` +
/// the ordering defined by [f64::total_cmp
].
``
``
4141
`+
///
`
``
4142
`+
/// # Current implementation
`
``
4143
`+
///
`
``
4144
`` +
/// This uses the same sorting algorithm as sort_unstable_by
.
``
``
4145
`+
///
`
``
4146
`+
/// # Examples
`
``
4147
`+
///
`
``
4148
/// ```
``
4149
`+
/// #![feature(sort_floats)]
`
``
4150
`+
/// let mut v = [2.6, -5e-8, f64::NAN, 8.29, f64::INFINITY, -1.0, 0.0, -f64::INFINITY, -0.0];
`
``
4151
`+
///
`
``
4152
`+
/// v.sort_floats();
`
``
4153
`+
/// let sorted = [-f64::INFINITY, -1.0, -5e-8, -0.0, 0.0, 2.6, 8.29, f64::INFINITY, f64::NAN];
`
``
4154
`+
/// assert_eq!(&v[..8], &sorted[..8]);
`
``
4155
`+
/// assert!(v[8].is_nan());
`
``
4156
/// ```
``
4157
`+
#[unstable(feature = "sort_floats", issue = "93396")]
`
``
4158
`+
#[inline]
`
``
4159
`+
pub fn sort_floats(&mut self) {
`
``
4160
`+
self.sort_unstable_by(f64::total_cmp);
`
``
4161
`+
}
`
``
4162
`+
}
`
``
4163
+
4104
4164
`trait CloneFromSpec {
`
4105
4165
`fn spec_clone_from(&mut self, src: &[T]);
`
4106
4166
`}
`