BigValue
The object a Scribe.Big field hands back from Get: a mantissa and an
exponent, carrying about 15 significant digits at any magnitude. There is no
public constructor, so you get one from a big field and write one back through
that field.
It supports +, -, *, /, unary - and tostring. Each binary operator
takes a number, a numeric string like "1.5e100", or another big value on
either side, so essence + 5 and 5 + essence both work. Any other operand
errors naming its type, and dividing by zero errors rather than handing back an
infinity that no save would survive.
Numeric strings are limited to 256 bytes, including whitespace, and are never truncated.
Methods are called with a colon, essence:Short(), so the signatures below drop
the implicit self. The Big Numbers guide covers the rest.
Find a member
Section titled “Find a member”Choose a group, then follow a member link for its signature and behavior.
Methods
Add · Subtract · Multiply · Divide · Negate · Compare · Equals · Pow · Log10 · Short · ToNumber
Fields
Methods
Section titled “Methods”BigValue:Add(other: number | string | BigValue) → BigValueReturns the sum, like self + other. Does not change the stored field: save
the returned value with Set, or use the field’s Increment to write directly.
:Subtract
Section titled “:Subtract”BigValue:Subtract(other: number | string | BigValue) → BigValueReturns the difference, like self - other, without writing the stored field.
:Multiply
Section titled “:Multiply”BigValue:Multiply(other: number | string | BigValue) → BigValueReturns the product, like self * other, without writing the stored field.
The accessor’s Multiply method writes; this value method only calculates.
:Divide
Section titled “:Divide”BigValue:Divide(other: number | string | BigValue) → BigValueReturns the quotient, like self / other, without writing the stored field.
Division by zero errors, matching the operator and the accessor’s Divide.
:Negate
Section titled “:Negate”BigValue:Negate() → BigValueReturns the opposite value, like -self, without writing the stored field.
:Compare
Section titled “:Compare”BigValue:Compare(other: number | string | BigValue) → numberReturns -1, 0 or 1 when this value is smaller, equal or larger than other.
Accepts a number or numeric string even beyond the double range. Invalid operands
error; neither operand is changed.
:Equals
Section titled “:Equals”BigValue:Equals(other: number | string | BigValue) → booleanWhether Compare(other) is zero. Accepts numeric strings and numbers as well
as other big values, and errors on an invalid operand.
BigValue:Pow(n: number) → BigValueRaises the value to the power n and returns a new big. x:Pow(0) is 1 for
every x, zero included.
data.Essence.Set(data.Essence.Get():Pow(2)) -- square the balancen must be a non-negative integer no larger than 2^53. Anything else errors,
so Pow(2.5), Pow(-3) and Pow(math.huge) raise instead of returning a
plausible wrong answer; for a negative power, divide by the positive one. A
result past the exponent ceiling saturates, exactly as * does.
Prefer it to a chain of Multiply calls whenever the result has to rank. Pow
rounds once at the end where a chain rounds at every step; the measured
difference is in the Big Numbers guide.
:Log10
Section titled “:Log10”BigValue:Log10() → numberThe base-10 logarithm, as a plain number. E is its exact integer part
and this adds the fraction, which makes it the cheap way to turn a magnitude
into a tier:
local tier = math.floor(data.Essence.Get():Log10() / 3)Total and unguarded, matching what the same call on a plain number does: zero
gives -inf and a negative value gives nan, so a fresh 0 balance needs no
special case at the call site. Precision decays as the value grows, from about
17 significant digits at 1e0 to 10 at 1e1000000 and none near the exponent
ceiling, so read E when you need the integer part exactly.
:Short
Section titled “:Short”BigValue:Short(decimals: number?) → stringThe display form. Uses a letter suffix while there is one and falls back to
scientific notation once it runs out, so 1500 is "1.50K", 1e40 is
"10.00DDc" and 1.5e100 is "1.5e100". A negative value keeps its sign.
data.Essence.Observe(function(essence) essenceLabel.Text = essence:Short()end)decimals defaults to 2 and rounds rather than truncates, so Short(0) on
1500 gives "2K". The full suffix table is in the
Big Numbers guide.
:ToNumber
Section titled “:ToNumber”BigValue:ToNumber() → numberThe value as a plain Luau number. Lossy on purpose: digits past the 53rd bit are
gone, and anything past 1.8e308 saturates to math.huge.
This is how you test a big against a constant, since < and == both need a
big on the other side:
if data.Essence.Get():ToNumber() >= price then data.Essence.Decrement(price)endA read, not a round trip. Writing the result back through the field rounds the balance to what a double can hold, which is the ceiling the field exists to escape.
Fields
Section titled “Fields”BigValue.M: numberThe mantissa: exactly 0, or in [1, 10) carrying the value’s sign and its ~15
significant digits. 1.5e100 has M = 1.5.
Read it, do not write it. Get builds a fresh object on every call, detached
from the stored form, so assigning to M changes a copy nothing will save.
BigValue.E: numberThe exponent: the exact integer part of the base-10 logarithm. 1.5e100 has
E = 100, and zero has E = 0. Use it rather than Log10 when you
need that integer exactly at any magnitude.
It caps at 2^52, the largest exponent the wire encoding can carry back, and a
value that would exceed it saturates there rather than storing an infinity the
save could not round-trip. Assigning to it is the same no-op as assigning to M.