diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-08-28 10:49:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-28 10:49:31 -0700 |
| commit | 31fef6f1103ea64a899729adea13b0ab9b66cb46 (patch) | |
| tree | 31c13b06483af84cd0977be8de00d3539e3e3c4d /lib/std/math | |
| parent | 9a12905a2da045b0948f612583b526bca3a1b2f0 (diff) | |
| parent | aaa7e739831f39151a37c7beb08660f0fb6ae0ed (diff) | |
| download | zig-31fef6f1103ea64a899729adea13b0ab9b66cb46.tar.gz zig-31fef6f1103ea64a899729adea13b0ab9b66cb46.zip | |
Merge pull request #21225 from mlugg/std-builtin-type
std: update `std.builtin.Type` fields to follow naming conventions
Diffstat (limited to 'lib/std/math')
| -rw-r--r-- | lib/std/math/big.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/big/int.zig | 24 | ||||
| -rw-r--r-- | lib/std/math/big/int_test.zig | 26 | ||||
| -rw-r--r-- | lib/std/math/big/rational.zig | 14 | ||||
| -rw-r--r-- | lib/std/math/copysign.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/float.zig | 20 | ||||
| -rw-r--r-- | lib/std/math/frexp.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/gcd.zig | 4 | ||||
| -rw-r--r-- | lib/std/math/hypot.zig | 4 | ||||
| -rw-r--r-- | lib/std/math/ilogb.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/isfinite.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/isinf.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/isnormal.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/iszero.zig | 4 | ||||
| -rw-r--r-- | lib/std/math/ldexp.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/log.zig | 10 | ||||
| -rw-r--r-- | lib/std/math/log10.zig | 12 | ||||
| -rw-r--r-- | lib/std/math/log2.zig | 8 | ||||
| -rw-r--r-- | lib/std/math/log_int.zig | 8 | ||||
| -rw-r--r-- | lib/std/math/nextafter.zig | 12 | ||||
| -rw-r--r-- | lib/std/math/pow.zig | 6 | ||||
| -rw-r--r-- | lib/std/math/powi.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/signbit.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/sqrt.zig | 12 |
24 files changed, 91 insertions, 93 deletions
diff --git a/lib/std/math/big.zig b/lib/std/math/big.zig index c0d8e74eb2..c201bf1df2 100644 --- a/lib/std/math/big.zig +++ b/lib/std/math/big.zig @@ -4,7 +4,7 @@ const assert = std.debug.assert; pub const Rational = @import("big/rational.zig").Rational; pub const int = @import("big/int.zig"); pub const Limb = usize; -const limb_info = @typeInfo(Limb).Int; +const limb_info = @typeInfo(Limb).int; pub const SignedLimb = std.meta.Int(.signed, limb_info.bits); pub const DoubleLimb = std.meta.Int(.unsigned, 2 * limb_info.bits); pub const HalfLimb = std.meta.Int(.unsigned, limb_info.bits / 2); diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index f0fd6fca4e..2c656033e9 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -2,9 +2,9 @@ const std = @import("../../std.zig"); const builtin = @import("builtin"); const math = std.math; const Limb = std.math.big.Limb; -const limb_bits = @typeInfo(Limb).Int.bits; +const limb_bits = @typeInfo(Limb).int.bits; const HalfLimb = std.math.big.HalfLimb; -const half_limb_bits = @typeInfo(HalfLimb).Int.bits; +const half_limb_bits = @typeInfo(HalfLimb).int.bits; const DoubleLimb = std.math.big.DoubleLimb; const SignedDoubleLimb = std.math.big.SignedDoubleLimb; const Log2Limb = std.math.big.Log2Limb; @@ -23,7 +23,7 @@ const debug_safety = false; /// primitive integer value. /// Note: A comptime-known upper bound of this value that may be used /// instead if `scalar` is not already comptime-known is -/// `calcTwosCompLimbCount(@typeInfo(@TypeOf(scalar)).Int.bits)` +/// `calcTwosCompLimbCount(@typeInfo(@TypeOf(scalar)).int.bits)` pub fn calcLimbLen(scalar: anytype) usize { if (scalar == 0) { return 1; @@ -236,7 +236,7 @@ pub const Mutable = struct { self.positive = value >= 0; switch (@typeInfo(T)) { - .Int => |info| { + .int => |info| { var w_value = @abs(value); if (info.bits <= limb_bits) { @@ -251,7 +251,7 @@ pub const Mutable = struct { } } }, - .ComptimeInt => { + .comptime_int => { comptime var w_value = @abs(value); if (w_value <= maxInt(Limb)) { @@ -405,8 +405,8 @@ pub const Mutable = struct { // is well worth being able to use the stack and not needing an allocator passed in. // Note that Mutable.init still sets len to calcLimbLen(scalar) in any case. const limb_len = comptime switch (@typeInfo(@TypeOf(scalar))) { - .ComptimeInt => calcLimbLen(scalar), - .Int => |info| calcTwosCompLimbCount(info.bits), + .comptime_int => calcLimbLen(scalar), + .int => |info| calcTwosCompLimbCount(info.bits), else => @compileError("expected scalar to be an int"), }; var limbs: [limb_len]Limb = undefined; @@ -2158,7 +2158,7 @@ pub const Const = struct { /// Returns whether self can fit into an integer of the requested type. pub fn fits(self: Const, comptime T: type) bool { - const info = @typeInfo(T).Int; + const info = @typeInfo(T).int; return self.fitsInTwosComp(info.signedness, info.bits); } @@ -2181,7 +2181,7 @@ pub const Const = struct { /// Returns an error if self cannot be narrowed into the requested type without truncation. pub fn to(self: Const, comptime T: type) ConvertError!T { switch (@typeInfo(T)) { - .Int => |info| { + .int => |info| { // Make sure -0 is handled correctly. if (self.eqlZero()) return 0; @@ -2495,8 +2495,8 @@ pub const Const = struct { // is well worth being able to use the stack and not needing an allocator passed in. // Note that Mutable.init still sets len to calcLimbLen(scalar) in any case. const limb_len = comptime switch (@typeInfo(@TypeOf(scalar))) { - .ComptimeInt => calcLimbLen(scalar), - .Int => |info| calcTwosCompLimbCount(info.bits), + .comptime_int => calcLimbLen(scalar), + .int => |info| calcTwosCompLimbCount(info.bits), else => @compileError("expected scalar to be an int"), }; var limbs: [limb_len]Limb = undefined; @@ -2555,7 +2555,7 @@ pub const Const = struct { /// Memory is allocated as needed to ensure operations never overflow. The range /// is bounded only by available memory. pub const Managed = struct { - pub const sign_bit: usize = 1 << (@typeInfo(usize).Int.bits - 1); + pub const sign_bit: usize = 1 << (@typeInfo(usize).int.bits - 1); /// Default number of limbs to allocate on creation of a `Managed`. pub const default_capacity = 4; diff --git a/lib/std/math/big/int_test.zig b/lib/std/math/big/int_test.zig index f06917f0f2..17652179f5 100644 --- a/lib/std/math/big/int_test.zig +++ b/lib/std/math/big/int_test.zig @@ -22,13 +22,13 @@ test "comptime_int set" { var a = try Managed.initSet(testing.allocator, s); defer a.deinit(); - const s_limb_count = 128 / @typeInfo(Limb).Int.bits; + const s_limb_count = 128 / @typeInfo(Limb).int.bits; comptime var i: usize = 0; inline while (i < s_limb_count) : (i += 1) { const result = @as(Limb, s & maxInt(Limb)); - s >>= @typeInfo(Limb).Int.bits / 2; - s >>= @typeInfo(Limb).Int.bits / 2; + s >>= @typeInfo(Limb).int.bits / 2; + s >>= @typeInfo(Limb).int.bits / 2; try testing.expect(a.limbs[i] == result); } } @@ -299,7 +299,7 @@ test "twos complement limit set" { } fn testTwosComplementLimit(comptime T: type) !void { - const int_info = @typeInfo(T).Int; + const int_info = @typeInfo(T).int; var a = try Managed.init(testing.allocator); defer a.deinit(); @@ -1893,7 +1893,7 @@ test "truncate multi to single signed" { } test "truncate multi to multi unsigned" { - const bits = @typeInfo(SignedDoubleLimb).Int.bits; + const bits = @typeInfo(SignedDoubleLimb).int.bits; const Int = std.meta.Int(.unsigned, bits - 1); var a = try Managed.initSet(testing.allocator, maxInt(SignedDoubleLimb)); @@ -2239,11 +2239,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 = @Type(.{ .int = .{ .signedness = .unsigned, .bits = bits } }); try testing.expectEqual((try res.to(Unsigned)), ~@as(Unsigned, maxInt(Limb))); try res.bitNotWrap(&a, .signed, bits); - const Signed = @Type(.{ .Int = .{ .signedness = .signed, .bits = bits } }); + const Signed = @Type(.{ .int = .{ .signedness = .signed, .bits = bits } }); try testing.expectEqual((try res.to(Signed)), ~@as(Signed, maxInt(Limb))); } @@ -3037,8 +3037,8 @@ test "big int conversion write twos complement zero" { } fn bitReverseTest(comptime T: type, comptime input: comptime_int, comptime expected_output: comptime_int) !void { - const bit_count = @typeInfo(T).Int.bits; - const signedness = @typeInfo(T).Int.signedness; + const bit_count = @typeInfo(T).int.bits; + const signedness = @typeInfo(T).int.signedness; var a = try Managed.initSet(testing.allocator, input); defer a.deinit(); @@ -3084,8 +3084,8 @@ test "big int bit reverse" { } fn byteSwapTest(comptime T: type, comptime input: comptime_int, comptime expected_output: comptime_int) !void { - const byte_count = @typeInfo(T).Int.bits / 8; - const signedness = @typeInfo(T).Int.signedness; + const byte_count = @typeInfo(T).int.bits / 8; + const signedness = @typeInfo(T).int.signedness; var a = try Managed.initSet(testing.allocator, input); defer a.deinit(); @@ -3151,7 +3151,7 @@ test "mul multi-multi alias r with a and b" { try testing.expect(a.eql(want)); - if (@typeInfo(Limb).Int.bits == 64) { + if (@typeInfo(Limb).int.bits == 64) { try testing.expectEqual(@as(usize, 5), a.limbs.len); } } @@ -3167,7 +3167,7 @@ test "sqr multi alias r with a" { try testing.expect(a.eql(want)); - if (@typeInfo(Limb).Int.bits == 64) { + if (@typeInfo(Limb).int.bits == 64) { try testing.expectEqual(@as(usize, 5), a.limbs.len); } } diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig index bbfea9de74..ce93f40a25 100644 --- a/lib/std/math/big/rational.zig +++ b/lib/std/math/big/rational.zig @@ -135,9 +135,9 @@ pub const Rational = struct { /// completely represent the provided float. pub fn setFloat(self: *Rational, comptime T: type, f: T) !void { // Translated from golang.go/src/math/big/rat.go. - debug.assert(@typeInfo(T) == .Float); + debug.assert(@typeInfo(T) == .float); - const UnsignedInt = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + const UnsignedInt = std.meta.Int(.unsigned, @typeInfo(T).float.bits); const f_bits = @as(UnsignedInt, @bitCast(f)); const exponent_bits = math.floatExponentBits(T); @@ -193,9 +193,9 @@ pub const Rational = struct { pub fn toFloat(self: Rational, comptime T: type) !T { // Translated from golang.go/src/math/big/rat.go. // TODO: Indicate whether the result is not exact. - debug.assert(@typeInfo(T) == .Float); + debug.assert(@typeInfo(T) == .float); - const fsize = @typeInfo(T).Float.bits; + const fsize = @typeInfo(T).float.bits; const BitReprType = std.meta.Int(.unsigned, fsize); const msize = math.floatMantissaBits(T); @@ -473,10 +473,10 @@ pub const Rational = struct { }; fn extractLowBits(a: Int, comptime T: type) T { - debug.assert(@typeInfo(T) == .Int); + debug.assert(@typeInfo(T) == .int); - const t_bits = @typeInfo(T).Int.bits; - const limb_bits = @typeInfo(Limb).Int.bits; + const t_bits = @typeInfo(T).int.bits; + const limb_bits = @typeInfo(Limb).int.bits; if (t_bits <= limb_bits) { return @as(T, @truncate(a.limbs[0])); } else { diff --git a/lib/std/math/copysign.zig b/lib/std/math/copysign.zig index 63daf59047..65144dfe3f 100644 --- a/lib/std/math/copysign.zig +++ b/lib/std/math/copysign.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; /// Returns a value with the magnitude of `magnitude` and the sign of `sign`. pub fn copysign(magnitude: anytype, sign: @TypeOf(magnitude)) @TypeOf(magnitude) { const T = @TypeOf(magnitude); - const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + const TBits = std.meta.Int(.unsigned, @typeInfo(T).float.bits); const sign_bit_mask = @as(TBits, 1) << (@bitSizeOf(T) - 1); const mag = @as(TBits, @bitCast(magnitude)) & ~sign_bit_mask; const sgn = @as(TBits, @bitCast(sign)) & sign_bit_mask; diff --git a/lib/std/math/float.zig b/lib/std/math/float.zig index 1d19fdc57c..a10332f863 100644 --- a/lib/std/math/float.zig +++ b/lib/std/math/float.zig @@ -6,21 +6,21 @@ const expectEqual = std.testing.expectEqual; /// Creates a raw "1.0" mantissa for floating point type T. Used to dedupe f80 logic. inline fn mantissaOne(comptime T: type) comptime_int { - return if (@typeInfo(T).Float.bits == 80) 1 << floatFractionalBits(T) else 0; + return if (@typeInfo(T).float.bits == 80) 1 << floatFractionalBits(T) else 0; } /// 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 = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @bitSizeOf(T) } }); const biased_exponent = @as(TBits, exponent + floatExponentMax(T)); return @as(T, @bitCast((biased_exponent << floatMantissaBits(T)) | @as(TBits, mantissa))); } /// Returns the number of bits in the exponent of floating point type T. pub inline fn floatExponentBits(comptime T: type) comptime_int { - comptime assert(@typeInfo(T) == .Float); + comptime assert(@typeInfo(T) == .float); - return switch (@typeInfo(T).Float.bits) { + return switch (@typeInfo(T).float.bits) { 16 => 5, 32 => 8, 64 => 11, @@ -32,9 +32,9 @@ pub inline fn floatExponentBits(comptime T: type) comptime_int { /// Returns the number of bits in the mantissa of floating point type T. pub inline fn floatMantissaBits(comptime T: type) comptime_int { - comptime assert(@typeInfo(T) == .Float); + comptime assert(@typeInfo(T) == .float); - return switch (@typeInfo(T).Float.bits) { + return switch (@typeInfo(T).float.bits) { 16 => 10, 32 => 23, 64 => 52, @@ -46,12 +46,12 @@ pub inline fn floatMantissaBits(comptime T: type) comptime_int { /// Returns the number of fractional bits in the mantissa of floating point type T. pub inline fn floatFractionalBits(comptime T: type) comptime_int { - comptime assert(@typeInfo(T) == .Float); + comptime assert(@typeInfo(T) == .float); // standard IEEE floats have an implicit 0.m or 1.m integer part // f80 is special and has an explicitly stored bit in the MSB // this function corresponds to `MANT_DIG - 1' from C - return switch (@typeInfo(T).Float.bits) { + return switch (@typeInfo(T).float.bits) { 16 => 10, 32 => 23, 64 => 52, @@ -97,8 +97,8 @@ pub inline fn floatEps(comptime T: type) T { /// Returns the local epsilon of floating point 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 } }); + .float => |F| { + const U: type = @Type(.{ .int = .{ .signedness = .unsigned, .bits = F.bits } }); const u: U = @bitCast(x); const y: T = @bitCast(u ^ 1); return @abs(x - y); diff --git a/lib/std/math/frexp.zig b/lib/std/math/frexp.zig index 97b578db98..3fb3406075 100644 --- a/lib/std/math/frexp.zig +++ b/lib/std/math/frexp.zig @@ -21,7 +21,7 @@ pub fn Frexp(comptime T: type) type { pub fn frexp(x: anytype) Frexp(@TypeOf(x)) { const T: type = @TypeOf(x); - const bits: comptime_int = @typeInfo(T).Float.bits; + const bits: comptime_int = @typeInfo(T).float.bits; const Int: type = std.meta.Int(.unsigned, bits); const exp_bits: comptime_int = math.floatExponentBits(T); diff --git a/lib/std/math/gcd.zig b/lib/std/math/gcd.zig index 298bf5fc2b..36ba8e3614 100644 --- a/lib/std/math/gcd.zig +++ b/lib/std/math/gcd.zig @@ -8,8 +8,8 @@ pub fn gcd(a: anytype, b: anytype) @TypeOf(a, b) { // only unsigned integers are allowed and not both must be zero comptime switch (@typeInfo(@TypeOf(a, b))) { - .Int => |int| std.debug.assert(int.signedness == .unsigned), - .ComptimeInt => { + .int => |int| std.debug.assert(int.signedness == .unsigned), + .comptime_int => { std.debug.assert(a >= 0); std.debug.assert(b >= 0); }, diff --git a/lib/std/math/hypot.zig b/lib/std/math/hypot.zig index ddc9408aba..e90b6505ce 100644 --- a/lib/std/math/hypot.zig +++ b/lib/std/math/hypot.zig @@ -23,8 +23,8 @@ const floatMax = math.floatMax; pub fn hypot(x: anytype, y: anytype) @TypeOf(x, y) { const T = @TypeOf(x, y); switch (@typeInfo(T)) { - .Float => {}, - .ComptimeFloat => return @sqrt(x * x + y * y), + .float => {}, + .comptime_float => return @sqrt(x * x + y * y), else => @compileError("hypot not implemented for " ++ @typeName(T)), } const lower = @sqrt(floatMin(T)); diff --git a/lib/std/math/ilogb.zig b/lib/std/math/ilogb.zig index 6f4bb13189..ba6075208d 100644 --- a/lib/std/math/ilogb.zig +++ b/lib/std/math/ilogb.zig @@ -26,7 +26,7 @@ pub const fp_ilogbnan = minInt(i32); pub const fp_ilogb0 = minInt(i32); fn ilogbX(comptime T: type, x: T) i32 { - const typeWidth = @typeInfo(T).Float.bits; + const typeWidth = @typeInfo(T).float.bits; const significandBits = math.floatMantissaBits(T); const exponentBits = math.floatExponentBits(T); diff --git a/lib/std/math/isfinite.zig b/lib/std/math/isfinite.zig index 5d5bfd2a41..8f4e170989 100644 --- a/lib/std/math/isfinite.zig +++ b/lib/std/math/isfinite.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; /// Returns whether x is a finite value. pub fn isFinite(x: anytype) bool { const T = @TypeOf(x); - const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + const TBits = std.meta.Int(.unsigned, @typeInfo(T).float.bits); const remove_sign = ~@as(TBits, 0) >> 1; return @as(TBits, @bitCast(x)) & remove_sign < @as(TBits, @bitCast(math.inf(T))); } diff --git a/lib/std/math/isinf.zig b/lib/std/math/isinf.zig index 7a2e3943d6..220f43209d 100644 --- a/lib/std/math/isinf.zig +++ b/lib/std/math/isinf.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; /// Returns whether x is an infinity, ignoring sign. pub inline fn isInf(x: anytype) bool { const T = @TypeOf(x); - const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + const TBits = std.meta.Int(.unsigned, @typeInfo(T).float.bits); const remove_sign = ~@as(TBits, 0) >> 1; return @as(TBits, @bitCast(x)) & remove_sign == @as(TBits, @bitCast(math.inf(T))); } diff --git a/lib/std/math/isnormal.zig b/lib/std/math/isnormal.zig index 1ecaf39330..f3d09441e7 100644 --- a/lib/std/math/isnormal.zig +++ b/lib/std/math/isnormal.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; /// Returns whether x is neither zero, subnormal, infinity, or NaN. pub fn isNormal(x: anytype) bool { const T = @TypeOf(x); - const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + const TBits = std.meta.Int(.unsigned, @typeInfo(T).float.bits); const increment_exp = 1 << math.floatMantissaBits(T); const remove_sign = ~@as(TBits, 0) >> 1; diff --git a/lib/std/math/iszero.zig b/lib/std/math/iszero.zig index 2d288d01e8..57d8250afd 100644 --- a/lib/std/math/iszero.zig +++ b/lib/std/math/iszero.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; /// Returns whether x is positive zero. pub inline fn isPositiveZero(x: anytype) bool { const T = @TypeOf(x); - const bit_count = @typeInfo(T).Float.bits; + const bit_count = @typeInfo(T).float.bits; const TBits = std.meta.Int(.unsigned, bit_count); return @as(TBits, @bitCast(x)) == @as(TBits, 0); } @@ -13,7 +13,7 @@ pub inline fn isPositiveZero(x: anytype) bool { /// Returns whether x is negative zero. pub inline fn isNegativeZero(x: anytype) bool { const T = @TypeOf(x); - const bit_count = @typeInfo(T).Float.bits; + const bit_count = @typeInfo(T).float.bits; const TBits = std.meta.Int(.unsigned, bit_count); return @as(TBits, @bitCast(x)) == @as(TBits, 1) << (bit_count - 1); } diff --git a/lib/std/math/ldexp.zig b/lib/std/math/ldexp.zig index c785f719f0..3b982a9bc2 100644 --- a/lib/std/math/ldexp.zig +++ b/lib/std/math/ldexp.zig @@ -7,7 +7,7 @@ const expect = std.testing.expect; /// Returns x * 2^n. pub fn ldexp(x: anytype, n: i32) @TypeOf(x) { const T = @TypeOf(x); - const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + const TBits = std.meta.Int(.unsigned, @typeInfo(T).float.bits); const exponent_bits = math.floatExponentBits(T); const mantissa_bits = math.floatMantissaBits(T); diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig index 3ff13a7f19..47846fa688 100644 --- a/lib/std/math/log.zig +++ b/lib/std/math/log.zig @@ -14,26 +14,26 @@ pub fn log(comptime T: type, base: T, x: T) T { return math.log2(x); } else if (base == 10) { return math.log10(x); - } else if ((@typeInfo(T) == .Float or @typeInfo(T) == .ComptimeFloat) and base == math.e) { + } else if ((@typeInfo(T) == .float or @typeInfo(T) == .comptime_float) and base == math.e) { return @log(x); } const float_base = math.lossyCast(f64, base); switch (@typeInfo(T)) { - .ComptimeFloat => { + .comptime_float => { return @as(comptime_float, @log(@as(f64, x)) / @log(float_base)); }, - .ComptimeInt => { + .comptime_int => { return @as(comptime_int, math.log_int(comptime_int, base, x)); }, - .Int => |IntType| switch (IntType.signedness) { + .int => |IntType| switch (IntType.signedness) { .signed => @compileError("log not implemented for signed integers"), .unsigned => return @as(T, math.log_int(T, base, x)), }, - .Float => { + .float => { switch (T) { f32 => return @as(f32, @floatCast(@log(@as(f64, x)) / @log(float_base))), f64 => return @log(x) / @log(float_base), diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig index 5b3ee8a840..6f3d9a47f6 100644 --- a/lib/std/math/log10.zig +++ b/lib/std/math/log10.zig @@ -12,14 +12,14 @@ const testing = std.testing; pub fn log10(x: anytype) @TypeOf(x) { const T = @TypeOf(x); switch (@typeInfo(T)) { - .ComptimeFloat => { + .comptime_float => { return @as(comptime_float, @log10(x)); }, - .Float => return @log10(x), - .ComptimeInt => { + .float => return @log10(x), + .comptime_int => { return @as(comptime_int, @floor(@log10(@as(f64, x)))); }, - .Int => |IntType| switch (IntType.signedness) { + .int => |IntType| switch (IntType.signedness) { .signed => @compileError("log10 not implemented for signed integers"), .unsigned => return log10_int(x), }, @@ -37,12 +37,12 @@ pub fn log10(x: anytype) @TypeOf(x) { pub fn log10_int(x: anytype) std.math.Log2Int(@TypeOf(x)) { const T = @TypeOf(x); const OutT = std.math.Log2Int(T); - if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned) + if (@typeInfo(T) != .int or @typeInfo(T).int.signedness != .unsigned) @compileError("log10_int requires an unsigned integer, found " ++ @typeName(T)); std.debug.assert(x != 0); - const bit_size = @typeInfo(T).Int.bits; + const bit_size = @typeInfo(T).int.bits; if (bit_size <= 8) { return @as(OutT, @intCast(log10_int_u8(x))); diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig index 0902f3e10c..01a1bd3856 100644 --- a/lib/std/math/log2.zig +++ b/lib/std/math/log2.zig @@ -13,11 +13,11 @@ const expect = std.testing.expect; pub fn log2(x: anytype) @TypeOf(x) { const T = @TypeOf(x); switch (@typeInfo(T)) { - .ComptimeFloat => { + .comptime_float => { return @as(comptime_float, @log2(x)); }, - .Float => return @log2(x), - .ComptimeInt => comptime { + .float => return @log2(x), + .comptime_int => comptime { var x_shifted = x; // First, calculate floorPowerOfTwo(x) var shift_amt = 1; @@ -34,7 +34,7 @@ pub fn log2(x: anytype) @TypeOf(x) { } return result; }, - .Int => |IntType| switch (IntType.signedness) { + .int => |IntType| switch (IntType.signedness) { .signed => @compileError("log2 not implemented for signed integers"), .unsigned => return math.log2_int(T, x), }, diff --git a/lib/std/math/log_int.zig b/lib/std/math/log_int.zig index edf5c31782..376aa69a4d 100644 --- a/lib/std/math/log_int.zig +++ b/lib/std/math/log_int.zig @@ -8,8 +8,8 @@ const Log2Int = math.Log2Int; /// Asserts that `base > 1` and `x > 0`. pub fn log_int(comptime T: type, base: T, x: T) Log2Int(T) { const valid = switch (@typeInfo(T)) { - .ComptimeInt => true, - .Int => |IntType| IntType.signedness == .unsigned, + .comptime_int => true, + .int => |IntType| IntType.signedness == .unsigned, else => false, }; if (!valid) @compileError("log_int requires an unsigned integer, found " ++ @typeName(T)); @@ -64,9 +64,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(std.builtin.Type{ - .Int = std.builtin.Type.Int{ .signedness = .unsigned, .bits = @intCast(bits) }, - }); + const T = @Type(.{ .int = .{ .signedness = .unsigned, .bits = @intCast(bits) } }); // for base = 2, 3, ..., min(maxInt(T),1024) var base: T = 1; diff --git a/lib/std/math/nextafter.zig b/lib/std/math/nextafter.zig index b88648229b..12418b5a1a 100644 --- a/lib/std/math/nextafter.zig +++ b/lib/std/math/nextafter.zig @@ -14,15 +14,15 @@ const expect = std.testing.expect; /// pub fn nextAfter(comptime T: type, x: T, y: T) T { return switch (@typeInfo(T)) { - .Int, .ComptimeInt => nextAfterInt(T, x, y), - .Float => nextAfterFloat(T, x, y), + .int, .comptime_int => nextAfterInt(T, x, y), + .float => nextAfterFloat(T, x, y), else => @compileError("expected int or non-comptime float, found '" ++ @typeName(T) ++ "'"), }; } fn nextAfterInt(comptime T: type, x: T, y: T) T { - comptime assert(@typeInfo(T) == .Int or @typeInfo(T) == .ComptimeInt); - return if (@typeInfo(T) == .Int and @bitSizeOf(T) < 2) + comptime assert(@typeInfo(T) == .int or @typeInfo(T) == .comptime_int); + return if (@typeInfo(T) == .int and @bitSizeOf(T) < 2) // Special case for `i0`, `u0`, `i1`, and `u1`. y else if (y > x) @@ -38,7 +38,7 @@ fn nextAfterInt(comptime T: type, x: T, y: T) T { // <https://github.com/mingw-w64/mingw-w64/blob/e89de847dd3e05bb8e46344378ce3e124f4e7d1c/mingw-w64-crt/math/nextafterl.c> fn nextAfterFloat(comptime T: type, x: T, y: T) T { - comptime assert(@typeInfo(T) == .Float); + comptime assert(@typeInfo(T) == .float); if (x == y) { // Returning `y` ensures that (0.0, -0.0) returns -0.0 and that (-0.0, 0.0) returns 0.0. return y; @@ -320,7 +320,7 @@ test "float" { /// Helps ensure that 0.0 doesn't compare equal to -0.0. fn bitwiseEqual(comptime T: type, x: T, y: T) bool { - comptime assert(@typeInfo(T) == .Float); + comptime assert(@typeInfo(T) == .float); const Bits = std.meta.Int(.unsigned, @bitSizeOf(T)); return @as(Bits, @bitCast(x)) == @as(Bits, @bitCast(y)); } diff --git a/lib/std/math/pow.zig b/lib/std/math/pow.zig index 2e50cc16dd..7409561e1f 100644 --- a/lib/std/math/pow.zig +++ b/lib/std/math/pow.zig @@ -31,7 +31,7 @@ const expect = std.testing.expect; /// - pow(-inf, y) = pow(-0, -y) /// - pow(x, y) = nan for finite x < 0 and finite non-integer y pub fn pow(comptime T: type, x: T, y: T) T { - if (@typeInfo(T) == .Int) { + if (@typeInfo(T) == .int) { return math.powi(T, x, y) catch unreachable; } @@ -122,7 +122,7 @@ pub fn pow(comptime T: type, x: T, y: T) T { if (yf != 0 and x < 0) { return math.nan(T); } - if (yi >= 1 << (@typeInfo(T).Float.bits - 1)) { + if (yi >= 1 << (@typeInfo(T).float.bits - 1)) { return @exp(y * @log(x)); } @@ -144,7 +144,7 @@ pub fn pow(comptime T: type, x: T, y: T) T { var xe = r2.exponent; var x1 = r2.significand; - var i = @as(std.meta.Int(.signed, @typeInfo(T).Float.bits), @intFromFloat(yi)); + var i = @as(std.meta.Int(.signed, @typeInfo(T).float.bits), @intFromFloat(yi)); while (i != 0) : (i >>= 1) { const overflow_shift = math.floatExponentBits(T) + 1; if (xe < -(1 << overflow_shift) or (1 << overflow_shift) < xe) { diff --git a/lib/std/math/powi.zig b/lib/std/math/powi.zig index 271d24352a..aed79e097c 100644 --- a/lib/std/math/powi.zig +++ b/lib/std/math/powi.zig @@ -27,7 +27,7 @@ pub fn powi(comptime T: type, x: T, y: T) (error{ Overflow, Underflow, }!T) { - const bit_size = @typeInfo(T).Int.bits; + const bit_size = @typeInfo(T).int.bits; // `y & 1 == 0` won't compile when `does_one_overflow`. const does_one_overflow = math.maxInt(T) < 1; diff --git a/lib/std/math/signbit.zig b/lib/std/math/signbit.zig index eeb729ceb7..97dd03613a 100644 --- a/lib/std/math/signbit.zig +++ b/lib/std/math/signbit.zig @@ -5,7 +5,7 @@ const expect = std.testing.expect; /// Returns whether x is negative or negative 0. pub fn signbit(x: anytype) bool { const T = @TypeOf(x); - const TBits = std.meta.Int(.unsigned, @typeInfo(T).Float.bits); + const TBits = std.meta.Int(.unsigned, @typeInfo(T).float.bits); return @as(TBits, @bitCast(x)) >> (@bitSizeOf(T) - 1) != 0; } diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index a000911897..0753277bb7 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -15,8 +15,8 @@ const maxInt = std.math.maxInt; pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) { const T = @TypeOf(x); switch (@typeInfo(T)) { - .Float, .ComptimeFloat => return @sqrt(x), - .ComptimeInt => comptime { + .float, .comptime_float => return @sqrt(x), + .comptime_int => comptime { if (x > maxInt(u128)) { @compileError("sqrt not implemented for comptime_int greater than 128 bits"); } @@ -25,7 +25,7 @@ pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) { } return @as(T, sqrt_int(u128, x)); }, - .Int => |IntType| switch (IntType.signedness) { + .int => |IntType| switch (IntType.signedness) { .signed => @compileError("sqrt not implemented for signed integers"), .unsigned => return sqrt_int(T, x), }, @@ -34,10 +34,10 @@ pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) { } fn sqrt_int(comptime T: type, value: T) Sqrt(T) { - if (@typeInfo(T).Int.bits <= 2) { + if (@typeInfo(T).int.bits <= 2) { return if (value == 0) 0 else 1; // shortcut for small number of bits to simplify general case } else { - const bits = @typeInfo(T).Int.bits; + const bits = @typeInfo(T).int.bits; const max = math.maxInt(T); const minustwo = (@as(T, 2) ^ max) + 1; // unsigned int cannot represent -2 var op = value; @@ -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| std.meta.Int(.unsigned, (int.bits + 1) / 2), + .int => |int| @Type(.{ .int = .{ .signedness = .unsigned, .bits = (int.bits + 1) / 2 } }), else => T, }; } |
