Skip to content

Commit 17f94d6

Browse files
committed
Add back Floor, Ceil, and Round on integer types
It can be helpful to treat floating point and integer types the same in a generic context when you need to find an integral bounding box or the closest integer coordinate.
1 parent 2894075 commit 17f94d6

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/num.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ pub trait Ceil: Copy {
7070
fn ceil(self) -> Self;
7171
}
7272

73+
macro_rules! num_int {
74+
($ty:ty) => {
75+
impl Round for $ty {
76+
#[inline]
77+
fn round(self) -> $ty {
78+
self
79+
}
80+
}
81+
impl Floor for $ty {
82+
#[inline]
83+
fn floor(self) -> $ty {
84+
self
85+
}
86+
}
87+
impl Ceil for $ty {
88+
#[inline]
89+
fn ceil(self) -> $ty {
90+
self
91+
}
92+
}
93+
};
94+
}
95+
7396
macro_rules! num_float {
7497
($ty:ty) => {
7598
impl Round for $ty {
@@ -92,5 +115,14 @@ macro_rules! num_float {
92115
}
93116
};
94117
}
118+
119+
num_int!(i16);
120+
num_int!(u16);
121+
num_int!(i32);
122+
num_int!(u32);
123+
num_int!(i64);
124+
num_int!(u64);
125+
num_int!(isize);
126+
num_int!(usize);
95127
num_float!(f32);
96128
num_float!(f64);

0 commit comments

Comments
 (0)