Implement saturated add/subtract

This commit is contained in:
ayazhafiz 2022-01-10 22:37:08 -05:00
parent 4ea91b54eb
commit 2c41c43aea
10 changed files with 177 additions and 66 deletions

View file

@ -2155,3 +2155,39 @@ fn u8_mul_greater_than_i8() {
u8
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn add_saturated() {
assert_evals_to!(
indoc!(
r#"
x : U8
x = 200
y : U8
y = 200
Num.addSaturated x y
"#
),
255,
u8
)
}
#[test]
#[cfg(any(feature = "gen-llvm"))]
fn sub_saturated() {
assert_evals_to!(
indoc!(
r#"
x : U8
x = 10
y : U8
y = 20
Num.subSaturated x y
"#
),
0,
u8
)
}