mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-18 20:40:28 +00:00
Add intrinsics.constant_(floor|truncate|ceil|round)
This commit is contained in:
@@ -4768,6 +4768,42 @@ gb_internal bool check_builtin_procedure(CheckerContext *c, Operand *operand, As
|
||||
break;
|
||||
}
|
||||
|
||||
case BuiltinProc_constant_floor:
|
||||
case BuiltinProc_constant_truncate:
|
||||
case BuiltinProc_constant_ceil:
|
||||
case BuiltinProc_constant_round:
|
||||
{
|
||||
Operand o = {};
|
||||
check_expr(c, &o, ce->args[0]);
|
||||
|
||||
if (!is_type_integer_or_float(o.type) && (o.mode != Addressing_Constant)) {
|
||||
error(ce->args[0], "Expected a constant number for '%.*s'", LIT(builtin_name));
|
||||
return false;
|
||||
}
|
||||
operand->mode = Addressing_Constant;
|
||||
operand->type = o.type;
|
||||
|
||||
ExactValue value = o.value;
|
||||
if (value.kind == ExactValue_Integer) {
|
||||
// do nothing
|
||||
} else if (value.kind == ExactValue_Float) {
|
||||
f64 f = value.value_float;
|
||||
switch (id) {
|
||||
case BuiltinProc_constant_floor: f = floor(f); break;
|
||||
case BuiltinProc_constant_truncate: f = trunc(f); break;
|
||||
case BuiltinProc_constant_ceil: f = ceil(f); break;
|
||||
case BuiltinProc_constant_round: f = round(f); break;
|
||||
default:
|
||||
GB_PANIC("Unhandled built-in: %.*s", LIT(builtin_name));
|
||||
break;
|
||||
}
|
||||
value = exact_value_float(f);
|
||||
}
|
||||
|
||||
operand->value = value;
|
||||
break;
|
||||
}
|
||||
|
||||
case BuiltinProc_soa_struct: {
|
||||
Operand x = {};
|
||||
Operand y = {};
|
||||
|
||||
Reference in New Issue
Block a user