summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Ryde <user42@zip.com.au>2002-11-19 22:58:02 +0100
committerKevin Ryde <user42@zip.com.au>2002-11-19 22:58:02 +0100
commit1958e047ee6478cc49a17b3568e620c71bbb5414 (patch)
tree066ab11118e88a8200a45291d490fad5030aaf9f
parent0e83baa85df7a45ccea7f98b7366e5f2c3011c62 (diff)
downloadgmp-1958e047ee6478cc49a17b3568e620c71bbb5414.tar.gz
* gmp-impl.h (GMP_DECIMAL_POINT): New macro.
* mpf/out_str.c, mpf/set_str.c, scanf/doscan.c: Use it, and don't bother with special code for non-locale systems. * mpf/set_str.c, scanf/doscan.c: Cast through "unsigned char" for decimal point string, same as input chars.
-rw-r--r--mpf/set_str.c35
-rw-r--r--scanf/doscan.c22
2 files changed, 24 insertions, 33 deletions
diff --git a/mpf/set_str.c b/mpf/set_str.c
index 042034ae4..0673692ec 100644
--- a/mpf/set_str.c
+++ b/mpf/set_str.c
@@ -22,12 +22,18 @@ 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. */
+#define _GNU_SOURCE /* for DECIMAL_POINT in langinfo.h */
+
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#if HAVE_LANGINFO_H
+#include <langinfo.h> /* for nl_langinfo */
+#endif
+
#if HAVE_LOCALE_H
#include <locale.h> /* for localeconv */
#endif
@@ -55,20 +61,9 @@ digit_value_in_base (int c, int base)
return -1;
}
-#if HAVE_LOCALECONV
/* Avoid memcmp for the usual case that point is one character. Don't
bother with str+1,point+1,pointlen-1 since those offsets would add to the
code size. */
-#define POINTCMP_FAST(c, str) \
- ((c) == point0 \
- && (pointlen == 1 || memcmp (str, point, pointlen) == 0))
-#define POINTCMP_SMALL(c, str) (memcmp (str, point, pointlen) == 0)
-#define POINTLEN (pointlen)
-#else
-#define POINTCMP_FAST(c, str) ((c) == '.')
-#define POINTCMP_SMALL(c, str) ((c) == '.')
-#define POINTLEN 1
-#endif
int
mpf_set_str (mpf_ptr x, const char *str, int base)
@@ -82,11 +77,9 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
char *dotpos = 0;
int expflag;
int decimal_exponent_flag;
-#if HAVE_LOCALECONV
- const char *point = localeconv()->decimal_point;
+ const char *point = GMP_DECIMAL_POINT;
size_t pointlen = strlen (point);
- int point0 = point[0];
-#endif
+ int point0 = (unsigned char) point[0];
TMP_DECL (marker);
TMP_MARK (marker);
@@ -110,9 +103,9 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
/* require at least one digit, possibly after an initial decimal point */
if (digit_value_in_base (c, base == 0 ? 10 : base) < 0)
{
- if (! POINTCMP_SMALL (c, str))
+ if (memcmp (str, point, pointlen) != 0)
return -1;
- if (digit_value_in_base (str[POINTLEN], base == 0 ? 10 : base) < 0)
+ if (digit_value_in_base (str[pointlen], base == 0 ? 10 : base) < 0)
return -1;
}
@@ -158,7 +151,9 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
{
int dig;
- if (POINTCMP_FAST (c, str))
+ if (UNLIKELY (c == point0)
+ && (LIKELY (pointlen == 1)
+ || memcmp (str+1, point+1, pointlen-1) == 0))
{
if (dotpos != 0)
{
@@ -166,8 +161,8 @@ mpf_set_str (mpf_ptr x, const char *str, int base)
return -1;
}
dotpos = s;
- str += POINTLEN - 1;
- i += POINTLEN - 1;
+ str += pointlen - 1;
+ i += pointlen - 1;
}
else
{
diff --git a/scanf/doscan.c b/scanf/doscan.c
index 51a0e64d9..fb4b345ac 100644
--- a/scanf/doscan.c
+++ b/scanf/doscan.c
@@ -23,6 +23,8 @@ 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. */
+#define _GNU_SOURCE /* for DECIMAL_POINT in langinfo.h */
+
#include "config.h"
#if HAVE_STDARG
@@ -36,6 +38,10 @@ MA 02111-1307, USA. */
#include <stdio.h>
#include <string.h>
+#if HAVE_LANGINFO_H
+#include <langinfo.h> /* for nl_langinfo */
+#endif
+
#if HAVE_LOCALE_H
#include <locale.h> /* for localeconv */
#endif
@@ -235,21 +241,18 @@ gmpscan (const struct gmp_doscan_funs_t *funs, void *data,
/* decimal point */
if (p->type == 'F' && ! seen_point)
{
-#if HAVE_LOCALECONV
/* For a multi-character decimal point, if the first character is
present then all of it must be, otherwise the input is
considered invalid. */
- const char *point;
- int pc;
- point = localeconv()->decimal_point;
- pc = *point++;
+ const char *point = GMP_DECIMAL_POINT;
+ int pc = (unsigned char) *point++;
if (c == pc)
{
for (;;)
{
STORE (c);
GET (c);
- pc = *point++;
+ pc = (unsigned char) *point++;
if (pc == '\0')
break;
if (c != pc)
@@ -258,13 +261,6 @@ gmpscan (const struct gmp_doscan_funs_t *funs, void *data,
seen_point = 1;
goto digits;
}
-#else
- if (c == '.')
- {
- seen_point = 1;
- goto store_get_digits;
- }
-#endif
}
/* exponent */