From e6d5805a0256f196082f9d9701fbd7aa3871c8b8 Mon Sep 17 00:00:00 2001 From: Gray Olson Date: Tue, 10 Nov 2020 14:32:05 -0700 Subject: [PATCH] add trunc and fract to MathExt --- crates/spirv-std/src/math_ext.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/spirv-std/src/math_ext.rs b/crates/spirv-std/src/math_ext.rs index f196cd086c..c5b5495d9d 100644 --- a/crates/spirv-std/src/math_ext.rs +++ b/crates/spirv-std/src/math_ext.rs @@ -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