Function atod

Synopsis

#include <src/c4/charconv.hpp>

bool atod(csubstr str, double *C4_RESTRICT v)

Description

Convert a string to a double 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
atod_first() if the string is not trimmed

Mentioned in

Source

Lines 1208-1223 in src/c4/charconv.hpp.

inline bool atod(csubstr str, double * 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, "lf", v);
    return ret != csubstr::npos;
#endif
}





Add Discussion as Guest

Log in