authorgravatar for hi@dnydxn.moealice <hi@dnydxn.moe> 2022-05-17 22:04:12+01:00
committergravatar for hi@dnydxn.moealice <hi@dnydxn.moe> 2022-05-17 22:04:12+01:00
log951ab802a38ede9f5329aeae1fed00161321d558
treeb72445012f44c57c5e4670ebfc9e675777958fc4
parent70b6b98e91fb9d1d5575da4d59c5c523864a8f0e
signaturelock-open Commit is signed but in an unrecognized format.

std.math: simpler error handling


4 files changed, 4 insertions(+), 16 deletions(-)

lib/std/math/isfinite.zig+1-4
......@@ -5,10 +5,7 @@ const expect = std.testing.expect;
55/// Returns whether x is a finite value.
66pub fn isFinite(x: anytype) bool {
77 const T = @TypeOf(x);
8 const TBits = std.meta.Int(.unsigned, @bitSizeOf(T));
9 if (@typeInfo(T) != .Float) {
10 @compileError("isFinite not implemented for " ++ @typeName(T));
11 }
8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
129 const remove_sign = ~@as(TBits, 0) >> 1;
1310 return @bitCast(TBits, x) & remove_sign < @bitCast(TBits, math.inf(T));
1411}
lib/std/math/isinf.zig+1-4
......@@ -5,10 +5,7 @@ const expect = std.testing.expect;
55/// Returns whether x is an infinity, ignoring sign.
66pub fn isInf(x: anytype) bool {
77 const T = @TypeOf(x);
8 const TBits = std.meta.Int(.unsigned, @bitSizeOf(T));
9 if (@typeInfo(T) != .Float) {
10 @compileError("isInf not implemented for " ++ @typeName(T));
11 }
8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
129 const remove_sign = ~@as(TBits, 0) >> 1;
1310 return @bitCast(TBits, x) & remove_sign == @bitCast(TBits, math.inf(T));
1411}
lib/std/math/isnormal.zig+1-4
......@@ -5,10 +5,7 @@ const expect = std.testing.expect;
55/// Returns whether x is neither zero, subnormal, infinity, or NaN.
66pub fn isNormal(x: anytype) bool {
77 const T = @TypeOf(x);
8 const TBits = std.meta.Int(.unsigned, @bitSizeOf(T));
9 if (@typeInfo(T) != .Float) {
10 @compileError("isNormal not implemented for " ++ @typeName(T));
11 }
8 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
129
1310 const increment_exp = 1 << math.floatMantissaBits(T);
1411 const remove_sign = ~@as(TBits, 0) >> 1;
lib/std/math/ldexp.zig+1-4
......@@ -15,10 +15,7 @@ pub fn ldexp(x: anytype, n: i32) @TypeOf(x) {
1515 var shift = n;
1616
1717 const T = @TypeOf(base);
18 const TBits = std.meta.Int(.unsigned, @bitSizeOf(T));
19 if (@typeInfo(T) != .Float) {
20 @compileError("ldexp not implemented for " ++ @typeName(T));
21 }
18 const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits);
2219
2320 const mantissa_bits = math.floatMantissaBits(T);
2421 const exponent_min = math.floatExponentMin(T);