#![allow(unreachable_pub)]
#[cfg(feature = "std")]
extern crate std;
#[cfg(not(any(feature = "std", feature = "libm")))]
compile_error!("Either the 'std' or 'libm' feature must be enabled for alpha-blend.");
pub fn round(f: f32) -> f32 {
#[cfg(feature = "std")]
return f32::round(f);
#[cfg(not(feature = "std"))]
return libm::roundf(f);
}
pub fn sqrt(f: f32) -> f32 {
#[cfg(feature = "std")]
return f32::sqrt(f);
#[cfg(not(feature = "std"))]
return libm::sqrtf(f);
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
#[allow(clippy::float_cmp)]
fn round_up() {
assert_eq!(round(1.5), 2.0);
}
#[test]
#[allow(clippy::float_cmp)]
fn round_down() {
assert_eq!(round(1.4), 1.0);
}
#[test]
#[allow(clippy::float_cmp)]
fn sqrt_exact() {
assert_eq!(sqrt(0.25), 0.5);
assert_eq!(sqrt(0.0), 0.0);
assert_eq!(sqrt(1.0), 1.0);
}
}