From: John Darrington Date: Fri, 23 Mar 2012 10:15:11 +0000 (+0100) Subject: chart_rounded_tick: Avoid arithmetic problems with inputs close to zero X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8afe280ae36feb9ba7af31094f163795b84f2df8;p=pspp chart_rounded_tick: Avoid arithmetic problems with inputs close to zero --- 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) {