std::experimental::lcm(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::experimental::lcm πŸ’–

🌸 NAME 🌸

okay so this page lives in the C++ Standard Libary manual (yes, β€œLibary” β€” that’s literally how the header spells it, and we are not editing the header, bestie πŸ’…), and the name is exactly:

std::experimental::lcm - std::experimental::lcm

like, that’s the whole name. no extra subtitle. it ate and left no crumbs. ✨


✨ Synopsis ✨

Defined in header <experimental/numeric>:

template< class M, class N >                         (library
fundamentals TS v2)
constexpr std::common_type_t<M, N> lcm( M m, N n );

this bad boy computes the least common multiple of the integers m and n. it’s giving math but make it constexpr. 🧚

πŸŽ€ Parameters πŸŽ€

  • m, n β€” integer values. that’s the whole vibe. πŸ“

πŸ’– Return value πŸ’–

okay so here’s the tea:

  • If either m or n is zero, it returns zero. periodt. πŸ’€
  • Otherwise, it returns the least common multiple of |m| and |n|. slay. πŸ”₯

Remarks

  • If either M or N is not an integer type, or if either is (possibly cv-qualified) bool, the program is ill-formed. 🚨
  • The behavior is undefined if |m|, |n|, or the least common multiple of |m| and |n| is not representable as a value of type std::common_type_t<M, N>. no cap, that’s undefined behavior, so don’t play with it. 😭

πŸ¦‹ Exceptions πŸ¦‹

Throws no exceptions. not a single one. iconic. 🫢

🌈 See also 🌈

  • gcd β€” constexpr function template returning the greatest common divisor of two integers (function template). bestie behavior. πŸ’œ

source vibe check: http://cppreference.com, dated 2024.06.10. mwah πŸ’‹

πŸ“¦ where this page comes from