https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110653
--- Comment #12 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to dave.anglin from comment #11) > Yes, this works. Great, thanks. > hppa64-hpux does not have have strtof. Could std::stof be implemented using > strtod in this case? Maybe something like this: --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -4153,6 +4153,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 inline float stof(const string& __str, size_t* __idx = 0) { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } +#else + inline float + stof(const string& __str, size_t* __idx = 0) + { + double __d = std::stod(__str, __idx); + if (__builtin_isfinite(__d)) + { + double __abs_d = __builtin_fabs(__d); + if (__abs_d < __FLT_MIN__) + errno = ERANGE; + else if (__abs_d > __FLT_MAX__) + { + errno = ERANGE; + float __f = __builtin_huge_valf(); + return __d > 0.0 ? __f : -__f; + } + } + return __d; + } #endif #if _GLIBCXX_USE_C99_STDLIB || _GLIBCXX_HAVE_STRTOLD > I'm thinking a test to check the presence and maybe compliance of these > routines might be good. We have some: testsuite/21_strings/basic_string/numeric_conversions/char/stof.cc testsuite/21_strings/basic_string/numeric_conversions/char/stold.cc But they depend on { dg-require-string-conversions "" } which is only true if we have the full set of them: return [check_v3_target_prop_cached et_string_conversions { set cond "_GLIBCXX_USE_C99_STDIO && _GLIBCXX_USE_C99_STDLIB" set cond "$cond && _GLIBCXX_USE_C99_WCHAR" set cond "$cond && !defined _GLIBCXX_HAVE_BROKEN_VSWPRINTF" return [v3_check_preprocessor_condition string_conversions $cond] }]