authorgravatar for shawn@git.icuShawn Landden <shawn@git.icu> 2019-11-04 18:13:47-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-05 11:34:33-05:00
log55685ae7801a222ddaaf46660dd0acfa34ed71f4
tree8c77a5ab7b1051e85040f77e08a687c7515511b8
parent3d907b29433bf722f8c0ca188d1144f9ebdbfd55

remove duplicate isNan implementation


1 files changed, 2 insertions(+), 13 deletions(-)

lib/std/special/c.zig+2-13
......@@ -7,6 +7,7 @@
77const std = @import("std");
88const builtin = @import("builtin");
99const maxInt = std.math.maxInt;
10const isNan = std.math.isNan;
1011
1112const is_wasm = switch (builtin.arch) {
1213 .wasm32, .wasm64 => true,
......@@ -480,7 +481,7 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
480481 const sx = if (T == f32) @intCast(u32, ux & 0x80000000) else @intCast(i32, ux >> bits_minus_1);
481482 var i: uint = undefined;
482483
483 if (uy << 1 == 0 or isNan(uint, uy) or ex == mask)
484 if (uy << 1 == 0 or isNan(@bitCast(T, uy)) or ex == mask)
484485 return (x * y) / (x * y);
485486
486487 if (ux << 1 <= uy << 1) {
......@@ -549,18 +550,6 @@ fn generic_fmod(comptime T: type, x: T, y: T) T {
549550 return @bitCast(T, ux);
550551}
551552
552fn isNan(comptime T: type, bits: T) bool {
553 if (T == u16) {
554 return (bits & 0x7fff) > 0x7c00;
555 } else if (T == u32) {
556 return (bits & 0x7fffffff) > 0x7f800000;
557 } else if (T == u64) {
558 return (bits & (maxInt(u64) >> 1)) > (u64(0x7ff) << 52);
559 } else {
560 unreachable;
561 }
562}
563
564553// NOTE: The original code is full of implicit signed -> unsigned assumptions and u32 wraparound
565554// behaviour. Most intermediate i32 values are changed to u32 where appropriate but there are
566555// potentially some edge cases remaining that are not handled in the same way.