@@ -78,10 +78,14 @@ impl f32 {
7878 /// let f = 3.3_f32;
7979 /// let g = -3.3_f32;
8080 /// let h = -3.7_f32;
81+ /// let i = 3.5_f32;
82+ /// let j = 4.5_f32;
8183 ///
8284 /// assert_eq!(f.round(), 3.0);
8385 /// assert_eq!(g.round(), -3.0);
8486 /// assert_eq!(h.round(), -4.0);
87+ /// assert_eq!(i.round(), 4.0);
88+ /// assert_eq!(j.round(), 5.0);
8589 /// ```
8690 #[ rustc_allow_incoherent_impl]
8791 #[ must_use = "method returns a new number and does not mutate the original value" ]
@@ -91,6 +95,33 @@ impl f32 {
9195 unsafe { intrinsics:: roundf32 ( self ) }
9296 }
9397
98+ /// Returns the nearest integer to a number. Rounds half-way cases to the number
99+ /// with an even least significant digit.
100+ ///
101+ /// # Examples
102+ ///
103+ /// ```
104+ /// #![feature(round_ties_even)]
105+ ///
106+ /// let f = 3.3_f32;
107+ /// let g = -3.3_f32;
108+ /// let h = 3.5_f32;
109+ /// let i = 4.5_f32;
110+ ///
111+ /// assert_eq!(f.round_ties_even(), 3.0);
112+ /// assert_eq!(g.round_ties_even(), -3.0);
113+ /// assert_eq!(h.round_ties_even(), 4.0);
114+ /// assert_eq!(i.round_ties_even(), 4.0);
115+ /// ```
116+ #[ cfg( not( bootstrap) ) ]
117+ #[ cfg_attr( not( bootstrap) , rustc_allow_incoherent_impl) ]
118+ #[ must_use = "method returns a new number and does not mutate the original value" ]
119+ #[ unstable( feature = "round_ties_even" , issue = "none" ) ]
120+ #[ inline]
121+ pub fn round_ties_even ( self ) -> f32 {
122+ unsafe { intrinsics:: roundevenf32 ( self ) }
123+ }
124+
94125 /// Returns the integer part of `self`.
95126 /// This means that non-integer numbers are always truncated towards zero.
96127 ///
0 commit comments