For factorial calculations, when the value is greater than Double(Int.largestSupportedIntegerFactorial) but less than Double(Int.max), the current implementation uses a direct for-loop, which can cause the process to hang for large numbers.
It would be better to return infinity directly for values ≥ 172.