aboutsummaryrefslogtreecommitdiff
path: root/src/check_builtin.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-05-19 10:32:41 +0100
committergingerBill <bill@gingerbill.org>2021-05-19 10:32:41 +0100
commite0225c3579147557ad4fe2241d8fbe61851a6389 (patch)
treeb4ed52e1962010c95a4347ff7edf8b6712f6ecec /src/check_builtin.cpp
parent8d044fd442f2f8fef678c2aef4b4de733b817f1c (diff)
Add `intrinsics.sqrt` for floating-point values
Diffstat (limited to 'src/check_builtin.cpp')
-rw-r--r--src/check_builtin.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/check_builtin.cpp b/src/check_builtin.cpp
index 8932ac914..54cd21582 100644
--- a/src/check_builtin.cpp
+++ b/src/check_builtin.cpp
@@ -2026,6 +2026,34 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
}
break;
+ case BuiltinProc_sqrt:
+ {
+ Operand x = {};
+ check_expr(c, &x, ce->args[0]);
+ if (x.mode == Addressing_Invalid) {
+ return false;
+ }
+ if (!is_type_float(x.type)) {
+ gbString xts = type_to_string(x.type);
+ error(x.expr, "Expected a floating point value for '%.*s', got %s", LIT(builtin_procs[id].name), xts);
+ gb_string_free(xts);
+ return false;
+ }
+
+ if (x.mode == Addressing_Constant) {
+ f64 v = exact_value_to_f64(x.value);
+
+ operand->mode = Addressing_Constant;
+ operand->type = x.type;
+ operand->value = exact_value_float(gb_sqrt(v));
+ break;
+ }
+ operand->mode = Addressing_Value;
+ operand->type = default_type(x.type);
+ }
+ break;
+
+
case BuiltinProc_atomic_fence:
case BuiltinProc_atomic_fence_acq:
case BuiltinProc_atomic_fence_rel: