*This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TS status.*

### 2792. [fund.ts.v2] `gcd` and `lcm` should support a wider range of input values

**Section:** 13.1.2 [fund.ts.v2::numeric.ops.gcd], 13.1.3 [fund.ts.v2::numeric.ops.lcm] **Status:** TS
**Submitter:** Marshall Clow **Opened:** 2016-11-09 **Last modified:** 2017-07-30

**Priority: **Not Prioritized

**View all other** issues in [fund.ts.v2::numeric.ops.gcd].

**View all issues with** TS status.

**Discussion:**

**Addresses fund.ts.v2: JP 010, JP 011**

By the current definition, `gcd((int64_t)1234, (int32_t)-2147483648)` is
ill-formed (because `2147483648` is not representable as a value of `int32_t`.)
We want to change this case to be well-formed. As long as both `|m|` and `|n|`
are representable as values of the common type, absolute values can
be calculate `d` without causing unspecified behavior, by converting `m` and `n`
to the common type before taking the negation.

Suggested resolution:

`|m|` shall be representable as a value of type `M` and `|n|` shall
be representable as a value of type `N``|m|` and `|n|` shall be
representable as a value of `common_type_t<M, N>`.

*[Issues Telecon 16-Dec-2016]*

Resolved by N4616

**Proposed resolution:**

This wording is relative to N4600.

Edit 13.1.2 [fund.ts.v2::numeric.ops.gcd] as indicated:

template<class M, class N>
constexpr common_type_t<M, N> gcd(M m, N n);

-2- *Requires:* `|m|` shall be representable as a value of type `M` and `|n|` shall
be representable as a value of type `N``|m|` and `|n|` shall be representable as
a value of `common_type_t<M, N>`. [*Note:* These requirements ensure, for example, that
`gcd(m, m) = |m|` is representable as a value of type `M`. — *end note*]

Edit 13.1.3 [fund.ts.v2::numeric.ops.lcm] as indicated:

template<class M, class N>
constexpr common_type_t<M, N> lcm(M m, N n);

-2- *Requires:* `|m|` shall be representable as a value of type `M` and `|n|` shall
be representable as a value of type `N``|m|` and `|n|` shall be representable as
a value of `common_type_t<M, N>`. The least common multiple of `|m|` and `|n|` shall
be representable as a value of type `common_type_t<M, N>`.