tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
div.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_CSTDLIB_DIV_HPP
4#define TETL_CSTDLIB_DIV_HPP
5
7
8namespace etl {
9
11struct div_t {
12 int quot;
13 int rem;
14};
15
17struct ldiv_t {
18 long quot;
19 long rem;
20};
21
23struct lldiv_t {
24 long long quot;
25 long long rem;
26};
27
33
37[[nodiscard]] constexpr auto div(int x, int y) noexcept -> div_t
38{
39 return {
40 .quot = x / y,
41 .rem = x % y,
42 };
43}
44
48[[nodiscard]] constexpr auto div(long x, long y) noexcept -> ldiv_t
49{
50 return {
51 .quot = x / y,
52 .rem = x % y,
53 };
54}
55
59[[nodiscard]] constexpr auto div(long long x, long long y) noexcept -> lldiv_t
60{
61 return {
62 .quot = x / y,
63 .rem = x % y,
64 };
65}
66
70[[nodiscard]] constexpr auto ldiv(long x, long y) noexcept -> ldiv_t
71{
72 return {
73 .quot = x / y,
74 .rem = x % y,
75 };
76}
77
81[[nodiscard]] constexpr auto lldiv(long long x, long long y) noexcept -> lldiv_t
82{
83 return {
84 .quot = x / y,
85 .rem = x % y,
86 };
87}
88
92[[nodiscard]] constexpr auto imaxdiv(intmax_t x, intmax_t y) noexcept -> imaxdiv_t
93{
94 return {
95 .quot = x / y,
96 .rem = x % y,
97 };
98}
99
100} // namespace etl
101
102#endif // TETL_CSTDLIB_DIV_HPP
Definition adjacent_find.hpp:8
constexpr auto div(int x, int y) noexcept -> div_t
Computes both the quotient and the remainder of the division of the numerator x by the denominator y....
Definition div.hpp:37
constexpr auto lldiv(long long x, long long y) noexcept -> lldiv_t
Computes both the quotient and the remainder of the division of the numerator x by the denominator y....
Definition div.hpp:81
TETL_BUILTIN_INTMAX intmax_t
Maximum-width signed integer type.
Definition intmax_t.hpp:11
constexpr auto imaxdiv(intmax_t x, intmax_t y) noexcept -> imaxdiv_t
Computes both the quotient and the remainder of the division of the numerator x by the denominator y....
Definition div.hpp:92
constexpr auto ldiv(long x, long y) noexcept -> ldiv_t
Computes both the quotient and the remainder of the division of the numerator x by the denominator y....
Definition div.hpp:70
Return type for div.
Definition div.hpp:11
int rem
Definition div.hpp:13
int quot
Definition div.hpp:12
Return type for imaxdiv.
Definition div.hpp:29
intmax_t rem
Definition div.hpp:31
intmax_t quot
Definition div.hpp:30
Return type for ldiv.
Definition div.hpp:17
long rem
Definition div.hpp:19
long quot
Definition div.hpp:18
Return type for lldiv.
Definition div.hpp:23
long long quot
Definition div.hpp:24
long long rem
Definition div.hpp:25