FastLED 3.10.8
Loading...
Searching...
No Matches

◆ strtod()

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

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

277 {
278 if (!str) {
279 if (endptr) {
280 *endptr = const_cast<char*>(str);
281 }
282 return 0.0;
283 }
284
285 const char* p = str;
286 double result = 0.0;
287 bool negative = false;
288
289 // Skip leading whitespace
290 while (*p == ' ' || *p == '\t' || *p == '\n' || *p == '\r' || *p == '\f' || *p == '\v') {
291 p++;
292 }
293
294 // Handle sign
295 if (*p == '-') {
296 negative = true;
297 p++;
298 } else if (*p == '+') {
299 p++;
300 }
301
302 const char* start = p;
303
304 // Parse integer part
305 while (*p >= '0' && *p <= '9') {
306 result = result * 10.0 + (*p - '0');
307 p++;
308 }
309
310 // Parse fractional part
311 if (*p == '.') {
312 p++;
313 double fraction = 0.1;
314 while (*p >= '0' && *p <= '9') {
315 result += (*p - '0') * fraction;
316 fraction *= 0.1;
317 p++;
318 }
319 }
320
321 // Parse exponent
322 if (*p == 'e' || *p == 'E') {
323 p++;
324 bool expNegative = false;
325 if (*p == '-') {
326 expNegative = true;
327 p++;
328 } else if (*p == '+') {
329 p++;
330 }
331
332 int exp = 0;
333 while (*p >= '0' && *p <= '9') {
334 exp = exp * 10 + (*p - '0');
335 p++;
336 }
337
338 double multiplier = 1.0;
339 for (int i = 0; i < exp; i++) {
340 multiplier *= 10.0;
341 }
342
343 if (expNegative) {
344 result /= multiplier;
345 } else {
346 result *= multiplier;
347 }
348 }
349
350 // Set endptr
351 if (endptr) {
352 if (p == start) {
353 *endptr = const_cast<char*>(str);
354 } else {
355 *endptr = const_cast<char*>(p);
356 }
357 }
358
359 return negative ? -result : result;
360}
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_NO_EXCEPT

References fl::exp(), and fl::FL_NO_EXCEPT.

Referenced by fl::strtod().

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