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

Function lcm

std/math/src/main/int.rs:48–57  ·  view source on GitHub ↗
(nums: Args)

Source from the content-addressed store, hash-verified

46// Variadic lcm, matching `math.lcm(*integers)`; `lcm()` is 1, any zero yields 0.
47#[plugin_fn]
48fn lcm(nums: Args) -> Result<i128> {
49 let mut l: i128 = 1;
50 for h in &nums.0 {
51 let n = i128::from_handle(h.raw())?.abs();
52 if n == 0 { return Ok(0); }
53 let g = gcd2(l, n);
54 l = (l / g).checked_mul(n).ok_or_else(|| too_large("lcm"))?;
55 }
56 Ok(l)
57}
58
59#[plugin_fn]
60fn isqrt(n: i128) -> Result<i128> {

Callers

nothing calls this directly

Calls 3

gcd2Function · 0.85
too_largeFunction · 0.85
rawMethod · 0.45

Tested by

no test coverage detected