add trunc and fract to MathExt (#222)

This commit is contained in:
Gray Olson 2020-11-13 02:20:12 -07:00 committed by GitHub
parent 0f3948dc27
commit a79da96307
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,8 @@ pub trait MathExt {
fn ceil(self) -> Self;
fn exp(self) -> Self;
fn saturate(self) -> Self;
fn trunc(self) -> Self;
fn fract(self) -> Self;
fn signum(self) -> Self;
fn copysign(self, sign: Self) -> Self;
@ -71,6 +73,14 @@ impl MathExt for f32 {
self.max(0.0).min(1.0)
}
fn trunc(self) -> f32 {
unsafe { core::intrinsics::truncf32(self) }
}
fn fract(self) -> f32 {
self - self.trunc()
}
fn signum(self) -> f32 {
if self.is_nan() {
Self::NAN