Issue #511 - Properly recognize +inf.0 / -inf.0

This commit is contained in:
Justin Ethier 2023-08-21 19:11:59 -07:00
parent fd56e21e90
commit cc24c6be6d
2 changed files with 18 additions and 10 deletions

View file

@ -4,6 +4,7 @@
Bug Fixes
- Ensure the runtime properly differentiates between `+inf.0` and `-inf.0`. Thanks to jpellegrini for the bug report.
- lassik and jpellegrini reported that `abs` was incorrectly returning the real part of a complex number argument. Modified `abs` to return an error for complex numbers.
- jpellegrini fixed `(srfi 143)` so that the following are constants instead of procedures: `fx-width`, `fx-greatest`, and `fx-least`.
- Raise an error if `odd?` or `even?` is passed a decimal number. Thanks to jpellegrini for the bug report.

View file

@ -984,14 +984,19 @@ object Cyc_is_list(object lst)
*/
int double2buffer(char *buf, int buf_size, double num)
{
int i;
i = snprintf(buf, buf_size, "%.15g", num);
if (!strchr(buf, '.') && !strchr(buf, 'e')) {
buf[i++] = '.';
buf[i++] = '0';
buf[i++] = '\0';
if (num == INFINITY) {
return snprintf(buf, buf_size, "+inf.0");
} else if (num == -INFINITY) {
return snprintf(buf, buf_size, "-inf.0");
} else {
int i = snprintf(buf, buf_size, "%.15g", num);
if (!strchr(buf, '.') && !strchr(buf, 'e')) {
buf[i++] = '.';
buf[i++] = '0';
buf[i++] = '\0';
}
return i;
}
return i;
}
void dispatch_display_va(void *data, object cont, int argc, object *args)
@ -7776,9 +7781,11 @@ static void _read_return_atom(void *data, object cont, port_type *p)
} else {
return_thread_runnable_with_obj(data, &opq, p);
}
} else if (strncmp("+inf.0", p->tok_buf, 6) == 0 ||
strncmp("-inf.0", p->tok_buf, 6) == 0) {
make_double(d, pow(2.0, 1000000));
} else if (strncmp("+inf.0", p->tok_buf, 6) == 0) {
make_double(d, INFINITY);
return_thread_runnable_with_obj(data, &d, p);
} else if (strncmp("-inf.0", p->tok_buf, 6) == 0) {
make_double(d, -INFINITY);
return_thread_runnable_with_obj(data, &d, p);
} else if (strncmp("+nan.0", p->tok_buf, 6) == 0 ||
strncmp("-nan.0", p->tok_buf, 6) == 0) {