User:Merlin11188/Math.huge

From Legacy Roblox Wiki
Jump to navigationJump to search

math.huge is any number greater than or equal to 2 to the power of 1024 minus 1, which can be represented in Lua by math.huge >= 2^1024 - 1 and maintains the standard form of:

179,769,313,486,231,590,772,930,519,078,902,473,361,797,697,894,230,657,273,430,081,157,732,675,805,500,963,132,708,477,322, 407,536,021,120,113,879,871,393,357,658,789,768,814,416,622,492,847,430,639,474,124,377,767,893,424,865,485,276,302,219,601, 246,094,119,453,082,952,085,005,768,838,150,682,342,462,881,473,913,110,540,827,237,163,350,510,684,586,298,239,947,245,938, 479,716,304,835,356,329,624,224,137,215

Of course, Lua only allows numbers to go so far out, so there's no way to do a direct comparison, but this should give you the right idea:

print(2^1023.9999999999999 >= math.huge)
print(2^1024 >= math.huge)

false

true

This is the source code of the Lua code I used to compute 2^1024. It also computes the powers of 2 from 1 to 20,000 in 76 seconds. Lua is powerful. Anyway, here it is:

local powersOfTwo = setmetatable({"2"}, {__index = function(t, j)
	local function multiplyStringBy2(aString)
		local carryOver = 0
		local charArray = {}
		for i = #aString, 1, -1 do
			local current = aString:sub(i, i)
			local num = tonumber(current) * 2 + carryOver
			charArray[#charArray + 1] = ((num < 10 or i == 1) and num) or (num >= 10 and num % 10)
			carryOver = num < 10 and 0 or 1
		end
		local temp = {}
		for i = #charArray, 1, -1 do
			temp[#temp + 1] = charArray[i]
		end
		return table.concat(temp)
	end
	for i = #t, j - 1 do
		t[i + 1] = multiplyStringBy2(t[i])
	end
	return t[j]
end, __call = function(t, j)
	return t[j]
end})