@@ -34,6 +34,7 @@
#include <string>
#include <memory_resource>
#include <cfenv>
+#include <cfloat>
#include <cmath>
#include <cstdlib>
#include <cstring>
@@ -52,6 +53,18 @@
extern "C" __ieee128 __strtoieee128(const char*, char**);
#endif
+#if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64
+# define USE_LIB_FAST_FLOAT 1
+#endif
+
+#if USE_LIB_FAST_FLOAT
+# define FASTFLOAT_DEBUG_ASSERT __glibcxx_assert
+namespace
+{
+# include "fast_float/fast_float.h"
+} // anon namespace
+#endif
+
#if _GLIBCXX_HAVE_USELOCALE
namespace std _GLIBCXX_VISIBILITY(default)
{
@@ -406,6 +419,11 @@ from_chars_result
from_chars(const char* first, const char* last, float& value,
chars_format fmt) noexcept
{
+#if USE_LIB_FAST_FLOAT
+ if (fmt != chars_format::hex)
+ return fast_float::from_chars(first, last, value, fmt);
+#endif
+
errc ec = errc::invalid_argument;
#if _GLIBCXX_USE_CXX11_ABI
buffer_resource mr;
@@ -432,6 +450,11 @@ from_chars_result
from_chars(const char* first, const char* last, double& value,
chars_format fmt) noexcept
{
+#if USE_LIB_FAST_FLOAT
+ if (fmt != chars_format::hex)
+ return fast_float::from_chars(first, last, value, fmt);
+#endif
+
errc ec = errc::invalid_argument;
#if _GLIBCXX_USE_CXX11_ABI
buffer_resource mr;