mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Fix #2299 by handling very large value cases correctly
This commit is contained in:
@@ -561,6 +561,28 @@ gb_internal String big_int_to_string(gbAllocator allocator, BigInt const *x, u64
|
|||||||
Array<char> buf = {};
|
Array<char> buf = {};
|
||||||
array_init(&buf, allocator, 0, 32);
|
array_init(&buf, allocator, 0, 32);
|
||||||
|
|
||||||
|
if (x->used >= 498) { // 2^498 ~ 10^150
|
||||||
|
mp_int val = {};
|
||||||
|
mp_abs(x, &val);
|
||||||
|
int exp = 0;
|
||||||
|
mp_err err = mp_log_n(&val, 10, &exp);
|
||||||
|
GB_ASSERT(err == MP_OKAY);
|
||||||
|
GB_ASSERT(exp >= 100);
|
||||||
|
|
||||||
|
mp_int thousand_below = {};
|
||||||
|
mp_int thousand_above = {};
|
||||||
|
mp_init_i32(&thousand_below, 10);
|
||||||
|
|
||||||
|
mp_expt_n(&thousand_below, exp-3, &thousand_below);
|
||||||
|
mp_div(&val, &thousand_below, &thousand_above, nullptr);
|
||||||
|
|
||||||
|
double mant = 1.0e-3 * mp_get_double(&thousand_above);
|
||||||
|
|
||||||
|
char val_buf[256] = {};
|
||||||
|
isize n = gb_snprintf(val_buf, gb_size_of(val_buf)-1, "~ %s%.fe%u", (x->sign ? "-" : ""), mant, exp);
|
||||||
|
|
||||||
|
array_add_elems(&buf, val_buf, n-1);
|
||||||
|
} else {
|
||||||
BigInt v = {};
|
BigInt v = {};
|
||||||
mp_init_copy(&v, x);
|
mp_init_copy(&v, x);
|
||||||
|
|
||||||
@@ -596,5 +618,6 @@ gb_internal String big_int_to_string(gbAllocator allocator, BigInt const *x, u64
|
|||||||
buf[j] = tmp;
|
buf[j] = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return make_string(cast(u8 *)buf.data, buf.count);
|
return make_string(cast(u8 *)buf.data, buf.count);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2321,7 +2321,7 @@ gb_internal void lb_emit_defer_stmts(lbProcedure *p, lbDeferExitKind kind, lbBlo
|
|||||||
|
|
||||||
if (kind == lbDeferExit_Default) {
|
if (kind == lbDeferExit_Default) {
|
||||||
if (p->scope_index == d.scope_index &&
|
if (p->scope_index == d.scope_index &&
|
||||||
d.scope_index > 0) { // TODO(bill): Which is correct: > 0 or > 1?
|
d.scope_index > 0) {
|
||||||
lb_build_defer_stmt(p, d);
|
lb_build_defer_stmt(p, d);
|
||||||
array_pop(&p->defer_stmts);
|
array_pop(&p->defer_stmts);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user