concision_core/utils/math.rs
1/*
2 Appellation: math <module>
3 Contrib: FL03 <jo3mccain@icloud.com>
4*/
5use num::traits::{Float, Num};
6
7///
8pub fn floor_div<T>(numerator: T, denom: T) -> T
9where
10 T: Copy + Num,
11{
12 (numerator - (numerator % denom)) / denom
13}
14
15/// Round the given value to the given number of decimal places.
16pub fn round_to<T>(val: T, decimals: usize) -> T
17where
18 T: Float,
19{
20 let factor = T::from(10).expect("").powi(decimals as i32);
21 (val * factor).round() / factor
22}