tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
lcm.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3#ifndef TETL_NUMERIC_LCM_HPP
4#define TETL_NUMERIC_LCM_HPP
5
6#include <etl/_numeric/gcd.hpp>
7#include <etl/_type_traits/common_type.hpp>
8#include <etl/_type_traits/is_integral.hpp>
9#include <etl/_type_traits/is_same.hpp>
10
11namespace etl {
12
13/// \brief Computes the least common multiple of the integers m and n.
14///
15/// \returns If either m or n is zero, returns zero. Otherwise, returns the
16/// least common multiple of |m| and |n|.
17///
18/// \ingroup numeric
19template <typename M, typename N>
20 requires(is_integral_v<M> and not is_same_v<M, bool> and is_integral_v<N> and not is_same_v<N, bool>)
21[[nodiscard]] constexpr auto lcm(M m, N n) -> common_type_t<M, N>
22{
23 return (m * n) / gcd(m, n);
24}
25
26} // namespace etl
27
28#endif // TETL_NUMERIC_LCM_HPP
constexpr auto lcm(M m, N n) -> common_type_t< M, N >
Computes the least common multiple of the integers m and n.
Definition lcm.hpp:21
Definition adjacent_find.hpp:9