mirror of
https://github.com/roc-lang/roc.git
synced 2025-07-24 15:03:46 +00:00
Fix division of zero by zero for Dec
This commit is contained in:
parent
4217ffa333
commit
61ca278e31
2 changed files with 12 additions and 5 deletions
|
@ -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).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue