work on docs
[pspp] / src / libpspp / misc.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18 #include "misc.h"
19 #include <gl/ftoastr.h>
20
21 /* Returns the number of digits in X. */
22 int
23 intlog10 (unsigned x)
24 {
25   int digits = 0;
26
27   do
28     {
29       digits++;
30       x /= 10;
31     }
32   while (x > 0);
33
34   return digits;
35 }
36
37
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)
41 {
42   int i;
43   int result = dtoastr (buf, bufsize, flags, width, x);
44
45   /* Replace the first , (if any) by a . */
46   for (i = 0; i < result; ++i)
47     {
48       if (buf[i] == ',')
49         {
50           buf[i] = '.';
51           break;
52         }
53     }
54
55   return result;
56 }