Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no_std build failure #138

Merged
merged 1 commit into from Aug 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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