aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/floatop.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-05-01 15:02:06 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-05-01 15:02:06 -0700
commit60c2972c5d976e2dc8bf2432c8ab06edcf5c6d35 (patch)
tree2ed60b8283b58604b406446ed588f97f601b143d /test/behavior/floatop.zig
parent615a98351768598db65fcfc521d3c67eb443eed6 (diff)
downloadzig-60c2972c5d976e2dc8bf2432c8ab06edcf5c6d35.tar.gz
zig-60c2972c5d976e2dc8bf2432c8ab06edcf5c6d35.zip
stage2: fix comptime fixed-width float division
Diffstat (limited to 'test/behavior/floatop.zig')
-rw-r--r--test/behavior/floatop.zig21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/behavior/floatop.zig b/test/behavior/floatop.zig
index cc978f3b8d..ab87283627 100644
--- a/test/behavior/floatop.zig
+++ b/test/behavior/floatop.zig
@@ -687,3 +687,24 @@ test "f128 at compile time is lossy" {
try expect(@as(f128, 10384593717069655257060992658440192.0) + 1 == 10384593717069655257060992658440192.0);
}
+
+test "comptime fixed-width float zero divided by zero produces NaN" {
+ inline for (.{ f16, f32, f64, f80, f128 }) |F| {
+ try expect(math.isNan(@as(F, 0) / @as(F, 0)));
+ }
+}
+
+test "comptime fixed-width float non-zero divided by zero produces signed Inf" {
+ inline for (.{ f16, f32, f64, f80, f128 }) |F| {
+ const pos = @as(F, 1) / @as(F, 0);
+ const neg = @as(F, -1) / @as(F, 0);
+ try expect(math.isInf(pos));
+ try expect(math.isInf(neg));
+ try expect(pos > 0);
+ try expect(neg < 0);
+ }
+}
+
+test "comptime_float zero divided by zero produces zero" {
+ try expect((0.0 / 0.0) == 0.0);
+}