Import std.math.bits
std.math.bits
std.math.bits: an integer's bits, counted, rotated, swapped, and aligned, for any integer type, and saturating arithmetic beside the Checked and Wrapping Methods the integers have. A signed integer's bits are its two's complement: PopCount of an Int8 -1 is 8.
std/math/bits.fb
Functions
PopCount
function
Public Function PopCount<T: Integer>(value: T): Int
How many of the value's bits are 1.
LeadingZeros
function
Public Function LeadingZeros<T: Integer>(value: T): Int
How many 0 bits are above the highest 1: all of them for 0.
TrailingZeros
function
Public Function TrailingZeros<T: Integer>(value: T): Int
How many 0 bits are below the lowest 1: all of them for 0.
RotateLeft
function
Public Function RotateLeft<T: Integer>(value: T, count: Int): T
The bits moved count places up, those that go past the top coming in at the bottom. A
negative count rotates down, and one past the type's width goes around.
RotateRight
function
Public Function RotateRight<T: Integer>(value: T, count: Int): T
The bits moved count places down, those that go past the bottom coming in at the top. A
negative count rotates up, and one past the type's width goes around.
ByteSwap
function
Public Function ByteSwap<T: Integer>(value: T): T
The value's bytes in the other order, as from little-endian to big-endian.
IsPowerOfTwo
function
Public Function IsPowerOfTwo<T>(value: T): Bool
Whether the value is a power of two: 1, 2, 4, and so on.
NextPowerOfTwo
function
@PanicsAtCaller Public Function NextPowerOfTwo<T>(value: T): T
The smallest power of two that isn't below the value: 1 for 1 and below. One too large for the
type panics.
AlignDown
function
@PanicsAtCaller Public Function AlignDown<T>(value: T, alignment: T): T
The value rounded down to a multiple of alignment, a power of two: AlignDown(13, 8) is 8,
and AlignDown(-5, 4) is -8. Any other alignment panics.
AlignUp
function
@PanicsAtCaller Public Function AlignUp<T>(value: T, alignment: T): T
The value rounded up to a multiple of alignment, a power of two: AlignUp(13, 8) is 16. Any
other alignment panics, and so does a multiple too large for the type.
Extends
Int8
extend
Extend Int8
No doc comment.
-
The sum, or the lowest or highest Int8 in place of an overflow.
-
The difference, or the lowest or highest Int8 in place of an overflow.
-
The product, or the lowest or highest Int8 in place of an overflow.
Int16
extend
Extend Int16
No doc comment.
-
The sum, or the lowest or highest Int16 in place of an overflow.
-
The difference, or the lowest or highest Int16 in place of an overflow.
-
The product, or the lowest or highest Int16 in place of an overflow.
Int32
extend
Extend Int32
No doc comment.
-
The sum, or the lowest or highest Int32 in place of an overflow.
-
The difference, or the lowest or highest Int32 in place of an overflow.
-
The product, or the lowest or highest Int32 in place of an overflow.
Int64
extend
Extend Int64
No doc comment.
-
The sum, or the lowest or highest Int64 in place of an overflow.
-
The difference, or the lowest or highest Int64 in place of an overflow.
-
The product, or the lowest or highest Int64 in place of an overflow.
UInt8
extend
Extend UInt8
No doc comment.
-
The sum, or the lowest or highest UInt8 in place of an overflow.
-
The difference, or the lowest or highest UInt8 in place of an overflow.
-
The product, or the lowest or highest UInt8 in place of an overflow.
UInt16
extend
Extend UInt16
No doc comment.
-
The sum, or the lowest or highest UInt16 in place of an overflow.
-
The difference, or the lowest or highest UInt16 in place of an overflow.
-
The product, or the lowest or highest UInt16 in place of an overflow.
UInt32
extend
Extend UInt32
No doc comment.
-
The sum, or the lowest or highest UInt32 in place of an overflow.
-
The difference, or the lowest or highest UInt32 in place of an overflow.
-
The product, or the lowest or highest UInt32 in place of an overflow.
UInt64
extend
Extend UInt64
No doc comment.
-
The sum, or the lowest or highest UInt64 in place of an overflow.
-
The difference, or the lowest or highest UInt64 in place of an overflow.
-
The product, or the lowest or highest UInt64 in place of an overflow.
Report an issue with this page or with FutureBlitz on GitHub.