Return #f from string->number on conv error

This commit is contained in:
Justin Ethier 2016-11-16 19:07:20 +00:00
parent d5ac136642
commit f0e4d65794

View file

@ -1685,21 +1685,6 @@ str2int_errno str2int(int *out, char *s, int base)
return STR2INT_SUCCESS; return STR2INT_SUCCESS;
} }
int str2double(double *out, char *s)
{
*out = strtold(s, NULL);
// TODO: error checking, EG: HUGE_VALL
return 0;
}
int str2double_error(char *str, double result) {
//int i, len = strlen(str);
//for (i = 0; i < len; i++) {
// if (!isspace(str[i]) && str[i] != '.' &&
//}
return 0;
}
object Cyc_string2number_(void *data, object cont, object str) object Cyc_string2number_(void *data, object cont, object str)
{ {
int result, rv; int result, rv;
@ -1714,17 +1699,15 @@ object Cyc_string2number_(void *data, object cont, object str)
if (rv == STR2INT_SUCCESS) { if (rv == STR2INT_SUCCESS) {
_return_closcall1(data, cont, obj_int2obj(result)); _return_closcall1(data, cont, obj_int2obj(result));
} else { } else {
str2double(&n, s); char *str_end;
if (n > 0.0L || n < 0.0L || !str2double_error(s, n)) { n = strtold(s, &str_end);
if (s != str_end && *str_end == '\0') {
make_double(result, n); make_double(result, n);
_return_closcall1(data, cont, &result); _return_closcall1(data, cont, &result);
} else { } else {
_return_closcall1(data, cont, boolean_f); _return_closcall1(data, cont, boolean_f);
} }
} }
} else {
// TODO: not good enough because we do pointer comparisons to #f
//result.boolean_t = boolean_f;
} }
Cyc_rt_raise2(data, "Expected string but received", str); Cyc_rt_raise2(data, "Expected string but received", str);