toSignedBinaryFixedPoint

function toSignedBinaryFixedPoint<TTotalBits, TFractionalBits>(
    value,
): BinaryFixedPoint<'signed', TTotalBits, TFractionalBits>;

Converts a BinaryFixedPoint to its signed equivalent at the same totalBits and fractionalBits.

Signed inputs are returned by reference unchanged; unsigned inputs are accepted as long as their raw value fits the signed range, i.e. raw <= 2 ** (totalBits - 1) - 1.

Throws SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE when the input's raw value exceeds the maximum representable signed value at its totalBits.

Type Parameters

Type Parameter
TTotalBits extends number
TFractionalBits extends number

Parameters

ParameterType
valueBinaryFixedPoint<Signedness, TTotalBits, TFractionalBits>

Returns

BinaryFixedPoint<"signed", TTotalBits, TFractionalBits>

Example

const unsigned = rawBinaryFixedPoint('unsigned', 8, 0);
toSignedBinaryFixedPoint(unsigned(100n)); // signed, raw === 100n
toSignedBinaryFixedPoint(unsigned(200n)); // throws (200 > 127)

See

toUnsignedBinaryFixedPoint

On this page