117 {
119 if (
auto* p = val.
data.template ptr<float>()) {
120 *out_value = *p;
122 }
123 if (
auto* p = val.
data.template ptr<i64>()) {
124#if FL_PLATFORM_HAS_LARGE_MEMORY
125 *out_value = static_cast<float>(*p);
126 if (sizeof(float) < 8 && (*p > 16777216 || *p < -16777216)) {
128 " may lose precision as float");
129 }
130#else
131
132 if (*p > 2147483647LL) {
133 *out_value = static_cast<float>(2147483647);
134 } else if (*p < -2147483648LL) {
135 *out_value = static_cast<float>(-2147483648);
136 } else {
137 *out_value = static_cast<float>(static_cast<fl::i32>(*p));
138 }
139#endif
141 }
142 if (
auto* p = val.
data.template ptr<bool>()) {
143 *out_value = *p ? 1.0f : 0.0f;
144 result.addWarning(fl::string(
"bool converted to float ") +
145 (*p ? "1.0" : "0.0"));
147 }
148 if (
auto* p = val.
data.template ptr<fl::string>()) {
149#if FL_PLATFORM_HAS_LARGE_MEMORY
152 if (
end != p->c_str() && *
end ==
'\0') {
153 *out_value = static_cast<float>(parsed);
154 result.addWarning(fl::string(
"string '") + *p +
"' parsed to float");
155 } else {
156 result.setError(fl::string(
"cannot parse string '") + *p +
"' as float");
157 *out_value = 0.0f;
158 }
159#else
160 (void)p;
161 *out_value = 0.0f;
162 result.setError(
"string -> float not supported on Low-memory");
163#endif
165 }
166 if (val.
data.template ptr<fl::nullptr_t>()) {
167 result.setError(
"cannot convert null to float");
168 *out_value = 0.0f;
170 }
171 result.setError(
"cannot convert array or object to float");
172 *out_value = 0.0f;
174}
expected< T, E > result
Alias for expected (Rust-style naming)
string to_string(T value) FL_NO_EXCEPT
double strtod(const char *str, char **endptr)