#count significant bits

1 messages · Page 1 of 1 (latest)

upper wyvern
#
fn significant_bits(x: anytype) @TypeOf(@clz(x))
{ const int_bits: @TypeOf(@clz(x)) =
    @truncate(@typeInfo(@TypeOf(x)).Int.bits);
  if (x >= 0) return int_bits - @clz(x);
  return int_bits - @clz(~x) + 1; }

is there a better way to accomplish this?

olive quail
#

what does "significant bits" mean to you