Class: NumberUnit<F, U>
Defined in: src/sdk/math/NumberUnit.ts:151
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
Type Parameter | Default 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
>
Defined in: src/sdk/math/NumberUnit.ts:162
Constructor.
Parameters
Parameter | 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
>
Properties
readonly
readonly
readonly:NumberUnitReadOnly
<F
,U
>
Defined in: src/sdk/math/NumberUnit.ts:155
Accessors
number
Get Signature
get number():
number
Defined in: src/sdk/math/NumberUnit.ts:172
Gets this NumberUnit's numeric value.
Returns
number
This NumberUnit's numeric value.
This NumberUnit's numeric value.
Implementation of
unit
Get Signature
get unit():
U
Defined in: src/sdk/math/NumberUnit.ts:180
Gets this NumberUnit's unit type.
Returns
U
This NumberUnit's unit type.
This NumberUnit's unit type.
Implementation of
Methods
abs()
Call Signature
abs<
OU
>(out
):NumberUnit
<F
,OU
>
Defined in: src/sdk/math/NumberUnit.ts:379
Calculates the absolute value of this NumberUnit and returns the result.
Type Parameters
Type Parameter |
---|
OU extends Unit <F > |
Parameters
Parameter | Type | Description |
---|---|---|
out | NumberUnit <F , OU > | The NumberUnit to which to write the result. |
Returns
NumberUnit
<F
, OU
>
The absolute value.
Implementation of
Call Signature
abs():
this
Defined in: src/sdk/math/NumberUnit.ts:384
Calculates the absolute value of this NumberUnit in place and returns the result.
Returns
this
The absolute value.
Implementation of
NumberUnitInterface.abs
add()
Call Signature
add<
OU
>(value
,out
):NumberUnit
<F
,OU
>
Defined in: src/sdk/math/NumberUnit.ts:234
Adds a value to this NumberUnit and returns the result.
Type Parameters
Type Parameter |
---|
OU extends Unit <F > |
Parameters
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <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
Call Signature
add(
value
):this
Defined in: src/sdk/math/NumberUnit.ts:241
Adds a value to this NumberUnit in place and returns the result.
Parameters
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <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
Call Signature
add<
OU
>(value
,unit
,out
):NumberUnit
<F
,OU
>
Defined in: src/sdk/math/NumberUnit.ts:250
Adds a value to this NumberUnit and returns the result.
Type Parameters
Type Parameter |
---|
OU extends Unit <F > |
Parameters
Parameter | 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
Call Signature
add(
value
,unit
):this
Defined in: src/sdk/math/NumberUnit.ts:258
Adds a value to this NumberUnit in place and returns the result.
Parameters
Parameter | 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
asUnit()
asUnit(
unit
):number
Defined in: src/sdk/math/NumberUnit.ts:401
Returns the numeric value of this NumberUnit after conversion to a specified unit.
Parameters
Parameter | 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
compare()
Call Signature
compare(
value
):number
Defined in: src/sdk/math/NumberUnit.ts:411
Checks whether this NumberUnit is greater than, equal to, or less than another value.
Parameters
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <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
Call Signature
compare(
value
,unit?
):number
Defined in: src/sdk/math/NumberUnit.ts:419
Checks whether this NumberUnit is greater than, equal to, or less than another value.
Parameters
Parameter | 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
copy()
copy():
NumberUnit
<F
,U
>
Defined in: src/sdk/math/NumberUnit.ts:478
Copies this NumberUnit.
Returns
NumberUnit
<F
, U
>
A copy of this NumberUnit.
Implementation of
equals()
Call Signature
equals(
value
):boolean
Defined in: src/sdk/math/NumberUnit.ts:441
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
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <string > | The other value. |
Returns
boolean
Whether this NumberUnit is equal to the other value.
Implementation of
Call Signature
equals(
value
,unit?
):boolean
Defined in: src/sdk/math/NumberUnit.ts:450
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
Parameter | 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
isNaN()
isNaN():
boolean
Defined in: src/sdk/math/NumberUnit.ts:470
Checks whether this NumberUnit has a numeric value of NaN.
Returns
boolean
Whether this NumberUnit has a numeric value of NaN.
Implementation of
ratio()
Call Signature
ratio(
value
):number
Defined in: src/sdk/math/NumberUnit.ts:356
Finds the ratio of this NumberUnit to another value.
Parameters
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <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
Call Signature
ratio(
value
,unit
):number
Defined in: src/sdk/math/NumberUnit.ts:364
Finds the ratio of this NumberUnit to another value.
Parameters
Parameter | 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
scale()
Call Signature
scale<
OU
>(factor
,out
):NumberUnit
<F
,OU
>
Defined in: src/sdk/math/NumberUnit.ts:333
Scales this NumberUnit by a unit-less factor and returns the result.
Type Parameters
Type Parameter |
---|
OU extends Unit <F > |
Parameters
Parameter | 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
Call Signature
scale(
factor
):this
Defined in: src/sdk/math/NumberUnit.ts:339
Scales this NumberUnit by a unit-less factor in place and returns the result.
Parameters
Parameter | Type | Description |
---|---|---|
factor | number | The factor by which to scale. |
Returns
this
The scaled value.
Implementation of
NumberUnitInterface.scale
set()
Call Signature
set(
value
):this
Defined in: src/sdk/math/NumberUnit.ts:208
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
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <F > | the new value. |
Returns
this
this NumberUnit, after it has been changed, or undefined if the operation could not be carried out.
Call Signature
set(
value
,unit?
):this
Defined in: src/sdk/math/NumberUnit.ts:216
Sets this NumberUnit's numeric value. This method will not change this NumberUnit's unit type.
Parameters
Parameter | 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.
subtract()
Call Signature
subtract<
OU
>(value
,out
):NumberUnit
<F
,OU
>
Defined in: src/sdk/math/NumberUnit.ts:284
Subtracts a value from this NumberUnit and returns the result.
Type Parameters
Type Parameter |
---|
OU extends Unit <F > |
Parameters
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <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
Call Signature
subtract(
value
):this
Defined in: src/sdk/math/NumberUnit.ts:291
Subtracts a value from this NumberUnit in place and returns the result.
Parameters
Parameter | Type | Description |
---|---|---|
value | NumberUnitInterface <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
Call Signature
subtract<
OU
>(value
,unit
,out
):NumberUnit
<F
,OU
>
Defined in: src/sdk/math/NumberUnit.ts:300
Subtracts a value from this NumberUnit and returns the result.
Type Parameters
Type Parameter |
---|
OU extends Unit <F > |
Parameters
Parameter | 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
Call Signature
subtract(
value
,unit
):this
Defined in: src/sdk/math/NumberUnit.ts:308
Subtracts a value from this NumberUnit in place and returns the result.
Parameters
Parameter | 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