1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
/* Test locale support, or attempt to do so.
Copyright 2001 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
The GNU MP Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or (at your
option) any later version.
The GNU MP Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the GNU MP Library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA. */
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_LOCALE_H
#include <locale.h> /* for lconv */
#endif
#include "gmp.h"
#include "gmp-impl.h"
#include "tests.h"
#if HAVE_LOCALECONV
char *decimal_point;
/* Replace the libc localeconv with one we can manipulate. */
struct lconv *
localeconv (void)
{
static struct lconv l;
l.decimal_point = decimal_point;
return &l;
}
void
check_input (void)
{
static char *point[] = {
".", ",", "xy", "xyz", "xyz***"
};
static const struct {
const char *str;
double d;
} data[] = {
{ "1%s", 1.0 },
{ "1%s0", 1.0 },
{ "1%s00", 1.0 },
{ "%s5", 0.5 },
{ "0%s5", 0.5 },
{ "00%s5", 0.5 },
{ "00%s50", 0.5 },
{ "1%s5", 1.5 },
{ "1%s5e1", 15.0 },
};
int i, j, neg;
char str[128];
mpf_t f;
double d;
mpf_init (f);
for (i = 0; i < numberof (point); i++)
{
decimal_point = point[i];
for (neg = 0; neg <= 1; neg++)
{
for (j = 0; j < numberof (data); j++)
{
strcpy (str, neg ? "-" : "");
sprintf (str+strlen(str), data[j].str, decimal_point);
d = data[j].d;
if (neg)
d = -d;
mpf_set_d (f, 123.0);
if (mpf_set_str (f, str, 10) != 0)
{
printf ("mpf_set_str error\n");
printf (" point %s\n", decimal_point);
printf (" str %s\n", str);
abort ();
}
if (mpf_cmp_d (f, d) != 0)
{
printf ("mpf_set_str wrong result\n");
printf (" point %s\n", decimal_point);
printf (" str %s\n", str);
mpf_trace (" f", f);
printf (" d=%g\n", d);
abort ();
}
mpf_set_d (f, 123.0);
if (gmp_sscanf (str, "%Ff", f) != 1)
{
printf ("gmp_sscanf wrong return value\n");
printf (" point %s\n", decimal_point);
printf (" str %s\n", str);
abort ();
}
if (mpf_cmp_d (f, d) != 0)
{
printf ("gmp_sscanf wrong result\n");
printf (" point %s\n", decimal_point);
printf (" str %s\n", str);
mpf_trace (" f", f);
printf (" d=%g\n", d);
abort ();
}
}
}
}
mpf_clear (f);
}
int
main (void)
{
/* The localeconv replacement breaks printf "%lu" on SunOS 4, so we can't
print the seed in tests_rand_start(). Nothing random is used in this
program though, so just use the memory tests alone. */
tests_memory_start ();
{
mpf_t f;
char buf[128];
mpf_init (f);
decimal_point = ",";
mpf_set_d (f, 1.5);
gmp_snprintf (buf, sizeof(buf), "%.1Ff", f);
if (strcmp (buf, "1,5") != 0)
{
printf ("Test skipped, replacing localeconv doesn't work\n");
goto done;
}
mpf_clear (f);
}
check_input ();
done:
tests_memory_end ();
exit (0);
}
#else
int
main (void)
{
printf ("Test skipped, no locale support\n");
exit (0);
}
#endif
|