From 8afe280ae36feb9ba7af31094f163795b84f2df8 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 23 Mar 2012 11:15:11 +0100 Subject: [PATCH] chart_rounded_tick: Avoid arithmetic problems with inputs close to zero --- src/math/chart-geometry.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/math/chart-geometry.c b/src/math/chart-geometry.c index 736f89934b..573459892e 100644 --- a/src/math/chart-geometry.c +++ b/src/math/chart-geometry.c @@ -25,7 +25,6 @@ double chart_rounded_tick(double tick) { - int i; double diff = DBL_MAX; @@ -33,7 +32,13 @@ chart_rounded_tick(double tick) static const double standard_ticks[] = {1, 2, 5, 10}; - const double factor = pow(10,ceil(log10(standard_ticks[0] / tick))) ; + double factor; + + /* Avoid arithmetic problems with very small values */ + if (abs (tick) < DBL_EPSILON) + return 0; + + factor = pow(10,ceil(log10(standard_ticks[0] / tick))) ; for (i = 3 ; i >= 0 ; --i) { -- 2.30.2