1 /* Test of strtod() in a French locale.
2 Copyright (C) 2019-2021 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 <https://www.gnu.org/licenses/>. */
27 main (int argc, char *argv[])
29 /* Try to set the locale by implicitly looking at the LC_ALL environment
31 configure should already have checked that the locale is supported. */
32 if (setlocale (LC_ALL, "") == NULL)
36 const char input[] = "1,";
40 result = strtod (input, &ptr);
41 ASSERT (result == 1.0);
42 ASSERT (ptr == input + 2);
46 const char input[] = ",5";
50 result = strtod (input, &ptr);
51 ASSERT (result == 0.5);
52 ASSERT (ptr == input + 2);
56 const char input[] = "1,5";
60 result = strtod (input, &ptr);
61 ASSERT (result == 1.5);
62 ASSERT (ptr == input + 3);
66 const char input[] = "1.5";
70 result = strtod (input, &ptr);
71 /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
73 ASSERT ((ptr == input + 1 && result == 1.0)
74 || (ptr == input + 3 && result == 1.5));
78 const char input[] = "123.456,789";
82 result = strtod (input, &ptr);
83 /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
85 ASSERT ((ptr == input + 3 && result == 123.0)
86 || (ptr == input + 7 && result > 123.45 && result < 123.46));
90 const char input[] = "123,456.789";
94 result = strtod (input, &ptr);
95 ASSERT (result > 123.45 && result < 123.46);
96 ASSERT (ptr == input + 7);