summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-10-19 20:54:10 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-10-19 20:54:10 +0200
commite59090089d997c3246757df118240c0886f31a4c (patch)
treea8935ba9c29be44fa2ec1e2a00309c61f2470d4b /options
parenta38e3f7c61004a0844fb6c300c0b77d39a683fa6 (diff)
options/slider: check for floating-point division by zero
It's not strictly necessary but a good practice nevertheless.
Diffstat (limited to 'options')
-rw-r--r--options/slider.cpp6
1 files changed, 5 insertions, 1 deletions
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