diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-02-24 21:57:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-24 21:57:29 -0500 |
| commit | 61a50a23e88945af71c0e4c56bf378869c670f49 (patch) | |
| tree | 0281872fbe5bbfba6de1b527a14ec8fb932c9e3a /lib/std/math | |
| parent | 544bc42fd9b612462579928298ec467484763ae1 (diff) | |
| parent | d56115ef4189a7716d9371ef87df9124a61f5ab1 (diff) | |
| download | zig-61a50a23e88945af71c0e4c56bf378869c670f49.tar.gz zig-61a50a23e88945af71c0e4c56bf378869c670f49.zip | |
Merge pull request #4547 from Vexu/deprecate
Remove deprecated builtins
Diffstat (limited to 'lib/std/math')
| -rw-r--r-- | lib/std/math/big/int.zig | 17 | ||||
| -rw-r--r-- | lib/std/math/big/rational.zig | 15 | ||||
| -rw-r--r-- | lib/std/math/cos.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/ln.zig | 12 | ||||
| -rw-r--r-- | lib/std/math/log.zig | 14 | ||||
| -rw-r--r-- | lib/std/math/log10.zig | 12 | ||||
| -rw-r--r-- | lib/std/math/log2.zig | 12 | ||||
| -rw-r--r-- | lib/std/math/pow.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/sin.zig | 2 | ||||
| -rw-r--r-- | lib/std/math/sqrt.zig | 6 | ||||
| -rw-r--r-- | lib/std/math/tan.zig | 2 |
11 files changed, 41 insertions, 55 deletions
diff --git a/lib/std/math/big/int.zig b/lib/std/math/big/int.zig index d42d9fc676..8fda3f647a 100644 --- a/lib/std/math/big/int.zig +++ b/lib/std/math/big/int.zig @@ -1,5 +1,4 @@ const std = @import("../../std.zig"); -const builtin = @import("builtin"); const debug = std.debug; const testing = std.testing; const math = std.math; @@ -9,10 +8,8 @@ const ArrayList = std.ArrayList; const maxInt = std.math.maxInt; const minInt = std.math.minInt; -const TypeId = builtin.TypeId; - pub const Limb = usize; -pub const DoubleLimb = @IntType(false, 2 * Limb.bit_count); +pub const DoubleLimb = std.meta.IntType(false, 2 * Limb.bit_count); pub const Log2Limb = math.Log2Int(Limb); comptime { @@ -270,8 +267,8 @@ pub const Int = struct { const T = @TypeOf(value); switch (@typeInfo(T)) { - TypeId.Int => |info| { - const UT = if (T.is_signed) @IntType(false, T.bit_count - 1) else T; + .Int => |info| { + const UT = if (T.is_signed) std.meta.IntType(false, T.bit_count - 1) else T; try self.ensureCapacity(@sizeOf(UT) / @sizeOf(Limb)); self.metadata = 0; @@ -294,7 +291,7 @@ pub const Int = struct { } } }, - TypeId.ComptimeInt => { + .ComptimeInt => { comptime var w_value = if (value < 0) -value else value; const req_limbs = @divFloor(math.log2(w_value), Limb.bit_count) + 1; @@ -332,9 +329,9 @@ pub const Int = struct { /// /// Returns an error if self cannot be narrowed into the requested type without truncation. pub fn to(self: Int, comptime T: type) ConvertError!T { - switch (@typeId(T)) { - TypeId.Int => { - const UT = @IntType(false, T.bit_count); + switch (@typeInfo(T)) { + .Int => { + const UT = std.meta.IntType(false, T.bit_count); if (self.bitCountTwosComp() > T.bit_count) { return error.TargetTooSmall; diff --git a/lib/std/math/big/rational.zig b/lib/std/math/big/rational.zig index 438c6c94fc..a57183a623 100644 --- a/lib/std/math/big/rational.zig +++ b/lib/std/math/big/rational.zig @@ -1,5 +1,4 @@ const std = @import("../../std.zig"); -const builtin = @import("builtin"); const debug = std.debug; const math = std.math; const mem = std.mem; @@ -7,8 +6,6 @@ const testing = std.testing; const Allocator = mem.Allocator; const ArrayList = std.ArrayList; -const TypeId = builtin.TypeId; - const bn = @import("int.zig"); const Limb = bn.Limb; const DoubleLimb = bn.DoubleLimb; @@ -129,9 +126,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(@typeId(T) == builtin.TypeId.Float); + debug.assert(@typeInfo(T) == .Float); - const UnsignedIntType = @IntType(false, T.bit_count); + const UnsignedIntType = std.meta.IntType(false, T.bit_count); const f_bits = @bitCast(UnsignedIntType, f); const exponent_bits = math.floatExponentBits(T); @@ -187,10 +184,10 @@ 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(@typeId(T) == builtin.TypeId.Float); + debug.assert(@typeInfo(T) == .Float); const fsize = T.bit_count; - const BitReprType = @IntType(false, T.bit_count); + const BitReprType = std.meta.IntType(false, T.bit_count); const msize = math.floatMantissaBits(T); const msize1 = msize + 1; @@ -465,7 +462,7 @@ pub const Rational = struct { } }; -const SignedDoubleLimb = @IntType(true, DoubleLimb.bit_count); +const SignedDoubleLimb = std.meta.IntType(true, DoubleLimb.bit_count); fn gcd(rma: *Int, x: Int, y: Int) !void { rma.assertWritable(); @@ -653,7 +650,7 @@ test "big.rational gcd one large" { } fn extractLowBits(a: Int, comptime T: type) T { - testing.expect(@typeId(T) == builtin.TypeId.Int); + testing.expect(@typeInfo(T) == .Int); if (T.bit_count <= Limb.bit_count) { return @truncate(T, a.limbs[0]); diff --git a/lib/std/math/cos.zig b/lib/std/math/cos.zig index 248243e288..8a599aece4 100644 --- a/lib/std/math/cos.zig +++ b/lib/std/math/cos.zig @@ -44,7 +44,7 @@ const pi4c = 2.69515142907905952645E-15; const m4pi = 1.273239544735162542821171882678754627704620361328125; fn cos_(comptime T: type, x_: T) T { - const I = @IntType(true, T.bit_count); + const I = std.meta.IntType(true, T.bit_count); var x = x_; if (math.isNan(x) or math.isInf(x)) { diff --git a/lib/std/math/ln.zig b/lib/std/math/ln.zig index da3e60202d..555a786907 100644 --- a/lib/std/math/ln.zig +++ b/lib/std/math/ln.zig @@ -7,8 +7,6 @@ const std = @import("../std.zig"); const math = std.math; const expect = std.testing.expect; -const builtin = @import("builtin"); -const TypeId = builtin.TypeId; /// Returns the natural logarithm of x. /// @@ -19,21 +17,21 @@ const TypeId = builtin.TypeId; /// - ln(nan) = nan pub fn ln(x: var) @TypeOf(x) { const T = @TypeOf(x); - switch (@typeId(T)) { - TypeId.ComptimeFloat => { + switch (@typeInfo(T)) { + .ComptimeFloat => { return @as(comptime_float, ln_64(x)); }, - TypeId.Float => { + .Float => { return switch (T) { f32 => ln_32(x), f64 => ln_64(x), else => @compileError("ln not implemented for " ++ @typeName(T)), }; }, - TypeId.ComptimeInt => { + .ComptimeInt => { return @as(comptime_int, math.floor(ln_64(@as(f64, x)))); }, - TypeId.Int => { + .Int => { return @as(T, math.floor(ln_64(@as(f64, x)))); }, else => @compileError("ln not implemented for " ++ @typeName(T)), diff --git a/lib/std/math/log.zig b/lib/std/math/log.zig index 9d77397e17..6f5025cd50 100644 --- a/lib/std/math/log.zig +++ b/lib/std/math/log.zig @@ -6,8 +6,6 @@ const std = @import("../std.zig"); const math = std.math; -const builtin = @import("builtin"); -const TypeId = builtin.TypeId; const expect = std.testing.expect; /// Returns the logarithm of x for the provided base. @@ -16,24 +14,24 @@ 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 ((@typeId(T) == TypeId.Float or @typeId(T) == TypeId.ComptimeFloat) and base == math.e) { + } else if ((@typeInfo(T) == .Float or @typeInfo(T) == .ComptimeFloat) and base == math.e) { return math.ln(x); } const float_base = math.lossyCast(f64, base); - switch (@typeId(T)) { - TypeId.ComptimeFloat => { + switch (@typeInfo(T)) { + .ComptimeFloat => { return @as(comptime_float, math.ln(@as(f64, x)) / math.ln(float_base)); }, - TypeId.ComptimeInt => { + .ComptimeInt => { return @as(comptime_int, math.floor(math.ln(@as(f64, x)) / math.ln(float_base))); }, - builtin.TypeId.Int => { + .Int => { // TODO implement integer log without using float math return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base))); }, - builtin.TypeId.Float => { + .Float => { switch (T) { f32 => return @floatCast(f32, math.ln(@as(f64, x)) / math.ln(float_base)), f64 => return math.ln(x) / math.ln(float_base), diff --git a/lib/std/math/log10.zig b/lib/std/math/log10.zig index a0deee69d1..7367af28c6 100644 --- a/lib/std/math/log10.zig +++ b/lib/std/math/log10.zig @@ -7,8 +7,6 @@ const std = @import("../std.zig"); const math = std.math; const testing = std.testing; -const builtin = @import("builtin"); -const TypeId = builtin.TypeId; const maxInt = std.math.maxInt; /// Returns the base-10 logarithm of x. @@ -20,21 +18,21 @@ const maxInt = std.math.maxInt; /// - log10(nan) = nan pub fn log10(x: var) @TypeOf(x) { const T = @TypeOf(x); - switch (@typeId(T)) { - TypeId.ComptimeFloat => { + switch (@typeInfo(T)) { + .ComptimeFloat => { return @as(comptime_float, log10_64(x)); }, - TypeId.Float => { + .Float => { return switch (T) { f32 => log10_32(x), f64 => log10_64(x), else => @compileError("log10 not implemented for " ++ @typeName(T)), }; }, - TypeId.ComptimeInt => { + .ComptimeInt => { return @as(comptime_int, math.floor(log10_64(@as(f64, x)))); }, - TypeId.Int => { + .Int => { return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))); }, else => @compileError("log10 not implemented for " ++ @typeName(T)), diff --git a/lib/std/math/log2.zig b/lib/std/math/log2.zig index d3b655a56a..54f8bc2baa 100644 --- a/lib/std/math/log2.zig +++ b/lib/std/math/log2.zig @@ -7,8 +7,6 @@ const std = @import("../std.zig"); const math = std.math; const expect = std.testing.expect; -const builtin = @import("builtin"); -const TypeId = builtin.TypeId; const maxInt = std.math.maxInt; /// Returns the base-2 logarithm of x. @@ -20,18 +18,18 @@ const maxInt = std.math.maxInt; /// - log2(nan) = nan pub fn log2(x: var) @TypeOf(x) { const T = @TypeOf(x); - switch (@typeId(T)) { - TypeId.ComptimeFloat => { + switch (@typeInfo(T)) { + .ComptimeFloat => { return @as(comptime_float, log2_64(x)); }, - TypeId.Float => { + .Float => { return switch (T) { f32 => log2_32(x), f64 => log2_64(x), else => @compileError("log2 not implemented for " ++ @typeName(T)), }; }, - TypeId.ComptimeInt => comptime { + .ComptimeInt => comptime { var result = 0; var x_shifted = x; while (b: { @@ -40,7 +38,7 @@ pub fn log2(x: var) @TypeOf(x) { }) : (result += 1) {} return result; }, - TypeId.Int => { + .Int => { return math.log2_int(T, x); }, else => @compileError("log2 not implemented for " ++ @typeName(T)), diff --git a/lib/std/math/pow.zig b/lib/std/math/pow.zig index 18c9f80634..4f623377e6 100644 --- a/lib/std/math/pow.zig +++ b/lib/std/math/pow.zig @@ -145,7 +145,7 @@ pub fn pow(comptime T: type, x: T, y: T) T { var xe = r2.exponent; var x1 = r2.significand; - var i = @floatToInt(@IntType(true, T.bit_count), yi); + var i = @floatToInt(std.meta.IntType(true, T.bit_count), 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/sin.zig b/lib/std/math/sin.zig index 00225449bb..0c339ba1f2 100644 --- a/lib/std/math/sin.zig +++ b/lib/std/math/sin.zig @@ -45,7 +45,7 @@ const pi4c = 2.69515142907905952645E-15; const m4pi = 1.273239544735162542821171882678754627704620361328125; fn sin_(comptime T: type, x_: T) T { - const I = @IntType(true, T.bit_count); + const I = std.meta.IntType(true, T.bit_count); var x = x_; if (x == 0 or math.isNan(x)) { diff --git a/lib/std/math/sqrt.zig b/lib/std/math/sqrt.zig index 800a7574ae..e5d8a822f5 100644 --- a/lib/std/math/sqrt.zig +++ b/lib/std/math/sqrt.zig @@ -31,7 +31,7 @@ pub fn sqrt(x: var) Sqrt(@TypeOf(x)) { } } -fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) { +fn sqrt_int(comptime T: type, value: T) std.meta.IntType(false, T.bit_count / 2) { var op = value; var res: T = 0; var one: T = 1 << (T.bit_count - 2); @@ -50,7 +50,7 @@ fn sqrt_int(comptime T: type, value: T) @IntType(false, T.bit_count / 2) { one >>= 2; } - const ResultType = @IntType(false, T.bit_count / 2); + const ResultType = std.meta.IntType(false, T.bit_count / 2); return @intCast(ResultType, res); } @@ -66,7 +66,7 @@ test "math.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| @IntType(false, int.bits / 2), + .Int => |int| std.meta.IntType(false, int.bits / 2), else => T, }; } diff --git a/lib/std/math/tan.zig b/lib/std/math/tan.zig index 01a0314d74..737f5b0e09 100644 --- a/lib/std/math/tan.zig +++ b/lib/std/math/tan.zig @@ -38,7 +38,7 @@ const pi4c = 2.69515142907905952645E-15; const m4pi = 1.273239544735162542821171882678754627704620361328125; fn tan_(comptime T: type, x_: T) T { - const I = @IntType(true, T.bit_count); + const I = std.meta.IntType(true, T.bit_count); var x = x_; if (x == 0 or math.isNan(x)) { |
