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