diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-06-19 22:36:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-19 22:36:24 -0700 |
| commit | a72d634b731952ee227d026c27e83c5702dcea4a (patch) | |
| tree | 8bfc4c9afa75a27ebb1108924589a8e7d5cc89ed /lib/std/math.zig | |
| parent | c6e2e1ae4b85fc36acc89c9a5e2673834146d628 (diff) | |
| parent | a4d1edac8d65e1aa4b565f6fb11ab78541d97efa (diff) | |
| download | zig-a72d634b731952ee227d026c27e83c5702dcea4a.tar.gz zig-a72d634b731952ee227d026c27e83c5702dcea4a.zip | |
Merge pull request #16046 from BratishkaErik/issue-6128
Renaming `@xtoy` to `@YfromX`
Diffstat (limited to 'lib/std/math.zig')
| -rw-r--r-- | lib/std/math.zig | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/std/math.zig b/lib/std/math.zig index e62a208d0b..c7d354f787 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -1104,7 +1104,7 @@ pub const AlignCastError = error{UnalignedMemory}; /// Align cast a pointer but return an error if it's the wrong alignment pub fn alignCast(comptime alignment: u29, ptr: anytype) AlignCastError!@TypeOf(@alignCast(alignment, ptr)) { - const addr = @ptrToInt(ptr); + const addr = @intFromPtr(ptr); if (addr % alignment != 0) { return error.UnalignedMemory; } @@ -1311,7 +1311,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T { switch (@typeInfo(T)) { .Float => { switch (@typeInfo(@TypeOf(value))) { - .Int => return @intToFloat(T, value), + .Int => return @floatFromInt(T, value), .Float => return @floatCast(T, value), .ComptimeInt => return @as(T, value), .ComptimeFloat => return @as(T, value), @@ -1335,7 +1335,7 @@ pub fn lossyCast(comptime T: type, value: anytype) T { } else if (value <= minInt(T)) { return @as(T, minInt(T)); } else { - return @floatToInt(T, value); + return @intFromFloat(T, value); } }, else => @compileError("bad type"), @@ -1401,7 +1401,7 @@ pub fn maxInt(comptime T: type) comptime_int { const info = @typeInfo(T); const bit_count = info.Int.bits; if (bit_count == 0) return 0; - return (1 << (bit_count - @boolToInt(info.Int.signedness == .signed))) - 1; + return (1 << (bit_count - @intFromBool(info.Int.signedness == .signed))) - 1; } /// Returns the minimum value of integer type T. @@ -1624,7 +1624,7 @@ test "order.compare" { test "compare.reverse" { inline for (@typeInfo(CompareOperator).Enum.fields) |op_field| { - const op = @intToEnum(CompareOperator, op_field.value); + const op = @enumFromInt(CompareOperator, 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)); try testing.expect(compare(4, op, 3) == compare(3, op.reverse(), 4)); @@ -1643,13 +1643,13 @@ pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt { // The u1 and i1 cases tend to overflow, // so we special case them here. - if (MaskInt == u1) return @boolToInt(value); + if (MaskInt == u1) return @intFromBool(value); if (MaskInt == i1) { // The @as here is a workaround for #7950 - return @bitCast(i1, @as(u1, @boolToInt(value))); + return @bitCast(i1, @as(u1, @intFromBool(value))); } - return -%@intCast(MaskInt, @boolToInt(value)); + return -%@intCast(MaskInt, @intFromBool(value)); } test "boolMask" { @@ -1708,8 +1708,8 @@ 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, @boolToInt(i > 0)) - @as(T, @boolToInt(i < 0)), - .Float, .ComptimeFloat => @intToFloat(T, @boolToInt(i > 0)) - @intToFloat(T, @boolToInt(i < 0)), + .Int, .ComptimeInt => @as(T, @intFromBool(i > 0)) - @as(T, @intFromBool(i < 0)), + .Float, .ComptimeFloat => @floatFromInt(T, @intFromBool(i > 0)) - @floatFromInt(T, @intFromBool(i < 0)), .Vector => |vinfo| blk: { switch (@typeInfo(vinfo.child)) { .Int, .Float => { |
