Skip to content

Commit

Permalink
Auto merge of #464 - kyren:master, r=nical
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors-servo authored Aug 20, 2020
2 parents 2894075 + 17f94d6 commit 27b7a27
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,29 @@ pub trait Ceil: Copy {
fn ceil(self) -> Self;
}

macro_rules! num_int {
($ty:ty) => {
impl Round for $ty {
#[inline]
fn round(self) -> $ty {
self
}
}
impl Floor for $ty {
#[inline]
fn floor(self) -> $ty {
self
}
}
impl Ceil for $ty {
#[inline]
fn ceil(self) -> $ty {
self
}
}
};
}

macro_rules! num_float {
($ty:ty) => {
impl Round for $ty {
Expand All @@ -92,5 +115,14 @@ macro_rules! num_float {
}
};
}

num_int!(i16);
num_int!(u16);
num_int!(i32);
num_int!(u32);
num_int!(i64);
num_int!(u64);
num_int!(isize);
num_int!(usize);
num_float!(f32);
num_float!(f64);

0 comments on commit 27b7a27

Please sign in to comment.