(nums: Args)
| 46 | // Variadic lcm, matching `math.lcm(*integers)`; `lcm()` is 1, any zero yields 0. |
| 47 | #[plugin_fn] |
| 48 | fn 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] |
| 60 | fn isqrt(n: i128) -> Result<i128> { |