1 /* Test of c_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/>. */
28 main (int argc
, char *argv
[])
30 /* Try to set the locale by implicitly looking at the LC_ALL environment
32 configure should already have checked that the locale is supported. */
33 if (setlocale (LC_ALL
, "") == NULL
)
37 const char input
[] = "1.";
41 result
= c_strtod (input
, &ptr
);
42 ASSERT (result
== 1.0);
43 ASSERT (ptr
== input
+ 2);
47 const char input
[] = ".5";
51 result
= c_strtod (input
, &ptr
);
52 ASSERT (result
== 0.5);
53 ASSERT (ptr
== input
+ 2);
57 const char input
[] = "1.5";
61 result
= c_strtod (input
, &ptr
);
62 ASSERT (result
== 1.5);
63 ASSERT (ptr
== input
+ 3);
67 const char input
[] = "1,5";
71 result
= c_strtod (input
, &ptr
);
72 ASSERT (result
== 1.0);
73 ASSERT (ptr
== input
+ 1);
77 const char input
[] = "123,456.789";
81 result
= c_strtod (input
, &ptr
);
82 ASSERT (result
== 123.0);
83 ASSERT (ptr
== input
+ 3);
87 const char input
[] = "123.456,789";
91 result
= c_strtod (input
, &ptr
);
92 ASSERT (result
> 123.45 && result
< 123.46);
93 ASSERT (ptr
== input
+ 7);
97 return test_exit_status
;