Class: NumberUnit<F, U>
A number with an associated unit. Each NumberUnit is created with a reference unit type, which cannot be changed after instantiation. The reference unit type determines how the value of the NumberUnit is internally represented. Each NumberUnit also maintains an active unit type, which can be dynamically changed at any time.
Type parameters
Name | Type |
---|---|
F | extends string |
U | extends Unit <F > = Unit <F > |
Implements
NumberUnitInterface
<F
,U
>
Constructors
constructor
• new NumberUnit<F
, U
>(number
, unit
): NumberUnit
<F
, U
>
Constructor.
Type parameters
Name | Type |
---|---|
F | extends string |
U | extends Unit <F > = Unit <F > |
Parameters
Name | Type | Description |
---|---|---|
number | number | the initial numeric value of the new NumberUnit. |
unit | U | the unit type of the new NumberUnit. |
Returns
NumberUnit
<F
, U
>
Defined in
src/sdk/math/NumberUnit.ts:161
Properties
readonly
• Readonly
readonly: NumberUnitReadOnly
<F
, U
>
Defined in
src/sdk/math/NumberUnit.ts:154
Accessors
number
• get
number(): number
Gets this NumberUnit's numeric value.
Returns
number
This NumberUnit's numeric value.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:171
unit
• get
unit(): U
Gets this NumberUnit's unit type.
Returns
U
This NumberUnit's unit type.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:179
Methods
abs
▸ abs<OU
>(out
): NumberUnit
<F
, OU
>
Calculates the absolute value of this NumberUnit and returns the result.
Type parameters
Name | Type |
---|---|
OU | extends Unit <F > |
Parameters
Name | Type | Description |
---|---|---|
out | NumberUnit <F , OU > | The NumberUnit to which to write the result. |
Returns
NumberUnit
<F
, OU
>
The absolute value.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:378
▸ abs(): this
Calculates the absolute value of this NumberUnit in place and returns the result.
Returns
this
The absolute value.
Implementation of
NumberUnitInterface.abs
Defined in
src/sdk/math/NumberUnit.ts:383
add
▸ add<OU
>(value
, out
): NumberUnit
<F
, OU
>
Adds a value to this NumberUnit and returns the result.
Type parameters
Name | Type |
---|---|
OU | extends Unit <F > |
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <F , Unit <F >> | The other value. |
out | NumberUnit <F , OU > | The NumberUnit to which to write the result. |
Returns
NumberUnit
<F
, OU
>
The sum.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:233
▸ add(value
): this
Adds a value to this NumberUnit in place and returns the result.
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <F , Unit <F >> | The other value. |
Returns
this
The sum.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:240
▸ add<OU
>(value
, unit
, out
): NumberUnit
<F
, OU
>
Adds a value to this NumberUnit and returns the result.
Type parameters
Name | Type |
---|---|
OU | extends Unit <F > |
Parameters
Name | Type | Description |
---|---|---|
value | number | The other value. |
unit | Unit <F > | The unit type of the other value. |
out | NumberUnit <F , OU > | The NumberUnit to which to write the result. |
Returns
NumberUnit
<F
, OU
>
The sum.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
NumberUnitInterface.add
Defined in
src/sdk/math/NumberUnit.ts:249
▸ add(value
, unit
): this
Adds a value to this NumberUnit in place and returns the result.
Parameters
Name | Type | Description |
---|---|---|
value | number | The other value. |
unit | Unit <F > | The unit type of the other value. |
Returns
this
The sum.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
NumberUnitInterface.add
Defined in
src/sdk/math/NumberUnit.ts:257
asUnit
▸ asUnit(unit
): number
Returns the numeric value of this NumberUnit after conversion to a specified unit.
Parameters
Name | Type | Description |
---|---|---|
unit | Unit <F > | The unit to which to convert. |
Returns
number
The converted numeric value.
Throws
Error if this NumberUnit's unit type cannot be converted to the specified unit.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:400
compare
▸ compare(value
): number
Checks whether this NumberUnit is greater than, equal to, or less than another value.
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <F , Unit <F >> | The other value. |
Returns
number
0 if this NumberUnit is equal to the other value, -1 if this number is less, 1 if this number is greater.
Throws
Error if this NumberUnit cannot be compared to the other value.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:410
▸ compare(value
, unit?
): number
Checks whether this NumberUnit is greater than, equal to, or less than another value.
Parameters
Name | Type | Description |
---|---|---|
value | number | The other value. |
unit? | Unit <F > | The unit type of the other value. Defaults to this NumberUnit's unit type. |
Returns
number
0 if this NumberUnit is equal to the other value, -1 if this number is less, 1 if this number is greater.
Throws
Error if this NumberUnit cannot be compared to the other value.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:418
copy
▸ copy(): NumberUnit
<F
, U
>
Copies this NumberUnit.
Returns
NumberUnit
<F
, U
>
A copy of this NumberUnit.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:477
equals
▸ equals(value
): boolean
Checks whether this NumberUnit is equal to another value. Two values are considered equal if and only if their
unit types are interconvertable and when converted to the same unit type, their numeric values are equal to each
other or both equal to NaN
.
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <string , Unit <string >> | The other value. |
Returns
boolean
Whether this NumberUnit is equal to the other value.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:440
▸ equals(value
, unit?
): boolean
Checks whether this NumberUnit is equal to another value. Two values are considered equal if and only if their
unit types are interconvertable and when converted to the same unit type, their numeric values are equal to each
other or both equal to NaN
.
Parameters
Name | Type | Description |
---|---|---|
value | number | The other value. |
unit? | Unit <string > | The unit type of the other value. Defaults to this NumberUnit's unit type. |
Returns
boolean
Whether this NumberUnit is equal to the other value.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:449
isNaN
▸ isNaN(): boolean
Checks whether this NumberUnit has a numeric value of NaN.
Returns
boolean
Whether this NumberUnit has a numeric value of NaN.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:469
ratio
▸ ratio(value
): number
Finds the ratio of this NumberUnit to another value.
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <F , Unit <F >> | The other value. |
Returns
number
The ratio.
Throws
Error if the other value cannot be converted to this NumberUnit's unit type.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:355
▸ ratio(value
, unit
): number
Finds the ratio of this NumberUnit to another value.
Parameters
Name | Type | Description |
---|---|---|
value | number | The other value. |
unit | Unit <F > | The unit type of the other value. |
Returns
number
the ratio.
Throws
Error if the other value cannot be converted to this NumberUnit's unit type.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:363
scale
▸ scale<OU
>(factor
, out
): NumberUnit
<F
, OU
>
Scales this NumberUnit by a unit-less factor and returns the result.
Type parameters
Name | Type |
---|---|
OU | extends Unit <F > |
Parameters
Name | Type | Description |
---|---|---|
factor | number | The factor by which to scale. |
out | NumberUnit <F , OU > | The NumberUnit to which to write the result. |
Returns
NumberUnit
<F
, OU
>
The scaled value.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:332
▸ scale(factor
): this
Scales this NumberUnit by a unit-less factor in place and returns the result.
Parameters
Name | Type | Description |
---|---|---|
factor | number | The factor by which to scale. |
Returns
this
The scaled value.
Implementation of
NumberUnitInterface.scale
Defined in
src/sdk/math/NumberUnit.ts:338
set
▸ set(value
): this
Sets this NumberUnit's numeric value. This method will not change this NumberUnit's unit type. If the supplied value cannot be converted to this NumberUnit's unit type, this NumberUnit will not be changed and this method will return undefined.
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <F , Unit <F >> | the new value. |
Returns
this
this NumberUnit, after it has been changed, or undefined if the operation could not be carried out.
Defined in
src/sdk/math/NumberUnit.ts:207
▸ set(value
, unit?
): this
Sets this NumberUnit's numeric value. This method will not change this NumberUnit's unit type.
Parameters
Name | Type | Description |
---|---|---|
value | number | the new value. |
unit? | Unit <F > | the unit type of the new value. Defaults to this NumberUnit's unit type. |
Returns
this
this NumberUnit, after it has been changed.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Defined in
src/sdk/math/NumberUnit.ts:215
subtract
▸ subtract<OU
>(value
, out
): NumberUnit
<F
, OU
>
Subtracts a value from this NumberUnit and returns the result.
Type parameters
Name | Type |
---|---|
OU | extends Unit <F > |
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <F , Unit <F >> | The other value. |
out | NumberUnit <F , OU > | The NumberUnit to which to write the result. |
Returns
NumberUnit
<F
, OU
>
The difference.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:283
▸ subtract(value
): this
Subtracts a value from this NumberUnit in place and returns the result.
Parameters
Name | Type | Description |
---|---|---|
value | NumberUnitInterface <F , Unit <F >> | The other value. |
Returns
this
The difference.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
Defined in
src/sdk/math/NumberUnit.ts:290
▸ subtract<OU
>(value
, unit
, out
): NumberUnit
<F
, OU
>
Subtracts a value from this NumberUnit and returns the result.
Type parameters
Name | Type |
---|---|
OU | extends Unit <F > |
Parameters
Name | Type | Description |
---|---|---|
value | number | The other value. |
unit | Unit <F > | The unit type of the other value. |
out | NumberUnit <F , OU > | The NumberUnit to which to write the result. |
Returns
NumberUnit
<F
, OU
>
The difference.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
NumberUnitInterface.subtract
Defined in
src/sdk/math/NumberUnit.ts:299
▸ subtract(value
, unit
): this
Subtracts a value from this NumberUnit in place and returns the result.
Parameters
Name | Type | Description |
---|---|---|
value | number | The other value. |
unit | Unit <F > | The unit type of the other value. |
Returns
this
The difference.
Throws
Error if the supplied value cannot be converted to this NumberUnit's unit type.
Implementation of
NumberUnitInterface.subtract
Defined in
src/sdk/math/NumberUnit.ts:307