mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
gen-dev: complete Num{Mul,Add,Sub}Saturated impls
MulSaturated and AddSaturated are now implemented for u128, i128 SubSaturated is now implemented for Dec even if it's a little strange to saturate at a decimal value: ``` » Num.subSaturated -170_141_183_460_469_231_731dec 1 -170141183460469231731.687303715884105728 : Dec ``` I decided to rm the `build_num_{mul,add}_saturated` methods because they don't require any asm-specifics. They either call out to bitcode, or use the non-saturated version for floats.
This commit is contained in:
parent
49ab969ff3
commit
8fd2fbc3a1
4 changed files with 231 additions and 192 deletions
|
@ -1758,7 +1758,7 @@ fn build_float_binop<'ctx>(
|
|||
};
|
||||
|
||||
match op {
|
||||
NumAdd => bd.new_build_float_add(lhs, rhs, "add_float").into(),
|
||||
NumAdd | NumAddSaturated => bd.new_build_float_add(lhs, rhs, "add_float").into(),
|
||||
NumAddChecked => {
|
||||
let context = env.context;
|
||||
|
||||
|
@ -1785,7 +1785,7 @@ fn build_float_binop<'ctx>(
|
|||
struct_value.into()
|
||||
}
|
||||
NumAddWrap => unreachable!("wrapping addition is not defined on floats"),
|
||||
NumSub => bd.new_build_float_sub(lhs, rhs, "sub_float").into(),
|
||||
NumSub | NumSubSaturated => bd.new_build_float_sub(lhs, rhs, "sub_float").into(),
|
||||
NumSubChecked => {
|
||||
let context = env.context;
|
||||
|
||||
|
@ -1812,8 +1812,7 @@ fn build_float_binop<'ctx>(
|
|||
struct_value.into()
|
||||
}
|
||||
NumSubWrap => unreachable!("wrapping subtraction is not defined on floats"),
|
||||
NumMul => bd.new_build_float_mul(lhs, rhs, "mul_float").into(),
|
||||
NumMulSaturated => bd.new_build_float_mul(lhs, rhs, "mul_float").into(),
|
||||
NumMul | NumMulSaturated => bd.new_build_float_mul(lhs, rhs, "mul_float").into(),
|
||||
NumMulChecked => {
|
||||
let context = env.context;
|
||||
|
||||
|
@ -1855,7 +1854,7 @@ fn build_float_binop<'ctx>(
|
|||
&bitcode::NUM_POW[float_width],
|
||||
),
|
||||
_ => {
|
||||
unreachable!("Unrecognized int binary operation: {:?}", op);
|
||||
unreachable!("Unrecognized float binary operation: {:?}", op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2286,6 +2285,9 @@ fn build_dec_binop<'a, 'ctx>(
|
|||
rhs,
|
||||
"Decimal multiplication overflowed",
|
||||
),
|
||||
NumAddSaturated => dec_binary_op(env, bitcode::DEC_ADD_SATURATED, lhs, rhs),
|
||||
NumSubSaturated => dec_binary_op(env, bitcode::DEC_SUB_SATURATED, lhs, rhs),
|
||||
NumMulSaturated => dec_binary_op(env, bitcode::DEC_MUL_SATURATED, lhs, rhs),
|
||||
NumDivFrac => dec_binop_with_unchecked(env, bitcode::DEC_DIV, lhs, rhs),
|
||||
|
||||
NumLt => call_bitcode_fn(env, &[lhs, rhs], &bitcode::NUM_LESS_THAN[IntWidth::I128]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue