Skip to content

Commit

Permalink
Fixed negative comparison, adds :SetValue, fixed ConvertFromLeaderboa…
Browse files Browse the repository at this point in the history
…rd error, fixed aaNotation
  • Loading branch information
KdudeDev authored Jan 10, 2024
1 parent 3e02db6 commit d182e52
Showing 1 changed file with 46 additions and 3 deletions.
49 changes: 46 additions & 3 deletions src/InfiniteMath/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ function Number.__lt(a, b)
a, b = checkNumber(a), checkNumber(b)
local first1, second1 = fixNumber(a.first, a.second)
local first2, second2 = fixNumber(b.first, b.second)


second1 *= math.sign(first1)
second2 *= math.sign(second2)

if second1 == second2 then
return first1 < first2
end
Expand All @@ -317,6 +320,9 @@ function Number.__le(a, b)
a, b = checkNumber(a), checkNumber(b)
local first1, second1 = fixNumber(a.first, a.second)
local first2, second2 = fixNumber(b.first, b.second)

second1 *= math.sign(first1)
second2 *= math.sign(second2)

if second1 == second2 then
return first1 <= first2
Expand Down Expand Up @@ -397,6 +403,37 @@ function InfiniteMath.new(val : number | string | {} | Number) : Number
}, Number)
end

--[=[
@within Number
Sets the value of the constructed number without creating a new Number metatable. If you want to set the value of a constructed number it is better to use this than setting it to a new `.new()`.
`SetValue` takes a new `first` and `second` to set the value to, if you want to set the value to `100` you must pass `1, 3`.
```lua
local Number = InfiniteMath.new(1000)
print(Number) -- 1000
Number:SetValue(5, 4)
print(Number) -- 5000
```
@method SetValue
@param newFirst number
@param newSecond number
@return number
]=]

function Number:SetValue(newFirst, newSecond)
if type(newFirst) ~= "number" and type(newSecond) ~= "number" then
error('Both parameters of SetValue must be "number"')
end

newFirst, newSecond = fixNumber(newFirst, newSecond)

self.first = newFirst
self.second = newSecond
end

--[=[
@within Number
Expand Down Expand Up @@ -607,12 +644,12 @@ function Number:aaNotation()
local secondUnit = unitInt % 26
local firstUnit = math.ceil(unitInt / 26)

if firstUnit > 26 or secondUnit == 0 then
if firstUnit > 26 then
return self:ScientificNotation()
end

local str = math.floor(first * 10^InfiniteMath.DECIMALPOINTS)/10^InfiniteMath.DECIMALPOINTS -- The * 10 / 10 controls decimal precision, more zeros = more decimals
local unit = Alphabet[firstUnit]..Alphabet[secondUnit]
local unit = Alphabet[firstUnit]..(Alphabet[secondUnit] or Alphabet[26])

return str..unit
end
Expand Down Expand Up @@ -655,6 +692,11 @@ end
]=]

function InfiniteMath:ConvertFromLeaderboards(GivenNumber)
--return 0
if GivenNumber == 0 then
return InfiniteMath.new(0)
end

GivenNumber /= LEADERBOARDPRECISION

local numbers = tostring(GivenNumber):split('.')
Expand Down Expand Up @@ -849,6 +891,7 @@ function InfiniteMath.max(...)
return Max
end


--[=[
@within InfiniteMath
Expand Down

0 comments on commit d182e52

Please sign in to comment.