{"version":3,"sources":["../src/assertions.ts","../src/rounding.ts","../src/binary/arithmetics.ts","../src/codecs.ts","../src/binary/codecs.ts","../src/binary/comparisons.ts","../src/binary/conversions.ts","../src/parsing.ts","../src/binary/core.ts","../src/formatting.ts","../src/binary/formatting.ts","../src/binary/guards.ts","../src/decimal/arithmetics.ts","../src/decimal/codecs.ts","../src/decimal/comparisons.ts","../src/decimal/conversions.ts","../src/decimal/core.ts","../src/decimal/formatting.ts","../src/decimal/guards.ts"],"names":["SolanaError","SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS","SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS","SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS","SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED","SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE","SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH","SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE","SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW","SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO","SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS","toArrayBuffer","createEncoder","createDecoder","assertByteArrayIsNotEmptyForCodec","assertByteArrayHasEnoughBytesForCodec","combineCodec","SOLANA_ERROR__FIXED_POINTS__INVALID_STRING","SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO"],"mappings":";;;;;;AA6BO,SAAS,WAAA,CAAY,YAAwB,SAAA,EAAiD;AACjG,EAAA,IAAI,eAAe,QAAA,EAAU;AACzB,IAAA,MAAM,IAAA,GAAO,EAAA,IAAM,MAAA,CAAO,SAAA,GAAY,CAAC,CAAA;AACvC,IAAA,OAAO,EAAE,GAAA,EAAK,IAAA,GAAO,EAAA,EAAI,GAAA,EAAK,CAAC,IAAA,EAAK;AAAA,EACxC;AACA,EAAA,OAA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A,GAAI,MAAM,KAAA,CAAM,QAAA;AAC3C;;;ACnEO,SAAS,yBAAA,CAKZ,KAAA,EACA,UAAA,EACA,SAAA,EACA,QAAA,EACsE;AACtE,EAAA,MAAM,MAAA,GAAS,cAAc,KAAK,CAAA;AAClC,EAAA,MAAM,QAAA,GAAW;AAAA,IACb,IAAA,EAAM,mBAAA;AAAA,IACN,KAAA,EAAO,QAAA;AAAA,IACP,UAAA,EAAY,UAAA;AAAA,IACZ,UAAA;AAAA,IACA;AAAA,GACJ;AACA,EAAA,kBAAA,CAAmB,2BAAA,EAA6B,QAAQ,QAAQ,CAAA;AAChE,EAAA,iBAAA,CAAkB,qBAAqB,KAAK,CAAA;AAC5C,EAAA,oBAAA,CAAqB,qBAAqB,MAAA,CAAO,UAAA,EAA0B,MAAA,CAAO,SAAA,EAAW,MAAM,GAAG,CAAA;AAC1G;AAsBO,SAAS,mBAAA,CAKZ,KAAA,EACA,UAAA,EACA,SAAA,EACA,QAAA,EAC8D;AAC9D,EAAA,IAAI;AACA,IAAA,yBAAA,CAA0B,KAAA,EAAO,UAAA,EAAY,SAAA,EAAW,QAAQ,CAAA;AAChE,IAAA,OAAO,IAAA;AAAA,EACX,CAAA,CAAA,MAAQ;AACJ,IAAA,OAAO,KAAA;AAAA,EACX;AACJ","file":"index.browser.cjs","sourcesContent":["import {\n    SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW,\n    SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO,\n    SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS,\n    SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS,\n    SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS,\n    SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE,\n    SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH,\n    SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED,\n    SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE,\n    SolanaError,\n} from '@solana/errors';\n\nimport type { Signedness } from './signedness';\n\ntype FixedPointKind = 'binaryFixedPoint' | 'decimalFixedPoint';\n\n/**\n * Returns the inclusive raw bigint range for a fixed-point number with the\n * given signedness and total bits.\n *\n * Signed ranges use two's-complement semantics, so an 8-bit signed value\n * spans `[-128n, 127n]` and an 8-bit unsigned value spans `[0n, 255n]`.\n *\n * This helper trusts that `totalBits` has already been validated as a\n * positive integer by the caller.\n *\n * @internal\n */\nexport function getRawRange(signedness: Signedness, totalBits: number): { max: bigint; min: bigint } {\n    if (signedness === 'signed') {\n        const half = 1n << BigInt(totalBits - 1);\n        return { max: half - 1n, min: -half };\n    }\n    return { max: (1n << BigInt(totalBits)) - 1n, min: 0n };\n}\n\n/**\n * Asserts that `totalBits` is a positive integer. Throws\n * `SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS` otherwise.\n *\n * @internal\n */\nexport function assertValidTotalBits(kind: FixedPointKind, totalBits: unknown): asserts totalBits is number {\n    if (typeof totalBits !== 'number' || !Number.isInteger(totalBits) || totalBits <= 0) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__INVALID_TOTAL_BITS, {\n            kind,\n            totalBits,\n        });\n    }\n}\n\n/**\n * Asserts that `fractionalBits` is a non-negative integer. Throws\n * `SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS` otherwise.\n *\n * @internal\n */\nexport function assertValidFractionalBits(fractionalBits: unknown): asserts fractionalBits is number {\n    if (typeof fractionalBits !== 'number' || !Number.isInteger(fractionalBits) || fractionalBits < 0) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__INVALID_FRACTIONAL_BITS, {\n            fractionalBits,\n        });\n    }\n}\n\n/**\n * Asserts that `decimals` is a non-negative integer. Throws\n * `SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS` otherwise.\n *\n * @internal\n */\nexport function assertValidDecimals(decimals: unknown): asserts decimals is number {\n    if (typeof decimals !== 'number' || !Number.isInteger(decimals) || decimals < 0) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__INVALID_DECIMALS, {\n            decimals,\n        });\n    }\n}\n\n/**\n * Asserts that `totalBits` is a multiple of 8. Throws\n * `SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED` otherwise.\n *\n * This is a codec-only constraint: fixed-point values themselves accept\n * any positive `totalBits`, but the byte-oriented codec can only serialize\n * sizes that are exact multiples of 8 bits.\n *\n * @internal\n */\nexport function assertTotalBitsIsByteAligned(kind: FixedPointKind, totalBits: number): void {\n    if (totalBits % 8 !== 0) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED, {\n            kind,\n            totalBits,\n        });\n    }\n}\n\n/**\n * Asserts that a raw bigint fits the range claimed by the given signedness\n * and total bits. Throws `SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE`\n * otherwise.\n *\n * @internal\n */\nexport function assertRawFitsInRange(\n    kind: FixedPointKind,\n    signedness: Signedness,\n    totalBits: number,\n    raw: bigint,\n): void {\n    const { max, min } = getRawRange(signedness, totalBits);\n    if (raw < min || raw > max) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE, {\n            kind,\n            max,\n            min,\n            raw,\n            signedness,\n            totalBits,\n        });\n    }\n}\n\n/**\n * Describes the concrete shape of a fixed-point value for `SHAPE_MISMATCH`\n * error context. The `scale` is `fractionalBits` for binary values and\n * `decimals` for decimal values; `scaleLabel` is the matching\n * human-readable label.\n *\n * @internal\n */\nexport type FixedPointShape = {\n    kind: string;\n    scale: number;\n    scaleLabel: string;\n    signedness: string;\n    totalBits: number;\n};\n\n/**\n * Expected shape for {@link assertShapeMatches}. Each field except `kind`\n * and `scaleLabel` is optional: `undefined` means \"don't constrain this\n * field\". `kind` is always required because mismatched kinds are always\n * mismatches; `scaleLabel` is always required because it appears in the\n * expected side of the error message even when `scale` is not pinned.\n *\n * @internal\n */\nexport type ExpectedFixedPointShape = {\n    kind: string;\n    scale?: number;\n    scaleLabel: string;\n    signedness?: string;\n    totalBits?: number;\n};\n\n/**\n * Best-effort {@link FixedPointShape} description for an unknown value.\n * Used to populate the `actual*` half of `SHAPE_MISMATCH` contexts when\n * the input may not be a valid fixed-point value at all.\n *\n * @internal\n */\nexport function describeShape(value: unknown): FixedPointShape {\n    const record = value && typeof value === 'object' ? (value as Record<string, unknown>) : {};\n    const kind = typeof record.kind === 'string' ? record.kind : 'unknown';\n    const signedness = typeof record.signedness === 'string' ? record.signedness : 'unknown';\n    const totalBits = typeof record.totalBits === 'number' ? record.totalBits : 0;\n    let scale: number;\n    let scaleLabel: string;\n    if (kind === 'decimalFixedPoint') {\n        scale = typeof record.decimals === 'number' ? record.decimals : 0;\n        scaleLabel = 'decimals';\n    } else if (kind === 'binaryFixedPoint') {\n        scale = typeof record.fractionalBits === 'number' ? record.fractionalBits : 0;\n        scaleLabel = 'fractional bits';\n    } else {\n        scale = 0;\n        scaleLabel = 'unknown';\n    }\n    return { kind, scale, scaleLabel, signedness, totalBits };\n}\n\n/**\n * Asserts that `actual` matches the `expected` shape. Throws\n * `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` otherwise.\n *\n * Fields left `undefined` on `expected` are not constrained — the actual\n * value may carry any value for that field. This is how partial shape\n * checks (e.g. \"any signed value\" without pinning `totalBits`) are\n * expressed.\n *\n * @internal\n */\nexport function assertShapeMatches(\n    operation: string,\n    actual: FixedPointShape,\n    expected: ExpectedFixedPointShape,\n): void {\n    const actualIsStructurallyValid =\n        (actual.signedness === 'signed' || actual.signedness === 'unsigned') &&\n        Number.isInteger(actual.totalBits) &&\n        actual.totalBits > 0 &&\n        Number.isInteger(actual.scale) &&\n        actual.scale >= 0;\n    if (\n        !actualIsStructurallyValid ||\n        actual.kind !== expected.kind ||\n        (expected.signedness !== undefined && actual.signedness !== expected.signedness) ||\n        (expected.totalBits !== undefined && actual.totalBits !== expected.totalBits) ||\n        (expected.scale !== undefined && actual.scale !== expected.scale)\n    ) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH, {\n            actualKind: actual.kind,\n            actualScale: actual.scale,\n            actualScaleLabel: actual.scaleLabel,\n            actualSignedness: actual.signedness,\n            actualTotalBits: actual.totalBits,\n            expectedKind: expected.kind,\n            expectedScale: expected.scale ?? actual.scale,\n            expectedScaleLabel: expected.scaleLabel,\n            expectedSignedness: expected.signedness ?? actual.signedness,\n            expectedTotalBits: expected.totalBits ?? actual.totalBits,\n            operation,\n        });\n    }\n}\n\n/**\n * Asserts that `value.raw` is a bigint, so that downstream range checks\n * can compare it against the claimed signedness and total bits. Throws\n * `SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE` otherwise.\n *\n * @internal\n */\nexport function assertRawIsBigint(kind: FixedPointKind, value: unknown): asserts value is { raw: bigint } {\n    const raw = value && typeof value === 'object' ? (value as { raw?: unknown }).raw : undefined;\n    if (typeof raw !== 'bigint') {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__MALFORMED_RAW_VALUE, {\n            kind,\n            raw,\n        });\n    }\n}\n\n/**\n * Asserts that a bigint `result` produced by an arithmetic operation fits\n * the range claimed by the given signedness and total bits. Throws\n * `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW` otherwise, carrying\n * the operation name so the error message can identify which op overflowed.\n *\n * @internal\n */\nexport function assertNoArithmeticOverflow(\n    kind: FixedPointKind,\n    operation: string,\n    signedness: Signedness,\n    totalBits: number,\n    result: bigint,\n): void {\n    const { max, min } = getRawRange(signedness, totalBits);\n    if (result < min || result > max) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW, {\n            kind,\n            max,\n            min,\n            operation,\n            result,\n            signedness,\n            totalBits,\n        });\n    }\n}\n\n/**\n * Asserts that a divisor is non-zero. Throws\n * `SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO` otherwise.\n *\n * @internal\n */\nexport function assertNoDivisionByZero(\n    kind: FixedPointKind,\n    signedness: Signedness,\n    totalBits: number,\n    denominator: bigint,\n): void {\n    if (denominator === 0n) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO, {\n            kind,\n            signedness,\n            totalBits,\n        });\n    }\n}\n","import { SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS, SolanaError } from '@solana/errors';\n\n/**\n * Rounding mode used by fixed-point operations that must coerce an exact\n * mathematical result into a value with fewer bits of precision. Applies to\n * factories that accept lossy inputs, as well as to downscaling rescales and\n * divisions.\n *\n * - `'floor'` rounds toward negative infinity.\n * - `'ceil'` rounds toward positive infinity.\n * - `'trunc'` rounds toward zero, discarding the fractional part.\n * - `'round'` rounds to the nearest representable value, with ties rounded\n *   away from zero. That is, `0.5` rounds to `1`, `-0.5` rounds to `-1`, and\n *   `-1.5` rounds to `-2`. This is symmetric around zero and differs from\n *   JavaScript's `Math.round`, which breaks ties toward positive infinity.\n * - `'strict'` rejects any input that would require rounding and throws\n *   `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` instead of\n *   coercing the result.\n */\nexport type RoundingMode = 'ceil' | 'floor' | 'round' | 'strict' | 'trunc';\n\n/**\n * Divides `numerator` by `denominator` and rounds the quotient according to\n * the given {@link RoundingMode}.\n *\n * If the division is exact, the quotient is returned unchanged regardless\n * of the rounding mode. Otherwise, `'strict'` throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` and the other\n * modes round as documented on {@link RoundingMode}.\n *\n * The helper handles negative numerators and denominators correctly and\n * assumes `denominator !== 0n` — callers must check for and report\n * division-by-zero before invoking this function.\n *\n * @internal\n */\nexport function roundDivision(\n    kind: 'binaryFixedPoint' | 'decimalFixedPoint',\n    operation: string,\n    numerator: bigint,\n    denominator: bigint,\n    mode: RoundingMode,\n): bigint {\n    const quotient = numerator / denominator;\n    const remainder = numerator - quotient * denominator;\n    if (remainder === 0n) {\n        return quotient;\n    }\n    if (mode === 'strict') {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS, {\n            kind,\n            operation,\n        });\n    }\n    const sameSign = numerator < 0n === denominator < 0n;\n    if (mode === 'trunc') {\n        return quotient;\n    }\n    if (mode === 'floor') {\n        return sameSign ? quotient : quotient - 1n;\n    }\n    if (mode === 'ceil') {\n        return sameSign ? quotient + 1n : quotient;\n    }\n    // 'round': ties away from zero.\n    const absRemainderDoubled = (remainder < 0n ? -remainder : remainder) * 2n;\n    const absDenominator = denominator < 0n ? -denominator : denominator;\n    if (absRemainderDoubled < absDenominator) {\n        return quotient;\n    }\n    return sameSign ? quotient + 1n : quotient - 1n;\n}\n","import { assertNoArithmeticOverflow, assertNoDivisionByZero, assertShapeMatches, describeShape } from '../assertions';\nimport { roundDivision, type RoundingMode } from '../rounding';\nimport type { Signedness } from '../signedness';\nimport type { BinaryFixedPoint } from './core';\n\n/**\n * Adds two {@link BinaryFixedPoint} values of the same shape and returns\n * the result at the same shape.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` if the two operands\n * differ in signedness, total bits, or fractional bits, and\n * `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW` if the sum does not\n * fit the target shape.\n *\n * @example\n * ```ts\n * const usd = binaryFixedPoint('signed', 32, 16);\n * addBinaryFixedPoint(usd('1.5'), usd('2.25')); // represents 3.75\n * ```\n *\n * @see {@link subtractBinaryFixedPoint}\n */\nexport function addBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    a: BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,\n    b: NoInfer<BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>>,\n): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    assertShapeMatches('addBinaryFixedPoint', describeShape(b), {\n        kind: a.kind,\n        scale: a.fractionalBits,\n        scaleLabel: 'fractional bits',\n        signedness: a.signedness,\n        totalBits: a.totalBits,\n    });\n    const result = a.raw + b.raw;\n    assertNoArithmeticOverflow(a.kind, 'add', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Subtracts `b` from `a` where both are {@link BinaryFixedPoint} values of\n * the same shape, and returns the result at the same shape.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` if the two operands\n * differ in shape, and `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW`\n * if the difference does not fit the target shape.\n *\n * @see {@link addBinaryFixedPoint}\n */\nexport function subtractBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    a: BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,\n    b: NoInfer<BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>>,\n): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    assertShapeMatches('subtractBinaryFixedPoint', describeShape(b), {\n        kind: a.kind,\n        scale: a.fractionalBits,\n        scaleLabel: 'fractional bits',\n        signedness: a.signedness,\n        totalBits: a.totalBits,\n    });\n    const result = a.raw - b.raw;\n    assertNoArithmeticOverflow(a.kind, 'subtract', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Multiplies a {@link BinaryFixedPoint} by a scalar.\n *\n * The second operand may be another {@link BinaryFixedPoint} with the same\n * signedness (any total bits or fractional bits) or a bare `bigint`. The\n * result always has `a`'s shape.\n *\n * Multiplication by a same-kind fixed-point rescales the product back to\n * `a`'s scale. When that rescaling is not exact, the optional\n * {@link RoundingMode} is consulted; it defaults to `'strict'` and throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` in that case.\n *\n * @example\n * ```ts\n * const audioSample = binaryFixedPoint('signed', 16, 15);\n * multiplyBinaryFixedPoint(audioSample('0.6'), audioSample('0.8')); // represents 0.48\n * multiplyBinaryFixedPoint(audioSample('0.5'), 2n);                 // represents 1.0 (overflows Q1.15)\n * ```\n *\n * @see {@link divideBinaryFixedPoint}\n */\nexport function multiplyBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    a: BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,\n    b: BinaryFixedPoint<NoInfer<TSignedness>, number, number> | bigint,\n    rounding: RoundingMode = 'strict',\n): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    let result: bigint;\n    if (typeof b === 'bigint') {\n        result = a.raw * b;\n    } else {\n        assertShapeMatches('multiplyBinaryFixedPoint', describeShape(b), {\n            kind: a.kind,\n            scaleLabel: 'fractional bits',\n            signedness: a.signedness,\n        });\n        result = roundDivision(a.kind, 'multiply', a.raw * b.raw, 1n << BigInt(b.fractionalBits), rounding);\n    }\n    assertNoArithmeticOverflow(a.kind, 'multiply', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Divides a {@link BinaryFixedPoint} by a scalar.\n *\n * The second operand may be another {@link BinaryFixedPoint} with the same\n * signedness (any total bits or fractional bits) or a bare `bigint`. The\n * result always has `a`'s shape.\n *\n * The optional {@link RoundingMode} is consulted whenever the division is\n * inexact; it defaults to `'strict'` and throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` in that case.\n * A zero divisor always throws\n * `SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO`.\n *\n * @example\n * ```ts\n * const q1_15 = binaryFixedPoint('signed', 16, 15);\n * divideBinaryFixedPoint(q1_15('0.5'), q1_15('0.25')); // represents 2.0 (overflows)\n * divideBinaryFixedPoint(q1_15('0.5'), 2n);            // represents 0.25\n * ```\n *\n * @see {@link multiplyBinaryFixedPoint}\n */\nexport function divideBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    a: BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,\n    b: BinaryFixedPoint<NoInfer<TSignedness>, number, number> | bigint,\n    rounding: RoundingMode = 'strict',\n): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    let result: bigint;\n    if (typeof b === 'bigint') {\n        assertNoDivisionByZero(a.kind, a.signedness, a.totalBits, b);\n        result = roundDivision(a.kind, 'divide', a.raw, b, rounding);\n    } else {\n        assertShapeMatches('divideBinaryFixedPoint', describeShape(b), {\n            kind: a.kind,\n            scaleLabel: 'fractional bits',\n            signedness: a.signedness,\n        });\n        assertNoDivisionByZero(a.kind, a.signedness, a.totalBits, b.raw);\n        result = roundDivision(a.kind, 'divide', a.raw * (1n << BigInt(b.fractionalBits)), b.raw, rounding);\n    }\n    assertNoArithmeticOverflow(a.kind, 'divide', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Returns the additive inverse of a signed {@link BinaryFixedPoint}.\n *\n * Unsigned values are rejected at the type level; they are also rejected\n * at runtime with `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` in case the\n * type safety is bypassed. Negating the minimum representable value\n * overflows and throws `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW`.\n *\n * @see {@link absoluteBinaryFixedPoint}\n */\nexport function negateBinaryFixedPoint<TTotalBits extends number, TFractionalBits extends number>(\n    a: BinaryFixedPoint<'signed', TTotalBits, TFractionalBits>,\n): BinaryFixedPoint<'signed', TTotalBits, TFractionalBits> {\n    assertShapeMatches('negateBinaryFixedPoint', describeShape(a), {\n        kind: a.kind,\n        scaleLabel: 'fractional bits',\n        signedness: 'signed',\n    });\n    const result = -a.raw;\n    assertNoArithmeticOverflow(a.kind, 'negate', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Returns the absolute value of a {@link BinaryFixedPoint}. Unsigned\n * inputs are returned unchanged.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW` when taking the\n * absolute value of the minimum representable signed value, which has no\n * positive counterpart in two's-complement.\n *\n * @see {@link negateBinaryFixedPoint}\n */\nexport function absoluteBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    a: BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,\n): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    const result = a.raw < 0n ? -a.raw : a.raw;\n    assertNoArithmeticOverflow(a.kind, 'absolute', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n","import { type ReadonlyUint8Array, toArrayBuffer } from '@solana/codecs-core';\n\nimport type { Signedness } from './signedness';\n\n/**\n * Configuration options for fixed-point codecs.\n */\nexport type FixedPointCodecConfig = {\n    /**\n     * Whether values are serialized in little- or big-endian byte order.\n     *\n     * @defaultValue `'le'`\n     */\n    endian?: 'be' | 'le';\n};\n\n/**\n * Maps a byte-aligned `totalBits` literal to its byte count. Falls back to\n * `number` when `totalBits` is not a known multiple of 8 between 8 and 256\n * inclusive — in which case the runtime still works, but the literal size\n * generic is erased.\n *\n * @internal\n */\n/* eslint-disable typescript-sort-keys/interface */\ntype TotalBitsToBytesTable = {\n    8: 1;\n    16: 2;\n    24: 3;\n    32: 4;\n    40: 5;\n    48: 6;\n    56: 7;\n    64: 8;\n    72: 9;\n    80: 10;\n    88: 11;\n    96: 12;\n    104: 13;\n    112: 14;\n    120: 15;\n    128: 16;\n    136: 17;\n    144: 18;\n    152: 19;\n    160: 20;\n    168: 21;\n    176: 22;\n    184: 23;\n    192: 24;\n    200: 25;\n    208: 26;\n    216: 27;\n    224: 28;\n    232: 29;\n    240: 30;\n    248: 31;\n    256: 32;\n};\n/* eslint-enable typescript-sort-keys/interface */\n\n/**\n * Byte count implied by a fixed-point codec's `totalBits`. Preserves the\n * byte-size literal in the codec type for common widths (multiples of 8\n * from 8 to 256); widens to `number` for other widths.\n *\n * @internal\n */\nexport type BytesForTotalBits<TTotalBits extends number> = TTotalBits extends keyof TotalBitsToBytesTable\n    ? TotalBitsToBytesTable[TTotalBits]\n    : number;\n\nconst MASK_64 = 0xffffffffffffffffn;\nconst MASK_32 = 0xffffffffn;\nconst MASK_16 = 0xffffn;\nconst MASK_8 = 0xffn;\n\n/**\n * Writes a raw bigint into `bytes` starting at `offset`, using `byteSize`\n * bytes with the given `signedness` and endianness.\n *\n * Signed negative values are serialized using two's-complement semantics:\n * `raw + 2 ** (byteSize * 8)` is written as if unsigned. The caller is\n * expected to have validated that `raw` fits the claimed range.\n *\n * The implementation processes 64-bit chunks via `DataView.setBigUint64`\n * and greedily consumes the remaining 0–7 bytes with at most one\n * `setUint32`, one `setUint16`, and one direct byte write. For common\n * widths this matches `@solana/codecs-numbers` performance exactly.\n *\n * @internal\n */\nexport function writeRawBigInt(\n    bytes: Uint8Array,\n    offset: number,\n    raw: bigint,\n    byteSize: number,\n    signedness: Signedness,\n    littleEndian: boolean,\n): void {\n    // Normalize to an unsigned bit pattern so downstream code can treat\n    // signed negatives as their two's-complement counterparts.\n    const unsigned = signedness === 'signed' && raw < 0n ? raw + (1n << BigInt(byteSize * 8)) : raw;\n\n    const fullChunks = byteSize >> 3;\n    const residual = byteSize & 7;\n    const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n\n    // Full 64-bit chunks. LE lays chunks low-to-high; BE lays higher-order\n    // chunks at lower memory addresses.\n    for (let c = 0; c < fullChunks; c++) {\n        const chunk = (unsigned >> BigInt(c * 64)) & MASK_64;\n        const position = littleEndian ? c * 8 : byteSize - (c + 1) * 8;\n        view.setBigUint64(offset + position, chunk, littleEndian);\n    }\n\n    if (residual > 0) {\n        const residualChunk = unsigned >> BigInt(fullChunks * 64);\n        // LE: residual bytes follow the chunks. BE: residual occupies the\n        // highest-order bytes, which sit at the start of the memory region.\n        const residualBase = littleEndian ? fullChunks * 8 : 0;\n        let consumed = 0;\n\n        if (residual - consumed >= 4) {\n            const chunk = Number((residualChunk >> BigInt(consumed * 8)) & MASK_32);\n            const position = littleEndian ? residualBase + consumed : residualBase + residual - consumed - 4;\n            view.setUint32(offset + position, chunk, littleEndian);\n            consumed += 4;\n        }\n        if (residual - consumed >= 2) {\n            const chunk = Number((residualChunk >> BigInt(consumed * 8)) & MASK_16);\n            const position = littleEndian ? residualBase + consumed : residualBase + residual - consumed - 2;\n            view.setUint16(offset + position, chunk, littleEndian);\n            consumed += 2;\n        }\n        if (residual - consumed >= 1) {\n            const chunk = Number((residualChunk >> BigInt(consumed * 8)) & MASK_8);\n            const position = littleEndian ? residualBase + consumed : residualBase + residual - consumed - 1;\n            bytes[offset + position] = chunk;\n        }\n    }\n}\n\n/**\n * Reads a raw bigint from `bytes` starting at `offset`, using `byteSize`\n * bytes with the given `signedness` and endianness.\n *\n * Signed values use two's-complement semantics: if the top bit of the\n * decoded unsigned value is set, `2 ** (byteSize * 8)` is subtracted to\n * produce the negative result.\n *\n * The implementation processes 64-bit chunks via `DataView.getBigUint64`\n * and greedily consumes the remaining 0–7 bytes with at most one\n * `getUint32`, one `getUint16`, and one direct byte read.\n *\n * @internal\n */\nexport function readRawBigInt(\n    bytes: ReadonlyUint8Array | Uint8Array,\n    offset: number,\n    byteSize: number,\n    signedness: Signedness,\n    littleEndian: boolean,\n): bigint {\n    const fullChunks = byteSize >> 3;\n    const residual = byteSize & 7;\n    // `toArrayBuffer` defensively copies when the backing is a\n    // SharedArrayBuffer and is safe to call where SharedArrayBuffer is\n    // undefined (React Native, non-isolated browser contexts).\n    const view = new DataView(toArrayBuffer(bytes, offset, byteSize));\n    let unsigned = 0n;\n\n    for (let c = 0; c < fullChunks; c++) {\n        const position = littleEndian ? c * 8 : byteSize - (c + 1) * 8;\n        const chunk = view.getBigUint64(position, littleEndian);\n        unsigned |= chunk << BigInt(c * 64);\n    }\n\n    if (residual > 0) {\n        const residualBase = littleEndian ? fullChunks * 8 : 0;\n        let residualChunk = 0n;\n        let consumed = 0;\n\n        if (residual - consumed >= 4) {\n            const position = littleEndian ? residualBase + consumed : residualBase + residual - consumed - 4;\n            residualChunk |= BigInt(view.getUint32(position, littleEndian)) << BigInt(consumed * 8);\n            consumed += 4;\n        }\n        if (residual - consumed >= 2) {\n            const position = littleEndian ? residualBase + consumed : residualBase + residual - consumed - 2;\n            residualChunk |= BigInt(view.getUint16(position, littleEndian)) << BigInt(consumed * 8);\n            consumed += 2;\n        }\n        if (residual - consumed >= 1) {\n            const position = littleEndian ? residualBase + consumed : residualBase + residual - consumed - 1;\n            residualChunk |= BigInt(bytes[offset + position]) << BigInt(consumed * 8);\n        }\n\n        unsigned |= residualChunk << BigInt(fullChunks * 64);\n    }\n\n    if (signedness === 'signed') {\n        const signBit = 1n << BigInt(byteSize * 8 - 1);\n        if ((unsigned & signBit) !== 0n) {\n            return unsigned - (1n << BigInt(byteSize * 8));\n        }\n    }\n    return unsigned;\n}\n","import {\n    assertByteArrayHasEnoughBytesForCodec,\n    assertByteArrayIsNotEmptyForCodec,\n    combineCodec,\n    createDecoder,\n    createEncoder,\n    type FixedSizeCodec,\n    type FixedSizeDecoder,\n    type FixedSizeEncoder,\n} from '@solana/codecs-core';\n\nimport {\n    assertShapeMatches,\n    assertTotalBitsIsByteAligned,\n    assertValidFractionalBits,\n    assertValidTotalBits,\n    describeShape,\n} from '../assertions';\nimport { type BytesForTotalBits, type FixedPointCodecConfig, readRawBigInt, writeRawBigInt } from '../codecs';\nimport type { Signedness } from '../signedness';\nimport type { BinaryFixedPoint } from './core';\n\n/**\n * Returns an encoder for {@link BinaryFixedPoint} values of a specific\n * shape. The encoder serializes `value.raw` as a fixed-size integer using\n * two's-complement for signed values and little-endian byte order by\n * default.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED` when\n * `totalBits` is not a multiple of 8. Encoding a value whose shape does\n * not match the codec's shape throws\n * `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH`.\n *\n * @example\n * ```ts\n * const encoder = getBinaryFixedPointEncoder('signed', 16, 15);\n * encoder.encode(binaryFixedPoint('signed', 16, 15)('0.5')); // 0x0040\n * ```\n *\n * @see {@link getBinaryFixedPointDecoder}\n * @see {@link getBinaryFixedPointCodec}\n */\nexport function getBinaryFixedPointEncoder<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    fractionalBits: TFractionalBits,\n    config: FixedPointCodecConfig = {},\n): FixedSizeEncoder<BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>, BytesForTotalBits<TTotalBits>> {\n    assertValidTotalBits('binaryFixedPoint', totalBits);\n    assertValidFractionalBits(fractionalBits);\n    assertTotalBitsIsByteAligned('binaryFixedPoint', totalBits);\n    const byteSize = (totalBits / 8) as BytesForTotalBits<TTotalBits>;\n    const littleEndian = config.endian !== 'be';\n    return createEncoder({\n        fixedSize: byteSize,\n        write(value, bytes, offset) {\n            assertShapeMatches('getBinaryFixedPointEncoder', describeShape(value), {\n                kind: 'binaryFixedPoint',\n                scale: fractionalBits,\n                scaleLabel: 'fractional bits',\n                signedness,\n                totalBits,\n            });\n            writeRawBigInt(bytes, offset, value.raw, byteSize, signedness, littleEndian);\n            return offset + byteSize;\n        },\n    });\n}\n\n/**\n * Returns a decoder for {@link BinaryFixedPoint} values of a specific\n * shape. The decoder reads a fixed-size integer using two's-complement for\n * signed values and little-endian byte order by default, and reconstructs\n * a frozen {@link BinaryFixedPoint} from the bytes.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED` when\n * `totalBits` is not a multiple of 8.\n *\n * @example\n * ```ts\n * const decoder = getBinaryFixedPointDecoder('signed', 16, 15);\n * decoder.decode(new Uint8Array([0x00, 0x40])); // represents 0.5\n * ```\n *\n * @see {@link getBinaryFixedPointEncoder}\n * @see {@link getBinaryFixedPointCodec}\n */\nexport function getBinaryFixedPointDecoder<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    fractionalBits: TFractionalBits,\n    config: FixedPointCodecConfig = {},\n): FixedSizeDecoder<BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>, BytesForTotalBits<TTotalBits>> {\n    assertValidTotalBits('binaryFixedPoint', totalBits);\n    assertValidFractionalBits(fractionalBits);\n    assertTotalBitsIsByteAligned('binaryFixedPoint', totalBits);\n    const byteSize = (totalBits / 8) as BytesForTotalBits<TTotalBits>;\n    const littleEndian = config.endian !== 'be';\n    const codecDescription = 'getBinaryFixedPointDecoder';\n    return createDecoder({\n        fixedSize: byteSize,\n        read(bytes, offset) {\n            assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset);\n            assertByteArrayHasEnoughBytesForCodec(codecDescription, byteSize, bytes, offset);\n            const raw = readRawBigInt(bytes, offset, byteSize, signedness, littleEndian);\n            const value = Object.freeze({\n                fractionalBits,\n                kind: 'binaryFixedPoint',\n                raw,\n                signedness,\n                totalBits,\n            }) as BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>;\n            return [value, offset + byteSize];\n        },\n    });\n}\n\n/**\n * Returns a codec for {@link BinaryFixedPoint} values of a specific shape,\n * combining {@link getBinaryFixedPointEncoder} and\n * {@link getBinaryFixedPointDecoder}.\n *\n * @example\n * ```ts\n * const codec = getBinaryFixedPointCodec('signed', 16, 15);\n * const bytes = codec.encode(binaryFixedPoint('signed', 16, 15)('0.5'));\n * const value = codec.decode(bytes); // represents 0.5\n * ```\n *\n * @see {@link getBinaryFixedPointEncoder}\n * @see {@link getBinaryFixedPointDecoder}\n */\nexport function getBinaryFixedPointCodec<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    fractionalBits: TFractionalBits,\n    config: FixedPointCodecConfig = {},\n): FixedSizeCodec<\n    BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,\n    BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits>,\n    BytesForTotalBits<TTotalBits>\n> {\n    return combineCodec(\n        getBinaryFixedPointEncoder(signedness, totalBits, fractionalBits, config),\n        getBinaryFixedPointDecoder(signedness, totalBits, fractionalBits, config),\n    );\n}\n","import { assertShapeMatches, describeShape } from '../assertions';\nimport type { Signedness } from '../signedness';\nimport type { BinaryFixedPoint } from './core';\n\n/**\n * Compares two {@link BinaryFixedPoint} values and returns `-1`, `0`, or\n * `1` depending on whether `a` is less than, equal to, or greater than `b`.\n *\n * Only the `kind` and `fractionalBits` of the two operands must match;\n * `signedness` and `totalBits` are allowed to differ because they are\n * storage concerns only and do not affect the mathematical value being\n * compared. Mismatches on the constrained dimensions throw\n * `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH`.\n *\n * @example\n * ```ts\n * const q1_15 = binaryFixedPoint('signed', 16, 15);\n * cmpBinaryFixedPoint(q1_15('0.25'), q1_15('0.5')); // -1\n * cmpBinaryFixedPoint(q1_15('0.5'), q1_15('0.5'));  // 0\n * cmpBinaryFixedPoint(q1_15('0.75'), q1_15('0.5')); // 1\n * ```\n *\n * @see {@link eqBinaryFixedPoint}\n * @see {@link ltBinaryFixedPoint}\n * @see {@link lteBinaryFixedPoint}\n * @see {@link gtBinaryFixedPoint}\n * @see {@link gteBinaryFixedPoint}\n */\nexport function cmpBinaryFixedPoint<TFractionalBits extends number>(\n    a: BinaryFixedPoint<Signedness, number, TFractionalBits>,\n    b: BinaryFixedPoint<Signedness, number, NoInfer<TFractionalBits>>,\n): -1 | 0 | 1 {\n    assertShapeMatches('cmpBinaryFixedPoint', describeShape(b), {\n        kind: a.kind,\n        scale: a.fractionalBits,\n        scaleLabel: 'fractional bits',\n    });\n    return a.raw < b.raw ? -1 : a.raw > b.raw ? 1 : 0;\n}\n\n/**\n * Returns `true` when `a` and `b` represent the same value.\n *\n * See {@link cmpBinaryFixedPoint} for shape-matching rules.\n */\nexport function eqBinaryFixedPoint<TFractionalBits extends number>(\n    a: BinaryFixedPoint<Signedness, number, TFractionalBits>,\n    b: BinaryFixedPoint<Signedness, number, NoInfer<TFractionalBits>>,\n): boolean {\n    return cmpBinaryFixedPoint(a, b) === 0;\n}\n\n/**\n * Returns `true` when `a` is strictly less than `b`.\n *\n * See {@link cmpBinaryFixedPoint} for shape-matching rules.\n */\nexport function ltBinaryFixedPoint<TFractionalBits extends number>(\n    a: BinaryFixedPoint<Signedness, number, TFractionalBits>,\n    b: BinaryFixedPoint<Signedness, number, NoInfer<TFractionalBits>>,\n): boolean {\n    return cmpBinaryFixedPoint(a, b) < 0;\n}\n\n/**\n * Returns `true` when `a` is less than or equal to `b`.\n *\n * See {@link cmpBinaryFixedPoint} for shape-matching rules.\n */\nexport function lteBinaryFixedPoint<TFractionalBits extends number>(\n    a: BinaryFixedPoint<Signedness, number, TFractionalBits>,\n    b: BinaryFixedPoint<Signedness, number, NoInfer<TFractionalBits>>,\n): boolean {\n    return cmpBinaryFixedPoint(a, b) <= 0;\n}\n\n/**\n * Returns `true` when `a` is strictly greater than `b`.\n *\n * See {@link cmpBinaryFixedPoint} for shape-matching rules.\n */\nexport function gtBinaryFixedPoint<TFractionalBits extends number>(\n    a: BinaryFixedPoint<Signedness, number, TFractionalBits>,\n    b: BinaryFixedPoint<Signedness, number, NoInfer<TFractionalBits>>,\n): boolean {\n    return cmpBinaryFixedPoint(a, b) > 0;\n}\n\n/**\n * Returns `true` when `a` is greater than or equal to `b`.\n *\n * See {@link cmpBinaryFixedPoint} for shape-matching rules.\n */\nexport function gteBinaryFixedPoint<TFractionalBits extends number>(\n    a: BinaryFixedPoint<Signedness, number, TFractionalBits>,\n    b: BinaryFixedPoint<Signedness, number, NoInfer<TFractionalBits>>,\n): boolean {\n    return cmpBinaryFixedPoint(a, b) >= 0;\n}\n","import {\n    assertNoArithmeticOverflow,\n    assertRawFitsInRange,\n    assertValidFractionalBits,\n    assertValidTotalBits,\n} from '../assertions';\nimport { roundDivision, type RoundingMode } from '../rounding';\nimport type { Signedness } from '../signedness';\nimport type { BinaryFixedPoint } from './core';\n\n/**\n * Converts a {@link BinaryFixedPoint} to its exact base-10 representation\n * as a `(raw, decimals)` pair such that the mathematical value equals\n * `raw / 10 ** decimals`.\n *\n * Because `1 / 2 ** F` has a finite decimal expansion of exactly `F`\n * digits, the conversion is always lossless:\n * `raw / 2 ** F === (raw * 5 ** F) / 10 ** F`. The transformed raw\n * therefore carries exactly `fractionalBits` decimal digits of\n * precision.\n *\n * Useful when you want to feed a binary fixed-point into a tool that\n * understands base-10 scaled integers (such as `Intl.NumberFormat`'s\n * string scientific notation).\n *\n * @example\n * ```ts\n * const q1_15 = binaryFixedPoint('signed', 16, 15);\n * binaryFixedPointToBase10(q1_15('0.5'));\n * // { raw: 500000000000000n, decimals: 15 }\n * ```\n *\n * @see {@link BinaryFixedPoint}\n */\nexport function binaryFixedPointToBase10(value: BinaryFixedPoint<Signedness, number, number>): {\n    decimals: number;\n    raw: bigint;\n} {\n    const decimals = value.fractionalBits;\n    const raw = decimals === 0 ? value.raw : value.raw * 5n ** BigInt(decimals);\n    return { decimals, raw };\n}\n\n/**\n * Converts a {@link BinaryFixedPoint} to its unsigned equivalent at the\n * same `totalBits` and `fractionalBits`.\n *\n * Unsigned inputs are returned by reference unchanged; signed inputs are\n * accepted as long as their raw value is non-negative.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE` when the input\n * represents a negative value that cannot be stored as unsigned.\n *\n * @example\n * ```ts\n * const signedUsd = binaryFixedPoint('signed', 16, 8);\n * toUnsignedBinaryFixedPoint(signedUsd('1.5')); // unsigned, raw unchanged\n * toUnsignedBinaryFixedPoint(signedUsd('-1'));  // throws\n * ```\n *\n * @see {@link toSignedBinaryFixedPoint}\n */\nexport function toUnsignedBinaryFixedPoint<TTotalBits extends number, TFractionalBits extends number>(\n    value: BinaryFixedPoint<Signedness, TTotalBits, TFractionalBits>,\n): BinaryFixedPoint<'unsigned', TTotalBits, TFractionalBits> {\n    if (value.signedness === 'unsigned') {\n        return value as BinaryFixedPoint<'unsigned', TTotalBits, TFractionalBits>;\n    }\n    assertRawFitsInRange('binaryFixedPoint', 'unsigned', value.totalBits, value.raw);\n    return Object.freeze({ ...value, signedness: 'unsigned' });\n}\n\n/**\n * Converts a {@link BinaryFixedPoint} to its signed equivalent at the same\n * `totalBits` and `fractionalBits`.\n *\n * Signed inputs are returned by reference unchanged; unsigned inputs are\n * accepted as long as their raw value fits the signed range, i.e.\n * `raw <= 2 ** (totalBits - 1) - 1`.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE` when the input's\n * raw value exceeds the maximum representable signed value at its\n * `totalBits`.\n *\n * @example\n * ```ts\n * const unsigned = rawBinaryFixedPoint('unsigned', 8, 0);\n * toSignedBinaryFixedPoint(unsigned(100n)); // signed, raw === 100n\n * toSignedBinaryFixedPoint(unsigned(200n)); // throws (200 > 127)\n * ```\n *\n * @see {@link toUnsignedBinaryFixedPoint}\n */\nexport function toSignedBinaryFixedPoint<TTotalBits extends number, TFractionalBits extends number>(\n    value: BinaryFixedPoint<Signedness, TTotalBits, TFractionalBits>,\n): BinaryFixedPoint<'signed', TTotalBits, TFractionalBits> {\n    if (value.signedness === 'signed') {\n        return value as BinaryFixedPoint<'signed', TTotalBits, TFractionalBits>;\n    }\n    assertRawFitsInRange('binaryFixedPoint', 'signed', value.totalBits, value.raw);\n    return Object.freeze({ ...value, signedness: 'signed' });\n}\n\n/**\n * Returns a {@link BinaryFixedPoint} with the same signedness as `value`\n * but a new `totalBits` and `fractionalBits`. If the requested shape\n * matches the input shape, the same reference is returned.\n *\n * Scale-up (higher `fractionalBits`) is always exact. Scale-down (lower\n * `fractionalBits`) is potentially lossy; the optional {@link RoundingMode}\n * is consulted on inexact results and defaults to `'strict'`, which throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS`.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW` when the\n * rescaled raw value does not fit the new `totalBits`.\n *\n * @example\n * ```ts\n * const q1_15 = binaryFixedPoint('signed', 16, 15);\n * rescaleBinaryFixedPoint(q1_15('0.5'), 32, 30);          // wider, higher precision\n * rescaleBinaryFixedPoint(q1_15('0.5'), 16, 8, 'floor');  // lower precision, explicit rounding\n * ```\n *\n * @see {@link toSignedBinaryFixedPoint}\n * @see {@link toUnsignedBinaryFixedPoint}\n */\nexport function rescaleBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TNewTotalBits extends number,\n    TNewFractionalBits extends number,\n>(\n    value: BinaryFixedPoint<TSignedness, number, number>,\n    newTotalBits: TNewTotalBits,\n    newFractionalBits: TNewFractionalBits,\n    rounding: RoundingMode = 'strict',\n): BinaryFixedPoint<TSignedness, TNewTotalBits, TNewFractionalBits> {\n    assertValidTotalBits('binaryFixedPoint', newTotalBits);\n    assertValidFractionalBits(newFractionalBits);\n    if (value.totalBits === newTotalBits && value.fractionalBits === newFractionalBits) {\n        return value as BinaryFixedPoint<TSignedness, TNewTotalBits, TNewFractionalBits>;\n    }\n    let result: bigint;\n    if (newFractionalBits === value.fractionalBits) {\n        result = value.raw;\n    } else if (newFractionalBits > value.fractionalBits) {\n        result = value.raw << BigInt(newFractionalBits - value.fractionalBits);\n    } else {\n        result = roundDivision(\n            'binaryFixedPoint',\n            'rescale',\n            value.raw,\n            1n << BigInt(value.fractionalBits - newFractionalBits),\n            rounding,\n        );\n    }\n    assertNoArithmeticOverflow('binaryFixedPoint', 'rescale', value.signedness, newTotalBits, result);\n    return Object.freeze({ ...value, fractionalBits: newFractionalBits, raw: result, totalBits: newTotalBits });\n}\n","import { SOLANA_ERROR__FIXED_POINTS__INVALID_STRING, SolanaError } from '@solana/errors';\n\n/**\n * Parses a human-readable decimal string into a decimal fixed-point\n * representation `{ raw, decimals }` such that the parsed value is exactly\n * `raw / 10 ** decimals`.\n *\n * Accepts strings of the form:\n * - `\"123\"`, `\"-123\"`\n * - `\"12.5\"`, `\"-0.25\"`\n * - `\".5\"`, `\"-.5\"`, `\"5.\"`\n *\n * Rejects scientific notation, leading `+`, whitespace, and any other\n * non-digit / non-sign / non-decimal-point characters.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__INVALID_STRING` for malformed input.\n *\n * @internal\n */\nexport function parseDecimalString(\n    kind: 'binaryFixedPoint' | 'decimalFixedPoint',\n    input: string,\n): { decimals: number; raw: bigint } {\n    if (typeof input !== 'string' || !/^-?(?:\\d+\\.?\\d*|\\.\\d+)$/.test(input)) {\n        throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__INVALID_STRING, {\n            input: String(input),\n            kind,\n        });\n    }\n    const isNegative = input.startsWith('-');\n    const unsigned = isNegative ? input.slice(1) : input;\n    const dotIndex = unsigned.indexOf('.');\n    let integerPart: string;\n    let fractionalPart: string;\n    if (dotIndex === -1) {\n        integerPart = unsigned;\n        fractionalPart = '';\n    } else {\n        integerPart = unsigned.slice(0, dotIndex);\n        fractionalPart = unsigned.slice(dotIndex + 1);\n    }\n    const digits = (integerPart || '0') + fractionalPart;\n    const rawAbs = BigInt(digits);\n    const raw = isNegative ? -rawAbs : rawAbs;\n    return { decimals: fractionalPart.length, raw };\n}\n","import { SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO, SolanaError } from '@solana/errors';\n\nimport { assertRawFitsInRange, assertValidFractionalBits, assertValidTotalBits } from '../assertions';\nimport { parseDecimalString } from '../parsing';\nimport { roundDivision, type RoundingMode } from '../rounding';\nimport type { Signedness } from '../signedness';\n\n/**\n * A fixed-point number whose scale is a power of 2. The stored `raw` bigint\n * represents the mathematical value `raw / 2 ** fractionalBits`.\n *\n * Binary fixed-point is the fastest fractional representation to compute\n * with — rescaling is a bit shift — so it is the preferred choice for\n * audio samples, graphics, probabilities, and any other quantity where\n * performance matters and the scale does not need to align with decimal\n * digits.\n *\n * @typeParam TSignedness - Whether the value can be negative.\n * @typeParam TTotalBits - The total number of bits used to store the raw value.\n * @typeParam TFractionalBits - The number of bits to the right of the binary point.\n *\n * @example\n * A 16-bit signed Q1.15 audio sample:\n * ```ts\n * type AudioSample = BinaryFixedPoint<'signed', 16, 15>;\n * ```\n *\n * @see {@link DecimalFixedPoint}\n * @see {@link Signedness}\n */\nexport type BinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n> = {\n    readonly fractionalBits: TFractionalBits;\n    readonly kind: 'binaryFixedPoint';\n    readonly raw: bigint;\n    readonly signedness: TSignedness;\n    readonly totalBits: TTotalBits;\n};\n\nfunction createBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    fractionalBits: TFractionalBits,\n    raw: bigint,\n): BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    assertRawFitsInRange('binaryFixedPoint', signedness, totalBits, raw);\n    return Object.freeze({ fractionalBits, kind: 'binaryFixedPoint', raw, signedness, totalBits });\n}\n\n/**\n * Returns a factory that constructs {@link BinaryFixedPoint} values from\n * decimal strings.\n *\n * The outer call validates the shape parameters once and the returned\n * factory can be called many times to construct values of that shape.\n *\n * The input string is parsed as a decimal number and scaled by\n * `2 ** fractionalBits` to compute the raw bigint. Values that cannot be\n * represented exactly in binary (such as `\"0.1\"`) trigger the rounding\n * behaviour documented on {@link RoundingMode}, with `'strict'` throwing\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` by default.\n *\n * @example\n * ```ts\n * const audioSample = binaryFixedPoint('signed', 16, 15);\n * audioSample('0.5');          // raw === 16384n (exact)\n * audioSample('0.1');          // throws under the default 'strict' mode\n * audioSample('0.1', 'round'); // raw === 3277n\n * ```\n *\n * @see {@link BinaryFixedPoint}\n * @see {@link rawBinaryFixedPoint}\n * @see {@link ratioBinaryFixedPoint}\n */\nexport function binaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    fractionalBits: TFractionalBits,\n): (input: string, rounding?: RoundingMode) => BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    assertValidTotalBits('binaryFixedPoint', totalBits);\n    assertValidFractionalBits(fractionalBits);\n    return (input, rounding = 'strict') => {\n        const parsed = parseDecimalString('binaryFixedPoint', input);\n        // The parsed value is `parsed.raw / 10^parsed.decimals`. We need\n        // `raw = value * 2^fractionalBits`, i.e.\n        // `raw = parsed.raw * 2^fractionalBits / 10^parsed.decimals`.\n        const scaledRaw = parsed.raw * (1n << BigInt(fractionalBits));\n        const raw =\n            parsed.decimals === 0\n                ? scaledRaw\n                : roundDivision('binaryFixedPoint', 'fromString', scaledRaw, 10n ** BigInt(parsed.decimals), rounding);\n        return createBinaryFixedPoint(signedness, totalBits, fractionalBits, raw);\n    };\n}\n\n/**\n * Returns a factory that constructs {@link BinaryFixedPoint} values from a\n * raw bigint in the smallest representable unit (i.e. already scaled by\n * `2 ** fractionalBits`).\n *\n * The outer call validates the shape parameters once and the returned\n * factory can be called many times to construct values of that shape.\n *\n * The raw value is range-checked against the claimed `totalBits` and\n * `signedness`; no rounding is ever required.\n *\n * @example\n * ```ts\n * const q1_15 = rawBinaryFixedPoint('signed', 16, 15);\n * q1_15(16384n); // Represents 0.5\n * ```\n *\n * @see {@link BinaryFixedPoint}\n * @see {@link binaryFixedPoint}\n * @see {@link ratioBinaryFixedPoint}\n */\nexport function rawBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    fractionalBits: TFractionalBits,\n): (raw: bigint) => BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    assertValidTotalBits('binaryFixedPoint', totalBits);\n    assertValidFractionalBits(fractionalBits);\n    return raw => createBinaryFixedPoint(signedness, totalBits, fractionalBits, raw);\n}\n\n/**\n * Returns a factory that constructs {@link BinaryFixedPoint} values from a\n * rational `numerator / denominator`.\n *\n * The outer call validates the shape parameters once and the returned\n * factory can be called many times to construct values of that shape.\n *\n * If the ratio cannot be exactly represented at the target\n * `fractionalBits`, the returned factory throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` under the\n * default `'strict'` rounding mode. Pass a different {@link RoundingMode}\n * to allow a rounded result. Zero denominators always throw\n * `SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO`.\n *\n * @example\n * ```ts\n * const probability = ratioBinaryFixedPoint('signed', 16, 15);\n * probability(1n, 4n);           // raw === 8192n (0.25, exact)\n * probability(1n, 3n);           // throws under 'strict'\n * probability(1n, 3n, 'floor');  // raw === 10922n\n * ```\n *\n * @see {@link BinaryFixedPoint}\n * @see {@link binaryFixedPoint}\n * @see {@link rawBinaryFixedPoint}\n */\nexport function ratioBinaryFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TFractionalBits extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    fractionalBits: TFractionalBits,\n): (\n    numerator: bigint,\n    denominator: bigint,\n    rounding?: RoundingMode,\n) => BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    assertValidTotalBits('binaryFixedPoint', totalBits);\n    assertValidFractionalBits(fractionalBits);\n    return (numerator, denominator, rounding = 'strict') => {\n        if (denominator === 0n) {\n            throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO, {\n                denominator,\n                kind: 'binaryFixedPoint',\n                numerator,\n            });\n        }\n        const raw = roundDivision(\n            'binaryFixedPoint',\n            'fromRatio',\n            numerator * (1n << BigInt(fractionalBits)),\n            denominator,\n            rounding,\n        );\n        return createBinaryFixedPoint(signedness, totalBits, fractionalBits, raw);\n    };\n}\n","import { roundDivision, type RoundingMode } from './rounding';\n\n/**\n * Options accepted by `binaryFixedPointToString` and\n * `decimalFixedPointToString` to control the emitted representation.\n *\n * - `decimals`: caps the number of fractional digits in the output. When\n *   this is lower than the value's native precision the raw value is\n *   rescaled using `rounding` (defaults to `'strict'`, which throws\n *   `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` on inexact\n *   results). When higher, the extra precision is zero-padded only if\n *   `padTrailingZeros` is also set.\n * - `padTrailingZeros`: emits exactly as many fractional digits as\n *   requested by `decimals`. When `decimals` is omitted, pads to the\n *   value's native scale (`decimals` for decimal values,\n *   `fractionalBits` for binary values — the length of the exact\n *   base-10 expansion). Defaults to `false`, which trims trailing zeros\n *   (and drops the decimal point altogether for whole numbers).\n * - `rounding`: only consulted when `decimals` forces a scale-down.\n *   Defaults to `'strict'`.\n */\nexport type FixedPointToStringOptions = {\n    decimals?: number;\n    padTrailingZeros?: boolean;\n    rounding?: RoundingMode;\n};\n\n/**\n * Rescales `raw` from `currentDecimals` decimal digits to `options.decimals`\n * decimal digits (when set), respecting `options.rounding`. Returns the\n * raw value to format and the number of fractional digits implied by it.\n *\n * @internal\n */\nexport function applyDecimalsOption(\n    kind: 'binaryFixedPoint' | 'decimalFixedPoint',\n    raw: bigint,\n    currentDecimals: number,\n    options: FixedPointToStringOptions | undefined,\n): { decimals: number; raw: bigint } {\n    const targetDecimals = options?.decimals;\n    if (targetDecimals === undefined || targetDecimals === currentDecimals) {\n        return { decimals: currentDecimals, raw };\n    }\n    if (targetDecimals > currentDecimals) {\n        return {\n            decimals: targetDecimals,\n            raw: raw * 10n ** BigInt(targetDecimals - currentDecimals),\n        };\n    }\n    const divisor = 10n ** BigInt(currentDecimals - targetDecimals);\n    const rescaled = roundDivision(kind, 'toString', raw, divisor, options?.rounding ?? 'strict');\n    return { decimals: targetDecimals, raw: rescaled };\n}\n\n/**\n * Formats a scaled bigint `(raw, decimals)` as a canonical decimal\n * string. When `padTrailingZeros` is `true`, the output emits exactly\n * `decimals` fractional digits; otherwise trailing zeros are trimmed and\n * the decimal point is dropped if the fractional part becomes empty.\n *\n * @internal\n */\nexport function formatScaledBigint(raw: bigint, decimals: number, padTrailingZeros: boolean): string {\n    if (decimals === 0) {\n        return raw.toString();\n    }\n    const isNegative = raw < 0n;\n    const absDigits = (isNegative ? -raw : raw).toString();\n    const padded = absDigits.padStart(decimals + 1, '0');\n    const integerPart = padded.slice(0, -decimals);\n    let fractionalPart = padded.slice(-decimals);\n    if (!padTrailingZeros) {\n        fractionalPart = fractionalPart.replace(/0+$/, '');\n    }\n    const sign = isNegative ? '-' : '';\n    if (fractionalPart.length === 0) {\n        return `${sign}${integerPart}`;\n    }\n    return `${sign}${integerPart}.${fractionalPart}`;\n}\n","import { applyDecimalsOption, type FixedPointToStringOptions, formatScaledBigint } from '../formatting';\nimport type { Signedness } from '../signedness';\nimport { binaryFixedPointToBase10 } from './conversions';\nimport type { BinaryFixedPoint } from './core';\n\n/**\n * Returns the canonical decimal string representation of a\n * {@link BinaryFixedPoint}.\n *\n * Because `1 / 2 ** fractionalBits` has a finite decimal expansion, the\n * default output is always exact. This means that values with many\n * `fractionalBits` can produce long strings — pass `options.decimals` to\n * cap the output at a desired precision, optionally with a\n * {@link RoundingMode}. Use `options.padTrailingZeros` to emit exactly as\n * many fractional digits as requested; when `decimals` is omitted, this\n * pads to `value.fractionalBits` (the full exact expansion length).\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` when\n * `options.decimals` forces a lossy rescale under the default `'strict'`\n * rounding mode.\n *\n * @example\n * ```ts\n * const q1_15 = binaryFixedPoint('signed', 16, 15);\n * binaryFixedPointToString(q1_15('0.5'));                                 // \"0.5\"\n * binaryFixedPointToString(q1_15('0.5'), { padTrailingZeros: true });     // \"0.500000000000000\"\n * binaryFixedPointToString(ugly, { decimals: 2, rounding: 'round' });     // \"0.48\"\n * ```\n *\n * @see {@link binaryFixedPointToNumber}\n */\nexport function binaryFixedPointToString(\n    value: BinaryFixedPoint<Signedness, number, number>,\n    options?: FixedPointToStringOptions,\n): string {\n    const base10 = binaryFixedPointToBase10(value);\n    const { decimals, raw } = applyDecimalsOption('binaryFixedPoint', base10.raw, base10.decimals, options);\n    return formatScaledBigint(raw, decimals, options?.padTrailingZeros ?? false);\n}\n\n/**\n * Formats a {@link BinaryFixedPoint} using a user-supplied\n * `Intl.NumberFormat` instance, preserving full precision regardless of\n * the value's magnitude.\n *\n * Internally calls {@link binaryFixedPointToBase10} and forwards the\n * resulting integer to `formatter.format` using ES2023 string scientific\n * notation (`\"<raw>E-<decimals>\"`). This preserves precision in\n * fully-compliant runtimes and bypasses the JavaScript `number` mantissa\n * limit.\n *\n * Use this when you want locale-aware output, currency formatting,\n * grouping separators, or rounding modes from the rich\n * `Intl.NumberFormat` API. Prefer {@link binaryFixedPointToString} when\n * portability across older runtimes (older Hermes/React Native, etc.) is\n * a concern.\n *\n * @example\n * ```ts\n * const q1_15 = binaryFixedPoint('signed', 16, 15);\n * const formatter = new Intl.NumberFormat('fr-FR', {\n *     maximumFractionDigits: 4,\n * });\n * formatBinaryFixedPoint(formatter, q1_15('0.1')); // \"0,1\"\n * ```\n *\n * @see {@link binaryFixedPointToString}\n * @see {@link binaryFixedPointToBase10}\n */\nexport function formatBinaryFixedPoint(\n    formatter: Intl.NumberFormat,\n    value: BinaryFixedPoint<Signedness, number, number>,\n): string {\n    const { decimals, raw } = binaryFixedPointToBase10(value);\n    return (formatter.format as unknown as (input: string) => string)(`${raw}E-${decimals}`);\n}\n\n/**\n * Converts a {@link BinaryFixedPoint} to a JavaScript `number`.\n *\n * Precision loss occurs only when `|value.raw / 2 ** fractionalBits|`\n * exceeds `Number.MAX_SAFE_INTEGER`, since JavaScript numbers have only\n * ~53 bits of mantissa. For values whose magnitude fits that budget the\n * result is exact, regardless of the raw value's magnitude.\n *\n * For exact representations prefer {@link binaryFixedPointToString}.\n *\n * @example\n * ```ts\n * const q1_15 = binaryFixedPoint('signed', 16, 15);\n * binaryFixedPointToNumber(q1_15('0.5')); // 0.5\n * ```\n *\n * @see {@link binaryFixedPointToString}\n */\nexport function binaryFixedPointToNumber(value: BinaryFixedPoint<Signedness, number, number>): number {\n    const { fractionalBits, raw } = value;\n    if (fractionalBits === 0) {\n        return Number(raw);\n    }\n    // Split `raw` into an integer and a fractional residue before coercing to\n    // Number. This preserves exactness for values whose final magnitude fits\n    // ~53 bits of mantissa even when `|raw|` itself exceeds MAX_SAFE_INTEGER.\n    const scale = 1n << BigInt(fractionalBits);\n    const integerPart = raw / scale;\n    const fractionalPart = Number(raw - integerPart * scale) / 2 ** fractionalBits;\n    return Number(integerPart) + fractionalPart;\n}\n","import { assertRawFitsInRange, assertRawIsBigint, assertShapeMatches, describeShape } from '../assertions';\nimport type { Signedness } from '../signedness';\nimport type { BinaryFixedPoint } from './core';\n\n/**\n * Asserts that `value` is a {@link BinaryFixedPoint}.\n *\n * Every shape parameter is independently optional. Pass `undefined` (or\n * simply omit trailing arguments) to leave a given field unconstrained.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` if the value does\n * not match the expected shape, or\n * `SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE` if the `raw` bigint\n * does not fit the claimed signedness and total bits.\n *\n * @example\n * ```ts\n * assertIsBinaryFixedPoint(value);                   // any binary fixed-point\n * assertIsBinaryFixedPoint(value, 'signed');         // any signed binary\n * assertIsBinaryFixedPoint(value, 'signed', 16, 15); // fully pinned\n * assertIsBinaryFixedPoint(value, undefined, 16);    // any binary with totalBits=16\n * ```\n *\n * @see {@link isBinaryFixedPoint}\n * @see {@link BinaryFixedPoint}\n */\nexport function assertIsBinaryFixedPoint<\n    TSignedness extends Signedness = Signedness,\n    TTotalBits extends number = number,\n    TFractionalBits extends number = number,\n>(\n    value: unknown,\n    signedness?: TSignedness,\n    totalBits?: TTotalBits,\n    fractionalBits?: TFractionalBits,\n): asserts value is BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    const actual = describeShape(value);\n    const expected = {\n        kind: 'binaryFixedPoint',\n        scale: fractionalBits,\n        scaleLabel: 'fractional bits',\n        signedness,\n        totalBits,\n    };\n    assertShapeMatches('assertIsBinaryFixedPoint', actual, expected);\n    assertRawIsBigint('binaryFixedPoint', value);\n    assertRawFitsInRange('binaryFixedPoint', actual.signedness as Signedness, actual.totalBits, value.raw);\n}\n\n/**\n * Type guard that refines an unknown value to a {@link BinaryFixedPoint}.\n *\n * Accepts the same partial-positional shape arguments as\n * {@link assertIsBinaryFixedPoint} and returns `true` if the assertion\n * would pass, `false` otherwise.\n *\n * @example\n * ```ts\n * if (isBinaryFixedPoint(value)) {\n *     value satisfies BinaryFixedPoint<Signedness, number, number>;\n * }\n * if (isBinaryFixedPoint(value, 'signed', 16, 15)) {\n *     value satisfies BinaryFixedPoint<'signed', 16, 15>;\n * }\n * ```\n *\n * @see {@link assertIsBinaryFixedPoint}\n * @see {@link BinaryFixedPoint}\n */\nexport function isBinaryFixedPoint<\n    TSignedness extends Signedness = Signedness,\n    TTotalBits extends number = number,\n    TFractionalBits extends number = number,\n>(\n    value: unknown,\n    signedness?: TSignedness,\n    totalBits?: TTotalBits,\n    fractionalBits?: TFractionalBits,\n): value is BinaryFixedPoint<TSignedness, TTotalBits, TFractionalBits> {\n    try {\n        assertIsBinaryFixedPoint(value, signedness, totalBits, fractionalBits);\n        return true;\n    } catch {\n        return false;\n    }\n}\n","import { assertNoArithmeticOverflow, assertNoDivisionByZero, assertShapeMatches, describeShape } from '../assertions';\nimport { roundDivision, type RoundingMode } from '../rounding';\nimport type { Signedness } from '../signedness';\nimport type { DecimalFixedPoint } from './core';\n\n/**\n * Adds two {@link DecimalFixedPoint} values of the same shape and returns\n * the result at the same shape.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` if the two operands\n * differ in signedness, total bits, or decimals, and\n * `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW` if the sum does not\n * fit the target shape.\n *\n * @example\n * ```ts\n * const usd = decimalFixedPoint('unsigned', 64, 2);\n * addDecimalFixedPoint(usd('1.50'), usd('2.25')); // represents 3.75\n * ```\n *\n * @see {@link subtractDecimalFixedPoint}\n */\nexport function addDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    a: DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,\n    b: NoInfer<DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>>,\n): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    assertShapeMatches('addDecimalFixedPoint', describeShape(b), {\n        kind: a.kind,\n        scale: a.decimals,\n        scaleLabel: 'decimals',\n        signedness: a.signedness,\n        totalBits: a.totalBits,\n    });\n    const result = a.raw + b.raw;\n    assertNoArithmeticOverflow(a.kind, 'add', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Subtracts `b` from `a` where both are {@link DecimalFixedPoint} values\n * of the same shape, and returns the result at the same shape.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` if the two operands\n * differ in shape, and `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW`\n * if the difference does not fit the target shape.\n *\n * @see {@link addDecimalFixedPoint}\n */\nexport function subtractDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    a: DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,\n    b: NoInfer<DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>>,\n): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    assertShapeMatches('subtractDecimalFixedPoint', describeShape(b), {\n        kind: a.kind,\n        scale: a.decimals,\n        scaleLabel: 'decimals',\n        signedness: a.signedness,\n        totalBits: a.totalBits,\n    });\n    const result = a.raw - b.raw;\n    assertNoArithmeticOverflow(a.kind, 'subtract', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Multiplies a {@link DecimalFixedPoint} by a scalar.\n *\n * The second operand may be another {@link DecimalFixedPoint} with the\n * same signedness (any total bits or decimals) or a bare `bigint`. The\n * result always has `a`'s shape.\n *\n * Multiplication by a same-kind fixed-point rescales the product back to\n * `a`'s scale. When that rescaling is not exact, the optional\n * {@link RoundingMode} is consulted; it defaults to `'strict'` and throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` in that case.\n *\n * @example\n * ```ts\n * const usd = decimalFixedPoint('unsigned', 64, 2);\n * const rate = decimalFixedPoint('unsigned', 64, 4);\n * multiplyDecimalFixedPoint(usd('100'), rate('0.0025')); // represents 0.25\n * multiplyDecimalFixedPoint(usd('1.50'), 3n);             // represents 4.50\n * ```\n *\n * @see {@link divideDecimalFixedPoint}\n */\nexport function multiplyDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    a: DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,\n    b: DecimalFixedPoint<NoInfer<TSignedness>, number, number> | bigint,\n    rounding: RoundingMode = 'strict',\n): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    let result: bigint;\n    if (typeof b === 'bigint') {\n        result = a.raw * b;\n    } else {\n        assertShapeMatches('multiplyDecimalFixedPoint', describeShape(b), {\n            kind: a.kind,\n            scaleLabel: 'decimals',\n            signedness: a.signedness,\n        });\n        result = roundDivision(a.kind, 'multiply', a.raw * b.raw, 10n ** BigInt(b.decimals), rounding);\n    }\n    assertNoArithmeticOverflow(a.kind, 'multiply', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Divides a {@link DecimalFixedPoint} by a scalar.\n *\n * The second operand may be another {@link DecimalFixedPoint} with the\n * same signedness (any total bits or decimals) or a bare `bigint`. The\n * result always has `a`'s shape.\n *\n * The optional {@link RoundingMode} is consulted whenever the division is\n * inexact; it defaults to `'strict'` and throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` in that case.\n * A zero divisor always throws\n * `SOLANA_ERROR__FIXED_POINTS__DIVISION_BY_ZERO`.\n *\n * @example\n * ```ts\n * const usd = decimalFixedPoint('unsigned', 64, 2);\n * const rate = decimalFixedPoint('unsigned', 64, 4);\n * divideDecimalFixedPoint(usd('10'), rate('0.05'));   // represents 200.00\n * divideDecimalFixedPoint(usd('10.50'), 3n, 'round'); // represents 3.50\n * ```\n *\n * @see {@link multiplyDecimalFixedPoint}\n */\nexport function divideDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    a: DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,\n    b: DecimalFixedPoint<NoInfer<TSignedness>, number, number> | bigint,\n    rounding: RoundingMode = 'strict',\n): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    let result: bigint;\n    if (typeof b === 'bigint') {\n        assertNoDivisionByZero(a.kind, a.signedness, a.totalBits, b);\n        result = roundDivision(a.kind, 'divide', a.raw, b, rounding);\n    } else {\n        assertShapeMatches('divideDecimalFixedPoint', describeShape(b), {\n            kind: a.kind,\n            scaleLabel: 'decimals',\n            signedness: a.signedness,\n        });\n        assertNoDivisionByZero(a.kind, a.signedness, a.totalBits, b.raw);\n        result = roundDivision(a.kind, 'divide', a.raw * 10n ** BigInt(b.decimals), b.raw, rounding);\n    }\n    assertNoArithmeticOverflow(a.kind, 'divide', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Returns the additive inverse of a signed {@link DecimalFixedPoint}.\n *\n * Unsigned values are rejected at the type level; they are also rejected\n * at runtime with `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` in case the\n * type safety is bypassed. Negating the minimum representable value\n * overflows and throws `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW`.\n *\n * @see {@link absoluteDecimalFixedPoint}\n */\nexport function negateDecimalFixedPoint<TTotalBits extends number, TDecimals extends number>(\n    a: DecimalFixedPoint<'signed', TTotalBits, TDecimals>,\n): DecimalFixedPoint<'signed', TTotalBits, TDecimals> {\n    assertShapeMatches('negateDecimalFixedPoint', describeShape(a), {\n        kind: a.kind,\n        scaleLabel: 'decimals',\n        signedness: 'signed',\n    });\n    const result = -a.raw;\n    assertNoArithmeticOverflow(a.kind, 'negate', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n\n/**\n * Returns the absolute value of a {@link DecimalFixedPoint}. Unsigned\n * inputs are returned unchanged.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW` when taking the\n * absolute value of the minimum representable signed value, which has no\n * positive counterpart in two's-complement.\n *\n * @see {@link negateDecimalFixedPoint}\n */\nexport function absoluteDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(a: DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    const result = a.raw < 0n ? -a.raw : a.raw;\n    assertNoArithmeticOverflow(a.kind, 'absolute', a.signedness, a.totalBits, result);\n    return Object.freeze({ ...a, raw: result });\n}\n","import {\n    assertByteArrayHasEnoughBytesForCodec,\n    assertByteArrayIsNotEmptyForCodec,\n    combineCodec,\n    createDecoder,\n    createEncoder,\n    type FixedSizeCodec,\n    type FixedSizeDecoder,\n    type FixedSizeEncoder,\n} from '@solana/codecs-core';\n\nimport {\n    assertShapeMatches,\n    assertTotalBitsIsByteAligned,\n    assertValidDecimals,\n    assertValidTotalBits,\n    describeShape,\n} from '../assertions';\nimport { type BytesForTotalBits, type FixedPointCodecConfig, readRawBigInt, writeRawBigInt } from '../codecs';\nimport type { Signedness } from '../signedness';\nimport type { DecimalFixedPoint } from './core';\n\n/**\n * Returns an encoder for {@link DecimalFixedPoint} values of a specific\n * shape. The encoder serializes `value.raw` as a fixed-size integer using\n * two's-complement for signed values and little-endian byte order by\n * default.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED` when\n * `totalBits` is not a multiple of 8. Encoding a value whose shape does\n * not match the codec's shape throws\n * `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH`.\n *\n * @example\n * ```ts\n * const encoder = getDecimalFixedPointEncoder('unsigned', 64, 6);\n * encoder.encode(decimalFixedPoint('unsigned', 64, 6)('42.5'));\n * ```\n *\n * @see {@link getDecimalFixedPointDecoder}\n * @see {@link getDecimalFixedPointCodec}\n */\nexport function getDecimalFixedPointEncoder<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    decimals: TDecimals,\n    config: FixedPointCodecConfig = {},\n): FixedSizeEncoder<DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>, BytesForTotalBits<TTotalBits>> {\n    assertValidTotalBits('decimalFixedPoint', totalBits);\n    assertValidDecimals(decimals);\n    assertTotalBitsIsByteAligned('decimalFixedPoint', totalBits);\n    const byteSize = (totalBits / 8) as BytesForTotalBits<TTotalBits>;\n    const littleEndian = config.endian !== 'be';\n    return createEncoder({\n        fixedSize: byteSize,\n        write(value, bytes, offset) {\n            assertShapeMatches('getDecimalFixedPointEncoder', describeShape(value), {\n                kind: 'decimalFixedPoint',\n                scale: decimals,\n                scaleLabel: 'decimals',\n                signedness,\n                totalBits,\n            });\n            writeRawBigInt(bytes, offset, value.raw, byteSize, signedness, littleEndian);\n            return offset + byteSize;\n        },\n    });\n}\n\n/**\n * Returns a decoder for {@link DecimalFixedPoint} values of a specific\n * shape. The decoder reads a fixed-size integer using two's-complement for\n * signed values and little-endian byte order by default, and reconstructs\n * a frozen {@link DecimalFixedPoint} from the bytes.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__TOTAL_BITS_NOT_BYTE_ALIGNED` when\n * `totalBits` is not a multiple of 8.\n *\n * @example\n * ```ts\n * const decoder = getDecimalFixedPointDecoder('unsigned', 64, 6);\n * decoder.decode(bytes); // represents 42.5 for appropriately encoded bytes\n * ```\n *\n * @see {@link getDecimalFixedPointEncoder}\n * @see {@link getDecimalFixedPointCodec}\n */\nexport function getDecimalFixedPointDecoder<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    decimals: TDecimals,\n    config: FixedPointCodecConfig = {},\n): FixedSizeDecoder<DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>, BytesForTotalBits<TTotalBits>> {\n    assertValidTotalBits('decimalFixedPoint', totalBits);\n    assertValidDecimals(decimals);\n    assertTotalBitsIsByteAligned('decimalFixedPoint', totalBits);\n    const byteSize = (totalBits / 8) as BytesForTotalBits<TTotalBits>;\n    const littleEndian = config.endian !== 'be';\n    const codecDescription = 'getDecimalFixedPointDecoder';\n    return createDecoder({\n        fixedSize: byteSize,\n        read(bytes, offset) {\n            assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset);\n            assertByteArrayHasEnoughBytesForCodec(codecDescription, byteSize, bytes, offset);\n            const raw = readRawBigInt(bytes, offset, byteSize, signedness, littleEndian);\n            const value = Object.freeze({\n                decimals,\n                kind: 'decimalFixedPoint',\n                raw,\n                signedness,\n                totalBits,\n            }) as DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>;\n            return [value, offset + byteSize];\n        },\n    });\n}\n\n/**\n * Returns a codec for {@link DecimalFixedPoint} values of a specific\n * shape, combining {@link getDecimalFixedPointEncoder} and\n * {@link getDecimalFixedPointDecoder}.\n *\n * @example\n * ```ts\n * const codec = getDecimalFixedPointCodec('unsigned', 64, 6);\n * const bytes = codec.encode(decimalFixedPoint('unsigned', 64, 6)('42.5'));\n * const value = codec.decode(bytes); // represents 42.5\n * ```\n *\n * @see {@link getDecimalFixedPointEncoder}\n * @see {@link getDecimalFixedPointDecoder}\n */\nexport function getDecimalFixedPointCodec<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    decimals: TDecimals,\n    config: FixedPointCodecConfig = {},\n): FixedSizeCodec<\n    DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,\n    DecimalFixedPoint<TSignedness, TTotalBits, TDecimals>,\n    BytesForTotalBits<TTotalBits>\n> {\n    return combineCodec(\n        getDecimalFixedPointEncoder(signedness, totalBits, decimals, config),\n        getDecimalFixedPointDecoder(signedness, totalBits, decimals, config),\n    );\n}\n","import { assertShapeMatches, describeShape } from '../assertions';\nimport type { Signedness } from '../signedness';\nimport type { DecimalFixedPoint } from './core';\n\n/**\n * Compares two {@link DecimalFixedPoint} values and returns `-1`, `0`, or\n * `1` depending on whether `a` is less than, equal to, or greater than `b`.\n *\n * Only the `kind` and `decimals` of the two operands must match;\n * `signedness` and `totalBits` are allowed to differ because they are\n * storage concerns only and do not affect the mathematical value being\n * compared. Mismatches on the constrained dimensions throw\n * `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH`.\n *\n * @example\n * ```ts\n * const usd = decimalFixedPoint('unsigned', 64, 2);\n * cmpDecimalFixedPoint(usd('1.25'), usd('2.50')); // -1\n * cmpDecimalFixedPoint(usd('2.50'), usd('2.50')); // 0\n * cmpDecimalFixedPoint(usd('3.75'), usd('2.50')); // 1\n * ```\n *\n * @see {@link eqDecimalFixedPoint}\n * @see {@link ltDecimalFixedPoint}\n * @see {@link lteDecimalFixedPoint}\n * @see {@link gtDecimalFixedPoint}\n * @see {@link gteDecimalFixedPoint}\n */\nexport function cmpDecimalFixedPoint<TDecimals extends number>(\n    a: DecimalFixedPoint<Signedness, number, TDecimals>,\n    b: DecimalFixedPoint<Signedness, number, NoInfer<TDecimals>>,\n): -1 | 0 | 1 {\n    assertShapeMatches('cmpDecimalFixedPoint', describeShape(b), {\n        kind: a.kind,\n        scale: a.decimals,\n        scaleLabel: 'decimals',\n    });\n    return a.raw < b.raw ? -1 : a.raw > b.raw ? 1 : 0;\n}\n\n/**\n * Returns `true` when `a` and `b` represent the same value.\n *\n * See {@link cmpDecimalFixedPoint} for shape-matching rules.\n */\nexport function eqDecimalFixedPoint<TDecimals extends number>(\n    a: DecimalFixedPoint<Signedness, number, TDecimals>,\n    b: DecimalFixedPoint<Signedness, number, NoInfer<TDecimals>>,\n): boolean {\n    return cmpDecimalFixedPoint(a, b) === 0;\n}\n\n/**\n * Returns `true` when `a` is strictly less than `b`.\n *\n * See {@link cmpDecimalFixedPoint} for shape-matching rules.\n */\nexport function ltDecimalFixedPoint<TDecimals extends number>(\n    a: DecimalFixedPoint<Signedness, number, TDecimals>,\n    b: DecimalFixedPoint<Signedness, number, NoInfer<TDecimals>>,\n): boolean {\n    return cmpDecimalFixedPoint(a, b) < 0;\n}\n\n/**\n * Returns `true` when `a` is less than or equal to `b`.\n *\n * See {@link cmpDecimalFixedPoint} for shape-matching rules.\n */\nexport function lteDecimalFixedPoint<TDecimals extends number>(\n    a: DecimalFixedPoint<Signedness, number, TDecimals>,\n    b: DecimalFixedPoint<Signedness, number, NoInfer<TDecimals>>,\n): boolean {\n    return cmpDecimalFixedPoint(a, b) <= 0;\n}\n\n/**\n * Returns `true` when `a` is strictly greater than `b`.\n *\n * See {@link cmpDecimalFixedPoint} for shape-matching rules.\n */\nexport function gtDecimalFixedPoint<TDecimals extends number>(\n    a: DecimalFixedPoint<Signedness, number, TDecimals>,\n    b: DecimalFixedPoint<Signedness, number, NoInfer<TDecimals>>,\n): boolean {\n    return cmpDecimalFixedPoint(a, b) > 0;\n}\n\n/**\n * Returns `true` when `a` is greater than or equal to `b`.\n *\n * See {@link cmpDecimalFixedPoint} for shape-matching rules.\n */\nexport function gteDecimalFixedPoint<TDecimals extends number>(\n    a: DecimalFixedPoint<Signedness, number, TDecimals>,\n    b: DecimalFixedPoint<Signedness, number, NoInfer<TDecimals>>,\n): boolean {\n    return cmpDecimalFixedPoint(a, b) >= 0;\n}\n","import {\n    assertNoArithmeticOverflow,\n    assertRawFitsInRange,\n    assertValidDecimals,\n    assertValidTotalBits,\n} from '../assertions';\nimport { roundDivision, type RoundingMode } from '../rounding';\nimport type { Signedness } from '../signedness';\nimport type { DecimalFixedPoint } from './core';\n\n/**\n * Converts a {@link DecimalFixedPoint} to its unsigned equivalent at the\n * same `totalBits` and `decimals`.\n *\n * Unsigned inputs are returned by reference unchanged; signed inputs are\n * accepted as long as their raw value is non-negative.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE` when the input\n * represents a negative value that cannot be stored as unsigned.\n *\n * @example\n * ```ts\n * const signedUsd = decimalFixedPoint('signed', 64, 2);\n * toUnsignedDecimalFixedPoint(signedUsd('1.50')); // unsigned, raw unchanged\n * toUnsignedDecimalFixedPoint(signedUsd('-1'));   // throws\n * ```\n *\n * @see {@link toSignedDecimalFixedPoint}\n */\nexport function toUnsignedDecimalFixedPoint<TTotalBits extends number, TDecimals extends number>(\n    value: DecimalFixedPoint<Signedness, TTotalBits, TDecimals>,\n): DecimalFixedPoint<'unsigned', TTotalBits, TDecimals> {\n    if (value.signedness === 'unsigned') {\n        return value as DecimalFixedPoint<'unsigned', TTotalBits, TDecimals>;\n    }\n    assertRawFitsInRange('decimalFixedPoint', 'unsigned', value.totalBits, value.raw);\n    return Object.freeze({ ...value, signedness: 'unsigned' });\n}\n\n/**\n * Converts a {@link DecimalFixedPoint} to its signed equivalent at the same\n * `totalBits` and `decimals`.\n *\n * Signed inputs are returned by reference unchanged; unsigned inputs are\n * accepted as long as their raw value fits the signed range, i.e.\n * `raw <= 2 ** (totalBits - 1) - 1`.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE` when the input's\n * raw value exceeds the maximum representable signed value at its\n * `totalBits`.\n *\n * @example\n * ```ts\n * const unsigned = rawDecimalFixedPoint('unsigned', 8, 0);\n * toSignedDecimalFixedPoint(unsigned(100n)); // signed, raw === 100n\n * toSignedDecimalFixedPoint(unsigned(200n)); // throws (200 > 127)\n * ```\n *\n * @see {@link toUnsignedDecimalFixedPoint}\n */\nexport function toSignedDecimalFixedPoint<TTotalBits extends number, TDecimals extends number>(\n    value: DecimalFixedPoint<Signedness, TTotalBits, TDecimals>,\n): DecimalFixedPoint<'signed', TTotalBits, TDecimals> {\n    if (value.signedness === 'signed') {\n        return value as DecimalFixedPoint<'signed', TTotalBits, TDecimals>;\n    }\n    assertRawFitsInRange('decimalFixedPoint', 'signed', value.totalBits, value.raw);\n    return Object.freeze({ ...value, signedness: 'signed' });\n}\n\n/**\n * Returns a {@link DecimalFixedPoint} with the same signedness as `value`\n * but a new `totalBits` and `decimals`. If the requested shape matches\n * the input shape, the same reference is returned.\n *\n * Scale-up (higher `decimals`) is always exact. Scale-down (lower\n * `decimals`) is potentially lossy; the optional {@link RoundingMode} is\n * consulted on inexact results and defaults to `'strict'`, which throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS`.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__ARITHMETIC_OVERFLOW` when the\n * rescaled raw value does not fit the new `totalBits`.\n *\n * @example\n * ```ts\n * // Bridge EVM USDC (u128 d18) down to SPL USDC (u64 d6).\n * const evmUsdc = decimalFixedPoint('unsigned', 128, 18);\n * rescaleDecimalFixedPoint(evmUsdc('100.123456789012345678'), 64, 6, 'floor');\n * // represents 100.123456\n * ```\n *\n * @see {@link toSignedDecimalFixedPoint}\n * @see {@link toUnsignedDecimalFixedPoint}\n */\nexport function rescaleDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TNewTotalBits extends number,\n    TNewDecimals extends number,\n>(\n    value: DecimalFixedPoint<TSignedness, number, number>,\n    newTotalBits: TNewTotalBits,\n    newDecimals: TNewDecimals,\n    rounding: RoundingMode = 'strict',\n): DecimalFixedPoint<TSignedness, TNewTotalBits, TNewDecimals> {\n    assertValidTotalBits('decimalFixedPoint', newTotalBits);\n    assertValidDecimals(newDecimals);\n    if (value.totalBits === newTotalBits && value.decimals === newDecimals) {\n        return value as DecimalFixedPoint<TSignedness, TNewTotalBits, TNewDecimals>;\n    }\n    let result: bigint;\n    if (newDecimals === value.decimals) {\n        result = value.raw;\n    } else if (newDecimals > value.decimals) {\n        result = value.raw * 10n ** BigInt(newDecimals - value.decimals);\n    } else {\n        result = roundDivision(\n            'decimalFixedPoint',\n            'rescale',\n            value.raw,\n            10n ** BigInt(value.decimals - newDecimals),\n            rounding,\n        );\n    }\n    assertNoArithmeticOverflow('decimalFixedPoint', 'rescale', value.signedness, newTotalBits, result);\n    return Object.freeze({ ...value, decimals: newDecimals, raw: result, totalBits: newTotalBits });\n}\n","import { SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO, SolanaError } from '@solana/errors';\n\nimport { assertRawFitsInRange, assertValidDecimals, assertValidTotalBits } from '../assertions';\nimport { parseDecimalString } from '../parsing';\nimport { roundDivision, type RoundingMode } from '../rounding';\nimport type { Signedness } from '../signedness';\n\n/**\n * A fixed-point number whose scale is a power of 10. The stored `raw` bigint\n * represents the mathematical value `raw / 10 ** decimals`.\n *\n * Decimal fixed-point is the natural representation for quantities that\n * users reason about in base-10 terms, such as token amounts, currency, or\n * probabilities with decimal precision.\n *\n * @typeParam TSignedness - Whether the value can be negative.\n * @typeParam TTotalBits - The total number of bits used to store the raw value.\n * @typeParam TDecimals - The number of decimal digits to the right of the decimal point.\n *\n * @example\n * An unsigned 64-bit USDC amount with 6 decimals of precision:\n * ```ts\n * type Usdc = DecimalFixedPoint<'unsigned', 64, 6>;\n * ```\n *\n * @see {@link BinaryFixedPoint}\n * @see {@link Signedness}\n */\nexport type DecimalFixedPoint<TSignedness extends Signedness, TTotalBits extends number, TDecimals extends number> = {\n    readonly decimals: TDecimals;\n    readonly kind: 'decimalFixedPoint';\n    readonly raw: bigint;\n    readonly signedness: TSignedness;\n    readonly totalBits: TTotalBits;\n};\n\nfunction createDecimalFixedPoint<TSignedness extends Signedness, TTotalBits extends number, TDecimals extends number>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    decimals: TDecimals,\n    raw: bigint,\n): DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    assertRawFitsInRange('decimalFixedPoint', signedness, totalBits, raw);\n    return Object.freeze({ decimals, kind: 'decimalFixedPoint', raw, signedness, totalBits });\n}\n\n/**\n * Returns a factory that constructs {@link DecimalFixedPoint} values from\n * decimal strings.\n *\n * The outer call validates the shape parameters once and the returned\n * factory can be called many times to construct values of that shape.\n *\n * If the string carries more precision than the target `decimals` can\n * represent exactly, the returned factory throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` under the\n * default `'strict'` rounding mode. Pass a different {@link RoundingMode}\n * to allow a rounded result.\n *\n * @example\n * ```ts\n * const usdc = decimalFixedPoint('unsigned', 64, 6);\n * usdc('42.5');          // raw === 42500000n\n * usdc('0.0000001');     // throws under the default 'strict' mode\n * usdc('0.0000001', 'round'); // raw === 0n\n * ```\n *\n * @see {@link DecimalFixedPoint}\n * @see {@link rawDecimalFixedPoint}\n * @see {@link ratioDecimalFixedPoint}\n */\nexport function decimalFixedPoint<TSignedness extends Signedness, TTotalBits extends number, TDecimals extends number>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    decimals: TDecimals,\n): (input: string, rounding?: RoundingMode) => DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    assertValidTotalBits('decimalFixedPoint', totalBits);\n    assertValidDecimals(decimals);\n    return (input, rounding = 'strict') => {\n        const parsed = parseDecimalString('decimalFixedPoint', input);\n        const raw =\n            parsed.decimals <= decimals\n                ? parsed.raw * 10n ** BigInt(decimals - parsed.decimals)\n                : roundDivision(\n                      'decimalFixedPoint',\n                      'fromString',\n                      parsed.raw,\n                      10n ** BigInt(parsed.decimals - decimals),\n                      rounding,\n                  );\n        return createDecimalFixedPoint(signedness, totalBits, decimals, raw);\n    };\n}\n\n/**\n * Returns a factory that constructs {@link DecimalFixedPoint} values from a\n * raw bigint in the smallest representable unit (i.e. already scaled by\n * `10 ** decimals`).\n *\n * The outer call validates the shape parameters once and the returned\n * factory can be called many times to construct values of that shape.\n *\n * The raw value is range-checked against the claimed `totalBits` and\n * `signedness`; no rounding is ever required.\n *\n * @example\n * ```ts\n * const cents = rawDecimalFixedPoint('unsigned', 16, 2);\n * cents(425n); // Represents 4.25\n * ```\n *\n * @see {@link DecimalFixedPoint}\n * @see {@link decimalFixedPoint}\n * @see {@link ratioDecimalFixedPoint}\n */\nexport function rawDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    decimals: TDecimals,\n): (raw: bigint) => DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    assertValidTotalBits('decimalFixedPoint', totalBits);\n    assertValidDecimals(decimals);\n    return raw => createDecimalFixedPoint(signedness, totalBits, decimals, raw);\n}\n\n/**\n * Returns a factory that constructs {@link DecimalFixedPoint} values from\n * a rational `numerator / denominator`.\n *\n * The outer call validates the shape parameters once and the returned\n * factory can be called many times to construct values of that shape.\n *\n * If the ratio cannot be exactly represented at the target `decimals`,\n * the returned factory throws\n * `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` under the\n * default `'strict'` rounding mode. Pass a different {@link RoundingMode}\n * to allow a rounded result. Zero denominators always throw\n * `SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO`.\n *\n * @example\n * ```ts\n * const probability = ratioDecimalFixedPoint('unsigned', 64, 4);\n * probability(1n, 4n);           // raw === 2500n (0.2500)\n * probability(1n, 3n);           // throws under 'strict'\n * probability(1n, 3n, 'floor');  // raw === 3333n\n * ```\n *\n * @see {@link DecimalFixedPoint}\n * @see {@link decimalFixedPoint}\n * @see {@link rawDecimalFixedPoint}\n */\nexport function ratioDecimalFixedPoint<\n    TSignedness extends Signedness,\n    TTotalBits extends number,\n    TDecimals extends number,\n>(\n    signedness: TSignedness,\n    totalBits: TTotalBits,\n    decimals: TDecimals,\n): (\n    numerator: bigint,\n    denominator: bigint,\n    rounding?: RoundingMode,\n) => DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    assertValidTotalBits('decimalFixedPoint', totalBits);\n    assertValidDecimals(decimals);\n    return (numerator, denominator, rounding = 'strict') => {\n        if (denominator === 0n) {\n            throw new SolanaError(SOLANA_ERROR__FIXED_POINTS__INVALID_ZERO_DENOMINATOR_RATIO, {\n                denominator,\n                kind: 'decimalFixedPoint',\n                numerator,\n            });\n        }\n        const raw = roundDivision(\n            'decimalFixedPoint',\n            'fromRatio',\n            numerator * 10n ** BigInt(decimals),\n            denominator,\n            rounding,\n        );\n        return createDecimalFixedPoint(signedness, totalBits, decimals, raw);\n    };\n}\n","import { applyDecimalsOption, type FixedPointToStringOptions, formatScaledBigint } from '../formatting';\nimport type { Signedness } from '../signedness';\nimport type { DecimalFixedPoint } from './core';\n\n/**\n * Returns the canonical decimal string representation of a\n * {@link DecimalFixedPoint}.\n *\n * By default, trailing zeros are trimmed and the decimal point is\n * dropped for whole numbers. Pass `options.decimals` to emit a different\n * number of fractional digits (with {@link RoundingMode} control when\n * scale-down is lossy), and `options.padTrailingZeros` to emit exactly\n * that many digits. When `padTrailingZeros` is set without `decimals`,\n * the output is padded to `value.decimals`.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__STRICT_MODE_PRECISION_LOSS` when\n * `options.decimals` forces a lossy rescale under the default `'strict'`\n * rounding mode.\n *\n * @example\n * ```ts\n * const usdc = decimalFixedPoint('unsigned', 64, 6);\n * decimalFixedPointToString(usdc('42.5'));                               // \"42.5\"\n * decimalFixedPointToString(usdc('42.5'), { padTrailingZeros: true });   // \"42.500000\"\n * decimalFixedPointToString(usdc('42.678'), { decimals: 2, rounding: 'floor' }); // \"42.67\"\n * ```\n *\n * @see {@link decimalFixedPointToNumber}\n */\nexport function decimalFixedPointToString(\n    value: DecimalFixedPoint<Signedness, number, number>,\n    options?: FixedPointToStringOptions,\n): string {\n    const { decimals, raw } = applyDecimalsOption('decimalFixedPoint', value.raw, value.decimals, options);\n    return formatScaledBigint(raw, decimals, options?.padTrailingZeros ?? false);\n}\n\n/**\n * Formats a {@link DecimalFixedPoint} using a user-supplied\n * `Intl.NumberFormat` instance, preserving full precision regardless of\n * the value's magnitude.\n *\n * Forwards `value.raw` to `formatter.format` using ES2023 string\n * scientific notation (`\"<raw>E-<decimals>\"`). This preserves precision\n * in fully-compliant runtimes and bypasses the JavaScript `number`\n * mantissa limit.\n *\n * Use this when you want locale-aware output, currency formatting,\n * grouping separators, or rounding modes from the rich\n * `Intl.NumberFormat` API. Prefer {@link decimalFixedPointToString} when\n * portability across older runtimes (older Hermes/React Native, etc.) is\n * a concern.\n *\n * @example\n * ```ts\n * const usdc = decimalFixedPoint('unsigned', 64, 6);\n * const formatter = new Intl.NumberFormat('en-US', {\n *     currency: 'USD',\n *     style: 'currency',\n * });\n * formatDecimalFixedPoint(formatter, usdc('1234.5')); // \"$1,234.50\"\n * ```\n *\n * @see {@link decimalFixedPointToString}\n */\nexport function formatDecimalFixedPoint(\n    formatter: Intl.NumberFormat,\n    value: DecimalFixedPoint<Signedness, number, number>,\n): string {\n    return (formatter.format as unknown as (input: string) => string)(`${value.raw}E-${value.decimals}`);\n}\n\n/**\n * Converts a {@link DecimalFixedPoint} to a JavaScript `number`.\n *\n * This conversion is inherently lossy: `1 / 10 ** decimals` is not\n * representable exactly in IEEE 754 for any positive `decimals`, and\n * additional precision is lost when `|value.raw|` exceeds\n * `Number.MAX_SAFE_INTEGER`, since JavaScript numbers have only ~53\n * bits of mantissa.\n *\n * For exact representations prefer {@link decimalFixedPointToString}.\n *\n * @example\n * ```ts\n * const usdc = decimalFixedPoint('unsigned', 64, 6);\n * decimalFixedPointToNumber(usdc('42.5')); // 42.5\n * ```\n *\n * @see {@link decimalFixedPointToString}\n */\nexport function decimalFixedPointToNumber(value: DecimalFixedPoint<Signedness, number, number>): number {\n    return Number(value.raw) / 10 ** value.decimals;\n}\n","import { assertRawFitsInRange, assertRawIsBigint, assertShapeMatches, describeShape } from '../assertions';\nimport type { Signedness } from '../signedness';\nimport type { DecimalFixedPoint } from './core';\n\n/**\n * Asserts that `value` is a {@link DecimalFixedPoint}.\n *\n * Every shape parameter is independently optional. Pass `undefined` (or\n * simply omit trailing arguments) to leave a given field unconstrained.\n *\n * Throws `SOLANA_ERROR__FIXED_POINTS__SHAPE_MISMATCH` if the value does\n * not match the expected shape, or\n * `SOLANA_ERROR__FIXED_POINTS__VALUE_OUT_OF_RANGE` if the `raw` bigint\n * does not fit the claimed signedness and total bits.\n *\n * @example\n * ```ts\n * assertIsDecimalFixedPoint(value);                   // any decimal fixed-point\n * assertIsDecimalFixedPoint(value, 'unsigned');        // any unsigned decimal\n * assertIsDecimalFixedPoint(value, 'unsigned', 64, 6); // fully pinned\n * assertIsDecimalFixedPoint(value, undefined, 64);     // any decimal with totalBits=64\n * ```\n *\n * @see {@link isDecimalFixedPoint}\n * @see {@link DecimalFixedPoint}\n */\nexport function assertIsDecimalFixedPoint<\n    TSignedness extends Signedness = Signedness,\n    TTotalBits extends number = number,\n    TDecimals extends number = number,\n>(\n    value: unknown,\n    signedness?: TSignedness,\n    totalBits?: TTotalBits,\n    decimals?: TDecimals,\n): asserts value is DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    const actual = describeShape(value);\n    const expected = {\n        kind: 'decimalFixedPoint',\n        scale: decimals,\n        scaleLabel: 'decimals',\n        signedness,\n        totalBits,\n    };\n    assertShapeMatches('assertIsDecimalFixedPoint', actual, expected);\n    assertRawIsBigint('decimalFixedPoint', value);\n    assertRawFitsInRange('decimalFixedPoint', actual.signedness as Signedness, actual.totalBits, value.raw);\n}\n\n/**\n * Type guard that refines an unknown value to a {@link DecimalFixedPoint}.\n *\n * Accepts the same partial-positional shape arguments as\n * {@link assertIsDecimalFixedPoint} and returns `true` if the assertion\n * would pass, `false` otherwise.\n *\n * @example\n * ```ts\n * if (isDecimalFixedPoint(value)) {\n *     value satisfies DecimalFixedPoint<Signedness, number, number>;\n * }\n * if (isDecimalFixedPoint(value, 'unsigned', 64, 6)) {\n *     value satisfies DecimalFixedPoint<'unsigned', 64, 6>;\n * }\n * ```\n *\n * @see {@link assertIsDecimalFixedPoint}\n * @see {@link DecimalFixedPoint}\n */\nexport function isDecimalFixedPoint<\n    TSignedness extends Signedness = Signedness,\n    TTotalBits extends number = number,\n    TDecimals extends number = number,\n>(\n    value: unknown,\n    signedness?: TSignedness,\n    totalBits?: TTotalBits,\n    decimals?: TDecimals,\n): value is DecimalFixedPoint<TSignedness, TTotalBits, TDecimals> {\n    try {\n        assertIsDecimalFixedPoint(value, signedness, totalBits, decimals);\n        return true;\n    } catch {\n        return false;\n    }\n}\n"]}