Skip to content

Replaced calls to external fmin/fmax by a Rust implementation. #6803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ delegate!(
fn erfc(n: c_float) -> c_float = c_float_utils::erfc,
fn exp_m1(n: c_float) -> c_float = c_float_utils::exp_m1,
fn abs_sub(a: c_float, b: c_float) -> c_float = c_float_utils::abs_sub,
fn fmax(a: c_float, b: c_float) -> c_float = c_float_utils::fmax,
fn fmin(a: c_float, b: c_float) -> c_float = c_float_utils::fmin,
fn next_after(x: c_float, y: c_float) -> c_float = c_float_utils::next_after,
fn frexp(n: c_float, value: &mut c_int) -> c_float = c_float_utils::frexp,
fn hypot(x: c_float, y: c_float) -> c_float = c_float_utils::hypot,
Expand Down Expand Up @@ -147,6 +145,16 @@ pub fn ge(x: f32, y: f32) -> bool { return x >= y; }
#[inline(always)]
pub fn gt(x: f32, y: f32) -> bool { return x > y; }

#[inline(always)]
pub fn fmax(x: f32, y: f32) -> f32 {
if x >= y || y.is_NaN() { x } else { y }
}

#[inline(always)]
pub fn fmin(x: f32, y: f32) -> f32 {
if x <= y || y.is_NaN() { x } else { y }
}


// FIXME (#1999): replace the predicates below with llvm intrinsics or
// calls to the libmath macros in the rust runtime for performance.
Expand Down
11 changes: 9 additions & 2 deletions src/libstd/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ delegate!(
fn erfc(n: c_double) -> c_double = c_double_utils::erfc,
fn exp_m1(n: c_double) -> c_double = c_double_utils::exp_m1,
fn abs_sub(a: c_double, b: c_double) -> c_double = c_double_utils::abs_sub,
fn fmax(a: c_double, b: c_double) -> c_double = c_double_utils::fmax,
fn fmin(a: c_double, b: c_double) -> c_double = c_double_utils::fmin,
fn next_after(x: c_double, y: c_double) -> c_double = c_double_utils::next_after,
fn frexp(n: c_double, value: &mut c_int) -> c_double = c_double_utils::frexp,
fn hypot(x: c_double, y: c_double) -> c_double = c_double_utils::hypot,
Expand Down Expand Up @@ -172,6 +170,15 @@ pub fn ge(x: f64, y: f64) -> bool { return x >= y; }
#[inline(always)]
pub fn gt(x: f64, y: f64) -> bool { return x > y; }

#[inline(always)]
pub fn fmax(x: f64, y: f64) -> f64 {
if x >= y || y.is_NaN() { x } else { y }
}

#[inline(always)]
pub fn fmin(x: f64, y: f64) -> f64 {
if x <= y || y.is_NaN() { x } else { y }
}

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

Expand Down