aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Landden <shawn@git.icu>2019-11-04 18:13:47 -0800
committerAndrew Kelley <andrew@ziglang.org>2019-11-05 11:34:33 -0500
commit55685ae7801a222ddaaf46660dd0acfa34ed71f4 (patch)
tree8c77a5ab7b1051e85040f77e08a687c7515511b8
parent3d907b29433bf722f8c0ca188d1144f9ebdbfd55 (diff)
downloadzig-55685ae7801a222ddaaf46660dd0acfa34ed71f4.tar.gz
zig-55685ae7801a222ddaaf46660dd0acfa34ed71f4.zip
remove duplicate isNan implementation
-rw-r--r--lib/std/special/c.zig15
1 files changed, 2 insertions, 13 deletions
diff --git a/lib/std/special/c.zig b/lib/std/special/c.zig
index b2fca86db3..a9fd9857ff 100644
--- a/lib/std/special/c.zig
+++ b/lib/std/special/c.zig
@@ -7,6 +7,7 @@
const std = @import("std");
const builtin = @import("builtin");
const maxInt = std.math.maxInt;
+const isNan = std.math.isNan;
const is_wasm = switch (builtin.arch) {
.wasm32, .wasm64 => true,
@@ -480,7 +481,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
const sx = if (T == f32) @intCast(u32, ux & 0x80000000) else @intCast(i32, ux >> bits_minus_1);
var i: uint = undefined;
- if (uy << 1 == 0 or isNan(uint, uy) or ex == mask)
+ if (uy << 1 == 0 or isNan(@bitCast(T, uy)) or ex == mask)
return (x * y) / (x * y);
if (ux << 1 <= uy << 1) {
@@ -549,18 +550,6 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
return @bitCast(T, ux);
}
-fn isNan(comptime T: type, bits: T) bool {
- if (T == u16) {
- return (bits & 0x7fff) > 0x7c00;
- } else if (T == u32) {
- return (bits & 0x7fffffff) > 0x7f800000;
- } else if (T == u64) {
- return (bits & (maxInt(u64) >> 1)) > (u64(0x7ff) << 52);
- } else {
- unreachable;
- }
-}
-
// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
// behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are
// potentially some edge cases remaining that are not handled in the same way.