Add signum
Signed-off-by: Benjamin Schultzer <benjamin@schultzer.com>
This commit is contained in:
parent
99ef5a062a
commit
4f5e28166f
1 changed files with 20 additions and 4 deletions
|
|
@ -73,8 +73,7 @@ pub trait F32Ext: private::Sealed + Sized {
|
|||
|
||||
fn abs(self) -> Self;
|
||||
|
||||
// NOTE depends on unstable intrinsics::copysignf32
|
||||
// fn signum(self) -> Self;
|
||||
fn signum(self) -> Self;
|
||||
|
||||
fn mul_add(self, a: Self, b: Self) -> Self;
|
||||
|
||||
|
|
@ -178,6 +177,15 @@ impl F32Ext for f32 {
|
|||
fabsf(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn signum(self) -> Self {
|
||||
if self.is_nan() {
|
||||
f32::NAN
|
||||
} else {
|
||||
copysignf(1., self)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mul_add(self, a: Self, b: Self) -> Self {
|
||||
fmaf(self, a, b)
|
||||
|
|
@ -361,8 +369,7 @@ pub trait F64Ext: private::Sealed + Sized {
|
|||
|
||||
fn abs(self) -> Self;
|
||||
|
||||
// NOTE depends on unstable intrinsics::copysignf64
|
||||
// fn signum(self) -> Self;
|
||||
fn signum(self) -> Self;
|
||||
|
||||
fn mul_add(self, a: Self, b: Self) -> Self;
|
||||
|
||||
|
|
@ -466,6 +473,15 @@ impl F64Ext for f64 {
|
|||
fabs(self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn signum(self) -> Self {
|
||||
if self.is_nan() {
|
||||
f64::NAN
|
||||
} else {
|
||||
copysign(1., self)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn mul_add(self, a: Self, b: Self) -> Self {
|
||||
fma(self, a, b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue