mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
Implement saturated add/subtract
This commit is contained in:
parent
4ea91b54eb
commit
2c41c43aea
10 changed files with 177 additions and 66 deletions
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue