rstmt_traits/ops/
precision.rs

1/*
2    Appellation: precision <module>
3    Created At: 2026.01.10:09:29:19
4    Contrib: @FL03
5*/
6
7/// The [`TruncDiv`] trait defines an operator for truncated division, which discards the
8/// fractional part of the quotient, returning only the integer component. This differs from
9/// `div_floor` in that it truncates towards zero rather than towards negative infinity.
10pub trait TruncDiv<Rhs = Self> {
11    type Output;
12
13    fn div_trunc(self, rhs: Rhs) -> Self::Output;
14}
15
16/*
17 ************* Implementations *************
18*/
19
20use num_traits::Float;
21
22impl<T> TruncDiv for T
23where
24    T: Float,
25{
26    type Output = T;
27
28    fn div_trunc(self, rhs: T) -> Self::Output {
29        (self / rhs).trunc()
30    }
31}