MCPcopy Create free account
hub / github.com/F-Stack/f-stack / string2ld

Function string2ld

app/redis-6.2.6/src/util.c:494–515  ·  view source on GitHub ↗

Convert a string into a double. Returns 1 if the string could be parsed * into a (non-overflowing) double, 0 otherwise. The value will be set to * the parsed value when appropriate. * * Note that this function demands that the string strictly represents * a double: no spaces or other characters before or after the string * representing the number are accepted. */

Source from the content-addressed store, hash-verified

492 * a double: no spaces or other characters before or after the string
493 * representing the number are accepted. */
494int string2ld(const char *s, size_t slen, long double *dp) {
495 char buf[MAX_LONG_DOUBLE_CHARS];
496 long double value;
497 char *eptr;
498
499 if (slen == 0 || slen >= sizeof(buf)) return 0;
500 memcpy(buf,s,slen);
501 buf[slen] = '\0';
502
503 errno = 0;
504 value = strtold(buf, &eptr);
505 if (isspace(buf[0]) || eptr[0] != '\0' ||
506 (size_t)(eptr-buf) != slen ||
507 (errno == ERANGE &&
508 (value == HUGE_VAL || value == -HUGE_VAL || value == 0)) ||
509 errno == EINVAL ||
510 isnan(value))
511 return 0;
512
513 if (dp) *dp = value;
514 return 1;
515}
516
517/* Convert a string into a double. Returns 1 if the string could be parsed
518 * into a (non-overflowing) double, 0 otherwise. The value will be set to

Callers 4

hincrbyfloatCommandFunction · 0.85
getLongDoubleFromObjectFunction · 0.85
RM_StringToLongDoubleFunction · 0.85
RM_LoadLongDoubleFunction · 0.85

Calls 2

isspaceFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected