@barchart/common-js
Version:
Library of common JavaScript utilities
397 lines (396 loc) • 11.3 kB
TypeScript
/**
* An immutable object that allows for arbitrary-precision calculations.
*
* @public
*/
export default class Decimal {
/**
* Clones a {@link Decimal} instance.
*
* @public
* @static
* @param {Decimal} value
* @returns {Decimal}
*/
public static clone(value: Decimal): Decimal;
/**
* An alias for the constructor. Creates a new instance. Suitable for
* use with the value emitted by {@link Decimal#toJSON}.
*
* @public
* @static
* @param {Decimal|number|string} value
* @returns {Decimal}
*/
public static parse(value: Decimal | number | string): Decimal;
/**
* Returns an instance with the value of zero.
*
* @public
* @static
* @returns {Decimal}
*/
public static get ZERO(): Decimal;
/**
* Returns an instance with the value of one.
*
* @public
* @static
* @returns {Decimal}
*/
public static get ONE(): Decimal;
/**
* Returns an instance with the value of one.
*
* @public
* @static
* @returns {Decimal}
*/
public static get NEGATIVE_ONE(): Decimal;
/**
* Returns the {@link RoundingMode} enumeration type.
*
* @public
* @static
* @returns {typeof RoundingMode}
*/
public static get ROUNDING_MODE(): typeof RoundingMode;
/**
* Runs {@link Decimal#getIsZero} and returns the result.
*
* @public
* @static
* @param {Decimal} instance
* @returns {boolean}
*/
public static getIsZero(instance: Decimal): boolean;
/**
* Runs {@link Decimal#getIsZero} and returns the inverse.
*
* @public
* @static
* @param {Decimal} instance
* @returns {boolean}
*/
public static getIsNotZero(instance: Decimal): boolean;
/**
* Runs {@link Decimal#getIsPositive} and returns the result.
*
* @public
* @static
* @param {Decimal} instance
* @returns {boolean}
*/
public static getIsPositive(instance: Decimal): boolean;
/**
* Checks an instance to see if its negative or zero.
*
* @public
* @static
* @param {Decimal} instance
* @returns {boolean}
*/
public static getIsNotPositive(instance: Decimal): boolean;
/**
* Runs {@link Decimal#getIsNegative} and returns the result.
*
* @public
* @static
* @param {Decimal} instance
* @returns {boolean}
*/
public static getIsNegative(instance: Decimal): boolean;
/**
* Checks an instance to see if its positive or zero.
*
* @public
* @static
* @param {Decimal} instance
* @returns {boolean}
*/
public static getIsNotNegative(instance: Decimal): boolean;
/**
* A comparator function for {@link Decimal} instances.
*
* @public
* @static
* @param {Decimal} a
* @param {Decimal} b
* @returns {number}
*/
public static compareDecimals(a: Decimal, b: Decimal): number;
static "__#private@#getBig"(value: any): any;
/**
* @param {Decimal|number|string} value - The value.
*/
constructor(value: Decimal | number | string);
/**
* Returns a new {@link Decimal} instance that is the sum of the
* current instance's value and the value supplied.
*
* @public
* @param {Decimal|number|string} other - The value to add.
* @returns {Decimal}
*/
public add(other: Decimal | number | string): Decimal;
/**
* Returns a new {@link Decimal} instance with a value that results
* from the subtraction of the value supplied from the current instance's
* value.
*
* @public
* @param {Decimal|number|string} other - The value to subtract.
* @returns {Decimal}
*/
public subtract(other: Decimal | number | string): Decimal;
/**
* Returns a new {@link Decimal} instance that is the product of the
* current instance's value and the value supplied.
*
* @public
* @param {Decimal|number|string} other - The value to multiply the current instance by.
* @returns {Decimal}
*/
public multiply(other: Decimal | number | string): Decimal;
/**
* Returns a new {@link Decimal} instance with a value that results
* from the division of the current instance's value by the value
* supplied.
*
* @public
* @param {Decimal|number|string} other - The value to divide the current instance by.
* @returns {Decimal}
*/
public divide(other: Decimal | number | string): Decimal;
/**
* Returns a new {@link Decimal} instance with a value that results
* from raising the current instance to the power of the exponent
* provided.
*
* @public
* @param {number} exponent
* @returns {Decimal}
*/
public raise(exponent: number): Decimal;
/**
* Returns a new {@link Decimal} with a value resulting from a rounding
* operation on the current value.
*
* @public
* @param {number} places - The number of decimal places to retain.
* @param {RoundingMode=} mode - The strategy to use for rounding.
* @returns {Decimal}
*/
public round(places: number, mode?: RoundingMode | undefined): Decimal;
/**
* Returns a new {@link Decimal} instance with of the remainder when
* dividing the current instance by the value supplied.
*
* @public
* @param {Decimal|number|string} other
* @returns {Decimal}
*/
public mod(other: Decimal | number | string): Decimal;
/**
* Returns a new {@link Decimal} instance having the absolute value of
* the current instance's value.
*
* @public
* @returns {Decimal}
*/
public absolute(): Decimal;
/**
* Returns a new {@link Decimal} instance the opposite sign as the
* current instance's value.
*
* @public
* @returns {Decimal}
*/
public opposite(): Decimal;
/**
* Returns a boolean value, indicating if the current instance's value is
* equal to zero (or approximately equal to zero).
*
* @public
* @param {boolean=} approximate
* @param {number=} places
* @returns {boolean}
*/
public getIsZero(approximate?: boolean | undefined, places?: number | undefined): boolean;
/**
* Returns true if the current instance is positive; otherwise false.
*
* @public
* @returns {boolean}
*/
public getIsPositive(): boolean;
/**
* Returns true if the current instance is negative; otherwise false.
*
* @public
* @returns {boolean}
*/
public getIsNegative(): boolean;
/**
* Returns true if the current instance is greater than the value.
*
* @public
* @param {Decimal|number|string} other - The value to compare.
* @returns {boolean}
*/
public getIsGreaterThan(other: Decimal | number | string): boolean;
/**
* Returns true if the current instance is greater than or equal to the value.
*
* @public
* @param {Decimal|number|string} other - The value to compare.
* @returns {boolean}
*/
public getIsGreaterThanOrEqual(other: Decimal | number | string): boolean;
/**
* Returns true if the current instance is less than the value.
*
* @public
* @param {Decimal|number|string} other - The value to compare.
* @returns {boolean}
*/
public getIsLessThan(other: Decimal | number | string): boolean;
/**
* Returns true if the current instance is less than or equal to the value.
*
* @public
* @param {Decimal|number|string} other - The value to compare.
* @returns {boolean}
*/
public getIsLessThanOrEqual(other: Decimal | number | string): boolean;
/**
* Returns true if the current instance between two other values. The
* test is inclusive, by default.
*
* @public
* @param {Decimal|number|string} minimum - The minimum value.
* @param {Decimal|number|string} maximum - The maximum value.
* @param {boolean=} exclusive - If true, the value cannot equal the minimum or maximum value and still be considered "between" the other values.
* @returns {boolean}
*/
public getIsBetween(minimum: Decimal | number | string, maximum: Decimal | number | string, exclusive?: boolean | undefined): boolean;
/**
* Returns true if the current instance is equal to the value.
*
* @public
* @param {Decimal|number|string} other - The value to compare.
* @returns {boolean}
*/
public getIsEqual(other: Decimal | number | string): boolean;
/**
* Returns true is close to another value.
*
* @public
* @param {Decimal|number|string} other - The value to compare.
* @param {number} places - The significant digits.
* @returns {boolean}
*/
public getIsApproximate(other: Decimal | number | string, places: number): boolean;
/**
* Returns true if the current instance is an integer (i.e. has no decimal
* component).
*
* @public
* @return {boolean}
*/
public getIsInteger(): boolean;
/**
* Returns the number of decimal places used.
*
* @public
* @returns {number}
*/
public getDecimalPlaces(): number;
/**
* Emits a floating point value that approximates the value of the current
* instance.
*
* @public
* @param {number=} places
* @returns {number}
*/
public toFloat(places?: number | undefined): number;
/**
* Returns a string-based representation of the instance's value.
*
* @public
* @returns {string}
*/
public toFixed(): string;
/**
* Returns a {@link number} that is approximately equal to the value of
* this {@link Decimal} instance.
*
* @public
* @returns {number}
*/
public toNumber(): number;
/**
* Returns the JSON representation.
*
* @public
* @returns {string}
*/
public toJSON(): string;
/**
* Returns a string representation.
*
* @public
* @returns {string}
*/
public toString(): string;
#private;
}
/**
* An enumeration of strategies for rounding a {@link Decimal} instance.
*
* @public
* @inner
* @extends {Enum}
*/
declare class RoundingMode extends Enum {
/**
* Rounds away from zero.
*
* @public
* @static
* @returns {RoundingMode}
*/
public static get UP(): RoundingMode;
/**
* Rounds towards zero.
*
* @public
* @static
* @returns {RoundingMode}
*/
public static get DOWN(): RoundingMode;
/**
* Rounds towards nearest neighbor. If equidistant, rounds away from zero.
*
* @public
* @static
* @returns {RoundingMode}
*/
public static get NORMAL(): RoundingMode;
/**
* @param {number} value
* @param {string} description
*/
constructor(value: number, description: string);
/**
* The code used by the Big.js library.
*
* @ignore
* @returns {number}
*/
get value(): number;
#private;
}
import Enum from './Enum.js';
export {};