cmpBinaryFixedPoint

function cmpBinaryFixedPoint<TFractionalBits>(a, b): -1 | 0 | 1;

Compares two BinaryFixedPoint values and returns -1, 0, or 1 depending on whether a is less than, equal to, or greater than b.

Only the kind and fractionalBits of the two operands must match; signedness and totalBits are allowed to differ because they are storage concerns only and do not affect the mathematical value being compared. Mismatches on the constrained dimensions throw SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH.

Type Parameters

Type Parameter
TFractionalBits extends number

Parameters

ParameterType
aBinaryFixedPoint<Signedness, number, TFractionalBits>
bBinaryFixedPoint<Signedness, number, NoInfer<TFractionalBits>>

Returns

-1 | 0 | 1

Example

const q1_15 = binaryFixedPoint('signed', 16, 15);
cmpBinaryFixedPoint(q1_15('0.25'), q1_15('0.5')); // -1
cmpBinaryFixedPoint(q1_15('0.5'), q1_15('0.5'));  // 0
cmpBinaryFixedPoint(q1_15('0.75'), q1_15('0.5')); // 1

See

On this page