mirror of
https://github.com/wiremod/wire.git
synced 2025-03-04 03:03:04 -05:00
``factorial(n)
`` function (#3253)
* factorial(n) function * Use local function * Woops * Return NaN if the number is less than 0 * Update function Co-authored-by: thegrb93 <grbrown93@sbcglobal.net> --------- Co-authored-by: thegrb93 <grbrown93@sbcglobal.net>
This commit is contained in:
parent
158ec276c6
commit
c75ee43ff1
@ -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]
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user