| author | |
| committer | |
| log | 1704971666bce25add6b4f6e409658c5ce8b59aa |
| tree | 2a31b6d2dd10c83e79129c38ba33863b54d77d53 |
| parent | 88b49ed00d6d2efb5b523ab15cbf8ffb37383c56 |
| signature | Signed by PGP key 4AEE18F83AFDEB23 |
3 files changed, 7 insertions(+), 6 deletions(-)
lib/std/builtin.zig+2-4| ... | ... | @@ -220,15 +220,13 @@ pub const Type = union(enum) { |
| 220 | 220 | /// therefore must be kept in sync with the compiler implementation. |
| 221 | 221 | pub const Int = struct { |
| 222 | 222 | signedness: Signedness, |
| 223 | /// TODO make this u16 instead of comptime_int | |
| 224 | bits: comptime_int, | |
| 223 | bits: u16, | |
| 225 | 224 | }; |
| 226 | 225 | |
| 227 | 226 | /// This data structure is used by the Zig language code generation and |
| 228 | 227 | /// therefore must be kept in sync with the compiler implementation. |
| 229 | 228 | pub const Float = struct { |
| 230 | /// TODO make this u16 instead of comptime_int | |
| 231 | bits: comptime_int, | |
| 229 | bits: u16, | |
| 232 | 230 | }; |
| 233 | 231 | |
| 234 | 232 | /// This data structure is used by the Zig language code generation and |
lib/std/math/sqrt.zig+4-1| ... | ... | @@ -37,9 +37,12 @@ fn sqrt_int(comptime T: type, value: T) Sqrt(T) { |
| 37 | 37 | if (@typeInfo(T).Int.bits <= 2) { |
| 38 | 38 | return if (value == 0) 0 else 1; // shortcut for small number of bits to simplify general case |
| 39 | 39 | } else { |
| 40 | const bits = @typeInfo(T).Int.bits; | |
| 41 | const max = math.maxInt(T); | |
| 42 | const minustwo = (@as(T, 2) ^ max) + 1; // unsigned int cannot represent -2 | |
| 40 | 43 | var op = value; |
| 41 | 44 | var res: T = 0; |
| 42 | var one: T = 1 << ((@typeInfo(T).Int.bits - 1) & -2); // highest power of four that fits into T | |
| 45 | var one: T = 1 << ((bits - 1) & minustwo); // highest power of four that fits into T | |
| 43 | 46 | |
| 44 | 47 | // "one" starts at the highest power of four <= than the argument. |
| 45 | 48 | while (one > op) { |
src/type.zig+1-1| ... | ... | @@ -4586,7 +4586,7 @@ pub const Type = extern union { |
| 4586 | 4586 | } |
| 4587 | 4587 | |
| 4588 | 4588 | /// Asserts the type is an integer, enum, error set, or vector of one of them. |
| 4589 | pub fn intInfo(self: Type, target: Target) struct { signedness: std.builtin.Signedness, bits: u16 } { | |
| 4589 | pub fn intInfo(self: Type, target: Target) std.builtin.Type.Int { | |
| 4590 | 4590 | var ty = self; |
| 4591 | 4591 | while (true) switch (ty.tag()) { |
| 4592 | 4592 | .int_unsigned => return .{ |