authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-15 18:15:44+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2021-04-15 18:17:21+02:00
log2d00f17d155b46e8effb47c363e051f50b866d47
tree997e0ee19ffbfbccda2e83234f6cae4f99db20e4
parent8e0b2f0e52b195933ae7df9d66f8763fd53b0281

test: Add test to ensure signed zeros are properly computed

Ensure everything's ok at comptime and runtime.

1 files changed, 17 insertions(+), 0 deletions(-)

test/stage1/behavior/math.zig+17
...@@ -843,3 +843,20 @@ test "compare undefined literal with comptime_int" {...@@ -843,3 +843,20 @@ test "compare undefined literal with comptime_int" {
843 x = true;843 x = true;
844 expect(x);844 expect(x);
845}845}
846
847test "signed zeros are represented properly" {
848 const S = struct {
849 fn doTheTest() void {
850 inline for ([_]type{ f16, f32, f64, f128 }) |T| {
851 const ST = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
852 var as_fp_val = -@as(T, 0.0);
853 var as_uint_val = @bitCast(ST, as_fp_val);
854 // Ensure the sign bit is set.
855 expect(as_uint_val >> (@typeInfo(T).Float.bits - 1) == 1);
856 }
857 }
858 };
859
860 S.doTheTest();
861 comptime S.doTheTest();
862}