Interface NumberOps<T>

Basic operations for a number type. All polynomial operations are constructed based on these.

We provide implementations for:

interface NumberOps<T> {
    one: T;
    zero: T;
    add(a, b): T;
    cbrt(a): T;
    div(a, b): T;
    divT(a, b): T;
    equals(a, b): boolean;
    format(c, i): string;
    gt(a, b): boolean;
    gte(a, b): boolean;
    lt(a, b): boolean;
    lte(a, b): boolean;
    mul(a, b): T;
    mulT(a, b): T;
    pow(a, b): T;
    powT(a, b): T;
    sqrt(a): T;
    sub(a, b): T;
    toNumber(a): number;
}

Type Parameters

  • T

Properties

one: T

The number one.

For NumberOps<number>, this is 1. For NumberOps<Decimal>, it's new Decimal(1)

zero: T

The number zero.

For NumberOps<number>, this is 0. For NumberOps<Decimal>, it's new Decimal(0)

Methods

  • Add two numbers.

    For NumberOps<number>, this is +.

    Parameters

    Returns T

  • Cube-root of a number.

    For NumberOps<number>, this is Math.cbrt.

    Equivalent to Math.pow(value, 1/3), but every number api has this, so we should too...?

    Parameters

    Returns T

  • Divide a number by a Javascript builtin number.

    For NumberOps<number>, this is /.

    Parameters

    • a: T
    • b: number

    Returns T

  • Divide a number by another number of this format.

    For NumberOps<number>, this is /, equivalent to div. The distinction is useful for NumberOps<Decimal> and other formats.

    Parameters

    Returns T

  • Are two numbers equal?

    For NumberOps<number>, this is ===.

    Parameters

    Returns boolean

  • Format a coefficient number.

    For NumberOps<number>, this is .toString().

    Parameters

    • c: T
    • i: number

    Returns string

  • Multiply a number by a Javascript builtin number.

    For NumberOps<number>, this is *.

    Parameters

    • a: T
    • b: number

    Returns T

  • Multiply a number by another number of this format.

    For NumberOps<number>, this is *, equivalent to mul. The distinction is useful for NumberOps<Decimal> and other formats.

    Parameters

    Returns T

  • Raise a number to a power.

    For NumberOps<number>, this is Math.pow.

    Parameters

    • a: T
    • b: number

    Returns T

  • Raise a number to a power.

    For NumberOps<number>, this is Math.pow, equivalent to pow. The distinction is useful for NumberOps<Decimal> and other formats.

    Parameters

    Returns T

  • Square-root of a number.

    For NumberOps<number>, this is Math.sqrt.

    Equivalent to Math.pow(value, 0.5), but every number api has this, so we should too...?

    Parameters

    Returns T

  • Add two numbers.

    For NumberOps<number>, this is -.

    Parameters

    Returns T

  • Convert to a native Javascript number, best-effort.

    Might return infinity or NaN if the original number isn't in range.

    Parameters

    Returns number

Generated using TypeDoc