Skip to content

Commit

Permalink
Factorial function micro-optimization (#3258)
Browse files Browse the repository at this point in the history
* Factorial function micro-optimization

* Formatting
  • Loading branch information
Astralcircle authored Feb 3, 2025
1 parent e39a632 commit a667672
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lua/entities/gmod_wire_expression2/core/number.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local abs = math.abs
local random = math.random
local pi = math.pi
local inf = math.huge
local nan = 0 / 0

local exp = math.exp
local frexp = math.frexp
Expand Down Expand Up @@ -307,8 +308,8 @@ __e2setcost(10)

[nodiscard]
e2function number factorial(number n)
if n < 0 then return 0 / 0 end
if n > 170 then return math.huge end
if n < 0 then return nan end
if n > 170 then return inf end

local res = 1
for i = 2, n do res = res * i end
Expand Down

0 comments on commit a667672

Please sign in to comment.