#[inline]
pub fn floorf(x: f32) -> f32 {
let xi = x as i32;
let xf = xi as f32;
if x < xf {
xf - 1.0
} else {
xf
}
}
#[inline]
pub fn ceilf(x: f32) -> f32 {
let xi = x as i32;
let xf = xi as f32;
if x > xf {
xf + 1.0
} else {
xf
}
}
#[inline]
pub fn roundf(x: f32) -> f32 {
if x >= 0.0 {
floorf(x + 0.5)
} else {
ceilf(x - 0.5)
}
}
#[inline]
pub fn truncf(x: f32) -> f32 {
x as i32 as f32
}
#[inline]
pub fn fractf(x: f32) -> f32 {
x - floorf(x)
}
#[inline]
pub fn absf(x: f32) -> f32 {
if x < 0.0 {
-x
} else {
x
}
}
#[inline]
pub fn signf(x: f32) -> f32 {
if x > 0.0 {
1.0
} else if x < 0.0 {
-1.0
} else {
0.0
}
}
#[inline]
pub fn copysignf(x: f32, y: f32) -> f32 {
let abs_x = absf(x);
if y >= 0.0 {
abs_x
} else {
-abs_x
}
}
#[inline]
pub fn fmodf(x: f32, y: f32) -> f32 {
x - truncf(x / y) * y
}
#[inline]
pub fn remf(x: f32, y: f32) -> f32 {
let r = fmodf(x, y);
if r < 0.0 {
r + absf(y)
} else {
r
}
}
#[inline]
pub fn floor(x: f64) -> f64 {
let xi = x as i64;
let xf = xi as f64;
if x < xf {
xf - 1.0
} else {
xf
}
}
#[inline]
pub fn ceil(x: f64) -> f64 {
let xi = x as i64;
let xf = xi as f64;
if x > xf {
xf + 1.0
} else {
xf
}
}
#[inline]
pub fn round(x: f64) -> f64 {
if x >= 0.0 {
floor(x + 0.5)
} else {
ceil(x - 0.5)
}
}
#[inline]
pub fn trunc(x: f64) -> f64 {
x as i64 as f64
}
#[inline]
pub fn abs(x: f64) -> f64 {
if x < 0.0 {
-x
} else {
x
}
}