Skip to content

Commit 6cc9a26

Browse files
committed
Replaced calls to external fmin/fmax by a Rust implementation.
1 parent e3e55c5 commit 6cc9a26

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/libstd/num/f32.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ delegate!(
8686
fn erfc(n: c_float) -> c_float = c_float_utils::erfc,
8787
fn exp_m1(n: c_float) -> c_float = c_float_utils::exp_m1,
8888
fn abs_sub(a: c_float, b: c_float) -> c_float = c_float_utils::abs_sub,
89-
fn fmax(a: c_float, b: c_float) -> c_float = c_float_utils::fmax,
90-
fn fmin(a: c_float, b: c_float) -> c_float = c_float_utils::fmin,
9189
fn next_after(x: c_float, y: c_float) -> c_float = c_float_utils::next_after,
9290
fn frexp(n: c_float, value: &mut c_int) -> c_float = c_float_utils::frexp,
9391
fn hypot(x: c_float, y: c_float) -> c_float = c_float_utils::hypot,
@@ -147,6 +145,22 @@ pub fn ge(x: f32, y: f32) -> bool { return x >= y; }
147145
#[inline(always)]
148146
pub fn gt(x: f32, y: f32) -> bool { return x > y; }
149147

148+
#[inline(always)]
149+
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 }
154+
}
155+
156+
#[inline(always)]
157+
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 }
162+
}
163+
150164

151165
// FIXME (#1999): replace the predicates below with llvm intrinsics or
152166
// calls to the libmath macros in the rust runtime for performance.

src/libstd/num/f64.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ delegate!(
8787
fn erfc(n: c_double) -> c_double = c_double_utils::erfc,
8888
fn exp_m1(n: c_double) -> c_double = c_double_utils::exp_m1,
8989
fn abs_sub(a: c_double, b: c_double) -> c_double = c_double_utils::abs_sub,
90-
fn fmax(a: c_double, b: c_double) -> c_double = c_double_utils::fmax,
91-
fn fmin(a: c_double, b: c_double) -> c_double = c_double_utils::fmin,
9290
fn next_after(x: c_double, y: c_double) -> c_double = c_double_utils::next_after,
9391
fn frexp(n: c_double, value: &mut c_int) -> c_double = c_double_utils::frexp,
9492
fn hypot(x: c_double, y: c_double) -> c_double = c_double_utils::hypot,
@@ -172,6 +170,21 @@ pub fn ge(x: f64, y: f64) -> bool { return x >= y; }
172170
#[inline(always)]
173171
pub fn gt(x: f64, y: f64) -> bool { return x > y; }
174172

173+
#[inline(always)]
174+
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 }
179+
}
180+
181+
#[inline(always)]
182+
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 }
187+
}
175188

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

0 commit comments

Comments
 (0)