Aller au contenu principal

Numeric

Index

Interfaces

Add

Add<Left, Right, Output>:

Type parameters

  • Left
  • Right = Left
  • Output = Left

+

  • +(left: Left, right: Right): Output
  • Addition operator

    @example
    type T = ...;
    const TNumeric: Numeric.Add<T> = ...;
    const result = TNumeric['+'](left, right);// represents (left + right)

CheckedAdd

CheckedAdd<Left, Right, Output>:

Type parameters

  • Left
  • Right = Left
  • Output = Left

+?

  • +?(left: Left, right: Right): Option<Output>
  • Addition operator that returns None instead of wrapping around on overflow.

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedAdd<T> = ...;
    const result = TNumeric['+?'](left, right);// represents (left + right)

CheckedDivide

CheckedDivide<Base, Divider, Output>:

Type parameters

  • Base
  • Divider = Base
  • Output = Base

/?

  • /?(left: Base, right: Divider): Option<Output>
  • Division operator

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedDivide<T> = ...;
    const result = Numeric['/?'](left, right);// represents (left / right)

CheckedMultiply

CheckedMultiply<Base, Multiplier, Output>:

Type parameters

  • Base
  • Multiplier = Base
  • Output = Base

*?

  • *?(base: Base, multiplier: Multiplier): Option<Output>
  • Multiplication operator that returns None instead of wrapping around on overflow.

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedMultiply<T> = ...;
    const result = Numeric['*?'](left, right);// represents (left * right)

CheckedPower

CheckedPower<Left, Right, Output>:

Type parameters

  • Left
  • Right = Left
  • Output = Left

**?

  • **?(left: Left, right: Right): Option<Output>
  • Power operator that returns None instead of wrapping around on overflow.

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedPower<T> = ...;
    const result = TNumeric['**?'](left, right);// represents (left ** right)

CheckedRemainder

CheckedRemainder<Base, Divider, Output>:

Type parameters

  • Base
  • Divider = Base
  • Output = Base

%?

  • %?(left: Base, right: Divider): Option<Output>
  • Remainder operator

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedRemainder<T> = ...;
    const result = Numeric['%?'](left, right);// represents (left % right)

CheckedSubtract

CheckedSubtract<Left, Right, Output>:

Type parameters

  • Left
  • Right = Left
  • Output = Left

-?

  • -?(left: Left, right: Right): Option<Output>
  • Subtraction operator that returns None instead of wrapping around on overflow.

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedSubtract<T> = ...;
    const result = TNumeric['-?'](left, right);// represents (left - right)

Divide

Divide<Base, Divider, Output>:

Type parameters

  • Base
  • Divider = Base
  • Output = Base

/

  • /(base: Base, divider: Divider): Output
  • Division operator

    @example
    type T = ...;
    const TNumeric: Numeric.Divide<T> = ...;
    const result = Numeric['/'](left, right);// represents (left / right)

Integral

Integral<T>:

Integral type


Type parameters

  • T

constructor

constructor:

%

  • %(left: T, right: T): T
  • Remainder operator

    @example
    type T = ...;
    const TNumeric: Numeric.Remainder<T> = ...;
    const result = Numeric['%'](left, right);// represents (left % right)

*

  • *(left: T, right: T): T
  • Multiplication operator

    @example
    type T = ...;
    const TNumeric: Numeric.Multiply<T> = ...;
    const result = Numeric['*'](left, right);// represents (left * right)

+

  • +(left: T, right: T): T
  • Addition operator

    @example
    type T = ...;
    const TNumeric: Numeric.Add<T> = ...;
    const result = TNumeric['+'](left, right);// represents (left + right)

-

  • -(left: T, right: T): T
  • Subtraction operator

    @example
    type T = ...;
    const TNumeric: Numeric.Subtract<T> = ...;
    const result = Numeric['-'](left, right);// represents (left - right)

/

  • /(base: T, divider: T): T
  • Division operator

    @example
    type T = ...;
    const TNumeric: Numeric.Divide<T> = ...;
    const result = Numeric['/'](left, right);// represents (left / right)

/%

  • /%(this: void, base: T, divider: T): [quot: T, mod: T]
  • Quotient/Modulo operator

    @example
    type T = ...;
    const TNumeric: Numeric.Integral<T> = ...;
    const result = Numeric['/%'](left, right);// represents [ left / right, left % right ]

