Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

lcm

Returns the least common multiple (LCM) of two integers (a and b). For example, the LCM of 8 and 12 is 24, that is, lcm(8, 12) == 24. If any of the arguments is zero, then the returned value is 0.

lcm.lcm
pub fn lcm(a: anytype, b: anytype) @TypeOf(a, b)

File

lib/std/math/lcm.zig:7

Code

pub fn lcm(a: anytype, b: anytype) @TypeOf(a, b) {
    // Behavior from C++ and Python
    // If an argument is zero, then the returned value is 0.
    if (a == 0 or b == 0) return 0;
    return @abs(b) * (@abs(a) / std.math.gcd(@abs(a), @abs(b)));
}