1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // Assumption: minValue < maxValue
11 // Assumption: minValue <= rhs <= maxValue
12 // Assumption: minValue <= lhs <= maxValue
13 // Assumption: minValue >= 0
14 template <typename T
, T minValue
, T maxValue
>
15 constexpr T
euclidian_addition(T rhs
, T lhs
) {
16 const T modulus
= maxValue
- minValue
+ 1;
23 // Assumption: minValue < maxValue
24 // Assumption: minValue <= rhs <= maxValue
25 // Assumption: minValue <= lhs <= maxValue
26 // Assumption: minValue >= 0
27 template <typename T
, T minValue
, T maxValue
>
28 constexpr T
euclidian_subtraction(T lhs
, T rhs
) {
29 const T modulus
= maxValue
- minValue
+ 1;
33 if (ret
> maxValue
) // this can happen if T is unsigned