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// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_CSTDLIB_DIV_HPP
5#define TETL_CSTDLIB_DIV_HPP
6
7#include <etl/_cstdint/intmax_t.hpp>
8
9namespace etl {
10
11/// Return type for div.
12struct div_t {
13 int quot;
14 int rem;
15};
16
17/// Return type for ldiv.
18struct ldiv_t {
19 long quot;
20 long rem;
21};
22
23/// Return type for lldiv.
24struct lldiv_t {
25 long long quot;
26 long long rem;
27};
28
29/// Return type for imaxdiv.
30struct imaxdiv_t {
31 intmax_t quot;
32 intmax_t rem;
33};
34
35/// Computes both the quotient and the remainder of the division of the
36/// numerator \p x by the denominator \p y. The quotient is the result of the
37/// expression `x/y`. The remainder is the result of the expression `x%y`.
38[[nodiscard]] constexpr auto div(int x, int y) noexcept -> div_t
39{
40 return {
41 .quot = x / y,
42 .rem = x % y,
43 };
44}
45
46/// Computes both the quotient and the remainder of the division of the
47/// numerator \p x by the denominator \p y. The quotient is the result of the
48/// expression `x/y`. The remainder is the result of the expression `x%y`.
49[[nodiscard]] constexpr auto div(long x, long y) noexcept -> ldiv_t
50{
51 return {
52 .quot = x / y,
53 .rem = x % y,
54 };
55}
56
57/// Computes both the quotient and the remainder of the division of the
58/// numerator \p x by the denominator \p y. The quotient is the result of the
59/// expression `x/y`. The remainder is the result of the expression `x%y`.
60[[nodiscard]] constexpr auto div(long long x, long long y) noexcept -> lldiv_t
61{
62 return {
63 .quot = x / y,
64 .rem = x % y,
65 };
66}
67
68/// Computes both the quotient and the remainder of the division of the
69/// numerator \p x by the denominator \p y. The quotient is the result of the
70/// expression `x/y`. The remainder is the result of the expression `x%y`.
71[[nodiscard]] constexpr auto ldiv(long x, long y) noexcept -> ldiv_t
72{
73 return {
74 .quot = x / y,
75 .rem = x % y,
76 };
77}
78
79/// Computes both the quotient and the remainder of the division of the
80/// numerator \p x by the denominator \p y. The quotient is the result of the
81/// expression `x/y`. The remainder is the result of the expression `x%y`.
82[[nodiscard]] constexpr auto lldiv(long long x, long long y) noexcept -> lldiv_t
83{
84 return {
85 .quot = x / y,
86 .rem = x % y,
87 };
88}
89
90/// Computes both the quotient and the remainder of the division of the
91/// numerator \p x by the denominator \p y. The quotient is the result of the
92/// expression `x/y`. The remainder is the result of the expression `x%y`.
93[[nodiscard]] constexpr auto imaxdiv(intmax_t x, intmax_t y) noexcept -> imaxdiv_t
94{
95 return {
96 .quot = x / y,
97 .rem = x % y,
98 };
99}
100
101} // namespace etl
102
103#endif // TETL_CSTDLIB_DIV_HPP
Definition adjacent_find.hpp:9
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:38
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:82
constexpr auto div(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:60
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:93
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:71
constexpr auto div(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:49
Return type for div.
Definition div.hpp:12
int rem
Definition div.hpp:14
int quot
Definition div.hpp:13
Return type for imaxdiv.
Definition div.hpp:30
intmax_t rem
Definition div.hpp:32
intmax_t quot
Definition div.hpp:31
Return type for ldiv.
Definition div.hpp:18
long rem
Definition div.hpp:20
long quot
Definition div.hpp:19
Return type for lldiv.
Definition div.hpp:24
long long quot
Definition div.hpp:25
long long rem
Definition div.hpp:26