From bd34524a1c2409f9bb0e7a4b337a2836163670c7 Mon Sep 17 00:00:00 2001 From: Daren Liang Date: Mon, 11 Nov 2019 15:37:32 -0500 Subject: [PATCH] fractions: panic when reciprocal produces invalid fraction --- vlib/math/fractions/fraction.v | 1 + 1 file changed, 1 insertion(+) diff --git a/vlib/math/fractions/fraction.v b/vlib/math/fractions/fraction.v index ac8a41853a..cc52cdc13c 100644 --- a/vlib/math/fractions/fraction.v +++ b/vlib/math/fractions/fraction.v @@ -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} }