diff --git a/lua/entities/gmod_wire_expression2/core/number.lua b/lua/entities/gmod_wire_expression2/core/number.lua index eff2e312..82aee7c3 100644 --- a/lua/entities/gmod_wire_expression2/core/number.lua +++ b/lua/entities/gmod_wire_expression2/core/number.lua @@ -303,6 +303,18 @@ end --[[************************************************************************]]-- +__e2setcost(10) + +[nodiscard] +e2function number factorial(number n) + if n < 0 then return 0 / 0 end + if n > 170 then return math.huge end + + local res = 1 + for i = 2, n do res = res * i end + return res +end + __e2setcost(2) -- approximation [nodiscard] diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index d0093edf..d2a153fd 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -54,6 +54,7 @@ E2Helper.Descriptions["isinf(n)"] = "Returns 1 if given value is a positive infi E2Helper.Descriptions["isnan(n)"] = "Returns 1 if given value is not a number (NaN); otherwise 0." E2Helper.Descriptions["inf()"] = "Returns a huge constant (infinity)" E2Helper.Descriptions["mod(nn)"] = "Modulo, returns the Remainder after Argument 1 has been divided by Argument 2. Note \"mod(-1, 3) = -1\"" +E2Helper.Descriptions["factorial(n)"] = "Returns the Factorial of the Argument" E2Helper.Descriptions["sqrt(n)"] = "Returns the Square Root of the Argument" E2Helper.Descriptions["cbrt(n)"] = "Returns the Cube Root of the Argument" E2Helper.Descriptions["root(nn)"] = "Returns the Nth Root of the first Argument"