Skip to content

Commit a79da96

Browse files
authored
add trunc and fract to MathExt (#222)
1 parent 0f3948d commit a79da96

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

crates/spirv-std/src/math_ext.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub trait MathExt {
1111
fn ceil(self) -> Self;
1212
fn exp(self) -> Self;
1313
fn saturate(self) -> Self;
14+
fn trunc(self) -> Self;
15+
fn fract(self) -> Self;
1416

1517
fn signum(self) -> Self;
1618
fn copysign(self, sign: Self) -> Self;
@@ -71,6 +73,14 @@ impl MathExt for f32 {
7173
self.max(0.0).min(1.0)
7274
}
7375

76+
fn trunc(self) -> f32 {
77+
unsafe { core::intrinsics::truncf32(self) }
78+
}
79+
80+
fn fract(self) -> f32 {
81+
self - self.trunc()
82+
}
83+
7484
fn signum(self) -> f32 {
7585
if self.is_nan() {
7686
Self::NAN

0 commit comments

Comments
 (0)