FastLED 3.9.15
Loading...
Searching...
No Matches

◆ strtod()

double fl::strtod ( const char * str,
char ** endptr )

Definition at line 238 of file cstdlib.cpp.hpp.

238 {
239 if (!str) {
240 if (endptr) {
241 *endptr = const_cast<char*>(str);
242 }
243 return 0.0;
244 }
245
246 const char* p = str;
247 double result = 0.0;
248 bool negative = false;
249
250 // Skip leading whitespace
251 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\f' || *p == '\v') {
252 p++;
253 }
254
255 // Handle sign
256 if (*p == '-') {
257 negative = true;
258 p++;
259 } else if (*p == '+') {
260 p++;
261 }
262
263 const char* start = p;
264
265 // Parse integer part
266 while (*p >= '0' && *p <= '9') {
267 result = result * 10.0 + (*p - '0');
268 p++;
269 }
270
271 // Parse fractional part
272 if (*p == '.') {
273 p++;
274 double fraction = 0.1;
275 while (*p >= '0' && *p <= '9') {
276 result += (*p - '0') * fraction;
277 fraction *= 0.1;
278 p++;
279 }
280 }
281
282 // Parse exponent
283 if (*p == 'e' || *p == 'E') {
284 p++;
285 bool expNegative = false;
286 if (*p == '-') {
287 expNegative = true;
288 p++;
289 } else if (*p == '+') {
290 p++;
291 }
292
293 int exp = 0;
294 while (*p >= '0' && *p <= '9') {
295 exp = exp * 10 + (*p - '0');
296 p++;
297 }
298
299 double multiplier = 1.0;
300 for (int i = 0; i < exp; i++) {
301 multiplier *= 10.0;
302 }
303
304 if (expNegative) {
305 result /= multiplier;
306 } else {
307 result *= multiplier;
308 }
309 }
310
311 // Set endptr
312 if (endptr) {
313 if (p == start) {
314 *endptr = const_cast<char*>(str);
315 } else {
316 *endptr = const_cast<char*>(p);
317 }
318 }
319
320 return negative ? -result : result;
321}
expected< T, E > result
Alias for expected (Rust-style naming)
Definition result.h:31
enable_if< is_fixed_point< T >::value, T >::type exp(T x) FL_NOEXCEPT

References exp().

Referenced by fl::detail::JsonToFloatVisitor< T >::operator()().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: