1 /* Test locale support, or attempt to do so.
3 Copyright 2001, 2002 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
20 #define _GNU_SOURCE /* for DECIMAL_POINT in glibc langinfo.h */
29 #include <nl_types.h> /* for nl_item (on netbsd 1.4.1 at least) */
33 #include <langinfo.h> /* for nl_langinfo */
37 #include <locale.h> /* for lconv */
47 /* Replace the libc localeconv with one we can manipulate. */
52 static struct lconv l;
53 l.decimal_point = decimal_point;
58 /* Replace the libc nl_langinfo with one we can manipulate. */
61 nl_langinfo (nl_item n)
63 #if defined (DECIMAL_POINT)
64 if (n == DECIMAL_POINT)
67 #if defined (RADIXCHAR)
78 static char *point[] = {
79 ".", ",", "WU", "STR", "ZTV***"
107 for (i = 0; i < numberof (point); i++)
109 decimal_point = point[i];
111 for (neg = 0; neg <= 1; neg++)
113 for (j = 0; j < numberof (data); j++)
115 strcpy (str, neg ? "-" : "");
116 sprintf (str+strlen(str), data[j].str, decimal_point);
122 mpf_set_d (f, 123.0);
123 if (mpf_set_str (f, str, 10) != 0)
125 printf ("mpf_set_str error\n");
126 printf (" point %s\n", decimal_point);
127 printf (" str %s\n", str);
130 if (mpf_cmp_d (f, d) != 0)
132 printf ("mpf_set_str wrong result\n");
133 printf (" point %s\n", decimal_point);
134 printf (" str %s\n", str);
136 printf (" d=%g\n", d);
140 mpf_set_d (f, 123.0);
141 ret = gmp_sscanf (str, "%Ff", f);
144 printf ("gmp_sscanf wrong return value\n");
145 printf (" point %s\n", decimal_point);
146 printf (" str %s\n", str);
147 printf (" ret %d\n", ret);
150 if (mpf_cmp_d (f, d) != 0)
152 printf ("gmp_sscanf wrong result\n");
153 printf (" point %s\n", decimal_point);
154 printf (" str %s\n", str);
156 printf (" d=%g\n", d);
168 /* The localeconv replacement breaks printf "%lu" on SunOS 4, so we can't
169 print the seed in tests_rand_start(). Nothing random is used in this
170 program though, so just use the memory tests alone. */
171 tests_memory_start ();
179 gmp_snprintf (buf, sizeof(buf), "%.1Ff", f);
181 if (strcmp (buf, "1,5") != 0)
183 printf ("Test skipped, replacing localeconv/nl_langinfo doesn't work\n");