MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / factorial

Function factorial

std/math/src/main/int.rs:24–33  ·  view source on GitHub ↗
(n: i128)

Source from the content-addressed store, hash-verified

22
23#[plugin_fn]
24fn factorial(n: i128) -> Result<i128> {
25 if n < 0 { return Err(Error::Value(String::from("factorial() not defined for negative values"))); }
26 let mut acc: i128 = 1;
27 let mut k: i128 = 2;
28 while k <= n {
29 acc = acc.checked_mul(k).ok_or_else(|| too_large("factorial"))?;
30 k += 1;
31 }
32 Ok(acc)
33}
34
35// Variadic gcd, matching `math.gcd(*integers)`; `gcd()` is 0.
36#[plugin_fn]

Callers

nothing calls this directly

Calls 2

too_largeFunction · 0.85
ValueEnum · 0.50

Tested by

no test coverage detected