Parse a floating point number from a character buffer.
- Parameters
-
| str | The character buffer to parse |
| len | The length of the buffer |
- Returns
- The parsed float value (0.0f if parsing fails)
Definition at line 199 of file charconv.cpp.hpp.
199 {
202 float fraction = 0.0f;
203 float divisor = 1.0f;
204 int isFractional = 0;
205
207
208
209 if (len == 0) {
210 return 0.0f;
211 }
212
213
215 (str[
pos] ==
' ' || str[
pos] ==
'\t' || str[
pos] ==
'\n' ||
216 str[
pos] ==
'\r' || str[
pos] ==
'\f' || str[
pos] ==
'\v')) {
218 }
219
220
221 if (
pos < len && str[
pos] ==
'-') {
224 }
else if (
pos < len && str[
pos] ==
'+') {
226 }
227
228
230 if (str[
pos] >=
'0' && str[
pos] <=
'9') {
231 if (isFractional) {
232 divisor *= 10.0f;
233 fraction += (str[
pos] -
'0') / divisor;
234 } else {
236 }
237 }
else if (str[
pos] ==
'.' && !isFractional) {
238 isFractional = 1;
239 } else {
240
241 break;
242 }
244 }
245
246
248
249
251}
constexpr enable_if< is_fixed_point< T >::value, int >::type sign(T x) FL_NOEXCEPT
expected< T, E > result
Alias for expected (Rust-style naming)
References pos, and sign().
Referenced by fl::float_conversion_visitor< FloatType >::operator()(), fl::float_conversion_visitor< double >::operator()(), and fl::basic_string::toFloat().