mirror of
https://github.com/ziglang/zig.git
synced 2026-01-04 04:25:05 +00:00
std: add math.isPowerOfTwo
This commit is contained in:
parent
5017a1d895
commit
ebedc99ac1
@ -680,6 +680,11 @@ pub fn alignCast(comptime alignment: u29, ptr: var) AlignCastError!@typeOf(@alig
|
||||
return @alignCast(alignment, ptr);
|
||||
}
|
||||
|
||||
pub fn isPowerOfTwo(v: var) bool {
|
||||
assert(v != 0);
|
||||
return (v & (v - 1)) == 0;
|
||||
}
|
||||
|
||||
pub fn floorPowerOfTwo(comptime T: type, value: T) T {
|
||||
var x = value;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user