pthread-once tests: Fix crash on mingw.
[gnulib.git] / tests / test-strtod1.c
blobc45313042b2b81b2e190193ae5116bc4cc472270
1 /* Test of strtod() in a French locale.
2 Copyright (C) 2019-2024 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/>. */
17 #include <config.h>
19 /* Specification. */
20 #include <stdlib.h>
22 #include <errno.h>
23 #include <locale.h>
25 #include "macros.h"
27 int
28 main (int argc, char *argv[])
30 /* Try to set the locale by implicitly looking at the LC_ALL environment
31 variable.
32 configure should already have checked that the locale is supported. */
33 if (setlocale (LC_ALL, "") == NULL)
34 return 1;
37 const char input[] = "1,";
38 char *ptr;
39 double result;
40 errno = 0;
41 result = strtod (input, &ptr);
42 ASSERT (result == 1.0);
43 ASSERT (ptr == input + 2);
44 ASSERT (errno == 0);
47 const char input[] = ",5";
48 char *ptr;
49 double result;
50 errno = 0;
51 result = strtod (input, &ptr);
52 ASSERT (result == 0.5);
53 ASSERT (ptr == input + 2);
54 ASSERT (errno == 0);
57 const char input[] = "1,5";
58 char *ptr;
59 double result;
60 errno = 0;
61 result = strtod (input, &ptr);
62 ASSERT (result == 1.5);
63 ASSERT (ptr == input + 3);
64 ASSERT (errno == 0);
67 const char input[] = "1.5";
68 char *ptr;
69 double result;
70 errno = 0;
71 result = strtod (input, &ptr);
72 /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
73 radix character. */
74 ASSERT ((ptr == input + 1 && result == 1.0)
75 || (ptr == input + 3 && result == 1.5));
76 ASSERT (errno == 0);
79 const char input[] = "123.456,789";
80 char *ptr;
81 double result;
82 errno = 0;
83 result = strtod (input, &ptr);
84 /* On AIX 7.2, in the French locale, '.' is recognized as an alternate
85 radix character. */
86 ASSERT ((ptr == input + 3 && result == 123.0)
87 || (ptr == input + 7 && result > 123.45 && result < 123.46));
88 ASSERT (errno == 0);
91 const char input[] = "123,456.789";
92 char *ptr;
93 double result;
94 errno = 0;
95 result = strtod (input, &ptr);
96 ASSERT (result > 123.45 && result < 123.46);
97 ASSERT (ptr == input + 7);
98 ASSERT (errno == 0);
101 return test_exit_status;