| ... | @@ -986,9 +986,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo( | ... | @@ -986,9 +986,9 @@ pub fn ceilPowerOfTwoPromote(comptime T: type, value: T) std.meta.Int(@typeInfo( |
| 986 | comptime assert(@typeInfo(T) == .Int); | 986 | comptime assert(@typeInfo(T) == .Int); |
| 987 | comptime assert(@typeInfo(T).Int.signedness == .unsigned); | 987 | comptime assert(@typeInfo(T).Int.signedness == .unsigned); |
| 988 | assert(value != 0); | 988 | assert(value != 0); |
| 989 | comptime const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1); | 989 | const PromotedType = std.meta.Int(@typeInfo(T).Int.signedness, @typeInfo(T).Int.bits + 1); |
| 990 | comptime const shiftType = std.math.Log2Int(PromotedType); | 990 | const ShiftType = std.math.Log2Int(PromotedType); |
| 991 | return @as(PromotedType, 1) << @intCast(shiftType, @typeInfo(T).Int.bits - @clz(T, value - 1)); | 991 | return @as(PromotedType, 1) << @intCast(ShiftType, @typeInfo(T).Int.bits - @clz(T, value - 1)); |
| 992 | } | 992 | } |
| 993 | | 993 | |
| 994 | /// Returns the next power of two (if the value is not already a power of two). | 994 | /// Returns the next power of two (if the value is not already a power of two). |
| ... | @@ -998,8 +998,8 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { | ... | @@ -998,8 +998,8 @@ pub fn ceilPowerOfTwo(comptime T: type, value: T) (error{Overflow}!T) { |
| 998 | comptime assert(@typeInfo(T) == .Int); | 998 | comptime assert(@typeInfo(T) == .Int); |
| 999 | const info = @typeInfo(T).Int; | 999 | const info = @typeInfo(T).Int; |
| 1000 | comptime assert(info.signedness == .unsigned); | 1000 | comptime assert(info.signedness == .unsigned); |
| 1001 | comptime const PromotedType = std.meta.Int(info.signedness, info.bits + 1); | 1001 | const PromotedType = std.meta.Int(info.signedness, info.bits + 1); |
| 1002 | comptime const overflowBit = @as(PromotedType, 1) << info.bits; | 1002 | const overflowBit = @as(PromotedType, 1) << info.bits; |
| 1003 | var x = ceilPowerOfTwoPromote(T, value); | 1003 | var x = ceilPowerOfTwoPromote(T, value); |
| 1004 | if (overflowBit & x != 0) { | 1004 | if (overflowBit & x != 0) { |
| 1005 | return error.Overflow; | 1005 | return error.Overflow; |
| ... | @@ -1327,7 +1327,7 @@ test "order.compare" { | ... | @@ -1327,7 +1327,7 @@ test "order.compare" { |
| 1327 | } | 1327 | } |
| 1328 | | 1328 | |
| 1329 | test "math.comptime" { | 1329 | test "math.comptime" { |
| 1330 | comptime const v = sin(@as(f32, 1)) + ln(@as(f32, 5)); | 1330 | const v = comptime (sin(@as(f32, 1)) + ln(@as(f32, 5))); |
| 1331 | testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5))); | 1331 | testing.expect(v == sin(@as(f32, 1)) + ln(@as(f32, 5))); |
| 1332 | } | 1332 | } |
| 1333 | | 1333 | |