#How to retrieve shift type for unsigned integer type?

1 messages · Page 1 of 1 (latest)

bitter bluff
#

For example for u64 shift type must be u6, for u32 must be u5 etc. How do I retrieve this type in a generic way? Is there any builtin function for that?

#

How to retrieve shift type for unsigned integer type?

silk thistle
#

its just the log base 2

#

im not sure beyond that tho

bitter bluff
#

Now I use this

 fn shiftTypeOf(comptime T: type) type {
    return switch(@sizeOf(T)) {
        1 => u3,
        2 => u4,
        4 => u5,
        8 => u6 
    };
}

Of course there should be some comptime checks if T is integer type dadada

vale plank
#

i think there's a Log2Int helper in std.meta