aboutsummaryrefslogtreecommitdiff
path: root/src/value.zig
diff options
context:
space:
mode:
authorg-w1 <58830309+g-w1@users.noreply.github.com>2021-06-21 11:47:34 -0400
committerGitHub <noreply@github.com>2021-06-21 18:47:34 +0300
commite13a182990c638bb69cd04e253ad6e0ecd734407 (patch)
tree2a27981e6f412fbfa8ad52cc46a98f62f0b0c007 /src/value.zig
parenta95fdb06352a6a1e60d0167bad62f5a46345177a (diff)
downloadzig-e13a182990c638bb69cd04e253ad6e0ecd734407.tar.gz
zig-e13a182990c638bb69cd04e253ad6e0ecd734407.zip
stage2 Sema: implement @intToPtr (#9144)
Co-authored-by: Veikka Tuominen <git@vexu.eu>
Diffstat (limited to 'src/value.zig')
-rw-r--r--src/value.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/value.zig b/src/value.zig
index c358975667..696f3d3d88 100644
--- a/src/value.zig
+++ b/src/value.zig
@@ -979,6 +979,26 @@ pub const Value = extern union {
};
}
+ /// Asserts the value is numeric
+ pub fn isZero(self: Value) bool {
+ return switch (self.tag()) {
+ .zero => true,
+ .one => false,
+
+ .int_u64 => self.castTag(.int_u64).?.data == 0,
+ .int_i64 => self.castTag(.int_i64).?.data == 0,
+
+ .float_16 => self.castTag(.float_16).?.data == 0,
+ .float_32 => self.castTag(.float_32).?.data == 0,
+ .float_64 => self.castTag(.float_64).?.data == 0,
+ .float_128 => self.castTag(.float_128).?.data == 0,
+
+ .int_big_positive => self.castTag(.int_big_positive).?.asBigInt().eqZero(),
+ .int_big_negative => self.castTag(.int_big_negative).?.asBigInt().eqZero(),
+ else => unreachable,
+ };
+ }
+
pub fn orderAgainstZero(lhs: Value) std.math.Order {
return switch (lhs.tag()) {
.zero,