all: replace all @Type usages

Co-authored-by: Matthew Lugg <mlugg@mlugg.co.uk>
This commit is contained in:
Ali Cheraghi
2025-04-30 18:42:23 +03:30
committed by Matthew Lugg
parent ce0df033cf
commit dec1163fbb
108 changed files with 629 additions and 1891 deletions
+2 -2
View File
@@ -2787,11 +2787,11 @@ test "bitNotWrap more than two limbs" {
const bits = @bitSizeOf(Limb) * 4 + 2;
try res.bitNotWrap(&a, .unsigned, bits);
const Unsigned = @Type(.{ .int = .{ .signedness = .unsigned, .bits = bits } });
const Unsigned = @Int(.unsigned, bits);
try testing.expectEqual((try res.toInt(Unsigned)), ~@as(Unsigned, maxInt(Limb)));
try res.bitNotWrap(&a, .signed, bits);
const Signed = @Type(.{ .int = .{ .signedness = .signed, .bits = bits } });
const Signed = @Int(.signed, bits);
try testing.expectEqual((try res.toInt(Signed)), ~@as(Signed, maxInt(Limb)));
}
+8 -26
View File
@@ -14,22 +14,10 @@ pub fn FloatRepr(comptime Float: type) type {
exponent: BiasedExponent,
sign: std.math.Sign,
pub const StoredMantissa = @Type(.{ .int = .{
.signedness = .unsigned,
.bits = floatMantissaBits(Float),
} });
pub const Mantissa = @Type(.{ .int = .{
.signedness = .unsigned,
.bits = 1 + fractional_bits,
} });
pub const Exponent = @Type(.{ .int = .{
.signedness = .signed,
.bits = exponent_bits,
} });
pub const BiasedExponent = enum(@Type(.{ .int = .{
.signedness = .unsigned,
.bits = exponent_bits,
} })) {
pub const StoredMantissa = @Int(.unsigned, floatMantissaBits(Float));
pub const Mantissa = @Int(.unsigned, 1 + fractional_bits);
pub const Exponent = @Int(.signed, exponent_bits);
pub const BiasedExponent = enum(@Int(.unsigned, exponent_bits)) {
denormal = 0,
min_normal = 1,
zero = (1 << (exponent_bits - 1)) - 1,
@@ -56,14 +44,8 @@ pub fn FloatRepr(comptime Float: type) type {
fraction: Fraction,
exponent: Normalized.Exponent,
pub const Fraction = @Type(.{ .int = .{
.signedness = .unsigned,
.bits = fractional_bits,
} });
pub const Exponent = @Type(.{ .int = .{
.signedness = .signed,
.bits = 1 + exponent_bits,
} });
pub const Fraction = @Int(.unsigned, fractional_bits);
pub const Exponent = @Int(.signed, 1 + exponent_bits);
/// This currently truncates denormal values, which needs to be fixed before this can be used to
/// produce a rounded value.
@@ -122,7 +104,7 @@ inline fn mantissaOne(comptime T: type) comptime_int {
/// Creates floating point type T from an unbiased exponent and raw mantissa.
inline fn reconstructFloat(comptime T: type, comptime exponent: comptime_int, comptime mantissa: comptime_int) T {
const TBits = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } });
const TBits = @Int(.unsigned, @bitSizeOf(T));
const biased_exponent = @as(TBits, exponent + floatExponentMax(T));
return @as(T, @bitCast((biased_exponent << floatMantissaBits(T)) | @as(TBits, mantissa)));
}
@@ -209,7 +191,7 @@ pub inline fn floatEps(comptime T: type) T {
pub inline fn floatEpsAt(comptime T: type, x: T) T {
switch (@typeInfo(T)) {
.float => |F| {
const U: type = @Type(.{ .int = .{ .signedness = .unsigned, .bits = F.bits } });
const U: type = @Int(.unsigned, F.bits);
const u: U = @bitCast(x);
const y: T = @bitCast(u ^ 1);
return @abs(x - y);
+1 -4
View File
@@ -33,10 +33,7 @@ pub fn log2(x: anytype) @TypeOf(x) {
return result;
},
.int => |int_info| math.log2_int(switch (int_info.signedness) {
.signed => @Type(.{ .int = .{
.signedness = .unsigned,
.bits = int_info.bits -| 1,
} }),
.signed => @Int(.unsigned, int_info.bits -| 1),
.unsigned => T,
}, @intCast(x)),
else => @compileError("log2 not implemented for " ++ @typeName(T)),
+1 -1
View File
@@ -65,7 +65,7 @@ test "log_int" {
// Test all unsigned integers with 2, 3, ..., 64 bits.
// We cannot test 0 or 1 bits since base must be > 1.
inline for (2..64 + 1) |bits| {
const T = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @intCast(bits) } });
const T = @Int(.unsigned, @intCast(bits));
// for base = 2, 3, ..., min(maxInt(T),1024)
var base: T = 1;
+1 -4
View File
@@ -6,10 +6,7 @@ const expect = std.testing.expect;
pub fn signbit(x: anytype) bool {
return switch (@typeInfo(@TypeOf(x))) {
.int, .comptime_int => x,
.float => |float| @as(@Type(.{ .int = .{
.signedness = .signed,
.bits = float.bits,
} }), @bitCast(x)),
.float => |float| @as(@Int(.signed, float.bits), @bitCast(x)),
.comptime_float => @as(i128, @bitCast(@as(f128, x))), // any float type will do
else => @compileError("std.math.signbit does not support " ++ @typeName(@TypeOf(x))),
} < 0;
+1 -1
View File
@@ -80,7 +80,7 @@ test sqrt_int {
/// Returns the return type `sqrt` will return given an operand of type `T`.
pub fn Sqrt(comptime T: type) type {
return switch (@typeInfo(T)) {
.int => |int| @Type(.{ .int = .{ .signedness = .unsigned, .bits = (int.bits + 1) / 2 } }),
.int => |int| @Int(.unsigned, (int.bits + 1) / 2),
else => T,
};
}