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()
static
create(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()
static
exact(x
):number
Parameters
Parameter | Type |
---|---|
x | number |
Returns
number
Source
getQ()
static
getQ(x
):number
Extracts the qualifier (QNUM_LESS, QNUM_EXACT, QNUM_GREATER). See also getValue
Parameters
Parameter | Type | Description |
---|---|---|
x | number |
Returns
number
Source
getValue()
static
getValue(x
):number
Extracts the value from x, stripping the qualifier . See also getQ
Parameters
Parameter | Type | Description |
---|---|---|
x | number |
Returns
number
Source
greater()
static
greater(x
):number
Parameters
Parameter | Type |
---|---|
x | number |
Returns
number
Source
less()
static
less(x
):number
Parameters
Parameter | Type |
---|---|
x | number |
Returns
number
Source
parse()
static
parse(s
):number
Parses a string into a qualified number.
Parameters
Parameter | Type | Description |
---|---|---|
s | string |
Returns
number
Source
qualifier()
static
qualifier(x
):string
Returns the string representation of the qualifier.
Parameters
Parameter | Type | Description |
---|---|---|
x | number |
Returns
string
Source
toString()
static
toString(x
):string
Converts a qualified number to a string representation.
Parameters
Parameter | Type | Description |
---|---|---|
x | number |
Returns
string