summaryrefslogtreecommitdiff
path: root/src/check.hh
blob: 91c1717157ad2dbcb3199ca67ced6a7bc6cbd3e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef CHECK_HH
#define CHECK_HH

#include <cstdlib>
#include <stdckdint.h>
#include <type_traits>

namespace check {

template <typename T>
  requires std::is_arithmetic_v<T>
T add(T a, T b) {
  T ret;
  if (ckd_add(&ret, a, b))
    abort();
  return ret;
}

template <typename T>
  requires std::is_arithmetic_v<T>
T sub(T a, T b) {
  T ret;
  if (ckd_sub(&ret, a, b))
    abort();
  return ret;
}

template <typename T>
  requires std::is_arithmetic_v<T>
T mul(T a, T b) {
  T ret;
  if (ckd_mul(&ret, a, b))
    abort();
  return ret;
}

}  // namespace check

#endif  // CHECK_HH