fractions: panic when reciprocal produces invalid fraction
parent
79599b7564
commit
bd34524a1c
|
@ -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}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue