@@ -3983,6 +3983,68 @@ impl<T> [T] {
39833983 }
39843984}
39853985
3986+ #[ cfg( not( bootstrap) ) ]
3987+ #[ cfg( not( test) ) ]
3988+ #[ lang = "slice_f32" ]
3989+ impl [ f32 ] {
3990+ /// Sorts the slice of floats.
3991+ ///
3992+ /// This sort is in-place (i.e. does not allocate), *O*(*n* \* log(*n*)) worst-case, and uses
3993+ /// the ordering defined by [`f32::total_cmp`].
3994+ ///
3995+ /// # Current implementation
3996+ ///
3997+ /// This uses the same sorting algorithm as [`sort_unstable_by`](slice::sort_unstable_by).
3998+ ///
3999+ /// # Examples
4000+ ///
4001+ /// ```
4002+ /// #![feature(sort_floats)]
4003+ /// let mut v = [2.6, -5e-8, f32::NAN, 8.29, f32::INFINITY, -1.0, 0.0, -f32::INFINITY, -0.0];
4004+ ///
4005+ /// v.sort_floats();
4006+ /// let sorted = [-f32::INFINITY, -1.0, -5e-8, -0.0, 0.0, 2.6, 8.29, f32::INFINITY, f32::NAN];
4007+ /// assert_eq!(&v[..8], &sorted[..8]);
4008+ /// assert!(v[8].is_nan());
4009+ /// ```
4010+ #[ unstable( feature = "sort_floats" , issue = "93396" ) ]
4011+ #[ inline]
4012+ pub fn sort_floats ( & mut self ) {
4013+ self . sort_unstable_by ( f32:: total_cmp) ;
4014+ }
4015+ }
4016+
4017+ #[ cfg( not( bootstrap) ) ]
4018+ #[ cfg( not( test) ) ]
4019+ #[ lang = "slice_f64" ]
4020+ impl [ f64 ] {
4021+ /// Sorts the slice of floats.
4022+ ///
4023+ /// This sort is in-place (i.e. does not allocate), *O*(*n* \* log(*n*)) worst-case, and uses
4024+ /// the ordering defined by [`f64::total_cmp`].
4025+ ///
4026+ /// # Current implementation
4027+ ///
4028+ /// This uses the same sorting algorithm as [`sort_unstable_by`](slice::sort_unstable_by).
4029+ ///
4030+ /// # Examples
4031+ ///
4032+ /// ```
4033+ /// #![feature(sort_floats)]
4034+ /// let mut v = [2.6, -5e-8, f64::NAN, 8.29, f64::INFINITY, -1.0, 0.0, -f64::INFINITY, -0.0];
4035+ ///
4036+ /// v.sort_floats();
4037+ /// let sorted = [-f64::INFINITY, -1.0, -5e-8, -0.0, 0.0, 2.6, 8.29, f64::INFINITY, f64::NAN];
4038+ /// assert_eq!(&v[..8], &sorted[..8]);
4039+ /// assert!(v[8].is_nan());
4040+ /// ```
4041+ #[ unstable( feature = "sort_floats" , issue = "93396" ) ]
4042+ #[ inline]
4043+ pub fn sort_floats ( & mut self ) {
4044+ self . sort_unstable_by ( f64:: total_cmp) ;
4045+ }
4046+ }
4047+
39864048trait CloneFromSpec < T > {
39874049 fn spec_clone_from ( & mut self , src : & [ T ] ) ;
39884050}
0 commit comments