(n: i128)
| 22 | |
| 23 | #[plugin_fn] |
| 24 | fn 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] |