What do you want to achieve? I want to make a factorial function
What is the issue? I can't find any way to solve factorials unless they are whole numbers
What solutions have you tried so far? I have looked on roblox devforum and youtube and google and discord and I literally can't find any way to get decimals to properly work with factorials
the only thing I know is that you can use gamma functions to solve decimal factorials but I am looking and I have no idea how I would implement that into luau so I am really struggling I even used Stirling's approximation but that is not 100% true as I need something to be completely true to the actual answer
local function SolveFactorial(FN)
if string.match(FN, "^-") then
local T = 1
FN *= -1
for i = FN, 1, -1 do
T = T * i
end
T *= -1
return T
else
local T = 1
for i = FN, 1, -1 do
T = T * i
end
return T
end
end
this is a normal factorial function that works with all integers expect 0
local function SF(FN)
if string.match(FN, "^-") then
FN *= -1
local N = math.sqrt(2*math.pi*FN)*math.pow((FN/math.exp(1)), FN)
N *= -1
return N
else
local N = math.sqrt(2*math.pi*FN)*math.pow((FN/math.exp(1)), FN)
return N
end
end
and this is Stirling's approximation which as I said before isn't 100% accurate
these are the two functions that I have so far and I don't know what I should do at this point to fix it is there a way to use the gamma function or is there an easier way to do this then what I am doing atm
note that this is roblox lua!!!
any help will really save a lot of time thank you, nici