diff options
Diffstat (limited to 'azalea-core/src')
| -rw-r--r-- | azalea-core/src/math.rs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/azalea-core/src/math.rs b/azalea-core/src/math.rs index aa9d88c8..7c0ac7b4 100644 --- a/azalea-core/src/math.rs +++ b/azalea-core/src/math.rs @@ -62,6 +62,12 @@ pub fn ceil_log2(x: u32) -> u32 { u32::BITS - x.leading_zeros() } +pub fn fract(x: f64) -> f64 { + let x_int = x as i64 as f64; + let floor = if x < x_int { x_int - 1. } else { x_int }; + x - floor +} + #[cfg(test)] mod tests { use super::*; |
