mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
throws subtraction overflow error for floats
This commit is contained in:
parent
59b850ba50
commit
5d2abc2bd2
2 changed files with 50 additions and 14 deletions
|
@ -3424,7 +3424,29 @@ fn build_float_binop<'a, 'ctx, 'env>(
|
|||
struct_value.into()
|
||||
}
|
||||
NumAddWrap => unreachable!("wrapping addition is not defined on floats"),
|
||||
NumSub => bd.build_float_sub(lhs, rhs, "sub_float").into(),
|
||||
NumSub => {
|
||||
let builder = env.builder;
|
||||
let context = env.context;
|
||||
|
||||
let result = bd.build_float_sub(lhs, rhs, "sub_float");
|
||||
|
||||
let is_finite =
|
||||
call_bitcode_fn(env, &[result.into()], &bitcode::NUM_IS_FINITE).into_int_value();
|
||||
|
||||
let then_block = context.append_basic_block(parent, "then_block");
|
||||
let throw_block = context.append_basic_block(parent, "throw_block");
|
||||
|
||||
builder.build_conditional_branch(is_finite, then_block, throw_block);
|
||||
|
||||
builder.position_at_end(throw_block);
|
||||
|
||||
throw_exception(env, "float subtraction overflowed!");
|
||||
|
||||
builder.position_at_end(then_block);
|
||||
|
||||
result.into()
|
||||
}
|
||||
NumSubWrap => unreachable!("wrapping subtraction is not defined on floats"),
|
||||
NumMul => bd.build_float_mul(lhs, rhs, "mul_float").into(),
|
||||
NumGt => bd.build_float_compare(OGT, lhs, rhs, "float_gt").into(),
|
||||
NumGte => bd.build_float_compare(OGE, lhs, rhs, "float_gte").into(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue