mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-19 04:25:03 +00:00
switch @panic to roc_panic to really throw panics for bad numeric ops
This commit is contained in:
parent
737d766841
commit
23e22693d4
2 changed files with 27 additions and 11 deletions
|
@ -369,7 +369,7 @@ pub const RocDec = extern struct {
|
|||
|
||||
// (n / 0) is an error
|
||||
if (denominator_i128 == 0) {
|
||||
@panic("TODO runtime exception for dividing by 0!");
|
||||
roc_panic("Decimal divison by 0", 0);
|
||||
}
|
||||
|
||||
// If they're both negative, or if neither is negative, the final answer
|
||||
|
@ -397,7 +397,8 @@ pub const RocDec = extern struct {
|
|||
if (denominator_i128 == one_point_zero_i128) {
|
||||
return self;
|
||||
} else {
|
||||
@panic("TODO runtime exception for overflow when dividing!");
|
||||
roc_panic("Decimal divison overflow in numerator", 0);
|
||||
unreachable;
|
||||
}
|
||||
};
|
||||
const numerator_u128 = @as(u128, @intCast(numerator_abs_i128));
|
||||
|
@ -410,7 +411,8 @@ pub const RocDec = extern struct {
|
|||
if (numerator_i128 == one_point_zero_i128) {
|
||||
return other;
|
||||
} else {
|
||||
@panic("TODO runtime exception for overflow when dividing!");
|
||||
roc_panic("Decimal divison overflow in denominator", 0);
|
||||
unreachable;
|
||||
}
|
||||
};
|
||||
const denominator_u128 = @as(u128, @intCast(denominator_abs_i128));
|
||||
|
@ -422,7 +424,7 @@ pub const RocDec = extern struct {
|
|||
if (answer.hi == 0 and answer.lo <= math.maxInt(i128)) {
|
||||
unsigned_answer = @as(i128, @intCast(answer.lo));
|
||||
} else {
|
||||
@panic("TODO runtime exception for overflow when dividing!");
|
||||
roc_panic("Decimal divison overflow", 0);
|
||||
}
|
||||
|
||||
return RocDec{ .num = if (is_answer_negative) -unsigned_answer else unsigned_answer };
|
||||
|
@ -632,7 +634,7 @@ fn mul_and_decimalize(a: u128, b: u128) i128 {
|
|||
const d = answer[0];
|
||||
|
||||
if (overflowed == 1) {
|
||||
@panic("TODO runtime exception for overflow!");
|
||||
roc_panic("Decimal multiplication overflow", 0);
|
||||
}
|
||||
|
||||
// Final 512bit value is d, c, b, a
|
||||
|
@ -1208,7 +1210,8 @@ pub fn fromF64C(arg: f64) callconv(.C) i128 {
|
|||
if (@call(.always_inline, RocDec.fromF64, .{arg})) |dec| {
|
||||
return dec.num;
|
||||
} else {
|
||||
@panic("TODO runtime exception failing convert f64 to RocDec");
|
||||
roc_panic("Decimal conversion from f64", 0);
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1217,7 +1220,8 @@ pub fn fromF32C(arg_f32: f32) callconv(.C) i128 {
|
|||
if (@call(.always_inline, RocDec.fromF64, .{arg_f64})) |dec| {
|
||||
return dec.num;
|
||||
} else {
|
||||
@panic("TODO runtime exception failing convert f64 to RocDec");
|
||||
roc_panic("Decimal conversion from f32", 0);
|
||||
unreachable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1232,7 +1236,8 @@ pub fn exportFromInt(comptime T: type, comptime name: []const u8) void {
|
|||
|
||||
const answer = @mulWithOverflow(this, RocDec.one_point_zero_i128);
|
||||
if (answer[1] == 1) {
|
||||
@panic("TODO runtime exception failing convert integer to RocDec");
|
||||
roc_panic("Decimal conversion from integer", 0);
|
||||
unreachable;
|
||||
} else {
|
||||
return answer[0];
|
||||
}
|
||||
|
@ -1258,11 +1263,17 @@ pub fn neqC(arg1: RocDec, arg2: RocDec) callconv(.C) bool {
|
|||
}
|
||||
|
||||
pub fn negateC(arg: RocDec) callconv(.C) i128 {
|
||||
return if (@call(.always_inline, RocDec.negate, .{arg})) |dec| dec.num else @panic("TODO overflow for negating RocDec");
|
||||
return if (@call(.always_inline, RocDec.negate, .{arg})) |dec| dec.num else {
|
||||
roc_panic("Decimal negation overflow", 0);
|
||||
unreachable;
|
||||
};
|
||||
}
|
||||
|
||||
pub fn absC(arg: RocDec) callconv(.C) i128 {
|
||||
const result = @call(.always_inline, RocDec.abs, .{arg}) catch @panic("TODO overflow for calling absolute value on RocDec");
|
||||
const result = @call(.always_inline, RocDec.abs, .{arg}) catch {
|
||||
roc_panic("Decimal absolute value overflow", 0);
|
||||
unreachable;
|
||||
};
|
||||
return result.num;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue