1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fractions: panic when reciprocal produces invalid fraction

This commit is contained in:
Daren Liang 2019-11-11 15:37:32 -05:00 committed by Alexander Medvednikov
parent 79599b7564
commit bd34524a1c

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}
}