#[cfg(feature = "std")]
#[inline]
#[must_use]
pub fn abs(x: f64) -> f64 {
x.abs()
}
#[cfg(not(feature = "std"))]
#[inline]
#[must_use]
pub fn abs(x: f64) -> f64 {
libm::fabs(x)
}
#[cfg(feature = "std")]
#[inline]
#[must_use]
pub fn max(a: f64, b: f64) -> f64 {
a.max(b)
}
#[cfg(not(feature = "std"))]
#[inline]
#[must_use]
pub fn max(a: f64, b: f64) -> f64 {
libm::fmax(a, b)
}
#[cfg(feature = "std")]
#[inline]
#[must_use]
pub fn mul_add(a: f64, b: f64, c: f64) -> f64 {
a.mul_add(b, c)
}
#[cfg(not(feature = "std"))]
#[inline]
#[must_use]
pub fn mul_add(a: f64, b: f64, c: f64) -> f64 {
libm::fma(a, b, c)
}
#[cfg(test)]
mod tests {
use super::{abs, max, mul_add};
#[test]
fn abs_matches_std() {
assert_eq!(abs(-3.5).to_bits(), 3.5_f64.to_bits());
assert_eq!(abs(3.5).to_bits(), 3.5_f64.to_bits());
assert_eq!(abs(0.0).to_bits(), 0.0_f64.to_bits());
}
#[test]
fn max_matches_std() {
assert_eq!(max(2.0, 7.0).to_bits(), 7.0_f64.max(2.0).to_bits());
assert_eq!(max(7.0, 2.0).to_bits(), 7.0_f64.max(2.0).to_bits());
}
#[test]
fn mul_add_matches_std() {
let (a, b, c) = (1.234_567, 8.910_11, -2.345_67);
assert_eq!(mul_add(a, b, c).to_bits(), a.mul_add(b, c).to_bits());
}
}