mirror of
https://github.com/odin-lang/Odin.git
synced 2026-10-09 06:12:05 -04:00
Fix big integer representation of large numbers such as 98765.0e309
This commit is contained in:
1 parent
395920130e
commit
ae63a4a4c6
3 files changed
+138
-5
No files matched your search
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user