* lib/c-strtod.h (c_strtof): New declaration.
* lib/c-strtod.c: Support FLOAT.
* lib/c-strtof.c: New file.
* m4/c-strtod.m4 (gl_C_STRTOF): New macro.
* modules/c-strtof: New file.
+2024-02-21 Bruno Haible <bruno@clisp.org>
+
+ c-strtof: New module.
+ * lib/c-strtod.h (c_strtof): New declaration.
+ * lib/c-strtod.c: Support FLOAT.
+ * lib/c-strtof.c: New file.
+ * m4/c-strtod.m4 (gl_C_STRTOF): New macro.
+ * modules/c-strtof: New file.
+
2024-02-21 Bruno Haible <bruno@clisp.org>
c-strtold: Use strtold_l when available (regr. 2019-01-31).
-/* Convert string to double, using the C locale.
+/* Convert string to floating-point number, using the C locale.
Copyright (C) 2003-2004, 2006, 2009-2024 Free Software Foundation, Inc.
#include <stdlib.h>
#include <string.h>
-#if LONG
+#if FLOAT
+# define C_STRTOD c_strtof
+# define DOUBLE float
+# define STRTOD_L strtof_l
+# define HAVE_GOOD_STRTOD_L (HAVE_STRTOF_L && !GNULIB_defined_strtof_function)
+# define STRTOD strtof
+#elif LONG
# define C_STRTOD c_strtold
# define DOUBLE long double
# define STRTOD_L strtold_l
-/* Convert string to double, using the C locale. -*- coding: utf-8 -*-
+/* Convert string to floating-point number, using the C locale.
Copyright (C) 2003-2004, 2009-2024 Free Software Foundation, Inc.
parsed number or to NPTR if the string does not start with a parsable
number.
Return value:
- - If successful, return the value as a double or 'long double',
+ - If successful, return the value as a float, double, or 'long double',
respectively, and don't modify errno.
- In case of overflow, return ±HUGE_VAL or ±HUGE_VALL, respectively, and
set errno to ERANGE.
that if ENDPTR != NULL, *ENDPTR is set to NPTR), and maybe set errno to
EINVAL.
- In case of other error, return 0 and set errno, for example to ENOMEM. */
+extern float c_strtof (char const *nptr, char **endptr);
extern double c_strtod (char const *nptr, char **endptr);
extern long double c_strtold (char const *nptr, char **endptr);
#ifdef __cplusplus
}
#endif
+
+/*
+ * Hey Emacs!
+ * Local Variables:
+ * coding: utf-8
+ * End:
+ */
--- /dev/null
+/* Convert string to 'float' in C locale.
+
+ Copyright (C) 2004-2024 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
+
+ This file 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#define FLOAT 1
+#include "c-strtod.c"
-# c-strtod.m4 serial 19
+# c-strtod.m4 serial 20
# Copyright (C) 2004-2006, 2009-2024 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
[Define to 1 if the system has the 'strtod_l' function.])
])
+dnl Prerequisites of lib/c-strtof.c.
+AC_DEFUN([gl_C_STRTOF],
+[
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+ AC_REQUIRE([gt_FUNC_USELOCALE])
+
+ AC_CHECK_HEADERS_ONCE([xlocale.h])
+ dnl We can't use AC_CHECK_FUNC here, because strtof_l() is defined as a
+ dnl static inline function when compiling for Android 7.1 or older.
+ AC_CACHE_CHECK([for strtof_l], [gl_cv_func_strtof_l],
+ [AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdlib.h>
+ #include <locale.h>
+ #if HAVE_XLOCALE_H
+ # include <xlocale.h>
+ #endif
+ locale_t loc;
+ ]],
+ [[char *end;
+ return strtof_l("0",&end,loc) < 0.0f;
+ ]])
+ ],
+ [gl_cv_func_strtof_l=yes],
+ [gl_cv_func_strtof_l=no])
+ ])
+ if test $gl_cv_func_strtof_l = yes; then
+ HAVE_STRTOF_L=1
+ else
+ HAVE_STRTOF_L=0
+ fi
+ AC_DEFINE_UNQUOTED([HAVE_STRTOF_L], [$HAVE_STRTOF_L],
+ [Define to 1 if the system has the 'strtof_l' function.])
+])
+
dnl Prerequisites of lib/c-strtold.c.
AC_DEFUN([gl_C_STRTOLD],
[
--- /dev/null
+Description:
+Convert string to float in C locale.
+
+Files:
+lib/c-strtod.h
+lib/c-strtof.c
+lib/c-strtod.c
+m4/c-strtod.m4
+m4/intl-thread-locale.m4
+
+Depends-on:
+c99
+extensions
+locale
+strdup-posix
+strtof
+
+configure.ac:
+gl_C_STRTOF
+
+Makefile.am:
+lib_SOURCES += c-strtof.c
+
+Include:
+"c-strtod.h"
+
+License:
+GPL
+
+Maintainer:
+Paul Eggert, Jim Meyering