decimals
.
If operations are performed that cause a value to grow too high (close to positive infinity) or too low (close to
negative infinity), the value is said to overflow.
For example, an 8-bit signed value, with 0 decimals may only be within the range -128
to 127
; so -128 - 1
will
overflow and become 127
. Likewise, 127 + 1
will overflow and become -127
.
Many operation have a normal and unsafe variant. The normal variant will throw a
NumericFaultError on any overflow, while the unsafe variant will silently allow
overflow, corrupting its value value.
If operations are performed that cause a value to become too small (close to zero), the value loses precison and is
said to underflow.
For example, an value with 1 decimal place may store a number as small as 0.1
, but the value of 0.1 / 2
is
0.05
, which cannot fit into 1 decimal place, so underflow occurs which means precision is lost and the value
becomes 0
.
Some operations have a normal and signalling variant. The normal variant will silently ignore underflow, while the
signalling variant will thow a NumericFaultError on underflow.
Property | Modifier | Type | Description |
---|---|---|---|
format | readonly | string | The specific fixed-point arithmetic field for this value. |
number
boolean
bigint
number
this
added to other
. A
NumericFaultError is thrown if overflow occurs.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to add to this . |
FixedNumber
The result of the addition.
this
added to other
, ignoring overflow.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to add to this . |
FixedNumber
The result of the addition.
this
.
The decimal component of the result will always be 0
.
FixedNumber
The ceiling value.
this
and other
.
This is suitable for use in sorting, where -1
implies this
is smaller, 1
implies this
is larger and 0
implies both are equal.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to compare to this . |
number
The comparison result.
this
divided by other
, ignoring
underflow (precision loss). A NumericFaultError is thrown if overflow occurs.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to divide this by. |
FixedNumber
The result of the division.
this
divided by other
. A
NumericFaultError is thrown if underflow (precision loss) occurs.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to divide this by. |
FixedNumber
The result of the division.
this
divided by other
, ignoring
underflow (precision loss). A NumericFaultError is thrown if overflow occurs.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to divide this by. |
FixedNumber
The result of the division.
other
is equal to this
.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to compare to this . |
boolean
True if other
is equal to this
.
this
.
The decimal component of the result will always be 0
.
FixedNumber
The floored value.
other
is greater than to this
.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to compare to this . |
boolean
True if other
is greater than to this
.
other
is greater than or equal to this
.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to compare to this . |
boolean
True if other
is greater than or equal to this
.
this
is less than 0
.
boolean
True if this
is less than 0
.
this
is equal to 0
.
boolean
True if this
is equal to 0
.
other
is less than to this
.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to compare to this . |
boolean
True if other
is less than to this
.
other
is less than or equal to this
.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to compare to this . |
boolean
True if other
is less than or equal to this
.
this
multiplied by other
. A
NumericFaultError is thrown if overflow occurs.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to multiply this by. |
FixedNumber
The result of the multiplication.
this
multiplied by other
. A
NumericFaultError is thrown if overflow occurs or if underflow (precision
loss) occurs.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to multiply this by. |
FixedNumber
The result of the multiplication.
this
multiplied by other
, ignoring
overflow and underflow (precision loss).
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to multiply this by. |
FixedNumber
The result of the multiplication.
decimals
places.
Parameter | Type | Description |
---|---|---|
decimals ? | number | The number of decimal places to round to. |
FixedNumber
The rounded value.
other
subtracted from this
. A
NumericFaultError is thrown if overflow occurs.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to subtract from this . |
FixedNumber
The result of the subtraction.
other
subtracted from this
, ignoring
overflow.
Parameter | Type | Description |
---|---|---|
other | FixedNumber | The value to subtract from this . |
FixedNumber
The result of the subtraction.
format
.
This will throw if the value cannot fit into format
.
Parameter | Type | Description |
---|---|---|
format | FixedFormat | The new format for the value. |
FixedNumber
this
.
string
The string representation.
number
The float approximation.
value
with format
.
This will throw a NumericFaultError if value
cannot fit in format
due to
overflow.
Parameter | Type | Description |
---|---|---|
_value | BytesLike | The big-endian representation of the value. |
_format ? | FixedFormat | The format for the FixedNumber. |
FixedNumber
The FixedNumber for value
.
value
with format
.
This will throw a NumericFaultError if value
cannot fit in format
, either
due to overflow or underflow (precision loss).
Parameter | Type | Description |
---|---|---|
_value | string | The value to create a FixedNumber for. |
_format ? | FixedFormat | The format for the FixedNumber. |
FixedNumber
The FixedNumber for value
.
value
divided by decimal
places with format
.
This will throw a NumericFaultError if value
(once adjusted for decimals
)
cannot fit in format
, either due to overflow or underflow (precision loss).
Parameter | Type | Description |
---|---|---|
_value | BigNumberish | The value to create a FixedNumber for. |
_decimals ? | Numeric | The number of decimal places in value . |
_format ? | FixedFormat | The format for the FixedNumber. |
FixedNumber
The FixedNumber for value
.