Skip to main content

Getting Started

1) Install

Add HugeNumbersFormatter to your wally.toml:

[dependencies]
HugeNumbersFormatter = "NotSimo26/HugeNumbersFormatter@version"

Then run:

wally install

2) Usage

Simply require the module:

local HugeNumbersFormatter = require(path.to.HugeNumberFormatter)

The module supports strict notation, you can get the ScientificNotation type like this:

(You may have to run wally-package-types if you're using wally)

type ScientificNotation = HugeNumberFormatter.ScientificNotation

3) Use Examples

Creating and converting numbers:

local myN = HugeNumbersFormatter.FromNumber(1000)
-- {mantissa = 1, exponent = 3, sign = true}

HugeNumbersFormatter.ToNumber(myN) -- should be 1000

Setting values:

local myN = {
mantissa = 1,
exponent = 3,
sign = true
} :: ScientificNotation

HugeNumbersFormatter.SetMantissa(myN, 5) -- myN.mantissa is now 5
HugeNumbersFormatter.SetExponent(myN, 6) -- myN.exponent is now 6
HugeNumbersFormatter.SetSign(myN, false) -- myN.sign is now false

Checking the sign, and negating:

local myN = {
mantissa = 1,
exponent = 3,
sign = false
} :: ScientificNotation

HugeNumbersFormatter.IsNegative(myN) -- should be true

HugeNumbersFormatter.Negate(myN) -- should be {mantissa = 1, exponent = 3, sign = true}

Formatting:

local myN = {
mantissa = 1,
exponent = 6,
sign = true
} :: ScientificNotation
HugeNumbersFormatter.GetFullScientific(myN) -- should be "1e6"
HugeNumbersFormatter.GetFullConway(myN) -- should be "1 million"
HugeNumbersFormatter.GetFullConwayShort(myN) -- should be "1 M"

Operations:

local myN = {
mantissa = 1,
exponent = 3,
sign = true
} :: ScientificNotation

HugeNumbersFormatter.Add(myN, 5000) -- should be {mantissa = 6, exponent = 3, sign = true}
HugeNumbersFormatter.Subtract(myN, 500) -- should be {mantissa = 5, exponent = 2, sign = true}
HugeNumbersFormatter.Multiply(myN, 2) -- should be {mantissa = 2, exponent = 3, sign = true}
HugeNumbersFormatter.Divide(myN, 2) -- should be {mantissa = 5, exponent = 2, sign = true}

Operations also accept another ScientificNotation instead of a plain number:

local myN = HugeNumbersFormatter.FromNumber(1000)
local other = HugeNumbersFormatter.FromNumber(500)

HugeNumbersFormatter.Add(myN, other) -- should be {mantissa = 1, exponent = 3, sign = true} (equiv. to 1500)

More info