addBinaryFixedPoint

function addBinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>(
    a,
    b,
): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>;

Adds two BinaryFixedPoint values of the same shape and returns the result at the same shape.

Throws SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH if the two operands differ in signedness, total bits, or fractional bits, and SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW if the sum does not fit the target shape.

Type Parameters

Type Parameter
TSignedness extends Signedness
TTotalBits extends number
TFractionalBits extends number

Parameters

ParameterType
aBinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>
bNoInfer<BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>>

Returns

BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>

Example

const usd = binaryFixedPoint('signed', 32, 16);
addBinaryFixedPoint(usd('1.5'), usd('2.25')); // represents 3.75

See

subtractBinaryFixedPoint

On this page