Fix division of zero by zero for Dec

This commit is contained in:
JRI98 2024-11-27 23:38:21 +00:00
parent 4217ffa333
commit 61ca278e31
No known key found for this signature in database
GPG key ID: F83B29916FF13F24
2 changed files with 12 additions and 5 deletions

View file

@ -437,16 +437,16 @@ pub const RocDec = extern struct {
const numerator_i128 = self.num;
const denominator_i128 = other.num;
// (0 / n) is always 0
if (numerator_i128 == 0) {
return RocDec{ .num = 0 };
}
// (n / 0) is an error
if (denominator_i128 == 0) {
roc_panic("Decimal division by 0!", 0);
}
// (0 / n) is always 0
if (numerator_i128 == 0) {
return RocDec{ .num = 0 };
}
// If they're both negative, or if neither is negative, the final answer
// is positive or zero. If one is negative and the denominator isn't, the
// final answer is negative (or zero, in which case final sign won't matter).