fix floating point scanners

This commit is contained in:
2026-09-30 22:43:10 +02:00
parent 9ac4b4f061
commit 105295157c
+12 -15
View File
@@ -222,36 +222,33 @@ scan_result_t scan_u8(scanner_t *s) {
return scan_value(val);
}
bool scan_f64(scanner_t *s) {
scan_result_t scan_f64(scanner_t *s) {
char const *save = s->cur;
char *end;
errno = 0;
double val = strtod(s->cur, &end);
if (end == s->cur) {
s->cur = save;
return false;
return scan_error(s, "not a f64");
}
if (errno == ERANGE) {
scanner_error(s, "float does not fit in f64 value");
return false;
return scan_error(s, "float does not fit in f64 value");
}
s->cur = end;
s->value.f64 = val;
return true;
return scan_value(.f64=val);
}
bool scan_f32(scanner_t *s) {
if (!scan_f64(s)) {
return false;
scan_result_t scan_f32(scanner_t *s) {
scan_result_t result = scan_f64(s);
if (!result.ok) {
return result;
}
float val = (float)s->value.f64;
float val = (float)result.value.f64;
double back = (double)val;
if (back != s->value.f64) {
scanner_error(s, "float does not fit in f32 value");
return false;
if (back != result.value.f64) {
return scan_error(s, "float does not fit in f32 value");
}
s->value.f32 = val;
return true;
return scan_value(.f32=val);
}
bool scan_identifier(scanner_t *s) {