Skip to content

Commit c479d05

Browse files
committed
Add unreachable to NaN values comptime_float in approxEq(Abs/Rel)
1 parent edba171 commit c479d05

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/std/math.zig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ pub fn approxEqAbs(comptime T: type, x: T, y: T, tolerance: T) bool {
8181
if (x == y)
8282
return true;
8383

84-
if (isNan(x) or isNan(y))
84+
if (isNan(x) or isNan(y)) {
85+
if (T == comptime_float) unreachable;
8586
return false;
87+
}
8688

8789
return @abs(x - y) <= tolerance;
8890
}
@@ -109,8 +111,10 @@ pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool {
109111
if (x == y)
110112
return true;
111113

112-
if (isNan(x) or isNan(y))
114+
if (isNan(x) or isNan(y)) {
115+
if (T == comptime_float) unreachable;
113116
return false;
117+
}
114118

115119
return @abs(x - y) <= @max(@abs(x), @abs(y)) * tolerance;
116120
}

0 commit comments

Comments
 (0)