X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fformat.c;h=3c407f4a85f3c0bb842e41a3cca37098b1a5850a;hb=refs%2Fbuilds%2F20110914030501%2Fpspp;hp=e15931ad1a2b4764547747945e9399305f2b8946;hpb=92c474055d5af5557c5f9341018f4e1642586af2;p=pspp diff --git a/src/data/format.c b/src/data/format.c index e15931ad1a..3c407f4a85 100644 --- a/src/data/format.c +++ b/src/data/format.c @@ -500,6 +500,7 @@ fmt_resize (struct fmt_spec *fmt, int width) void fmt_fix (struct fmt_spec *fmt, bool for_input) { + unsigned int step; int min_w, max_w; int max_d; @@ -511,18 +512,19 @@ fmt_fix (struct fmt_spec *fmt, bool for_input) else if (fmt->w > max_w) fmt->w = max_w; - /* First, if FMT has more decimal places than allowed, attempt - to increase FMT's width until that number of decimal places - can be achieved. */ - if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, for_input)) + /* Round width to step. */ + step = fmt_step_width (fmt->type); + fmt->w = ROUND_DOWN (fmt->w, step); + + /* If FMT has more decimal places than allowed, attempt to increase FMT's + width until that number of decimal places can be achieved. */ + if (fmt->d > fmt_max_decimals (fmt->type, fmt->w, for_input) + && fmt_takes_decimals (fmt->type)) { - int w; - for (w = fmt->w; w <= max_w; w++) - if (fmt_max_decimals (fmt->type, w, for_input) >= fmt->d) - { - fmt->w = w; - break; - } + int max_w = fmt_max_width (fmt->type, for_input); + for (; fmt->w < max_w; fmt->w++) + if (fmt->d <= fmt_max_decimals (fmt->type, fmt->w, for_input)) + break; } /* Clamp decimals to those allowed by format and width. */