Skip to content

Commit

Permalink
Fix no_std build failure
Browse files Browse the repository at this point in the history
{f32|f64}::round() does not exist with just core, so libm's
implementation is used instead when the `std` feature is not activated.
  • Loading branch information
CryZe committed Aug 10, 2019
1 parent 483b57a commit f913c35
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions palette/src/float.rs
Expand Up @@ -57,6 +57,8 @@ mod no_std_float_trait {
/// `y.atan2(x)` computes the inverse tangent of `y / x`, in the
/// corresponding quadrant
fn atan2(self, other: Self) -> Self;
/// `x.round()` returns the nearest integer to a number. Round half-way cases away from 0.0.
fn round(self) -> Self;
}

impl Float for f32 {
Expand All @@ -78,6 +80,9 @@ mod no_std_float_trait {
fn atan2(self, other: f32) -> f32 {
F32Ext::atan2(self, other)
}
fn round(self) -> f32 {
F32Ext::round(self)
}
}

impl Float for f64 {
Expand All @@ -99,5 +104,8 @@ mod no_std_float_trait {
fn atan2(self, other: f64) -> f64 {
F64Ext::atan2(self, other)
}
fn round(self) -> f64 {
F64Ext::round(self)
}
}
}
12 changes: 6 additions & 6 deletions palette/src/lib.rs
Expand Up @@ -550,7 +550,7 @@ impl Component for f32 {
let scaled = *self * cast::<f32, _>(T::max_intensity());

if T::LIMITED {
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
cast(clamp(Float::round(scaled), 0.0, cast(T::max_intensity())))
} else {
cast(scaled)
}
Expand All @@ -568,7 +568,7 @@ impl Component for f64 {
let scaled = *self * cast::<f64, _>(T::max_intensity());

if T::LIMITED {
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
cast(clamp(Float::round(scaled), 0.0, cast(T::max_intensity())))
} else {
cast(scaled)
}
Expand All @@ -587,7 +587,7 @@ impl Component for u8 {
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));

if T::LIMITED {
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
cast(clamp(Float::round(scaled), 0.0, cast(T::max_intensity())))
} else {
cast(scaled)
}
Expand All @@ -606,7 +606,7 @@ impl Component for u16 {
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));

if T::LIMITED {
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
cast(clamp(Float::round(scaled), 0.0, cast(T::max_intensity())))
} else {
cast(scaled)
}
Expand All @@ -625,7 +625,7 @@ impl Component for u32 {
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));

if T::LIMITED {
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
cast(clamp(Float::round(scaled), 0.0, cast(T::max_intensity())))
} else {
cast(scaled)
}
Expand All @@ -644,7 +644,7 @@ impl Component for u64 {
* (cast::<f64, _>(*self) / cast::<f64, _>(Self::max_intensity()));

if T::LIMITED {
cast(clamp(scaled.round(), 0.0, cast(T::max_intensity())))
cast(clamp(Float::round(scaled), 0.0, cast(T::max_intensity())))
} else {
cast(scaled)
}
Expand Down

0 comments on commit f913c35

Please sign in to comment.