NumberConversion
Index
Interfaces
Module
Type parameters
- T
readonlyinheritedmaxValue
const anyNumber: number
anyNumber < Number.maxValue // true
readonlyinheritedminValue
Minimum value for this type
const anyNumber: number
anyNumber > Number.minValue // true
inherited-
Subtraction operator
type T = ...;const TNumeric: Numeric.Subtract<T> = ...;const result = Numeric['-'](left, right);// represents (left - right)
inherited!=
"Not equal to" operator
const TEqual: Equal<T>;TEqual['!='](value, otherValue); // trueTEqual['!='](value, value); // false
inherited*
Multiplication operator
type T = ...;const TNumeric: Numeric.Multiply<T> = ...;const result = Numeric['*'](left, right);// represents (left * right)
inherited**
Power operator
type T = ...;const TNumeric: Numeric.Power<T> = ...;const result = Numeric['**'](left, right);// represents (left ** right)
inherited%
Remainder operator
type T = ...;const TNumeric: Numeric.Remainder<T> = ...;const result = Numeric['%'](left, right);// represents (left % right)
inherited+
Addition operator
type T = ...;const TNumeric: Numeric.Add<T> = ...;const result = TNumeric['+'](left, right);// represents (left + right)
inherited<
"Less than" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['<'](smallerT, smallerT); // falseTCompare['<'](smallerT, greaterT); // trueTCompare['<'](greaterT, smallerT); // false
inherited<=
"Less than or equal to" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['<='](smallerT, smallerT); // trueTCompare['<='](smallerT, greaterT); // trueTCompare['<='](greaterT, smallerT); // false
inherited==
"Equal to" operator
type T = // ...const TEqual: Equal<T>;TEqual['=='](value, value); // trueTEqual['=='](value, otherValue); // false
inherited>
"Greater than" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['>'](smallerT, smallerT); // falseTCompare['>'](smallerT, greaterT); // falseTCompare['>'](greaterT, smallerT); // true
inherited>=
"Greater than or equal to" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare['>='](smallerT, smallerT); // trueTCompare['>='](smallerT, greaterT); // falseTCompare['>='](greaterT, smallerT); // true
inheritedabs
Absolute value. It should satisfy
Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == xtype T = ...;const TSigned: Numeric.Signed<T> = ...;const result = TSigned.abs(value);// absolute value of (value)
inheritedclamp
Clamp value between minValue and maxValue
type T;const TCompare: Comparable<T>;TCompare.clamp(value, min, max); // min if value < min, max if value > max, otherwise value itself
inheritedcompare
inheritedequals
Alias to '=='
type T = // ...const TEqual: Equal<T>;TEqual.equals(value, value); // trueTEqual.equals(value, otherValue); // false
inheritedisNegative
Returns true if the number is negative and false if the number is zero or positive.
Number.isPositive(-1);// trueNumber.isPositive(0);// falseNumber.isPositive(1);// false
inheritedisPositive
Returns true if the number is positive and false if the number is zero or negative.
Number.isPositive(-1);// falseNumber.isPositive(0);// falseNumber.isPositive(1);// true
inheritedisZero
Returns true if self is equal to the additive identity.
Number.isZero(0); // trueNumber.isZero(1); // false
inheritedmax
"maximum" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare.max(smallerT, greaterT); // greaterT
inheritedmin
"minimum" operator
type T;const TCompare: Comparable<T>;const smallerT: T;const greaterT: T;TCompare.min(smallerT, greaterT); // smallerT
inheritednegate
Negates the given value.
Number.negate(5); // -5Number.negate(Number.negate(5)); // 5
inheritedsign
Sign of a number. It should satisfy
TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == xNumber.sign(-2.5);// -1Number.sign(0);// 0Number.sign(2.5);// 1
inheritedzero
Returns the additive identity element of
T, 0.Number.zero(); // 0
Functions
__call__
Add
Bounded
Creates a Bounded instance for a type T that can be converted to and from Int.
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); ```
Maximum value for this type