Skip to content
FutureBlitz

    Install

    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.

    std/math/bits.fb, line 37

    LeadingZeros function

    Public Function LeadingZeros<T: Integer>(value: T): Int

    How many 0 bits are above the highest 1: all of them for 0.

    std/math/bits.fb, line 40

    TrailingZeros function

    Public Function TrailingZeros<T: Integer>(value: T): Int

    How many 0 bits are below the lowest 1: all of them for 0.

    std/math/bits.fb, line 45

    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.

    std/math/bits.fb, line 54

    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.

    std/math/bits.fb, line 64

    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.

    std/math/bits.fb, line 69

    IsPowerOfTwo function

    Public Function IsPowerOfTwo<T>(value: T): Bool

    Whether the value is a power of two: 1, 2, 4, and so on.

    std/math/bits.fb, line 74

    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.

    std/math/bits.fb, line 81

    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.

    std/math/bits.fb, line 94

    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.

    std/math/bits.fb, line 105

    Extends

    Int8 extend

    Extend Int8

    No doc comment.

    std/math/bits.fb, line 123

    • Public Method SaturatingAdd(other: Int8): Int8 method #

      The sum, or the lowest or highest Int8 in place of an overflow.

    • Public Method SaturatingSubtract(other: Int8): Int8 method #

      The difference, or the lowest or highest Int8 in place of an overflow.

    • Public Method SaturatingMultiply(other: Int8): Int8 method #

      The product, or the lowest or highest Int8 in place of an overflow.

    Int16 extend

    Extend Int16

    No doc comment.

    std/math/bits.fb, line 138

    • Public Method SaturatingAdd(other: Int16): Int16 method #

      The sum, or the lowest or highest Int16 in place of an overflow.

    • Public Method SaturatingSubtract(other: Int16): Int16 method #

      The difference, or the lowest or highest Int16 in place of an overflow.

    • Public Method SaturatingMultiply(other: Int16): Int16 method #

      The product, or the lowest or highest Int16 in place of an overflow.

    Int32 extend

    Extend Int32

    No doc comment.

    std/math/bits.fb, line 153

    • Public Method SaturatingAdd(other: Int32): Int32 method #

      The sum, or the lowest or highest Int32 in place of an overflow.

    • Public Method SaturatingSubtract(other: Int32): Int32 method #

      The difference, or the lowest or highest Int32 in place of an overflow.

    • Public Method SaturatingMultiply(other: Int32): Int32 method #

      The product, or the lowest or highest Int32 in place of an overflow.

    Int64 extend

    Extend Int64

    No doc comment.

    std/math/bits.fb, line 168

    • Public Method SaturatingAdd(other: Int64): Int64 method #

      The sum, or the lowest or highest Int64 in place of an overflow.

    • Public Method SaturatingSubtract(other: Int64): Int64 method #

      The difference, or the lowest or highest Int64 in place of an overflow.

    • Public Method SaturatingMultiply(other: Int64): Int64 method #

      The product, or the lowest or highest Int64 in place of an overflow.

    UInt8 extend

    Extend UInt8

    No doc comment.

    std/math/bits.fb, line 183

    • Public Method SaturatingAdd(other: UInt8): UInt8 method #

      The sum, or the lowest or highest UInt8 in place of an overflow.

    • Public Method SaturatingSubtract(other: UInt8): UInt8 method #

      The difference, or the lowest or highest UInt8 in place of an overflow.

    • Public Method SaturatingMultiply(other: UInt8): UInt8 method #

      The product, or the lowest or highest UInt8 in place of an overflow.

    UInt16 extend

    Extend UInt16

    No doc comment.

    std/math/bits.fb, line 198

    • Public Method SaturatingAdd(other: UInt16): UInt16 method #

      The sum, or the lowest or highest UInt16 in place of an overflow.

    • Public Method SaturatingSubtract(other: UInt16): UInt16 method #

      The difference, or the lowest or highest UInt16 in place of an overflow.

    • Public Method SaturatingMultiply(other: UInt16): UInt16 method #

      The product, or the lowest or highest UInt16 in place of an overflow.

    UInt32 extend

    Extend UInt32

    No doc comment.

    std/math/bits.fb, line 213

    • Public Method SaturatingAdd(other: UInt32): UInt32 method #

      The sum, or the lowest or highest UInt32 in place of an overflow.

    • Public Method SaturatingSubtract(other: UInt32): UInt32 method #

      The difference, or the lowest or highest UInt32 in place of an overflow.

    • Public Method SaturatingMultiply(other: UInt32): UInt32 method #

      The product, or the lowest or highest UInt32 in place of an overflow.

    UInt64 extend

    Extend UInt64

    No doc comment.

    std/math/bits.fb, line 228

    • Public Method SaturatingAdd(other: UInt64): UInt64 method #

      The sum, or the lowest or highest UInt64 in place of an overflow.

    • Public Method SaturatingSubtract(other: UInt64): UInt64 method #

      The difference, or the lowest or highest UInt64 in place of an overflow.

    • Public Method SaturatingMultiply(other: UInt64): UInt64 method #

      The product, or the lowest or highest UInt64 in place of an overflow.

    Report an issue with this page or with FutureBlitz on GitHub.