Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make this factorial function work with floats too?

Asked by 3 years ago

This is what I currently have.

function maths.fact(n)
    if not n then warn("invalid input.") return end

    local f = 1

    for i = 1, n do
        f *= i
    end

    print(f)
end
1
what do you mean by work with floats? do you want a factorial of a fractional number? you can check here. https://math.stackexchange.com/questions/454053/how-do-we-calculate-factorials-for-numbers-with-decimal-places Speedmask 661 — 3y
1
Factorials: 1 * 2 * 3 ... * n, this means that decimals can't be factorials. They do however exist as gamma functions which I haven't learned yet.. There are a bit of sources that can guide you, can I ask why you need it to work with floats? greatneil80 2647 — 3y

Answer this question