Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 164f790

Browse files
committedJul 17, 2023
Fix Signum for no_std
1 parent 068eb43 commit 164f790

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
 

‎palette/src/num.rs

+1
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ macro_rules! impl_float {
716716
}
717717
}
718718

719+
#[cfg(feature = "std")]
719720
impl Signum for $ty {
720721
#[inline]
721722
fn signum(self) -> Self {

‎palette/src/num/libm.rs

+22
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,25 @@ impl MulAdd for f64 {
253253
::libm::fma(self, m, a)
254254
}
255255
}
256+
257+
impl Signum for f32 {
258+
#[inline]
259+
fn signum(self) -> Self {
260+
if self.is_nan() {
261+
Self::NAN
262+
} else {
263+
::libm::copysignf(1.0, self)
264+
}
265+
}
266+
}
267+
268+
impl Signum for f64 {
269+
#[inline]
270+
fn signum(self) -> Self {
271+
if self.is_nan() {
272+
Self::NAN
273+
} else {
274+
::libm::copysign(1.0, self)
275+
}
276+
}
277+
}

‎palette/src/num/wide.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ macro_rules! impl_wide_float {
302302
impl Signum for $ty {
303303
#[inline]
304304
fn signum(self) -> Self {
305-
$ty::copysign(self, Self::from(1.0))
305+
self.is_nan().blend(Self::from($scalar::NAN), $ty::copysign(Self::from(1.0), self))
306306
}
307307
}
308308
)+

0 commit comments

Comments
 (0)
Please sign in to comment.