Qnum
A set of static methods for working with qualified numbers. The internal representation of a qualified number is a regular double precision floating point number (IEEE 754), except the two least significant bits in mantissa are reserved for holding the qualifier ([LESS], [EXACT], [GREATER]).
The advantage of that representation is that the standard arithmetic operations could be performed directly on the number, without unpacking it. This is especially important for batch operations such as aggregation or sorting. While there is a loss of precision, it is rather insignificant (50 bits for storing mantissa instead of 52), which makes perfect sense considering that qualified numbers represent imprecise measurements.
Use [create], [getValue], and [getQ] methods for packing/unpacking.
Constructors
new Qnum()
new Qnum():
Qnum
Returns
Methods
create()
staticcreate(value,q):number
Creates a QNum value out of the [value] and qualifier [q].
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | |
q | number | QNUM_EXACT |
Returns
number
Source
exact()
staticexact(x):number
Parameters
| Parameter | Type |
|---|---|
x | number |
Returns
number
Source
getQ()
staticgetQ(x):number
Extracts the qualifier (QNUM_LESS, QNUM_EXACT, QNUM_GREATER). See also getValue
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number |
Returns
number
Source
getValue()
staticgetValue(x):number
Extracts the value from x, stripping the qualifier . See also getQ
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number |
Returns
number
Source
greater()
staticgreater(x):number
Parameters
| Parameter | Type |
|---|---|
x | number |
Returns
number
Source
less()
staticless(x):number
Parameters
| Parameter | Type |
|---|---|
x | number |
Returns
number
Source
parse()
staticparse(s):number
Parses a string into a qualified number.
Parameters
| Parameter | Type | Description |
|---|---|---|
s | string |
Returns
number
Source
qualifier()
staticqualifier(x):string
Returns the string representation of the qualifier.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number |
Returns
string
Source
toString()
statictoString(x):string
Converts a qualified number to a string representation.
Parameters
| Parameter | Type | Description |
|---|---|---|
x | number |
Returns
string