dreamworkAPI
Ctrl K
GitHub
classDocs / BigFixed

BigFixed

classsharedmenusource
Object → 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

NameTypeDescription
mantissaBigInteger
scaleinteger
DEFAULT_SCALEintegerThe number of fractional decimal digits used when no explicit scale is given. = 18

Operators

OperatorOperandResult
add any BigFixed
sub any BigFixed
mul any BigFixed
div any BigFixed
unmBigFixed
concat any string

Methods

absMakes a big fixed object absolute ( removes the sign ).
addAdds the given value to the current BigFixed, in place.
compareCompares the BigFixed with the given value.
copyMakes a copy of the BigFixed object.
divDivides the current BigFixed by the given value, in place.
getScaleReturns the current scale ( number of fractional digits ) of the object.
isNegativeChecks if a big fixed object is negative.
isZeroChecks if a big fixed object is zero.
mulMultiplies the current BigFixed by the given value, in place.
negateNegates a big fixed object.
setScale
subSubtracts the given value from the current BigFixed, in place.
toBigIntegerConverts a BigFixed object to a BigInteger, truncating the fractional part.
toNumberConverts a BigFixed object to a Lua number ( precision loss is possible for values that don't fit in a double ).
toStringConverts a BigFixed object to a decimal string.

#BigFixed:abs

sharedmenusource
function BigFixed:abs(): BigFixed

Makes a big fixed object absolute ( removes the sign ).

Returns
TypeNameDescription
BigFixedself

#BigFixed:add

sharedmenusource
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
NameTypeDescription
valueanyThe second value to be converted into BigFixed.
Returns
TypeNameDescription
BigFixedself

#BigFixed:compare

sharedmenunodiscardsource
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
NameTypeDescription
valueanyThe value to compare with ( converted into BigFixed ).
Returns
TypeNameDescription
`-1` | `0` | `1`result-1 if self < value, 0 if equal, 1 if self > value.

#BigFixed:copy

sharedmenunodiscardsource
function BigFixed:copy(): BigFixed

Makes a copy of the BigFixed object.

Returns
TypeNameDescription
BigFixednew_obj

#BigFixed:div

sharedmenusource
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
NameTypeDescription
valueanyThe value to divide by ( converted into BigFixed ).
Returns
TypeNameDescription
BigFixedself

#BigFixed:getScale

sharedmenunodiscardsource
function BigFixed:getScale(): integer

Returns the current scale ( number of fractional digits ) of the object.

Returns
TypeNameDescription
integerscale

#BigFixed:isNegative

sharedmenunodiscardsource
function BigFixed:isNegative(): boolean

Checks if a big fixed object is negative.

Returns
TypeNameDescription
booleanis_negative

#BigFixed:isZero

sharedmenunodiscardsource
function BigFixed:isZero(): boolean

Checks if a big fixed object is zero.

Returns
TypeNameDescription
booleanis_zero

#BigFixed:mul

sharedmenusource
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
NameTypeDescription
valueanyThe second value to be converted into BigFixed.
Returns
TypeNameDescription
BigFixedself

#BigFixed:negate

sharedmenusource
function BigFixed:negate(): BigFixed

Negates a big fixed object.

Returns
TypeNameDescription
BigFixedself

#BigFixed:setScale

function BigFixed:setScale(scale: any)
Parameters
NameTypeDescription
scaleany

#BigFixed:sub

sharedmenusource
function BigFixed:sub(value: any): BigFixed

Subtracts the given value from the current BigFixed, in place.

Parameters
NameTypeDescription
valueanyThe second value to be converted into BigFixed.
Returns
TypeNameDescription
BigFixedself

#BigFixed:toBigInteger

sharedmenunodiscardsource
function BigFixed:toBigInteger(): BigInteger

Converts a BigFixed object to a BigInteger, truncating the fractional part.

Returns
TypeNameDescription
BigIntegerobj

#BigFixed:toNumber

sharedmenunodiscardsource
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
TypeNameDescription
numbervalue

#BigFixed:toString

sharedmenunodiscardsource
function BigFixed:toString(): string

Converts a BigFixed object to a decimal string.

Returns
TypeNameDescription
stringstr
Generated from the dreamwork meta branch.