Skip to content

Instantly share code, notes, and snippets.

@Blockzez
Blockzez / hypot.lua
Last active July 8, 2022 00:36
Hypot function with semantics similar to C's math.h hypot.
-- Hypot function for Lua. Better semantics than (x^2+y^2)^.5 as this accounts for overflow and underflow.
-- For:
-- - Lua 3.1
-- - Lua 3.2
-- - Lua 4.0
-- - Lua 4.1
-- - Lua 5.0
-- - Lua 5.1
-- - Lua 5.2
-- - Lua 5.3
@Blockzez
Blockzez / FormatInteger.lua
Created April 26, 2020 21:35
Quick locale-unaware positive integer formatting for Roblox Lua
local suffix={'K','M','G','T','P','E','Z','Y'};function FormatInteger(n)return tostring(math.floor(n)):reverse():gsub('%d%d%d','%1 '):gsub(' $',''):reverse()end;function FormatCompactInteger(n)return((((n<1000)and(n)or math.floor(n/(1000^math.floor(math.log10(n)/3))*((math.log10(n)%3<1)and 10 or 1))/((math.log10(n)%3<1)and 10 or 1))..(suffix[math.floor(math.log10(n)/3)]or'')):gsub('[.]',','))end;