aboutsummaryrefslogtreecommitdiff
path: root/lib/std/math.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/math.zig')
-rw-r--r--lib/std/math.zig196
1 files changed, 98 insertions, 98 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig
index f18739095c..67782bf93b 100644
--- a/lib/std/math.zig
+++ b/lib/std/math.zig
@@ -71,7 +71,7 @@ pub const snan = float.snan;
///
/// NaN values are never considered equal to any value.
pub fn approxEqAbs(comptime T: type, x: T, y: T, tolerance: T) bool {
- assert(@typeInfo(T) == .Float or @typeInfo(T) == .ComptimeFloat);
+ assert(@typeInfo(T) == .float or @typeInfo(T) == .comptime_float);
assert(tolerance >= 0);
// Fast path for equal values (and signed zeros and infinites).
@@ -99,7 +99,7 @@ pub fn approxEqAbs(comptime T: type, x: T, y: T, tolerance: T) bool {
///
/// NaN values are never considered equal to any value.
pub fn approxEqRel(comptime T: type, x: T, y: T, tolerance: T) bool {
- assert(@typeInfo(T) == .Float or @typeInfo(T) == .ComptimeFloat);
+ assert(@typeInfo(T) == .float or @typeInfo(T) == .comptime_float);
assert(tolerance > 0);
// Fast path for equal values (and signed zeros and infinites).
@@ -263,8 +263,8 @@ pub inline fn tan(value: anytype) @TypeOf(value) {
pub fn radiansToDegrees(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime_float else @TypeOf(ang) {
const T = @TypeOf(ang);
switch (@typeInfo(T)) {
- .Float, .ComptimeFloat, .ComptimeInt => return ang * deg_per_rad,
- .Vector => |V| if (@typeInfo(V.child) == .Float) return ang * @as(T, @splat(deg_per_rad)),
+ .float, .comptime_float, .comptime_int => return ang * deg_per_rad,
+ .vector => |V| if (@typeInfo(V.child) == .float) return ang * @as(T, @splat(deg_per_rad)),
else => {},
}
@compileError("Input must be float or a comptime number, or a vector of floats.");
@@ -298,8 +298,8 @@ test radiansToDegrees {
pub fn degreesToRadians(ang: anytype) if (@TypeOf(ang) == comptime_int) comptime_float else @TypeOf(ang) {
const T = @TypeOf(ang);
switch (@typeInfo(T)) {
- .Float, .ComptimeFloat, .ComptimeInt => return ang * rad_per_deg,
- .Vector => |V| if (@typeInfo(V.child) == .Float) return ang * @as(T, @splat(rad_per_deg)),
+ .float, .comptime_float, .comptime_int => return ang * rad_per_deg,
+ .vector => |V| if (@typeInfo(V.child) == .float) return ang * @as(T, @splat(rad_per_deg)),
else => {},
}
@compileError("Input must be float or a comptime number, or a vector of floats.");
@@ -408,8 +408,8 @@ test {
/// full range of the minimum value.
pub fn Min(comptime A: type, comptime B: type) type {
switch (@typeInfo(A)) {
- .Int => |a_info| switch (@typeInfo(B)) {
- .Int => |b_info| if (a_info.signedness == .unsigned and b_info.signedness == .unsigned) {
+ .int => |a_info| switch (@typeInfo(B)) {
+ .int => |b_info| if (a_info.signedness == .unsigned and b_info.signedness == .unsigned) {
if (a_info.bits < b_info.bits) {
return A;
} else {
@@ -437,21 +437,21 @@ pub fn Min(comptime A: type, comptime B: type) type {
pub fn wrap(x: anytype, r: anytype) @TypeOf(x) {
const info_x = @typeInfo(@TypeOf(x));
const info_r = @typeInfo(@TypeOf(r));
- if (info_x == .Int and info_x.Int.signedness != .signed) {
+ if (info_x == .int and info_x.int.signedness != .signed) {
@compileError("x must be floating point, comptime integer, or signed integer.");
}
switch (info_r) {
- .Int => {
+ .int => {
// in the rare usecase of r not being comptime_int or float,
// take the penalty of having an intermediary type conversion,
// otherwise the alternative is to unwind iteratively to avoid overflow
const R = comptime do: {
var info = info_r;
- info.Int.bits += 1;
- info.Int.signedness = .signed;
+ info.int.bits += 1;
+ info.int.signedness = .signed;
break :do @Type(info);
};
- const radius: if (info_r.Int.signedness == .signed) @TypeOf(r) else R = r;
+ const radius: if (info_r.int.signedness == .signed) @TypeOf(r) else R = r;
return @intCast(@mod(x - radius, 2 * @as(R, r)) - r); // provably impossible to overflow
},
else => {
@@ -520,9 +520,9 @@ test wrap {
pub fn clamp(val: anytype, lower: anytype, upper: anytype) @TypeOf(val, lower, upper) {
const T = @TypeOf(val, lower, upper);
switch (@typeInfo(T)) {
- .Int, .Float, .ComptimeInt, .ComptimeFloat => assert(lower <= upper),
- .Vector => |vinfo| switch (@typeInfo(vinfo.child)) {
- .Int, .Float => assert(@reduce(.And, lower <= upper)),
+ .int, .float, .comptime_int, .comptime_float => assert(lower <= upper),
+ .vector => |vinfo| switch (@typeInfo(vinfo.child)) {
+ .int, .float => assert(@reduce(.And, lower <= upper)),
else => @compileError("Expected vector of ints or floats, found " ++ @typeName(T)),
},
else => @compileError("Expected an int, float or vector of one, found " ++ @typeName(T)),
@@ -593,18 +593,18 @@ pub fn shl(comptime T: type, a: T, shift_amt: anytype) T {
const abs_shift_amt = @abs(shift_amt);
const casted_shift_amt = blk: {
- if (@typeInfo(T) == .Vector) {
- const C = @typeInfo(T).Vector.child;
- const len = @typeInfo(T).Vector.len;
- if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(0);
+ if (@typeInfo(T) == .vector) {
+ const C = @typeInfo(T).vector.child;
+ const len = @typeInfo(T).vector.len;
+ if (abs_shift_amt >= @typeInfo(C).int.bits) return @splat(0);
break :blk @as(@Vector(len, Log2Int(C)), @splat(@as(Log2Int(C), @intCast(abs_shift_amt))));
} else {
- if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;
+ if (abs_shift_amt >= @typeInfo(T).int.bits) return 0;
break :blk @as(Log2Int(T), @intCast(abs_shift_amt));
}
};
- if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.signedness == .signed) {
+ if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).int.signedness == .signed) {
if (shift_amt < 0) {
return a >> casted_shift_amt;
}
@@ -633,18 +633,18 @@ pub fn shr(comptime T: type, a: T, shift_amt: anytype) T {
const abs_shift_amt = @abs(shift_amt);
const casted_shift_amt = blk: {
- if (@typeInfo(T) == .Vector) {
- const C = @typeInfo(T).Vector.child;
- const len = @typeInfo(T).Vector.len;
- if (abs_shift_amt >= @typeInfo(C).Int.bits) return @splat(0);
+ if (@typeInfo(T) == .vector) {
+ const C = @typeInfo(T).vector.child;
+ const len = @typeInfo(T).vector.len;
+ if (abs_shift_amt >= @typeInfo(C).int.bits) return @splat(0);
break :blk @as(@Vector(len, Log2Int(C)), @splat(@as(Log2Int(C), @intCast(abs_shift_amt))));
} else {
- if (abs_shift_amt >= @typeInfo(T).Int.bits) return 0;
+ if (abs_shift_amt >= @typeInfo(T).int.bits) return 0;
break :blk @as(Log2Int(T), @intCast(abs_shift_amt));
}
};
- if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).Int.signedness == .signed) {
+ if (@TypeOf(shift_amt) == comptime_int or @typeInfo(@TypeOf(shift_amt)).int.signedness == .signed) {
if (shift_amt < 0) {
return a << casted_shift_amt;
}
@@ -670,26 +670,26 @@ test shr {
/// Rotates right. Only unsigned values can be rotated. Negative shift
/// values result in shift modulo the bit count.
pub fn rotr(comptime T: type, x: T, r: anytype) T {
- if (@typeInfo(T) == .Vector) {
- const C = @typeInfo(T).Vector.child;
+ if (@typeInfo(T) == .vector) {
+ const C = @typeInfo(T).vector.child;
if (C == u0) return 0;
- if (@typeInfo(C).Int.signedness == .signed) {
+ if (@typeInfo(C).int.signedness == .signed) {
@compileError("cannot rotate signed integers");
}
- const ar: Log2Int(C) = @intCast(@mod(r, @typeInfo(C).Int.bits));
+ const ar: Log2Int(C) = @intCast(@mod(r, @typeInfo(C).int.bits));
return (x >> @splat(ar)) | (x << @splat(1 + ~ar));
- } else if (@typeInfo(T).Int.signedness == .signed) {
+ } else if (@typeInfo(T).int.signedness == .signed) {
@compileError("cannot rotate signed integer");
} else {
if (T == u0) return 0;
- if (comptime isPowerOfTwo(@typeInfo(T).Int.bits)) {
- const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).Int.bits));
+ if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
+ const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
return x >> ar | x << (1 +% ~ar);
} else {
- const ar = @mod(r, @typeInfo(T).Int.bits);
- return shr(T, x, ar) | shl(T, x, @typeInfo(T).Int.bits - ar);
+ const ar = @mod(r, @typeInfo(T).int.bits);
+ return shr(T, x, ar) | shl(T, x, @typeInfo(T).int.bits - ar);
}
}
}
@@ -711,26 +711,26 @@ test rotr {
/// Rotates left. Only unsigned values can be rotated. Negative shift
/// values result in shift modulo the bit count.
pub fn rotl(comptime T: type, x: T, r: anytype) T {
- if (@typeInfo(T) == .Vector) {
- const C = @typeInfo(T).Vector.child;
+ if (@typeInfo(T) == .vector) {
+ const C = @typeInfo(T).vector.child;
if (C == u0) return 0;
- if (@typeInfo(C).Int.signedness == .signed) {
+ if (@typeInfo(C).int.signedness == .signed) {
@compileError("cannot rotate signed integers");
}
- const ar: Log2Int(C) = @intCast(@mod(r, @typeInfo(C).Int.bits));
+ const ar: Log2Int(C) = @intCast(@mod(r, @typeInfo(C).int.bits));
return (x << @splat(ar)) | (x >> @splat(1 +% ~ar));
- } else if (@typeInfo(T).Int.signedness == .signed) {
+ } else if (@typeInfo(T).int.signedness == .signed) {
@compileError("cannot rotate signed integer");
} else {
if (T == u0) return 0;
- if (comptime isPowerOfTwo(@typeInfo(T).Int.bits)) {
- const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).Int.bits));
+ if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
+ const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
return x << ar | x >> 1 +% ~ar;
} else {
- const ar = @mod(r, @typeInfo(T).Int.bits);
- return shl(T, x, ar) | shr(T, x, @typeInfo(T).Int.bits - ar);
+ const ar = @mod(r, @typeInfo(T).int.bits);
+ return shl(T, x, ar) | shr(T, x, @typeInfo(T).int.bits - ar);
}
}
}
@@ -754,7 +754,7 @@ test rotl {
pub fn Log2Int(comptime T: type) type {
// comptime ceil log2
if (T == comptime_int) return comptime_int;
- const bits: u16 = @typeInfo(T).Int.bits;
+ const bits: u16 = @typeInfo(T).int.bits;
const log2_bits = 16 - @clz(bits - 1);
return std.meta.Int(.unsigned, log2_bits);
}
@@ -763,7 +763,7 @@ pub fn Log2Int(comptime T: type) type {
pub fn Log2IntCeil(comptime T: type) type {
// comptime ceil log2
if (T == comptime_int) return comptime_int;
- const bits: u16 = @typeInfo(T).Int.bits;
+ const bits: u16 = @typeInfo(T).int.bits;
const log2_bits = 16 - @clz(bits);
return std.meta.Int(.unsigned, log2_bits);
}
@@ -849,7 +849,7 @@ fn testOverflow() !void {
pub fn divTrunc(comptime T: type, numerator: T, denominator: T) !T {
@setRuntimeSafety(false);
if (denominator == 0) return error.DivisionByZero;
- if (@typeInfo(T) == .Int and @typeInfo(T).Int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
+ if (@typeInfo(T) == .int and @typeInfo(T).int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
return @divTrunc(numerator, denominator);
}
@@ -873,7 +873,7 @@ fn testDivTrunc() !void {
pub fn divFloor(comptime T: type, numerator: T, denominator: T) !T {
@setRuntimeSafety(false);
if (denominator == 0) return error.DivisionByZero;
- if (@typeInfo(T) == .Int and @typeInfo(T).Int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
+ if (@typeInfo(T) == .int and @typeInfo(T).int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
return @divFloor(numerator, denominator);
}
@@ -899,10 +899,10 @@ pub fn divCeil(comptime T: type, numerator: T, denominator: T) !T {
if (denominator == 0) return error.DivisionByZero;
const info = @typeInfo(T);
switch (info) {
- .ComptimeFloat, .Float => return @ceil(numerator / denominator),
- .ComptimeInt, .Int => {
+ .comptime_float, .float => return @ceil(numerator / denominator),
+ .comptime_int, .int => {
if (numerator < 0 and denominator < 0) {
- if (info == .Int and numerator == minInt(T) and denominator == -1)
+ if (info == .int and numerator == minInt(T) and denominator == -1)
return error.Overflow;
return @divFloor(numerator + 1, denominator) + 1;
}
@@ -952,7 +952,7 @@ fn testDivCeil() !void {
pub fn divExact(comptime T: type, numerator: T, denominator: T) !T {
@setRuntimeSafety(false);
if (denominator == 0) return error.DivisionByZero;
- if (@typeInfo(T) == .Int and @typeInfo(T).Int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
+ if (@typeInfo(T) == .int and @typeInfo(T).int.signedness == .signed and numerator == minInt(T) and denominator == -1) return error.Overflow;
const result = @divTrunc(numerator, denominator);
if (result * denominator != numerator) return error.UnexpectedRemainder;
return result;
@@ -1029,7 +1029,7 @@ fn testRem() !void {
/// Returns the negation of the integer parameter.
/// Result is a signed integer.
pub fn negateCast(x: anytype) !std.meta.Int(.signed, @bitSizeOf(@TypeOf(x))) {
- if (@typeInfo(@TypeOf(x)).Int.signedness == .signed) return negate(x);
+ if (@typeInfo(@TypeOf(x)).int.signedness == .signed) return negate(x);
const int = std.meta.Int(.signed, @bitSizeOf(@TypeOf(x)));
if (x > -minInt(int)) return error.Overflow;
@@ -1052,9 +1052,9 @@ test negateCast {
/// Cast an integer to a different integer type. If the value doesn't fit,
/// return null.
pub fn cast(comptime T: type, x: anytype) ?T {
- comptime assert(@typeInfo(T) == .Int); // must pass an integer
+ comptime assert(@typeInfo(T) == .int); // must pass an integer
const is_comptime = @TypeOf(x) == comptime_int;
- comptime assert(is_comptime or @typeInfo(@TypeOf(x)) == .Int); // must pass an integer
+ comptime assert(is_comptime or @typeInfo(@TypeOf(x)) == .int); // must pass an integer
if ((is_comptime or maxInt(@TypeOf(x)) > maxInt(T)) and x > maxInt(T)) {
return null;
} else if ((is_comptime or minInt(@TypeOf(x)) < minInt(T)) and x < minInt(T)) {
@@ -1084,7 +1084,7 @@ pub const AlignCastError = error{UnalignedMemory};
fn AlignCastResult(comptime alignment: u29, comptime Ptr: type) type {
var ptr_info = @typeInfo(Ptr);
- ptr_info.Pointer.alignment = alignment;
+ ptr_info.pointer.alignment = alignment;
return @Type(ptr_info);
}
@@ -1117,7 +1117,7 @@ test isPowerOfTwo {
/// Aligns the given integer type bit width to a width divisible by 8.
pub fn ByteAlignedInt(comptime T: type) type {
- const info = @typeInfo(T).Int;
+ const info = @typeInfo(T).int;
const bits = (info.bits + 7) / 8 * 8;
const extended_type = std.meta.Int(info.signedness, bits);
return extended_type;
@@ -1157,7 +1157,7 @@ pub inline fn floor(value: anytype) @TypeOf(value) {
/// Returns the nearest power of two less than or equal to value, or
/// zero if value is less than or equal to zero.
pub fn floorPowerOfTwo(comptime T: type, value: T) T {
- const uT = std.meta.Int(.unsigned, @typeInfo(T).Int.bits);
+ const uT = std.meta.Int(.unsigned, @typeInfo(T).int.bits);
if (value <= 0) return 0;
return @as(T, 1) << log2_int(uT, @as(uT, @intCast(value)));
}
@@ -1192,21 +1192,21 @@ pub inline fn ceil(value: anytype) @TypeOf(value) {
/// Returns the next power of two (if the value is not already a power of two).
/// Only unsigned integers can be used. Zero is not an allowed input.
/// Result is a type with 1 more bit than the input type.
-pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1) {
- comptime assert(@typeInfo(T) == .Int);
- comptime assert(@typeInfo(T).Int.signedness == .unsigned);
+pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1) {
+ comptime assert(@typeInfo(T) == .int);
+ comptime assert(@typeInfo(T).int.signedness == .unsigned);
assert(value != 0);
- const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1);
+ const PromotedType = std.meta.Int(@typeInfo(T).int.signedness, @typeInfo(T).int.bits + 1);
const ShiftType = std.math.Log2Int(PromotedType);
- return @as(PromotedType, 1) << @as(ShiftType, @intCast(@typeInfo(T).Int.bits - @clz(value - 1)));
+ return @as(PromotedType, 1) << @as(ShiftType, @intCast(@typeInfo(T).int.bits - @clz(value - 1)));
}
/// Returns the next power of two (if the value is not already a power of two).
/// Only unsigned integers can be used. Zero is not an allowed input.
/// If the value doesn't fit, returns an error.
pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) {
- comptime assert(@typeInfo(T) == .Int);
- const info = @typeInfo(T).Int;
+ comptime assert(@typeInfo(T) == .int);
+ const info = @typeInfo(T).int;
comptime assert(info.signedness == .unsigned);
const PromotedType = std.meta.Int(info.signedness, info.bits + 1);
const overflowBit = @as(PromotedType, 1) << info.bits;
@@ -1261,16 +1261,16 @@ fn testCeilPowerOfTwo() !void {
/// Return the log base 2 of integer value x, rounding down to the
/// nearest integer.
pub fn log2_int(comptime T: type, x: T) Log2Int(T) {
- if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned)
+ if (@typeInfo(T) != .int or @typeInfo(T).int.signedness != .unsigned)
@compileError("log2_int requires an unsigned integer, found " ++ @typeName(T));
assert(x != 0);
- return @as(Log2Int(T), @intCast(@typeInfo(T).Int.bits - 1 - @clz(x)));
+ return @as(Log2Int(T), @intCast(@typeInfo(T).int.bits - 1 - @clz(x)));
}
/// Return the log base 2 of integer value x, rounding up to the
/// nearest integer.
pub fn log2_int_ceil(comptime T: type, x: T) Log2IntCeil(T) {
- if (@typeInfo(T) != .Int or @typeInfo(T).Int.signedness != .unsigned)
+ if (@typeInfo(T) != .int or @typeInfo(T).int.signedness != .unsigned)
@compileError("log2_int_ceil requires an unsigned integer, found " ++ @typeName(T));
assert(x != 0);
if (x == 1) return 0;
@@ -1296,35 +1296,35 @@ test log2_int_ceil {
/// converted to the closest possible representation.
pub fn lossyCast(comptime T: type, value: anytype) T {
switch (@typeInfo(T)) {
- .Float => {
+ .float => {
switch (@typeInfo(@TypeOf(value))) {
- .Int => return @as(T, @floatFromInt(value)),
- .Float => return @as(T, @floatCast(value)),
- .ComptimeInt => return @as(T, value),
- .ComptimeFloat => return @as(T, value),
+ .int => return @floatFromInt(value),
+ .float => return @floatCast(value),
+ .comptime_int => return value,
+ .comptime_float => return value,
else => @compileError("bad type"),
}
},
- .Int => {
+ .int => {
switch (@typeInfo(@TypeOf(value))) {
- .Int, .ComptimeInt => {
+ .int, .comptime_int => {
if (value >= maxInt(T)) {
- return @as(T, maxInt(T));
+ return maxInt(T);
} else if (value <= minInt(T)) {
- return @as(T, minInt(T));
+ return minInt(T);
} else {
- return @as(T, @intCast(value));
+ return @intCast(value);
}
},
- .Float, .ComptimeFloat => {
+ .float, .comptime_float => {
if (isNan(value)) {
return 0;
} else if (value >= maxInt(T)) {
- return @as(T, maxInt(T));
+ return maxInt(T);
} else if (value <= minInt(T)) {
- return @as(T, minInt(T));
+ return minInt(T);
} else {
- return @as(T, @intFromFloat(value));
+ return @intFromFloat(value);
}
},
else => @compileError("bad type"),
@@ -1405,16 +1405,16 @@ test lerp {
/// Returns the maximum value of integer type T.
pub fn maxInt(comptime T: type) comptime_int {
const info = @typeInfo(T);
- const bit_count = info.Int.bits;
+ const bit_count = info.int.bits;
if (bit_count == 0) return 0;
- return (1 << (bit_count - @intFromBool(info.Int.signedness == .signed))) - 1;
+ return (1 << (bit_count - @intFromBool(info.int.signedness == .signed))) - 1;
}
/// Returns the minimum value of integer type T.
pub fn minInt(comptime T: type) comptime_int {
const info = @typeInfo(T);
- const bit_count = info.Int.bits;
- if (info.Int.signedness == .unsigned) return 0;
+ const bit_count = info.int.bits;
+ if (info.int.signedness == .unsigned) return 0;
if (bit_count == 0) return 0;
return -(1 << (bit_count - 1));
}
@@ -1466,12 +1466,12 @@ test "max value type" {
/// Multiply a and b. Return type is wide enough to guarantee no
/// overflow.
pub fn mulWide(comptime T: type, a: T, b: T) std.meta.Int(
- @typeInfo(T).Int.signedness,
- @typeInfo(T).Int.bits * 2,
+ @typeInfo(T).int.signedness,
+ @typeInfo(T).int.bits * 2,
) {
const ResultInt = std.meta.Int(
- @typeInfo(T).Int.signedness,
- @typeInfo(T).Int.bits * 2,
+ @typeInfo(T).int.signedness,
+ @typeInfo(T).int.bits * 2,
);
return @as(ResultInt, a) * @as(ResultInt, b);
}
@@ -1616,7 +1616,7 @@ pub const CompareOperator = enum {
}
test reverse {
- inline for (@typeInfo(CompareOperator).Enum.fields) |op_field| {
+ inline for (@typeInfo(CompareOperator).@"enum".fields) |op_field| {
const op = @as(CompareOperator, @enumFromInt(op_field.value));
try testing.expect(compare(2, op, 3) == compare(3, op.reverse(), 2));
try testing.expect(compare(3, op, 3) == compare(3, op.reverse(), 3));
@@ -1669,7 +1669,7 @@ test order {
/// and a mask of all zeroes if value is false.
/// Compiles to one instruction for register sized integers.
pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt {
- if (@typeInfo(MaskInt) != .Int)
+ if (@typeInfo(MaskInt) != .int)
@compileError("boolMask requires an integer mask type.");
if (MaskInt == u0 or MaskInt == i0)
@@ -1742,11 +1742,11 @@ pub fn break_f80(x: f80) F80 {
pub inline fn sign(i: anytype) @TypeOf(i) {
const T = @TypeOf(i);
return switch (@typeInfo(T)) {
- .Int, .ComptimeInt => @as(T, @intFromBool(i > 0)) - @as(T, @intFromBool(i < 0)),
- .Float, .ComptimeFloat => @as(T, @floatFromInt(@intFromBool(i > 0))) - @as(T, @floatFromInt(@intFromBool(i < 0))),
- .Vector => |vinfo| blk: {
+ .int, .comptime_int => @as(T, @intFromBool(i > 0)) - @as(T, @intFromBool(i < 0)),
+ .float, .comptime_float => @as(T, @floatFromInt(@intFromBool(i > 0))) - @as(T, @floatFromInt(@intFromBool(i < 0))),
+ .vector => |vinfo| blk: {
switch (@typeInfo(vinfo.child)) {
- .Int, .Float => {
+ .int, .float => {
const zero: T = @splat(0);
const one: T = @splat(1);
break :blk @select(vinfo.child, i > zero, one, zero) - @select(vinfo.child, i < zero, one, zero);