From: John Darrington Date: Sun, 25 Mar 2012 22:37:07 +0000 (+0200) Subject: xrchart_write_scale: Use integer arithmetic X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=145c61f14ce6e1debe1ab756f60b677b0d1eeeaf;p=pspp xrchart_write_scale: Use integer arithmetic --- diff --git a/src/output/cairo-chart.c b/src/output/cairo-chart.c index 81c770354c..2f654390ab 100644 --- a/src/output/cairo-chart.c +++ b/src/output/cairo-chart.c @@ -317,15 +317,18 @@ xrchart_write_scale (cairo_t *cr, struct xrchart_geometry *geom, const double tick_interval = chart_rounded_tick ((smax - smin) / (double) ticks); - geom->axis[orient].max = ceil (smax / tick_interval) * tick_interval; - geom->axis[orient].min = floor (smin / tick_interval) * tick_interval; + int upper = ceil (smax / tick_interval); + int lower = floor (smin / tick_interval); + + geom->axis[orient].max = tick_interval * upper; + geom->axis[orient].min = tick_interval * lower; geom->axis[orient].scale = (fabs (geom->axis[orient].data_max - geom->axis[orient].data_min) / fabs (geom->axis[orient].max - geom->axis[orient].min)); - for (s = 0 ; s < (geom->axis[orient].max - geom->axis[orient].min) / tick_interval; ++s) + for (s = 0 ; s < upper - lower; ++s) { - double pos = s * tick_interval + geom->axis[orient].min; + double pos = (s + lower) * tick_interval; draw_tick (cr, geom, orient, s * tick_interval * geom->axis[orient].scale, "%g", pos); }