Add signum

Signed-off-by: Benjamin Schultzer <benjamin@schultzer.com>
This commit is contained in:
Benjamin Schultzer 2019-07-02 11:56:38 -07:00
parent 99ef5a062a
commit 4f5e28166f

View file

@ -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)