Skip to content

Commit 3141acf

Browse files
committed
Changed to a more efficient implementation.
1 parent 6cc9a26 commit 3141acf

File tree

2 files changed

+4
-16
lines changed

2 files changed

+4
-16
lines changed

src/libstd/num/f32.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,12 @@ pub fn gt(x: f32, y: f32) -> bool { return x > y; }
147147

148148
#[inline(always)]
149149
pub fn fmax(x: f32, y: f32) -> f32 {
150-
if x.is_NaN() { y }
151-
else if y.is_NaN() { x }
152-
else if x > y { x }
153-
else { y }
150+
if x >= y || y.is_NaN() { x } else { y }
154151
}
155152

156153
#[inline(always)]
157154
pub fn fmin(x: f32, y: f32) -> f32 {
158-
if x.is_NaN() { y }
159-
else if y.is_NaN() { x }
160-
else if x < y { x }
161-
else { y }
155+
if x <= y || y.is_NaN() { x } else { y }
162156
}
163157

164158

src/libstd/num/f64.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,12 @@ pub fn gt(x: f64, y: f64) -> bool { return x > y; }
172172

173173
#[inline(always)]
174174
pub fn fmax(x: f64, y: f64) -> f64 {
175-
if x.is_NaN() { y }
176-
else if y.is_NaN() { x }
177-
else if x > y { x }
178-
else { y }
175+
if x >= y || y.is_NaN() { x } else { y }
179176
}
180177

181178
#[inline(always)]
182179
pub fn fmin(x: f64, y: f64) -> f64 {
183-
if x.is_NaN() { y }
184-
else if y.is_NaN() { x }
185-
else if x < y { x }
186-
else { y }
180+
if x <= y || y.is_NaN() { x } else { y }
187181
}
188182

189183
// FIXME (#1999): add is_normal, is_subnormal, and fpclassify

0 commit comments

Comments
 (0)