/** * Basic operations for a number type. All polynomial operations are constructed based on these. * * We provide implementations for: * - javascript's built-in `number`, of course * - {@link https://mikemcl.github.io/decimal.js | Decimal.js} * - Any Decimal.js-compatible number, such as {@link https://patashu.github.io/break_infinity.js/index.html break_infinity.js} */ export interface NumberOps { /** * The number zero. * * For `NumberOps`, this is `0`. For `NumberOps`, it's `new Decimal(0)` */ readonly zero: T; /** * The number one. * * For `NumberOps`, this is `1`. For `NumberOps`, it's `new Decimal(1)` */ readonly one: T; /** * Are two numbers equal? * * For `NumberOps`, this is `===`. */ equals(a: T, b: T): boolean; /** * `a < b` */ lt(a: T, b: T): boolean; /** * `a > b` */ gt(a: T, b: T): boolean; /** * `a <= b` */ lte(a: T, b: T): boolean; /** * `a <= b` */ gte(a: T, b: T): boolean; /** * Add two numbers. * * For `NumberOps`, this is `+`. */ add(a: T, b: T): T; /** * Add two numbers. * * For `NumberOps`, this is `-`. */ sub(a: T, b: T): T; /** * Multiply a number by a Javascript builtin `number`. * * For `NumberOps`, this is `*`. */ mul(a: T, b: number): T; /** * Multiply a number by another number of this format. * * For `NumberOps`, this is `*`, equivalent to {@link mul}. The distinction is useful for `NumberOps` and other formats. */ mulT(a: T, b: T): T; /** * Divide a number by a Javascript builtin `number`. * * For `NumberOps`, this is `/`. */ div(a: T, b: number): T; /** * Divide a number by another number of this format. * * For `NumberOps`, this is `/`, equivalent to {@link div}. The distinction is useful for `NumberOps` and other formats. */ divT(a: T, b: T): T; /** * Raise a number to a power. * * For `NumberOps`, this is `Math.pow`. */ pow(a: T, b: number): T; /** * Raise a number to a power. * * For `NumberOps`, this is `Math.pow`, equivalent to {@link pow}. The distinction is useful for `NumberOps` and other formats. */ powT(a: T, b: T): T; /** * Square-root of a number. * * For `NumberOps`, this is `Math.sqrt`. * * Equivalent to `Math.pow(value, 0.5)`, but every number api has this, so we should too...? */ sqrt(a: T): T; /** * Cube-root of a number. * * For `NumberOps`, this is `Math.cbrt`. * * Equivalent to `Math.pow(value, 1/3)`, but every number api has this, so we should too...? */ cbrt(a: T): T; /** * Convert to a native Javascript number, best-effort. * * Might return infinity or NaN if the original number isn't in range. */ toNumber(a: T): number; /** * Format a coefficient number. * * For `NumberOps`, this is `.toString()`. */ format(c: T, i: number): string; } /** * Basic operations for Javascript's built-in number type. */ export declare const nativeNumberOps: NumberOps; /** * A {@link https://mikemcl.github.io/decimal.js/ | Decimal.js-compatible number}. * This matches Decimal.js's interface, without adding an explcit Decimal.js dependency. * * Tested with Decimal.js itself, and {@link https://patashu.github.io/break_infinity.js/index.html break_infinity.js}. * * @param T The number type. An implementation for the `Decimal` type would be typed as `IDecimal`. */ export interface IDecimal> { equals(this: T, a: number | T): boolean; lt(this: T, a: number | T): boolean; gt(this: T, a: number | T): boolean; lte(this: T, a: number | T): boolean; gte(this: T, a: number | T): boolean; lessThan(this: T, a: number | T): boolean; add(this: T, a: number | T): T; sub(this: T, a: number | T): T; mul(this: T, a: number | T): T; div(this: T, a: number | T): T; pow(this: T, a: number | T): T; sqrt(this: T): T; cbrt(this: T): T; abs(this: T): T; floor(this: T): T; toNumber(this: T): number; toPrecision(n: number): string; toString(): string; } /** * Basic operations for a {@link https://mikemcl.github.io/decimal.js/ | Decimal.js-compatible numbers}. Pass your number's constructor. * * decimalNumberOps(n => new Decimal(n)) */ export declare function decimalNumberOps>(ctor: (n: number) => T): NumberOps;