abs

  • abs(this: void, value: T): T
  • Absolute value. It should satisfy Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == x

    @example
    type T = ...;
    const TSigned: Numeric.Signed<T> = ...;
    const result = TSigned.abs(value);// absolute value of (value)

asInt

  • asInt(this: void, self: T): Int
  • Converts the given value to a Int.

    @example
    const SomeType: AsInt<T>;
    const value: T;
    SomeType.asInt(value); // Int(...)

fromInt

  • fromInt(this: void, value: Int): T

isNegative

  • isNegative(this: void, self: T): boolean
  • Returns true if the number is negative and false if the number is zero or positive.

    @example
    Number.isPositive(-1);// true
    Number.isPositive(0);// false
    Number.isPositive(1);// false

isOne

  • isOne(this: void, self: T): boolean
  • Returns true if self is equal to the multiplicative identity.

    @example
    Number.isOne(1); // true
    Number.isOne(0); // false

isPositive

  • isPositive(this: void, self: T): boolean
  • Returns true if the number is positive and false if the number is zero or negative.

    @example
    Number.isPositive(-1);// false
    Number.isPositive(0);// false
    Number.isPositive(1);// true

isZero

  • isZero(this: void, self: T): boolean
  • Returns true if self is equal to the additive identity.

    @example
    Number.isZero(0); // true
    Number.isZero(1); // false

negate

  • negate(this: void, self: T): T
  • Negates the given value.

    @example
    Number.negate(5); // -5
    Number.negate(Number.negate(5)); // 5

