divideBinaryFixedPoint

function divideBinaryFixedPoint<
    TSignedness,
    TTotalBits,
    TFractionalBits,
>(
    a,
    b,
    rounding?,
): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>;

Divides a BinaryFixedPoint by a scalar.

The second operand may be another BinaryFixedPoint with the same signedness (any total bits or fractional bits) or a bare bigint. The result always has a's shape.

The optional RoundingMode is consulted whenever the division is inexact; it defaults to 'strict' and throws SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS in that case. A zero divisor always throws SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TFractionalBits extends number

Parameters

ParameterType
aBinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>
b| bigint | BinaryFixedPoint<NoInfer<TSignedness>, number, number>
rounding?RoundingMode

Returns

BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>

Example

const q1_15 = binaryFixedPoint('signed', 16, 15);
divideBinaryFixedPoint(q1_15('0.5'), q1_15('0.25')); // represents 2.0 (overflows)
divideBinaryFixedPoint(q1_15('0.5'), 2n);            // represents 0.25

See

multiplyBinaryFixedPoint

On this page