21 lines
324 B
C
21 lines
324 B
C
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <math.h>
|
|
|
|
int
|
|
cli_parse_ufloat(const char *s, float *out)
|
|
{
|
|
char *end;
|
|
|
|
if (NULL == s || '\0' == *s)
|
|
return 1;
|
|
|
|
errno = 0;
|
|
float v = strtof(s, &end);
|
|
|
|
if (s == end || ERANGE == errno || '\0' != *end || 0 == isfinite(v) || v < 0.0f)
|
|
return 1;
|
|
|
|
*out = v;
|
|
return 0;
|
|
}
|