import { TokenInstance } from './Token'; export default class Quantity { #private; /** * Parse or load * @param base Quantity in integer/non-denominated format or string * @param denomination Denomination that belongs to the token */ constructor(base?: bigint | string | number | Quantity, denomination?: bigint); /** * Raw base quantity */ get raw(): bigint; /** * Integer/whole part */ get integer(): bigint; /** * Fractional part in integers */ get fractional(): bigint; /** * Denomination */ get denomination(): bigint; /** * Check if a value is a valid quantity * @param val Value to check * @returns Valid or not */ static isQuantity(val: unknown): val is Quantity; /** * Check if a value is a quantity of a token process * (this only works if the token info has been loaded) * @param val Value to check * @param token Token process instance * @returns Valid or not */ static isQuantityOf(val: Quantity, token: TokenInstance): boolean; /** * Load a quantity from a string while keeping precision * until the denomination is reached * @param value String to load as a quantity */ fromString(value: string): this; /** * Load a quantity from a number while keeping precision * until the denomination is reached * @param value Number to load as a quantity */ fromNumber(value: number): this; /** * Format a quantity as a floating point number string, * while keeping precision (using the provided * denomination) * @param options Optinal formatting for the number * @returns Formatted string */ toLocaleString(locales?: Intl.LocalesArgument, options?: BigIntToLocaleStringOptions): string; /** * Format a quantity as a floating point number string, * while keeping precision (using the provided * denomination) */ toString(): string; /** * Format a quantity as a JavaScript floating point number. * This while cause precision loss */ toNumber(): number; /** * Clone Quantity instance */ clone(): Quantity; /** * Shortcut/set to to one (in-place) */ _one(): this; /** * Shortcut/set to one */ static __one(denomination?: bigint): Quantity; /** * Convert the quantity (in-place) to use a different * denomination * @param newDenomination Denomination to convert to */ _convert(newDenomination: bigint): this; /** * Create a new instance with the same quantity, but a * different denomination. This will cause precision * loss if the new denomination is smaller than the * original * @param quantity Quantity to convert * @param newDenomination Denomination to convert to * @returns New instance */ static __convert(instance: Quantity, newDenomination: bigint): Quantity; /** * Operators */ /** * Bring two quantities to the same denomination * (will always bring to the larger one) * @param ... Quantities * @returns The quantitieson the same denomination */ static sameDenomination(...quantities: Quantity[]): Quantity[]; /** * Check if quantities are equal * @param x First quantity * @param y Second quantity * @returns x == y */ static eq(x: Quantity, y: Quantity): boolean; /** * Check if x is less than y * @param x First quantity * @param y Second quantity * @returns x < y */ static lt(x: Quantity, y: Quantity): boolean; /** * Check if x is less or equal than y * @param x First quantity * @param y Second quantity * @returns x <= y */ static le(x: Quantity, y: Quantity): boolean; /** * Add together two quantities * @param x First quantity * @param y Second quantity * @returns Result of the addition (with the larger denomination) */ static __add(x: Quantity, y: Quantity): Quantity; /** * Add together two quantities (in-place). This might cause * precision loss if y has a larger denomination * @param y Second quantity */ _add(y: Quantity): void; /** * Subtract one quantity from another * @param x Quantity to subtract from * @param y Quantity to subtract * @returns Result of the addition (with the larger denomination) */ static __sub(x: Quantity, y: Quantity): Quantity; /** * Subtract one quantity from another (in-place). This might cause * precision loss if y has a larger denomination * @param y Quantity to subtract */ _sub(y: Quantity): void; /** * Multiply one quantity by another * @param x First quantity * @param y Second quantity * @returns Result of the multiplication (with the larger denomination) */ static __mul(x: Quantity, y: Quantity): Quantity; /** * Multiply one quantity by another (in-place). This might cause * precision loss if y has a larger denomination * @param y Quantity to multiply by */ _mul(y: Quantity): void; /** * Divide one quantity by another (can cause precision loss) * @param x Quantity to divide * @param y Quantity to divide with * @returns Result of the addition (with the larger denomination) */ static __div(x: Quantity, y: Quantity): Quantity; /** * Divide one quantity by another (in-place). This might cause * precision loss if y has a larger denomination * @param y Quantity to divide with */ _div(y: Quantity): void; /** * Raise one quantity to the power of an integer. This can cause precision loss * @param x Quantity to raise * @param y Exponent * @returns Result of the power operation */ static __pow(x: Quantity, y: number): Quantity; /** * Raise one quantity to the power of an integer (in-place). This can cause * precision loss * @param y Exponent */ _pow(y: number): void; /** * Get the remainder left when x is divided by y * @param x Quantity to divide * @param y Quantity to divide with * @returns The remaineder left after the operation */ static __mod(x: Quantity, y: Quantity): Quantity; /** * Get the remainder left when divided by y (in-place) * @param y Quantity to divide with */ _mod(y: Quantity): void; /** * Other Math functions */ /** * Get the minimum of a list of quantities * @param ... Quantities to choose from * @returns Minimum quantity instance of the list */ static min(...quantities: Quantity[]): Quantity | undefined; /** * Get the maximum of a list of quantities * @param ... Quantities to choose from * @returns Maximum quantity instance of the list */ static max(...quantities: Quantity[]): Quantity | undefined; /** * Truncate a quantity * @param x Quantity to truncate * @returns Whole number (truncated) */ static __trunc(x: Quantity): Quantity; /** * Truncate a quantity (in-place) */ _trunc(): void; /** * Rounds down * @param x Quantity to round down * @returns Rounded down instance */ static __floor(x: Quantity): Quantity; /** * Rounds down (in-place) */ _floor(): void; /** * Rounds up * @param x Quantity to round up * @returns Rounded up instance */ static __ceil(x: Quantity): Quantity; /** * Rounds up (in-place) */ _ceil(): void; /** * Negate a quantity * @param x Quantity to negate * @returns Negated instance */ static __neg(x: Quantity): Quantity; /** * Negate a quantity (in-place) */ _neg(): void; /** * Get the absolute value of a quantity * @param x Quantity to get the absolute value of * @returns Absolute value */ static __abs(x: Quantity): Quantity; /** * Get the absolute value of a quantity (in-place) */ _abs(): void; }