MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / factorial

Function factorial

test/big-decimal/precision-comparison.test.ts:47–51  ·  view source on GitHub ↗

* Compute factorial as a BigDecimal string.

(n: number)

Source from the content-addressed store, hash-verified

45 * Compute factorial as a BigDecimal string.
46 */
47function factorial(n: number): string {
48 let result = 1n;
49 for (let i = 2; i <= n; i++) result *= BigInt(i);
50 return result.toString();
51}
52
53function withPrecision<T>(prec: number, fn: () => T): T {
54 const savedBD = BigDecimal.precision;

Callers 1

Calls 1

toStringMethod · 0.65

Tested by

no test coverage detected