View source code
Display the source code in std/numeric.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Function std.numeric.lcm

Computes the least common multiple of a and b. Arguments are the same as gcd.

typeof(Unqual!T.init%Unqual!U.init) lcm(T, U) (
  T a,
  U b
if (isIntegral!T && isIntegral!U);

auto lcm(T) (
  T a,
  T b
if (!isIntegral!T && is(typeof(T.init % T.init)) && is(typeof(T.init == 0 || T.init > 0)));


The least common multiple of the given arguments.


writeln(lcm(1, 2)); // 2
writeln(lcm(3, 4)); // 12
writeln(lcm(5, 6)); // 30


Andrei Alexandrescu, Don Clugston, Robert Jacques, Ilya Yaroshenko


Boost License 1.0.