How to make this factorial function work with floats too?

This is what I currently have and it doesn’t really accept float values.

function maths.fact(n)
	if not n or math.floor(n) ~= n then warn("invalid input.") return end
		
	local f = 1
	
	for i = 1, n do
		f *= i
	end
	
	print(f)
end

If you want to take the factorial of a floating point you have to use the gamma function. Might be non trivial to implement and not worth it unless you have a convincing use case

2 Likes

I just posted something on devforum that I think might help
factorial function module

1 Like