FastLED
3.10.8
Loading...
Searching...
No Matches
◆
operator()()
[6/13]
void
fl::float_conversion_visitor
< double >::operator()
(
const
fl::string
&
str
)
inline
Definition at line
480
of file
types.h
.
480
{
481
// NEW INSTRUCTIONS: AUTO CONVERT STRING TO FLOAT
482
// Try to parse the string as a float using FastLED's StringFormatter
483
// Validate by checking if string contains valid float characters
484
bool
isValidFloat
=
true
;
485
bool
hasDecimal
=
false
;
486
fl::size
startPos
= 0;
487
488
// Check for sign
489
if
(
str
.length() > 0 && (
str
[0] ==
'+'
||
str
[0] ==
'-'
)) {
490
startPos
= 1;
491
}
492
493
// Check that all remaining characters are valid for a float
494
for
(
fl::size
i
=
startPos
;
i
<
str
.length();
i
++) {
495
char
c
=
str
[
i
];
496
if
(
c
==
'.'
) {
497
if
(
hasDecimal
) {
498
// Multiple decimal points
499
isValidFloat
=
false
;
500
break
;
501
}
502
hasDecimal
=
true
;
503
}
else
if
(!
fl::isdigit
(
c
) &&
c
!=
'e'
&&
c
!=
'E'
) {
504
isValidFloat
=
false
;
505
break
;
506
}
507
}
508
509
// If it looks like a valid float, try to parse it
510
if
(
isValidFloat
&&
str
.length() > 0) {
511
// For simple cases, we can use a more precise approach
512
// Check if it's a simple decimal number
513
bool
isSimpleDecimal
=
true
;
514
for
(
fl::size
i
=
startPos
;
i
<
str
.length();
i
++) {
515
char
c
=
str
[
i
];
516
if
(
c
!=
'.'
&& !
fl::isdigit
(
c
)) {
517
isSimpleDecimal
=
false
;
518
break
;
519
}
520
}
521
522
#if FL_PLATFORM_HAS_LARGE_MEMORY
523
if
(
isSimpleDecimal
) {
524
// For simple decimals, we can do a more direct conversion
525
float
parsed
=
fl::parseFloat
(
str
.c_str(),
str
.length());
526
result
=
static_cast<
FloatType
>
(
parsed
);
527
}
else
{
528
// For complex floats (with exponents), use the standard approach
529
float
parsed
=
fl::parseFloat
(
str
.c_str(),
str
.length());
530
result
=
static_cast<
FloatType
>
(
parsed
);
531
}
532
#else
533
// Low-memory gate per FastLED #3224 Tier 1A: drop the string -> float
534
// path. `fl::parseFloat` uses float arithmetic (mul/add/div) which
535
// anchors `__aeabi_fmul / fadd / fsub / fdiv` (~4.5 KB of single-prec
536
// soft-FP on no-FPU targets). The integer-only LPC8xx RPC contract
537
// never receives JSON float strings, so saturate to zero.
538
(
void
)
isSimpleDecimal
;
539
result
=
static_cast<
FloatType
>
(0);
540
#endif
541
}
542
}
fl::parseFloat
float parseFloat(const char *str, fl::size len) FL_NO_EXCEPT
Parse a floating point number from a character buffer.
Definition
charconv.cpp.hpp:199
fl::float_conversion_visitor< double >::result
fl::optional< double > result
Definition
types.h:553
fl::float_conversion_visitor
Definition
types.h:425
fl
float_conversion_visitor< double >
Generated on Sun Oct 18 2026 00:57:06 for FastLED by
1.13.2