summaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-08-04 20:51:44 +0000
committerJakub Jelinek <jakub@redhat.com>2007-08-04 20:51:44 +0000
commit9452e30a05dd79850be35ba9886992f482761b1e (patch)
tree386776084a3fc4a14b2d560865dde715431d5e88 /stdlib
parente08057b1ff24258dd7460ad81e84491f7a28b424 (diff)
Updated to fedora-glibc-20070804T2027
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile3
-rw-r--r--stdlib/stdlib.h118
-rw-r--r--stdlib/strtod_l.c7
-rw-r--r--stdlib/tst-strtod5.c88
4 files changed, 94 insertions, 122 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index b4518b2bb3..7390647d8e 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -68,7 +68,7 @@ tests := tst-strtol tst-strtod testmb testrand testsort testdiv \
tst-limits tst-rand48 bug-strtod tst-setcontext \
test-a64l tst-qsort tst-system testmb2 bug-strtod2 \
tst-atof1 tst-atof2 tst-strtod2 tst-strtod3 tst-rand48-2 \
- tst-makecontext tst-strtod4
+ tst-makecontext tst-strtod4 tst-strtod5
include ../Makeconfig
@@ -115,6 +115,7 @@ test-canon-ARGS = --test-dir=${common-objpfx}stdlib
tst-strtod-ENV = LOCPATH=$(common-objpfx)localedata
tst-strtod3-ENV = LOCPATH=$(common-objpfx)localedata
tst-strtod4-ENV = LOCPATH=$(common-objpfx)localedata
+tst-strtod5-ENV = LOCPATH=$(common-objpfx)localedata
testmb2-ENV = LOCPATH=$(common-objpfx)localedata
# Run a test on the header files we use.
diff --git a/stdlib/stdlib.h b/stdlib/stdlib.h
index dd78744539..d475668926 100644
--- a/stdlib/stdlib.h
+++ b/stdlib/stdlib.h
@@ -273,125 +273,7 @@ extern long double strtold_l (__const char *__restrict __nptr,
#endif /* GNU */
-/* The internal entry points for `strtoX' take an extra flag argument
- saying whether or not to parse locale-dependent number grouping. */
-
-extern double __strtod_internal (__const char *__restrict __nptr,
- char **__restrict __endptr, int __group)
- __THROW __nonnull ((1)) __wur;
-extern float __strtof_internal (__const char *__restrict __nptr,
- char **__restrict __endptr, int __group)
- __THROW __nonnull ((1)) __wur;
-extern long double __strtold_internal (__const char *__restrict __nptr,
- char **__restrict __endptr,
- int __group)
- __THROW __nonnull ((1)) __wur;
-#ifndef __strtol_internal_defined
-extern long int __strtol_internal (__const char *__restrict __nptr,
- char **__restrict __endptr,
- int __base, int __group)
- __THROW __nonnull ((1)) __wur;
-# define __strtol_internal_defined 1
-#endif
-#ifndef __strtoul_internal_defined
-extern unsigned long int __strtoul_internal (__const char *__restrict __nptr,
- char **__restrict __endptr,
- int __base, int __group)
- __THROW __nonnull ((1)) __wur;
-# define __strtoul_internal_defined 1
-#endif
-#if defined __GNUC__ || defined __USE_ISOC99
-# ifndef __strtoll_internal_defined
-__extension__
-extern long long int __strtoll_internal (__const char *__restrict __nptr,
- char **__restrict __endptr,
- int __base, int __group)
- __THROW __nonnull ((1)) __wur;
-# define __strtoll_internal_defined 1
-# endif
-# ifndef __strtoull_internal_defined
-__extension__
-extern unsigned long long int __strtoull_internal (__const char *
- __restrict __nptr,
- char **__restrict __endptr,
- int __base, int __group)
- __THROW __nonnull ((1)) __wur;
-# define __strtoull_internal_defined 1
-# endif
-#endif /* GCC */
-
#ifdef __USE_EXTERN_INLINES
-/* Define inline functions which call the internal entry points. */
-
-__BEGIN_NAMESPACE_STD
-__extern_inline double
-__NTH (strtod (__const char *__restrict __nptr, char **__restrict __endptr))
-{
- return __strtod_internal (__nptr, __endptr, 0);
-}
-__extern_inline long int
-__NTH (strtol (__const char *__restrict __nptr, char **__restrict __endptr,
- int __base))
-{
- return __strtol_internal (__nptr, __endptr, __base, 0);
-}
-__extern_inline unsigned long int
-__NTH (strtoul (__const char *__restrict __nptr, char **__restrict __endptr,
- int __base))
-{
- return __strtoul_internal (__nptr, __endptr, __base, 0);
-}
-__END_NAMESPACE_STD
-
-# ifdef __USE_ISOC99
-__BEGIN_NAMESPACE_C99
-__extern_inline float
-__NTH (strtof (__const char *__restrict __nptr, char **__restrict __endptr))
-{
- return __strtof_internal (__nptr, __endptr, 0);
-}
-# ifndef __LDBL_COMPAT
-__extern_inline long double
-__NTH (strtold (__const char *__restrict __nptr, char **__restrict __endptr))
-{
- return __strtold_internal (__nptr, __endptr, 0);
-}
-# endif
-__END_NAMESPACE_C99
-# endif
-
-# ifdef __USE_BSD
-__extension__ __extern_inline long long int
-__NTH (strtoq (__const char *__restrict __nptr, char **__restrict __endptr,
- int __base))
-{
- return __strtoll_internal (__nptr, __endptr, __base, 0);
-}
-__extension__ __extern_inline unsigned long long int
-__NTH (strtouq (__const char *__restrict __nptr, char **__restrict __endptr,
- int __base))
-{
- return __strtoull_internal (__nptr, __endptr, __base, 0);
-}
-# endif
-
-# if defined __USE_MISC || defined __USE_ISOC99
-__BEGIN_NAMESPACE_C99
-__extension__ __extern_inline long long int
-__NTH (strtoll (__const char *__restrict __nptr, char **__restrict __endptr,
- int __base))
-{
- return __strtoll_internal (__nptr, __endptr, __base, 0);
-}
-__extension__ __extern_inline unsigned long long int
-__NTH (strtoull (__const char * __restrict __nptr, char **__restrict __endptr,
- int __base))
-{
- return __strtoull_internal (__nptr, __endptr, __base, 0);
-}
-__END_NAMESPACE_C99
-# endif
-
__BEGIN_NAMESPACE_STD
__extern_inline double
__NTH (atof (__const char *__nptr))
diff --git a/stdlib/strtod_l.c b/stdlib/strtod_l.c
index 4033e3bef8..939440f364 100644
--- a/stdlib/strtod_l.c
+++ b/stdlib/strtod_l.c
@@ -700,7 +700,8 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc)
#endif
/* If TP is at the start of the digits, there was no correctly
grouped prefix of the string; so no number found. */
- RETURN (0.0, tp == start_of_digits ? (base == 16 ? cp - 1 : nptr) : tp);
+ RETURN (negative ? -0.0 : 0.0,
+ tp == start_of_digits ? (base == 16 ? cp - 1 : nptr) : tp);
}
/* Remember first significant digit and read following characters until the
@@ -759,7 +760,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc)
if (tp < startp)
/* The number is validly grouped, but consists
only of zeroes. The whole value is zero. */
- RETURN (0.0, tp);
+ RETURN (negative ? -0.0 : 0.0, tp);
/* Recompute DIG_NO so we won't read more digits than
are properly grouped. */
@@ -862,7 +863,7 @@ ____STRTOF_INTERNAL (nptr, endptr, group, loc)
{
/* Overflow or underflow. */
__set_errno (ERANGE);
- result = (exp_negative ? 0.0 :
+ result = (exp_negative ? (negative ? -0.0 : 0.0) :
negative ? -FLOAT_HUGE_VAL : FLOAT_HUGE_VAL);
}
diff --git a/stdlib/tst-strtod5.c b/stdlib/tst-strtod5.c
new file mode 100644
index 0000000000..337c746989
--- /dev/null
+++ b/stdlib/tst-strtod5.c
@@ -0,0 +1,88 @@
+#include <locale.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#define NBSP "\xc2\xa0"
+
+static const struct
+{
+ const char *in;
+ int group;
+ double expected;
+} tests[] =
+ {
+ { "0", 0, 0.0 },
+ { "000", 0, 0.0 },
+ { "-0", 0, -0.0 },
+ { "-000", 0, -0.0 },
+ { "0,", 0, 0.0 },
+ { "-0,", 0, -0.0 },
+ { "0,0", 0, 0.0 },
+ { "-0,0", 0, -0.0 },
+ { "0e-10", 0, 0.0 },
+ { "-0e-10", 0, -0.0 },
+ { "0,e-10", 0, 0.0 },
+ { "-0,e-10", 0, -0.0 },
+ { "0,0e-10", 0, 0.0 },
+ { "-0,0e-10", 0, -0.0 },
+ { "0e-1000000", 0, 0.0 },
+ { "-0e-1000000", 0, -0.0 },
+ { "0,0e-1000000", 0, 0.0 },
+ { "-0,0e-1000000", 0, -0.0 },
+ { "0", 1, 0.0 },
+ { "000", 1, 0.0 },
+ { "-0", 1, -0.0 },
+ { "-000", 1, -0.0 },
+ { "0e-10", 1, 0.0 },
+ { "-0e-10", 1, -0.0 },
+ { "0e-1000000", 1, 0.0 },
+ { "-0e-1000000", 1, -0.0 },
+ { "000"NBSP"000"NBSP"000", 1, 0.0 },
+ { "-000"NBSP"000"NBSP"000", 1, -0.0 }
+ };
+#define NTESTS (sizeof (tests) / sizeof (tests[0]))
+
+
+static int
+do_test (void)
+{
+ if (setlocale (LC_ALL, "cs_CZ.UTF-8") == NULL)
+ {
+ puts ("could not set locale");
+ return 1;
+ }
+
+ int status = 0;
+
+ for (int i = 0; i < NTESTS; ++i)
+ {
+ char *ep;
+ double r;
+
+ if (tests[i].group)
+ r = __strtod_internal (tests[i].in, &ep, 1);
+ else
+ r = strtod (tests[i].in, &ep);
+
+ if (*ep != '\0')
+ {
+ printf ("%d: got rest string \"%s\", expected \"\"\n", i, ep);
+ status = 1;
+ }
+
+ if (r != tests[i].expected
+ || copysign (10.0, r) != copysign (10.0, tests[i].expected))
+ {
+ printf ("%d: got wrong results %g, expected %g\n",
+ i, r, tests[i].expected);
+ status = 1;
+ }
+ }
+
+ return status;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"