one

  • one(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.one(); // 1

sign

  • sign(this: void, value: T): T
  • Sign of a number. It should satisfy TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == x

    @example
    Number.sign(-2.5);// -1
    Number.sign(0);// 0
    Number.sign(2.5);// 1

zero

  • zero(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.zero(); // 0

IntegralParameters

IntegralParameters<T>:

Type parameters

  • T

compare

compare: (left: T, right: T) => Ordering

%

  • %(left: T, right: T): T
  • Remainder operator

    @example
    type T = ...;
    const TNumeric: Numeric.Remainder<T> = ...;
    const result = Numeric['%'](left, right);// represents (left % right)

*

  • *(left: T, right: T): T
  • Multiplication operator

    @example
    type T = ...;
    const TNumeric: Numeric.Multiply<T> = ...;
    const result = Numeric['*'](left, right);// represents (left * right)

+

  • +(left: T, right: T): T
  • Addition operator

    @example
    type T = ...;
    const TNumeric: Numeric.Add<T> = ...;
    const result = TNumeric['+'](left, right);// represents (left + right)

optional-

  • -(left: T, right: T): T
  • Subtraction operator

    @example
    type T = ...;
    const TNumeric: Numeric.Subtract<T> = ...;
    const result = Numeric['-'](left, right);// represents (left - right)

/

  • /(base: T, divider: T): T
  • Division operator

    @example
    type T = ...;
    const TNumeric: Numeric.Divide<T> = ...;
    const result = Numeric['/'](left, right);// represents (left / right)

optionalabs

  • abs(this: void, value: T): T
  • Absolute value. It should satisfy Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == x

    @example
    type T = ...;
    const TSigned: Numeric.Signed<T> = ...;
    const result = TSigned.abs(value);// absolute value of (value)

asInt

  • asInt(this: void, self: T): Int
  • Converts the given value to a Int.

    @example
    const SomeType: AsInt<T>;
    const value: T;
    SomeType.asInt(value); // Int(...)

fromInt

  • fromInt(this: void, value: Int): T

optionalisNegative

  • isNegative(this: void, self: T): boolean
  • Returns true if the number is negative and false if the number is zero or positive.

    @example
    Number.isPositive(-1);// true
    Number.isPositive(0);// false
    Number.isPositive(1);// false

optionalisOne

  • isOne(this: void, self: T): boolean
  • Returns true if self is equal to the multiplicative identity.

    @example
    Number.isOne(1); // true
    Number.isOne(0); // false

optionalisPositive

  • isPositive(this: void, self: T): boolean
  • Returns true if the number is positive and false if the number is zero or negative.

    @example
    Number.isPositive(-1);// false
    Number.isPositive(0);// false
    Number.isPositive(1);// true

optionalisZero

  • isZero(this: void, self: T): boolean
  • Returns true if self is equal to the additive identity.

    @example
    Number.isZero(0); // true
    Number.isZero(1); // false

optionalnegate

  • negate(this: void, self: T): T
  • Negates the given value.

    @example
    Number.negate(5); // -5
    Number.negate(Number.negate(5)); // 5

optionalone

  • one(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.one(); // 1

optionalsign

  • sign(this: void, value: T): T
  • Sign of a number. It should satisfy TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == x

    @example
    Number.sign(-2.5);// -1
    Number.sign(0);// 0
    Number.sign(2.5);// 1

optionalzero

  • zero(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.zero(); // 0

Multiply

Multiply<Left, Right, Output>:

Type parameters

  • Left
  • Right = Left
  • Output = Left

*

  • *(left: Left, right: Right): Output
  • Multiplication operator

    @example
    type T = ...;
    const TNumeric: Numeric.Multiply<T> = ...;
    const result = Numeric['*'](left, right);// represents (left * right)

Negate

Negate<Self, Output>:

Type parameters

  • Self
  • Output = Self

negate

  • negate(this: void, self: Self): Output
  • Negates the given value.

    @example
    Number.negate(5); // -5
    Number.negate(Number.negate(5)); // 5

Numeric

Numeric<T>:

Type parameters

  • T

constructor

constructor:

*

  • *(left: T, right: T): T
  • Multiplication operator

    @example
    type T = ...;
    const TNumeric: Numeric.Multiply<T> = ...;
    const result = Numeric['*'](left, right);// represents (left * right)

+

  • +(left: T, right: T): T
  • Addition operator

    @example
    type T = ...;
    const TNumeric: Numeric.Add<T> = ...;
    const result = TNumeric['+'](left, right);// represents (left + right)

-

  • -(left: T, right: T): T
  • Subtraction operator

    @example
    type T = ...;
    const TNumeric: Numeric.Subtract<T> = ...;
    const result = Numeric['-'](left, right);// represents (left - right)

abs

  • abs(this: void, value: T): T
  • Absolute value. It should satisfy Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == x

    @example
    type T = ...;
    const TSigned: Numeric.Signed<T> = ...;
    const result = TSigned.abs(value);// absolute value of (value)

asInt

  • asInt(this: void, self: T): Int
  • Converts the given value to a Int.

    @example
    const SomeType: AsInt<T>;
    const value: T;
    SomeType.asInt(value); // Int(...)

fromInt

  • fromInt(this: void, value: Int): T

isNegative

  • isNegative(this: void, self: T): boolean
  • Returns true if the number is negative and false if the number is zero or positive.

    @example
    Number.isPositive(-1);// true
    Number.isPositive(0);// false
    Number.isPositive(1);// false

isOne

  • isOne(this: void, self: T): boolean
  • Returns true if self is equal to the multiplicative identity.

    @example
    Number.isOne(1); // true
    Number.isOne(0); // false

isPositive

  • isPositive(this: void, self: T): boolean
  • Returns true if the number is positive and false if the number is zero or negative.

    @example
    Number.isPositive(-1);// false
    Number.isPositive(0);// false
    Number.isPositive(1);// true

isZero

  • isZero(this: void, self: T): boolean
  • Returns true if self is equal to the additive identity.

    @example
    Number.isZero(0); // true
    Number.isZero(1); // false

negate

  • negate(this: void, self: T): T
  • Negates the given value.

    @example
    Number.negate(5); // -5
    Number.negate(Number.negate(5)); // 5

one

  • one(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.one(); // 1

sign

  • sign(this: void, value: T): T
  • Sign of a number. It should satisfy TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == x

    @example
    Number.sign(-2.5);// -1
    Number.sign(0);// 0
    Number.sign(2.5);// 1

zero

  • zero(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.zero(); // 0

NumericParameters

NumericParameters<T>:

Type parameters

  • T

compare

compare: (left: T, right: T) => Ordering

*

  • *(left: T, right: T): T
  • Multiplication operator

    @example
    type T = ...;
    const TNumeric: Numeric.Multiply<T> = ...;
    const result = Numeric['*'](left, right);// represents (left * right)

+

  • +(left: T, right: T): T
  • Addition operator

    @example
    type T = ...;
    const TNumeric: Numeric.Add<T> = ...;
    const result = TNumeric['+'](left, right);// represents (left + right)

optional-

  • -(left: T, right: T): T
  • Subtraction operator

    @example
    type T = ...;
    const TNumeric: Numeric.Subtract<T> = ...;
    const result = Numeric['-'](left, right);// represents (left - right)

optionalabs

  • abs(this: void, value: T): T
  • Absolute value. It should satisfy Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == x

    @example
    type T = ...;
    const TSigned: Numeric.Signed<T> = ...;
    const result = TSigned.abs(value);// absolute value of (value)

asInt

  • asInt(this: void, self: T): Int
  • Converts the given value to a Int.

    @example
    const SomeType: AsInt<T>;
    const value: T;
    SomeType.asInt(value); // Int(...)

fromInt

  • fromInt(this: void, value: Int): T

optionalisNegative

  • isNegative(this: void, self: T): boolean
  • Returns true if the number is negative and false if the number is zero or positive.

    @example
    Number.isPositive(-1);// true
    Number.isPositive(0);// false
    Number.isPositive(1);// false

optionalisOne

  • isOne(this: void, self: T): boolean
  • Returns true if self is equal to the multiplicative identity.

    @example
    Number.isOne(1); // true
    Number.isOne(0); // false

optionalisPositive

  • isPositive(this: void, self: T): boolean
  • Returns true if the number is positive and false if the number is zero or negative.

    @example
    Number.isPositive(-1);// false
    Number.isPositive(0);// false
    Number.isPositive(1);// true

optionalisZero

  • isZero(this: void, self: T): boolean
  • Returns true if self is equal to the additive identity.

    @example
    Number.isZero(0); // true
    Number.isZero(1); // false

optionalnegate

  • negate(this: void, self: T): T
  • Negates the given value.

    @example
    Number.negate(5); // -5
    Number.negate(Number.negate(5)); // 5

optionalone

  • one(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.one(); // 1

optionalsign

  • sign(this: void, value: T): T
  • Sign of a number. It should satisfy TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == x

    @example
    Number.sign(-2.5);// -1
    Number.sign(0);// 0
    Number.sign(2.5);// 1

optionalzero

  • zero(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.zero(); // 0

One

One<T>:

Type parameters

  • T

isOne

  • isOne(this: void, self: T): boolean
  • Returns true if self is equal to the multiplicative identity.

    @example
    Number.isOne(1); // true
    Number.isOne(0); // false

one

  • one(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.one(); // 1

Power

Power<Left, Right, Output>:

Type parameters

  • Left
  • Right = Left
  • Output = Left

**

  • **(left: Left, right: Right): Output
  • Power operator

    @example
    type T = ...;
    const TNumeric: Numeric.Power<T> = ...;
    const result = Numeric['**'](left, right);// represents (left ** right)

Remainder

Remainder<Base, Divider, Output>:

Type parameters

  • Base
  • Divider = Base
  • Output = Base

%

  • %(left: Base, right: Divider): Output
  • Remainder operator

    @example
    type T = ...;
    const TNumeric: Numeric.Remainder<T> = ...;
    const result = Numeric['%'](left, right);// represents (left % right)

Signed

Signed<T>:

Type parameters

  • T

abs

  • abs(this: void, value: T): T
  • Absolute value. It should satisfy Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == x

    @example
    type T = ...;
    const TSigned: Numeric.Signed<T> = ...;
    const result = TSigned.abs(value);// absolute value of (value)

isNegative

  • isNegative(this: void, self: T): boolean
  • Returns true if the number is negative and false if the number is zero or positive.

    @example
    Number.isPositive(-1);// true
    Number.isPositive(0);// false
    Number.isPositive(1);// false

isPositive

  • isPositive(this: void, self: T): boolean
  • Returns true if the number is positive and false if the number is zero or negative.

    @example
    Number.isPositive(-1);// false
    Number.isPositive(0);// false
    Number.isPositive(1);// true

sign

  • sign(this: void, value: T): T
  • Sign of a number. It should satisfy TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == x

    @example
    Number.sign(-2.5);// -1
    Number.sign(0);// 0
    Number.sign(2.5);// 1

Subtract

Subtract<Left, Right, Output>:

Type parameters

  • Left
  • Right = Left
  • Output = Left

-

  • -(left: Left, right: Right): Output
  • Subtraction operator

    @example
    type T = ...;
    const TNumeric: Numeric.Subtract<T> = ...;
    const result = Numeric['-'](left, right);// represents (left - right)

Zero

Zero<T>:

Type parameters

  • T

isZero

  • isZero(this: void, self: T): boolean
  • Returns true if self is equal to the additive identity.

    @example
    Number.isZero(0); // true
    Number.isZero(1); // false

zero

  • zero(this: void): T
  • Returns the additive identity element of T, 0.

    @example
    Number.zero(); // 0

Functions

Integral

  • Type parameters

    • T

Numeric

  • Type parameters

    • T