From e59090089d997c3246757df118240c0886f31a4c Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 19 Oct 2016 20:54:10 +0200 Subject: options/slider: check for floating-point division by zero It's not strictly necessary but a good practice nevertheless. --- options/slider.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'options/slider.cpp') diff --git a/options/slider.cpp b/options/slider.cpp index 9cbe373c..147496cb 100644 --- a/options/slider.cpp +++ b/options/slider.cpp @@ -78,8 +78,12 @@ slider_value slider_value::update_from_slider(int pos, int q_min, int q_max) con int slider_value::to_slider_pos(int q_min, int q_max) const { const int q_diff = q_max - q_min; + const double div = max() - min(); - return int(std::round(((cur() - min()) * q_diff / (max() - min())) + q_min)); + if (std::fabs(div) < 1e-4) + return q_min; + else + return int(std::round(((cur() - min()) * q_diff / div) + q_min)); } } // end ns options -- cgit v1.2.3