Skip to content
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

Expose some more functions from libc #25780

Closed
wants to merge 1 commit 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
89 changes: 89 additions & 0 deletions src/libstd/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,59 @@ impl f32 {
unsafe { cmath::nextafterf(self, other) }
}

/// Returns floating point exponent of the input
///
/// ```
/// use std::f32;
///
/// let x = 0.5f32;
/// let abs_diff = ( -1 - x.logb()).abs();
///
/// assert!(abs_diff <= f32::EPSILON)
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn logb(self) -> f32 {
unsafe { cmath::logbf(self) }
}

/// Returns integer exponent of the input
///
/// ```
/// use std::f32;
///
/// let x = 0.5f32;
/// let abs_diff = (-1.0f32 - x.ilogb()).abs();
///
/// assert!(abs_diff <= f32::EPSILON)
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn ilogb(self) -> i32 {
unsafe { cmath::ilogbf(self) }
}

/// Returns the value of the gamma function
/// at the given point
///
/// ```
/// use std::f32;
///
/// let x = 1.2f32;
/// let g = 0.9181687f32;
/// let abs_diff = (x.gamma() - g ).abs();
///
/// assert!(abs_diff <= f32::EPSILON)
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn gamma(self) -> f32 {
unsafe { cmath::tgammaf(self) }
}

/// Returns the maximum of the two numbers.
///
/// ```
Expand Down Expand Up @@ -981,6 +1034,42 @@ impl f32 {
unsafe { cmath::coshf(self) }
}

/// Error function.
///
/// ```
/// use std::f32;
///
/// let x = 1.0f32;
/// let g = 0.8427008f32;
/// let f = x.erf();
/// let abs_difference = (f - g).abs();
/// assert!(abs_difference <= f32::EPSILON);
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn erf(self) -> f32 {
unsafe { cmath::erff(self) }
}

/// Complementary error function.
///
/// ```
/// use std::f32;
///
/// let x = 1.0f32;
/// let g = 0.1572992f32;
/// let f = x.erfc();
/// let abs_difference = (f - g).abs();
/// assert!(abs_difference <= f32::EPSILON);
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn erfc(self) -> f32 {
unsafe { cmath::erfcf(self) }
}

/// Hyperbolic tangent function.
///
/// ```
Expand Down
89 changes: 89 additions & 0 deletions src/libstd/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,59 @@ impl f64 {
unsafe { cmath::nextafter(self, other) }
}

/// Returns floating point exponent of the input
///
/// ```
/// use std::f64;
///
/// let x = 0.5f64;
/// let abs_diff = (x.logb() - 1).abs();
///
/// assert!(abs_diff <= f64::EPSILON)
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn logb(self) -> f64 {
unsafe { cmath::logb(self) }
}

/// Returns integer exponent of the input
///
/// ```
/// use std::f64;
///
/// let x = 0.5f64;
/// let abs_diff = (x.ilogb() - 1.0f64).abs();
///
/// assert!(abs_diff <= f64::EPSILON)
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn ilogb(self) -> i32 {
unsafe { cmath::ilogb(self) }
}

/// Returns the value of the gamma function
/// at the given point
///
/// ```
/// use std::f64;
///
/// let x = 1.2f64;
/// let g = 0.9182f64;
/// let abs_diff = (x.gamma() - g ).abs();
///
/// assert!(abs_diff <= f64::EPSILON)
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn gamma(self) -> f64 {
unsafe { cmath::tgamma(self) }
}

/// Returns the maximum of the two numbers.
///
/// ```
Expand Down Expand Up @@ -677,6 +730,42 @@ impl f64 {
unsafe { cmath::fdim(self, other) }
}

/// Error function.
///
/// ```
/// use std::f64;
///
/// let x = 1.0f64;
/// let g = 0.8427008f64;
/// let f = x.erf();
/// let abs_difference = (f - g).abs();
/// assert!(abs_difference <= f64::EPSILON);
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn erf(self) -> f64 {
unsafe { cmath::erf(self) }
}

/// Complementary error function.
///
/// ```
/// use std::f64;
///
/// let x = 1.0f64;
/// let g = 0.1572992f64;
/// let f = x.erfc();
/// let abs_difference = (f - g).abs();
/// assert!(abs_difference <= f64::EPSILON);
/// ```
#[unstable(feature = "float_extras",
reason = "unsure about its place in the world")]
#[inline]
pub fn erfc(self) -> f64 {
unsafe { cmath::erfc(self) }
}

/// Takes the cubic root of a number.
///
/// ```
Expand Down