mirror of
https://github.com/ziglang/zig.git
synced 2026-01-03 20:13:21 +00:00
pass division by zero test
This commit is contained in:
parent
6caf32195a
commit
8d27a02705
19
src/ir.cpp
19
src/ir.cpp
@ -6915,6 +6915,25 @@ static int ir_eval_bignum(ConstExprValue *op1_val, ConstExprValue *op2_val,
|
||||
ConstExprValue *out_val, bool (*bignum_fn)(BigNum *, BigNum *, BigNum *),
|
||||
TypeTableEntry *type, bool wrapping_op)
|
||||
{
|
||||
bool is_int = false;
|
||||
bool is_float = false;
|
||||
if (bignum_fn == bignum_div || bignum_fn == bignum_mod) {
|
||||
if (type->id == TypeTableEntryIdInt ||
|
||||
type->id == TypeTableEntryIdNumLitInt)
|
||||
{
|
||||
is_int = true;
|
||||
} else if (type->id == TypeTableEntryIdFloat ||
|
||||
type->id == TypeTableEntryIdNumLitFloat)
|
||||
{
|
||||
is_float = true;
|
||||
}
|
||||
if ((is_int && op2_val->data.x_bignum.data.x_uint == 0) ||
|
||||
(is_float && op2_val->data.x_bignum.data.x_float == 0.0))
|
||||
{
|
||||
return ErrorDivByZero;
|
||||
}
|
||||
}
|
||||
|
||||
bool overflow = bignum_fn(&out_val->data.x_bignum, &op1_val->data.x_bignum, &op2_val->data.x_bignum);
|
||||
if (overflow) {
|
||||
return ErrorOverflow;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user