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. */
| 522 | * a double: no spaces or other characters before or after the string |
| 523 | * representing the number are accepted. */ |
| 524 | int string2d(const char *s, size_t slen, double *dp) { |
| 525 | errno = 0; |
| 526 | char *eptr; |
| 527 | *dp = strtod(s, &eptr); |
| 528 | if (slen == 0 || |
| 529 | isspace(((const char*)s)[0]) || |
| 530 | (size_t)(eptr-(char*)s) != slen || |
| 531 | (errno == ERANGE && |
| 532 | (*dp == HUGE_VAL || *dp == -HUGE_VAL || *dp == 0)) || |
| 533 | isnan(*dp)) |
| 534 | return 0; |
| 535 | return 1; |
| 536 | } |
| 537 | |
| 538 | /* Convert a double to a string representation. Returns the number of bytes |
| 539 | * required. The representation should always be parsable by strtod(3). |
no outgoing calls
no test coverage detected