Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.
C++ Boost

gcd_lcm - GCD and LCM

Introduction

detail/gcd_lcm.hpp provides two generic integer algorithms: greatest common divisor and least common multiple.

Synopsis

namespace details {
namespace pool {

template <typename Integer>
Integer gcd(Integer A, Integer B);

template <typename Integer>
Integer lcm(Integer A, Integer B);

} // namespace pool
} // namespace details

Semantics

Symbol Table
Symbol Meaning
Integer An integral type
A, B Values of type Integer

Semantics
Expression Result Type Precondition Notes
gcd(A, B) Integer A > 0 && B > 0 Returns the greatest common divisor of A and B
lcm(A, B) Integer A > 0 && B > 0 Returns the least common multiple of A and B

Implementation Notes

For faster results, ensure A > B

Dependencies

None.

Future Directions

This header may be replaced by a Boost algorithms library.


Valid HTML 4.01 Transitional

Revised 05 December, 2006

Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)