solana_kit_fixed_points library

Fixed-point number helpers for the Solana Kit Dart SDK.

Provides arbitrary-precision binary arithmetic (addition, subtraction, multiplication, division, and modulus), comparisons, conversions between signed and unsigned representations, and base-10 decimal parsing and formatting helpers built on the same representation.

Classes

BinaryFixedPoint
A binary fixed-point value.
BinaryFixedPointBase10
Exact base-10 representation of a binary fixed-point value.
DecimalFixedPoint
A decimal fixed-point value.
FixedPointCodec<T>
Fixed-size codec for fixed-point values.
FixedPointDecoder<T>
Fixed-size decoder for fixed-point values.
FixedPointEncoder<T>
Fixed-size encoder for fixed-point values.
FixedPointToStringOptions
Options for fixed-point string formatting helpers.

Enums

FixedPointEndian
Byte order used by fixed-point codecs.
FixedPointRoundingMode
Rounding strategy used by fixed-point operations that must coerce an exact mathematical result into a value with fewer bits of precision.
FixedPointSignedness
Whether a fixed-point value may be negative.

Functions

absoluteBinaryFixedPoint(BinaryFixedPoint value) → BinaryFixedPoint
Returns the absolute value of value.
absoluteDecimalFixedPoint(DecimalFixedPoint value) → DecimalFixedPoint
Returns the absolute value of value.
addBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → BinaryFixedPoint
Adds two binary fixed-point values of the same shape.
addDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → DecimalFixedPoint
Adds two decimal fixed-point values of the same shape.
applyDecimalsOption(BigInt raw, int currentDecimals, [FixedPointToStringOptions options = const FixedPointToStringOptions()]) → ({int decimals, BigInt raw})
Applies the configured target decimal count to a base-10 scaled integer.
assertIsBinaryFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? fractionalBits]) → void
Asserts that value is a BinaryFixedPoint matching the optional shape.
assertIsDecimalFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? decimals]) → void
Asserts that value is a DecimalFixedPoint matching the optional shape.
binaryFixedPoint(FixedPointSignedness signedness, int totalBits, int fractionalBits) → BinaryFixedPoint Function(String value, [FixedPointRoundingMode rounding])
Returns a factory that parses decimal strings into BinaryFixedPoint values.
binaryFixedPointToBase10(BinaryFixedPoint value) → BinaryFixedPointBase10
Converts value to an exact base-10 (raw, decimals) representation.
binaryFixedPointToNumber(BinaryFixedPoint value) → double
Converts a binary fixed-point value to a Dart double.
binaryFixedPointToString(BinaryFixedPoint value, [FixedPointToStringOptions options = const FixedPointToStringOptions()]) → String
Formats a binary fixed-point value as a canonical decimal string.
cmpBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → int
Compares two binary fixed-point values with the same fractional bit count.
cmpDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → int
Compares two decimal fixed-point values with the same decimal scale.
decimalFixedPoint(FixedPointSignedness signedness, int totalBits, int decimals) → DecimalFixedPoint Function(String value, [FixedPointRoundingMode rounding])
Returns a factory that parses decimal strings into DecimalFixedPoint values.
decimalFixedPointToNumber(DecimalFixedPoint value) → double
Converts a decimal fixed-point value to a Dart double.
decimalFixedPointToString(DecimalFixedPoint value, [FixedPointToStringOptions options = const FixedPointToStringOptions()]) → String
Formats a decimal fixed-point value as a canonical decimal string.
divideBinaryFixedPoint(BinaryFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) → BinaryFixedPoint
Divides a by b and returns a value with a's shape.
divideDecimalFixedPoint(DecimalFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) → DecimalFixedPoint
Divides a by b and returns a value with a's shape.
eqBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → bool
Returns whether a and b represent the same binary fixed-point value.
eqDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → bool
Returns whether a and b represent the same decimal fixed-point value.
formatBinaryFixedPoint(String formatter(String scientificNotation), BinaryFixedPoint value) → String
Formats a binary fixed-point value using a caller-provided formatter.
formatDecimalFixedPoint(String formatter(String scientificNotation), DecimalFixedPoint value) → String
Formats a decimal fixed-point value using a caller-provided formatter.
formatScaledBigInt(BigInt raw, int decimals, {bool padTrailingZeros = false}) → String
Formats a base-10 scaled integer as a decimal string.
getBinaryFixedPointCodec(FixedPointSignedness signedness, int totalBits, int fractionalBits, {FixedPointEndian endian = FixedPointEndian.little}) → FixedPointCodec<BinaryFixedPoint>
Returns a codec for BinaryFixedPoint values with the given shape.
getBinaryFixedPointDecoder(FixedPointSignedness signedness, int totalBits, int fractionalBits, {FixedPointEndian endian = FixedPointEndian.little}) → FixedPointDecoder<BinaryFixedPoint>
Returns a decoder for BinaryFixedPoint values with the given shape.
getBinaryFixedPointEncoder(FixedPointSignedness signedness, int totalBits, int fractionalBits, {FixedPointEndian endian = FixedPointEndian.little}) → FixedPointEncoder<BinaryFixedPoint>
Returns an encoder for BinaryFixedPoint values with the given shape.
getDecimalFixedPointCodec(FixedPointSignedness signedness, int totalBits, int decimals, {FixedPointEndian endian = FixedPointEndian.little}) → FixedPointCodec<DecimalFixedPoint>
Returns a codec for DecimalFixedPoint values with the given shape.
getDecimalFixedPointDecoder(FixedPointSignedness signedness, int totalBits, int decimals, {FixedPointEndian endian = FixedPointEndian.little}) → FixedPointDecoder<DecimalFixedPoint>
Returns a decoder for DecimalFixedPoint values with the given shape.
getDecimalFixedPointEncoder(FixedPointSignedness signedness, int totalBits, int decimals, {FixedPointEndian endian = FixedPointEndian.little}) → FixedPointEncoder<DecimalFixedPoint>
Returns an encoder for DecimalFixedPoint values with the given shape.
getRawRange(FixedPointSignedness signedness, int totalBits) → ({BigInt max, BigInt min})
Returns the inclusive raw integer range for a fixed-point value.
gtBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → bool
Returns whether a is strictly greater than b.
gtDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → bool
Returns whether a is strictly greater than b.
gteBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → bool
Returns whether a is greater than or equal to b.
gteDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → bool
Returns whether a is greater than or equal to b.
isBinaryFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? fractionalBits]) → bool
Returns whether value is a BinaryFixedPoint matching the optional shape.
isDecimalFixedPoint(Object? value, [FixedPointSignedness? signedness, int? totalBits, int? decimals]) → bool
Returns whether value is a DecimalFixedPoint matching the optional shape.
ltBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → bool
Returns whether a is strictly less than b.
ltDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → bool
Returns whether a is strictly less than b.
lteBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → bool
Returns whether a is less than or equal to b.
lteDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → bool
Returns whether a is less than or equal to b.
multiplyBinaryFixedPoint(BinaryFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) → BinaryFixedPoint
Multiplies a by b and returns a value with a's shape.
multiplyDecimalFixedPoint(DecimalFixedPoint a, Object b, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) → DecimalFixedPoint
Multiplies a by b and returns a value with a's shape.
negateBinaryFixedPoint(BinaryFixedPoint value) → BinaryFixedPoint
Returns the additive inverse of a signed binary fixed-point value.
negateDecimalFixedPoint(DecimalFixedPoint value) → DecimalFixedPoint
Returns the additive inverse of a signed decimal fixed-point value.
ratioBinaryFixedPoint(FixedPointSignedness signedness, int totalBits, int fractionalBits) → BinaryFixedPoint Function(BigInt numerator, BigInt denominator, [FixedPointRoundingMode rounding])
Returns a factory that converts ratios into BinaryFixedPoint values.
ratioDecimalFixedPoint(FixedPointSignedness signedness, int totalBits, int decimals) → DecimalFixedPoint Function(BigInt numerator, BigInt denominator, [FixedPointRoundingMode rounding])
Returns a factory that converts ratios into DecimalFixedPoint values.
rawBinaryFixedPoint(FixedPointSignedness signedness, int totalBits, int fractionalBits) → BinaryFixedPoint Function(BigInt raw)
Returns a factory that wraps raw scaled integers as BinaryFixedPoint values.
rawDecimalFixedPoint(FixedPointSignedness signedness, int totalBits, int decimals) → DecimalFixedPoint Function(BigInt raw)
Returns a factory that wraps raw scaled integers as DecimalFixedPoint values.
rescaleBinaryFixedPoint(BinaryFixedPoint value, int newTotalBits, int newFractionalBits, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) → BinaryFixedPoint
Rescales value to newTotalBits and newFractionalBits.
rescaleDecimalFixedPoint(DecimalFixedPoint value, int newTotalBits, int newDecimals, [FixedPointRoundingMode rounding = FixedPointRoundingMode.strict]) → DecimalFixedPoint
Rescales value to newTotalBits and newDecimals.
subtractBinaryFixedPoint(BinaryFixedPoint a, BinaryFixedPoint b) → BinaryFixedPoint
Subtracts b from a, requiring both values to have the same shape.
subtractDecimalFixedPoint(DecimalFixedPoint a, DecimalFixedPoint b) → DecimalFixedPoint
Subtracts b from a, requiring both values to have the same shape.
toSignedBinaryFixedPoint(BinaryFixedPoint value) → BinaryFixedPoint
Converts value to a signed binary fixed-point value with the same raw value, total bit width, and fractional bit count.
toSignedDecimalFixedPoint(DecimalFixedPoint value) → DecimalFixedPoint
Converts value to a signed decimal fixed-point value with the same raw value, total bit width, and decimal scale.
toUnsignedBinaryFixedPoint(BinaryFixedPoint value) → BinaryFixedPoint
Converts value to an unsigned binary fixed-point value with the same raw value, total bit width, and fractional bit count.
toUnsignedDecimalFixedPoint(DecimalFixedPoint value) → DecimalFixedPoint
Converts value to an unsigned decimal fixed-point value with the same raw value, total bit width, and decimal scale.