MCPcopy Create free account
hub / github.com/comaps/comaps / ToReal

Function ToReal

libs/base/string_utils.cpp:39–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37
38template <typename T>
39bool ToReal(char const * start, T & result)
40{
41 // Try faster implementation first.
42 double d;
43 // TODO(AB): replace with more robust dependency that doesn't use std::is_finite in the implementation.
44 char const * endptr = fast_double_parser::parse_number(start, &d);
45 if (endptr == nullptr)
46 {
47 // Fallback to our implementation, it supports numbers like "1."
48 char * stop;
49 result = RealConverter<T>(start, &stop);
50 if (*stop == 0 && start != stop && math::is_finite(result))
51 return true;
52 }
53 else if (*endptr == 0 && math::is_finite(d))
54 {
55 result = static_cast<T>(d);
56 return true;
57 }
58 // Do not parse strings that contain additional non-number characters.
59 return false;
60}
61
62} // namespace
63

Callers 2

to_floatFunction · 0.85
to_doubleFunction · 0.85

Calls 1

is_finiteFunction · 0.85

Tested by

no test coverage detected