Fix big integer representation of large numbers such as 98765.0e309

This commit is contained in:
gingerBill committed 2026-09-29 11:41:50 +01:00
1 parent 395920130e
commit ae63a4a4c6
3 files changed
+138 -5

No files matched your search

+26
View File
@@ -2516,6 +2516,28 @@ gb_internal bool check_representable_as_constant(CheckerContext *c, ExactValue i
return false;
}
check_update_float_precision(&v, type);
if (in_value.kind == ExactValue_Integer) {
bool overflowed = isinf(v.value_float) || isnan(v.value_float);
if (!overflowed) {
switch (type->Basic.kind) {
case Basic_f16:
case Basic_f16le:
case Basic_f16be:
// `check_update_float_precision` only rounds `f16` to `f32` precision, so a value
// that is finite as `f32` but out of range for `f16` must be caught explicitly.
if (isinf(cast(f64)f16_to_f32(f32_to_f16(cast(f32)v.value_float)))) {
overflowed = true;
}
break;
}
}
if (overflowed) {
// Leave `out_value` unset so the diagnostic reports the exact (finite) source value.
return false;
}
}
if (out_value) *out_value = v;
switch (type->Basic.kind) {
@@ -12607,6 +12629,10 @@ gb_internal ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast
t = t_untyped_integer;
if (bl->token.kind == Token_Rune) {
t = t_untyped_rune;
} else if (string_contains_char(bl->token.string, '.')) {
// NOTE(bill): A floating-point literal whose value happens to be an integer (e.g. `98765.0e309`) keeps
// its exact value as an integer, but still defaults to untyped float because it was written in floating-point form.
t = t_untyped_float;
}
break;
default: