zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2d00f17d155b46e8effb47c363e051f50b866d47 (tree)
parent 8e0b2f0e52b195933ae7df9d66f8763fd53b0281
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu, 15 Apr 2021 18:15:44 +0200

test: Add test to ensure signed zeros are properly computed

Ensure everything's ok at comptime and runtime.

Diffstat:
Mtest/stage1/behavior/math.zig | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/test/stage1/behavior/math.zig b/test/stage1/behavior/math.zig @@ -843,3 +843,20 @@ test "compare undefined literal with comptime_int" { x = true; expect(x); } + +test "signed zeros are represented properly" { + 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. + expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1); + } + } + }; + + S.doTheTest(); + comptime S.doTheTest(); +}