BinaryFixedPoint

type BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> = object;

A fixed-point number whose scale is a power of 2. The stored raw bigint represents the mathematical value raw / 2 ** fractionalBits.

Binary fixed-point is the fastest fractional representation to compute with — rescaling is a bit shift — so it is the preferred choice for audio samples, graphics, probabilities, and any other quantity where performance matters and the scale does not need to align with decimal digits.

Example

A 16-bit signed Q1.15 audio sample:

type AudioSample = BinaryFixedPoint<'signed', 16, 15>;

See

Type Parameters

Type ParameterDescription
TSignedness extends SignednessWhether the value can be negative.
TTotalBits extends numberThe total number of bits used to store the raw value.
TFractionalBits extends numberThe number of bits to the right of the binary point.

Properties

fractionalBits

readonly fractionalBits: TFractionalBits;

kind

readonly kind: "binaryFixedPoint";

raw

readonly raw: bigint;

signedness

readonly signedness: TSignedness;

totalBits

readonly totalBits: TTotalBits;

On this page