(number->string) support for bignums

This commit is contained in:
Justin Ethier 2017-02-16 17:24:16 -05:00
parent 2f0f9ac322
commit 964614f9bb

View file

@ -1721,6 +1721,14 @@ object Cyc_number2string2(void *data, object cont, int argc, object n, ...)
snprintf(buffer, 1024, "%d", ((integer_type *) n)->value); snprintf(buffer, 1024, "%d", ((integer_type *) n)->value);
} else if (type_of(n) == double_tag) { } else if (type_of(n) == double_tag) {
double2buffer(buffer, 1024, ((double_type *) n)->value); double2buffer(buffer, 1024, ((double_type *) n)->value);
} else if (type_of(n) == bignum_tag) {
int sz;
mp_radix_size(&bignum_value(n), 10, &sz);
if (sz > 1024) {
// TODO: just temporary, need to handle this better
Cyc_rt_raise(data, "number->string - bignum is too large to print");
}
mp_toradix(&bignum_value(n), buffer, 10);
} else { } else {
Cyc_rt_raise2(data, "number->string - Unexpected object", n); Cyc_rt_raise2(data, "number->string - Unexpected object", n);
} }