#[cfg(feature = "std")]
#[inline]
pub fn sqrtf(x: f32) -> f32 {
x.sqrt()
}
#[cfg(feature = "std")]
#[inline]
pub fn roundf(x: f32) -> f32 {
x.round()
}
#[cfg(all(not(feature = "std"), feature = "libm"))]
#[inline]
pub fn sqrtf(x: f32) -> f32 {
libm::sqrtf(x)
}
#[cfg(all(not(feature = "std"), feature = "libm"))]
#[inline]
pub fn roundf(x: f32) -> f32 {
libm::roundf(x)
}
#[cfg(feature = "std")]
#[inline]
pub fn ceilf(x: f32) -> f32 {
x.ceil()
}
#[cfg(all(not(feature = "std"), feature = "libm"))]
#[inline]
pub fn ceilf(x: f32) -> f32 {
libm::ceilf(x)
}
#[inline]
pub fn fabsf(x: f32) -> f32 {
f32::from_bits(x.to_bits() & 0x7fff_ffff)
}
#[inline]
pub fn fabs(x: f64) -> f64 {
f64::from_bits(x.to_bits() & 0x7fff_ffff_ffff_ffff)
}
#[cfg(all(not(feature = "std"), not(feature = "libm")))]
compile_error!("a no_std build needs the `libm` feature: float sqrt/round are in std, not core");
#[cfg(all(test, feature = "libm"))]
mod tests {
#[test]
fn libm_matches_std_bit_for_bit() {
for i in -200_000..200_000i32 {
let x = i as f32 * 0.0137;
assert_eq!(libm::roundf(x).to_bits(), x.round().to_bits(), "round({x})");
if x >= 0.0 {
assert_eq!(libm::sqrtf(x).to_bits(), x.sqrt().to_bits(), "sqrt({x})");
}
}
}
}