Skip to main content

NumberConversion

Index

Interfaces

Module

Module<T>:

Type parameters

  • T

readonlymaxValue

maxValue: T

Maximum value for this type

@example
const anyNumber: number
anyNumber < Number.maxValue // true

readonlyminValue

minValue: T

Minimum value for this type

@example
const anyNumber: number
anyNumber > Number.minValue // true

!=

  • !=(this: void, left: T, right: T): boolean
  • "Not equal to" operator

    @example
    const TEqual: Equal<T>;
    TEqual['!='](value, otherValue); // true
    TEqual['!='](value, value); // false

%

  • %(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
  • Power operator

    @example
    type T = ...;
    const TNumeric: Numeric.Power<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)

  • (this: void, left: T, right: T): boolean
  • "Less than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<'](smallerT, smallerT); // false
    TCompare['<'](smallerT, greaterT); // true
    TCompare['<'](greaterT, smallerT); // false

<=

  • <=(this: void, left: T, right: T): boolean
  • "Less than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<='](smallerT, smallerT); // true
    TCompare['<='](smallerT, greaterT); // true
    TCompare['<='](greaterT, smallerT); // false

==

  • ==(this: void, left: T, right: T): boolean
  • "Equal to" operator

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual['=='](value, value); // true
    TEqual['=='](value, otherValue); // false

  • (this: void, left: T, right: T): boolean
  • "Greater than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>'](smallerT, smallerT); // false
    TCompare['>'](smallerT, greaterT); // false
    TCompare['>'](greaterT, smallerT); // true

>=

  • >=(this: void, left: T, right: T): boolean
  • "Greater than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>='](smallerT, smallerT); // true
    TCompare['>='](smallerT, greaterT); // false
    TCompare['>='](greaterT, smallerT); // true

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)

clamp

  • clamp(this: void, value: T, minValue: T, maxValue: T): T
  • Clamp value between minValue and maxValue

    @example
    type T;
    const TCompare: Comparable<T>;
    TCompare.clamp(value, min, max); // min if value < min, max if value > max, otherwise value itself

compare

  • compare(this: void, left: T, right: T): Ordering
  • Return an Ordering that represents comparison result

    @see
    @example
    type T;
    const TCompare: Comparable<T>;
    const sorted = [3, 1, 1].sort(TCompare.compare);

equals

  • equals(this: void, left: T, right: T): boolean
  • Alias to '=='

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual.equals(value, value); // true
    TEqual.equals(value, otherValue); // false

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

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

max

  • max(this: void, left: T, right: T): T
  • "maximum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.max(smallerT, greaterT); // greaterT

min

  • min(this: void, left: T, right: T): T
  • "minimum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.min(smallerT, greaterT); // smallerT

negate

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

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

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

Functions

Add

Bounded

  • Bounded(): Bounded<number>
  • Bounded<T>(BaseType: Pick<NumberConversion<T>, fromNumber>): Bounded<T>
  • Creates a Bounded instance for a type T that can be converted to and from Int.

    @example

    interface MyType { custom: boolean; value: number; } const MyTypeConversion: NumberConversion

    <MyType>
    = { fromInt: (v) => ({ custom: true, value: v }), asInt: (v) => v.value as Int, } const MyTypeBounded = NumberConversion.Bounded
    <MyType>
    (MyTypeConversion); ```

Comparable

  • Comparable(): CoreComparable<number>
  • Comparable<T>(BaseType: Pick<NumberConversion<T>, asNumber>): CoreComparable<T>

Multiply

  • Multiply(): Numeric.Multiply<number>
  • Multiply<T>(BaseType: NumberConversion<T>): Numeric.Multiply<T>

Negate

  • Negate(): Numeric.Negate<number>
  • Negate<T>(BaseType: NumberConversion<T>): Numeric.Negate<T>

Power

  • Power(): Numeric.Power<number>
  • Power<T>(BaseType: NumberConversion<T>): Numeric.Power<T>

Remainder

  • Remainder(): Numeric.Remainder<number>
  • Remainder<T>(BaseType: NumberConversion<T>): Numeric.Remainder<T>

Signed

  • Signed(): Numeric.Signed<number>
  • Signed<T>(BaseType: NumberConversion<T>): Numeric.Signed<T>

Subtract

  • Subtract(): Numeric.Subtract<number>
  • Subtract<T>(BaseType: NumberConversion<T>): Numeric.Subtract<T>

Zero

  • Zero(): Numeric.Zero<number>
  • Zero<T>(BaseType: NumberConversion<T>): Numeric.Zero<T>

__call__