/** * @module Amount */ import * as Unit from "./unit"; export interface Amount { readonly value: number; readonly unit: Unit.Unit; readonly decimalCount: number; } export declare type Comparer = (left: Amount, right: Amount) => number; /** * Default comparer * @param left {Amount} The left-hand amount * @param right {Amount} The right-hand amount * @returns {number} Comparer value */ export declare const defaultComparer: Comparer; /** * Creates an amount that represents the an exact/absolute value in the specified * unit. For example if you create an exact amount of 2 degrees Fahrenheit that * will represent -16.6666667 degrees Celsius. * @param value {number} The numeric value of the amount. * @param unit {Unit} The unit of the amount. * @param decimalCount {number | undefined} The decimalCount of the amount. * @returns {Amount} The created amount. */ export declare function create(value: number, unit: Unit.Unit, decimalCount?: number | undefined): Amount; /** * Returns a string representation of an Amount. * @param amount {Amount} The amount. * @returns {string} String representation of the Amount. */ export declare function toString(amount: Amount): string; /** * Negation unary operator. * @param amount {Amount} The amount. */ export declare function neg(amount: Amount): Amount; /** * Determines if an Amount is of a quantity. * @param quantity {Quantity} Quantity to check for. * @param amount {Amount} The amount to check. */ export declare function isQuantity(quantity: T, amount: Amount): boolean; /** * Adds two amounts together. * The two amounts amounts must have the same quantity. * The resulting amount will be of the same quantity as the two amounts. * The resulting amount will have it's decimal count set from the * most granular amount. * @param left The left-hand amount. * @param right The right-hand * @returns left + right */ export declare function plus(left: Amount, right: Amount): Amount; /** * Substracts two amounts from each other. * The two amounts amounts must have the same quantity. * The resulting amount will be of the same quantity as the two amounts. * The resulting amount will have it's decimal count set from the * most granular amount. * @param left The left-hand amount. * @param right The right-hand * @returns left + right */ export declare function minus(left: Amount, right: Amount): Amount; /** * Multiplies an amount with a number. * The resulting amount has the same unit and decimal count as the original amount. * @param left The amount to multiply * @param right The number to multiply with */ export declare function times(left: Amount, right: number | Amount): Amount; /** * Divides an amount with a number. * The resulting amount has the same unit and decimal count as the original amount. * @param left The amount to divide * @param right The number to divide by */ export declare function divide(left: Amount, right: number | Amount): Amount; /** * Compares to amounts for equality * @param left {Amount} The left-hand Amount. * @param right {Amount} The right-hand Amount. * @returns {boolean} True if the amounts are equal, false otherwise. */ export declare function equals(left: Amount, right: Amount, comparer?: Comparer): boolean; /** * Checks if one Amount is less than another. * @param left {Amount} The left-hand Amount. * @param right {Amount} The right-hand Amount. * @returns {boolean} True if the left-hand is less than the right-hand, false otherwise. */ export declare function lessThan(left: Amount, right: Amount, comparer?: Comparer): boolean; /** * Checks if one Amount is greater than another. * @param left {Amount} The left-hand Amount. * @param right {Amount} The right-hand Amount. * @returns {boolean} True if the left-hand is less than the right-hand, false otherwise. */ export declare function greaterThan(left: Amount, right: Amount, comparer?: Comparer): boolean; export declare const lessOrEqualTo: (left: Amount, right: Amount, comparer?: Comparer) => boolean; export declare const greaterOrEqualTo: (left: Amount, right: Amount, comparer?: Comparer) => boolean; export declare function clamp(minAmount: Amount, maxAmount: Amount, amount: Amount, comparer?: Comparer): Amount; export declare function max(a1: Amount, a2: Amount, comparer?: Comparer): Amount; export declare function min(a1: Amount, a2: Amount, comparer?: Comparer): Amount; /** * @param step Rounding step, for example 5.0 Celsius will round 23 to 20. * @param amount Amount to round. */ export declare function roundDown(step: Amount, amount: Amount): Amount; /** * @param step Rounding step, for example 5.0 Celsius will round 23 to 25. * @param amount Amount to round. */ export declare function roundUp(step: Amount, amount: Amount): Amount; export declare function compareTo(left: Amount, right: Amount, comparer?: Comparer): number; /** * Gets the absolute amount (equivalent of Math.Abs()) * @param amount The amount to get the aboslute amount from. */ export declare function abs(amount: Amount): Amount; /** * Gets the value of the amount as a number in the specified unit * @param toUnit The unit to get the amount in. * @param amount The amount to get the value from. */ export declare function valueAs(toUnit: Unit.Unit, amount: Amount): number; /** * Gets the most granular unit * For example Millimeter is more granular than Meter so in that case * both units should be converted to millimeter before being compared and * we should use the decimal count of the amount which was specified in Millimeter * To find which is the most granular unit, we find the difference between 1 and 2 * in the units. The one with the highest difference is the most granular. * @param leftUnit * @param rightUnit * @returns The most granular unit. * @private */ export declare function getMostGranularUnit(leftUnit: Unit.Unit, rightUnit: Unit.Unit): Unit.Unit;