aboutsummaryrefslogtreecommitdiff
path: root/test/behavior
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-10 21:46:24 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-05-10 21:50:55 -0700
commitb33c8b0b06dd6a24d89efb278eeb833db93b2f9b (patch)
tree6b5c91beeae7563c581279f8d08d553e08c40d3f /test/behavior
parentf5edf78eea403c14635a05e1729672cfb50aca89 (diff)
downloadzig-b33c8b0b06dd6a24d89efb278eeb833db93b2f9b.tar.gz
zig-b33c8b0b06dd6a24d89efb278eeb833db93b2f9b.zip
Sema: comptime float negation supports negative zero
When handling the `negate` ZIR instruction, Zig now checks for a comptime operand and handles it as a special case rather than lowering it as `0 - x` so that the expression `-x` where `x` is a floating point value known at compile-time, will get the negative zero bitwise representation.
Diffstat (limited to 'test/behavior')
-rw-r--r--test/behavior/math.zig29
1 files changed, 21 insertions, 8 deletions
diff --git a/test/behavior/math.zig b/test/behavior/math.zig
index 42f2635afd..eb07ffd7a5 100644
--- a/test/behavior/math.zig
+++ b/test/behavior/math.zig
@@ -1593,17 +1593,30 @@ test "compare undefined literal with comptime_int" {
}
test "signed zeros are represented properly" {
- if (builtin.zig_backend != .stage1) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
+ if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
const S = struct {
fn doTheTest() !void {
- inline for ([_]type{ f16, f32, f64, f128 }) |T| {
- const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
- var as_fp_val = -@as(T, 0.0);
- var as_uint_val = @bitCast(ST, as_fp_val);
- // Ensure the sign bit is set.
- try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
- }
+ try testOne(f16);
+ try testOne(f32);
+ try testOne(f64);
+ // TODO enable this
+ //try testOne(f80);
+ try testOne(f128);
+ // TODO enable this
+ //try testOne(c_longdouble);
+ }
+
+ fn testOne(comptime T: type) !void {
+ const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
+ var as_fp_val = -@as(T, 0.0);
+ var as_uint_val = @bitCast(ST, as_fp_val);
+ // Ensure the sign bit is set.
+ try expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
}
};