pivot-output: Fix crash when layers axis has no leaves.
[pspp.git] / src / libpspp / misc.c
blobcd2c2cfcf1a979e9fce0d58289b3e76b8be434b1
1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #include <config.h>
18 #include "misc.h"
19 #include <gl/ftoastr.h>
21 /* Returns the number of digits in X. */
22 int
23 intlog10 (unsigned x)
25 int digits = 0;
29 digits++;
30 x /= 10;
32 while (x > 0);
34 return digits;
38 /* A locale independent version of dtoastr (from gnulib) */
39 int
40 c_dtoastr (char *buf, size_t bufsize, int flags, int width, double x)
42 int i;
43 int result = dtoastr (buf, bufsize, flags, width, x);
45 /* Replace the first , (if any) by a . */
46 for (i = 0; i < result; ++i)
48 if (buf[i] == ',')
50 buf[i] = '.';
51 break;
55 return result;