toSignedDecimalFixedPoint

function toSignedDecimalFixedPoint<TTotalBits, TDecimals>(
    value,
): DecimalFixedPoint<'signed', TTotalBits, TDecimals>;

Converts a DecimalFixedPoint to its signed equivalent at the same totalBits and decimals.

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
TDecimals extends number

Parameters

ParameterType
valueDecimalFixedPoint<Signedness, TTotalBits, TDecimals>

Returns

DecimalFixedPoint<"signed", TTotalBits, TDecimals>

Example

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

See

toUnsignedDecimalFixedPoint

On this page