MCPcopy Create free account
hub / github.com/QuEST-Kit/QuEST / precisionAgnosticStringToFloat

Function precisionAgnosticStringToFloat

quest/src/core/parser.cpp:181–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

179
180
181qreal precisionAgnosticStringToFloat(string str) {
182
183 // remove whitespace which stold() et al cannot handle after the sign.
184 // beware this means that e.g. "1 0" (invalid number) would become "10"
185 // (valid) so this function cannot be used for duck-typing, though that
186 // is anyway the case since stold() et al permit "10abc"
187 removeWhiteSpace(str);
188
189 // below throws exception when the (prefix) of str cannot be/fit into a qreal
190 if (FLOAT_PRECISION == 1) return static_cast<qreal>(std::stof (str));
191 if (FLOAT_PRECISION == 2) return static_cast<qreal>(std::stod (str));
192 if (FLOAT_PRECISION == 4) return static_cast<qreal>(std::stold(str));
193
194 // unreachable
195 return -1;
196}
197
198
199bool parser_isAnySizedReal(string str) {

Callers 4

parser_isValidRealFunction · 0.85
parser_parseRealFunction · 0.85
parser_isValidComplexFunction · 0.85

Calls 1

removeWhiteSpaceFunction · 0.85

Tested by

no test coverage detected