Function `fact(x)` can potentially take a long time to execute for very large `x`
James103 opened this issue ยท 0 comments
As of Carpet mod commit 47c8484, the function fact(x)
can take a long time to execute for vary large values of x
. This is because the function loops through all numbers from 1 to x, multiplying them through, even though fact(x) == Infinity
for x > 170
due to the Java double limit.
fabric-carpet/src/main/java/carpet/script/language/Arithmetic.java
Lines 34 to 37 in 47c8484
To solve this, the function should check if its input exceeds the value 170, or alternatively if the factorial
variable in the loop goes infinite, and if so, return Infinity immediately.