Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2012-11-07 15:28:50 +0400
committerCampbell Barton <ideasman42@gmail.com>2012-11-07 15:28:50 +0400
commitf6c159654ff28c29dcc0c52bbe3152af966fb02e (patch)
tree4520ef5d58d07fe2b8d133f1bdd3edec29155e6f /source
parenta10ed84bf44b59c97639bf44f28b5afbfa24b0c7 (diff)
prevent floating point exceptions from being raised in soft_range_round_up/soft_range_round_down(), caused by log(0).
Diffstat (limited to 'source')
-rw-r--r--source/blender/editors/interface/interface.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index b8e4fec1259..c6e25ab9a34 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -1902,8 +1902,9 @@ void ui_set_but_default(bContext *C, short all)
static double soft_range_round_up(double value, double max)
{
- /* round up to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
- double newmax = pow(10.0, ceil(log(value) / M_LN10));
+ /* round up to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, ..
+ * checking for 0.0 prevents floating point exceptions */
+ double newmax = (value != 0.0) ? pow(10.0, ceil(log(value) / M_LN10)) : 0.0;
if (newmax * 0.2 >= max && newmax * 0.2 >= value)
return newmax * 0.2;
@@ -1915,8 +1916,9 @@ static double soft_range_round_up(double value, double max)
static double soft_range_round_down(double value, double max)
{
- /* round down to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, .. */
- double newmax = pow(10.0, floor(log(value) / M_LN10));
+ /* round down to .., 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, ..
+ * checking for 0.0 prevents floating point exceptions */
+ double newmax = (value != 0.0) ? pow(10.0, floor(log(value) / M_LN10)) : 0.0;
if (newmax * 5.0 <= max && newmax * 5.0 <= value)
return newmax * 5.0;