| 179 | |
| 180 | |
| 181 | qreal 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 | |
| 199 | bool parser_isAnySizedReal(string str) { |
no test coverage detected