BigFixed
Represents an arbitrary-precision signed fixed-point decimal number.
A BigFixed object stores its value as a BigInteger mantissa together with a scale (the number of digits kept after the decimal point). The value represented is always mantissa / 10^scale.
Arithmetic between two BigFixed objects of different scales is always performed at the wider (larger) of the two scales; multiplication and division let you keep the receiver's scale (truncating, never rounding, any extra digits produced by the operation).
Constructor
BigFixed(value: ( BigFixed | BigInteger | string | number | nil ), scale: ( integer | nil )): BigFixed
Fields
| Name | Type | Description |
|---|
mantissa | BigInteger | |
scale | integer | |
DEFAULT_SCALE | integer | The number of fractional decimal digits used when no explicit scale is given. = 18 |
Operators
Methods
abs | Makes a big fixed object absolute ( removes the sign ). |
add | Adds the given value to the current BigFixed, in place. |
compare | Compares the BigFixed with the given value. |
copy | Makes a copy of the BigFixed object. |
div | Divides the current BigFixed by the given value, in place. |
getScale | Returns the current scale ( number of fractional digits ) of the object. |
isNegative | Checks if a big fixed object is negative. |
isZero | Checks if a big fixed object is zero. |
mul | Multiplies the current BigFixed by the given value, in place. |
negate | Negates a big fixed object. |
setScale | |
sub | Subtracts the given value from the current BigFixed, in place. |
toBigInteger | Converts a BigFixed object to a BigInteger, truncating the fractional part. |
toNumber | Converts a BigFixed object to a Lua number ( precision loss is possible for values that don't fit in a double ). |
toString | Converts a BigFixed object to a decimal string. |
function BigFixed:abs(): BigFixed
Makes a big fixed object absolute ( removes the sign ).
Returns
function BigFixed:add(value: any): BigFixed
Adds the given value to the current BigFixed, in place.
The result keeps the wider ( larger ) of the two scales; plain numbers, strings and BigIntegers are converted at the receiver's scale.
Parameters
| Name | Type | Description |
|---|
value | any | The second value to be converted into BigFixed. |
Returns
function BigFixed:compare(value: any): `-1` | `0` | `1`
Compares the BigFixed with the given value.
Unlike the ==, < and <= operators, this also works with plain Lua numbers and strings.
Parameters
| Name | Type | Description |
|---|
value | any | The value to compare with ( converted into BigFixed ). |
Returns
| Type | Name | Description |
|---|
`-1` | `0` | `1` | result | -1 if self < value, 0 if equal, 1 if self > value. |
function BigFixed:copy(): BigFixed
Returns
function BigFixed:div(value: any): BigFixed
Divides the current BigFixed by the given value, in place.
The quotient is computed with ( and truncated to ) the receiver's current scale.
Parameters
| Name | Type | Description |
|---|
value | any | The value to divide by ( converted into BigFixed ). |
Returns
function BigFixed:getScale(): integer
Returns the current scale ( number of fractional digits ) of the object.
Returns
| Type | Name | Description |
|---|
integer | scale | |
function BigFixed:isNegative(): boolean
Checks if a big fixed object is negative.
Returns
| Type | Name | Description |
|---|
boolean | is_negative | |
function BigFixed:isZero(): boolean
Checks if a big fixed object is zero.
Returns
| Type | Name | Description |
|---|
boolean | is_zero | |
function BigFixed:mul(value: any): BigFixed
Multiplies the current BigFixed by the given value, in place.
The result is truncated back down to the receiver's original scale ( it is not rounded ).
Parameters
| Name | Type | Description |
|---|
value | any | The second value to be converted into BigFixed. |
Returns
function BigFixed:negate(): BigFixed
Negates a big fixed object.
Returns
function BigFixed:setScale(scale: any)
Parameters
| Name | Type | Description |
|---|
scale | any | |
function BigFixed:sub(value: any): BigFixed
Subtracts the given value from the current BigFixed, in place.
Parameters
| Name | Type | Description |
|---|
value | any | The second value to be converted into BigFixed. |
Returns
function BigFixed:toBigInteger(): BigInteger
Returns
function BigFixed:toNumber(): number
Converts a BigFixed object to a Lua number ( precision loss is possible for values that don't fit in a double ).
Returns
| Type | Name | Description |
|---|
number | value | |
function BigFixed:toString(): string
Converts a BigFixed object to a decimal string.
Returns
| Type | Name | Description |
|---|
string | str | |