Function atof

Synopsis

#include <src/c4/charconv.hpp>

bool atof(csubstr str, float *C4_RESTRICT v)

Description

Convert a string to a single precision real number. The input string must be trimmed to the value, ie no leading or trailing whitespace can be present.

Returns
true iff the conversion succeeded
See
atof_first() if the string is not trimmed

Mentioned in

Source

Lines 1184-1199 in src/c4/charconv.hpp.

inline bool atof(csubstr str, float * C4_RESTRICT v)
{
    C4_ASSERT(str == str.first_real_span());
#if C4CORE_HAVE_FAST_FLOAT
    fast_float::from_chars_result result;
    result = fast_float::from_chars(str.str, str.str + str.len, *v);
    return result.ec == std::errc();
#elif C4CORE_HAVE_STD_FROMCHARS
    std::from_chars_result result;
    result = std::from_chars(str.str, str.str + str.len, *v);
    return result.ec == std::errc();
#else
    size_t ret = detail::scan_one(str, "f", v);
    return ret != csubstr::npos;
#endif
}





Add Discussion as Guest

Log in