fractions: panic when reciprocal produces invalid fraction

pull/2737/head
Daren Liang 2019-11-11 15:37:32 -05:00 committed by Alexander Medvednikov
parent 79599b7564
commit bd34524a1c
1 changed files with 1 additions and 0 deletions

View File

@ -79,6 +79,7 @@ pub fn (f1 Fraction) divide(f2 Fraction) Fraction {
// Fraction reciprocal method
pub fn (f1 Fraction) reciprocal() Fraction {
if f1.n == 0 { panic('Denominator cannot be zero') }
return Fraction{f1.d, f1.n}
}