@@ -78,10 +78,14 @@ impl f32 {
78
78
/// let f = 3.3_f32;
79
79
/// let g = -3.3_f32;
80
80
/// let h = -3.7_f32;
81
+ /// let i = 3.5_f32;
82
+ /// let j = 4.5_f32;
81
83
///
82
84
/// assert_eq!(f.round(), 3.0);
83
85
/// assert_eq!(g.round(), -3.0);
84
86
/// assert_eq!(h.round(), -4.0);
87
+ /// assert_eq!(i.round(), 4.0);
88
+ /// assert_eq!(j.round(), 5.0);
85
89
/// ```
86
90
#[ rustc_allow_incoherent_impl]
87
91
#[ must_use = "method returns a new number and does not mutate the original value" ]
@@ -91,6 +95,33 @@ impl f32 {
91
95
unsafe { intrinsics:: roundf32 ( self ) }
92
96
}
93
97
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
+
94
125
/// Returns the integer part of `self`.
95
126
/// This means that non-integer numbers are always truncated towards zero.
96
127
///
0 commit comments