aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-02-07 16:48:37 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-02-07 16:52:19 -0700
commita028488384c599aa997ba04bbd5ed98f2172630c (patch)
treed61c60e53f167ecb3c5b24235f5fa30f01fd8c23 /src/value.zig
parent722d4a11bbba4052558f6f69b7e710d1206f3355 (diff)
downloadzig-a028488384c599aa997ba04bbd5ed98f2172630c.tar.gz
zig-a028488384c599aa997ba04bbd5ed98f2172630c.zip
Sema: clean up zirUnaryMath
* pass air_tag instead of zir_tag * also pass eval function so that the branch only happens once and the body of zirUnaryMath is simplified * Value.sqrt: update to handle f80 and f128 in the normalized way that includes handling c_longdouble. Semi-related change: fix incorrect sqrt builtin name for f80 in stage1.
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/value.zig b/src/value.zig
index 4bb0a58aed..23a04f2e5a 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -3265,24 +3265,34 @@ pub const Value = extern union {
}
}
- pub fn sqrt(val: Value, float_type: Type, arena: Allocator) !Value {
- switch (float_type.tag()) {
- .f16 => {
+ pub fn sqrt(val: Value, float_type: Type, arena: Allocator, target: Target) Allocator.Error!Value {
+ switch (float_type.floatBits(target)) {
+ 16 => {
const f = val.toFloat(f16);
return Value.Tag.float_16.create(arena, @sqrt(f));
},
- .f32 => {
+ 32 => {
const f = val.toFloat(f32);
return Value.Tag.float_32.create(arena, @sqrt(f));
},
- .f64 => {
+ 64 => {
const f = val.toFloat(f64);
return Value.Tag.float_64.create(arena, @sqrt(f));
},
-
- // TODO: implement @sqrt for these types
- .f128, .comptime_float, .c_longdouble => unreachable,
-
+ 80 => {
+ if (true) {
+ @panic("TODO implement compiler_rt __sqrtx");
+ }
+ const f = val.toFloat(f80);
+ return Value.Tag.float_80.create(arena, @sqrt(f));
+ },
+ 128 => {
+ if (true) {
+ @panic("TODO implement compiler_rt sqrtq");
+ }
+ const f = val.toFloat(f128);
+ return Value.Tag.float_128.create(arena, @sqrt(f));
+ },
else => unreachable,
}
}