tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
ratio.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_RATIO_RATIO_HPP
4#define TETL_RATIO_RATIO_HPP
5
7#include <etl/_math/abs.hpp>
8#include <etl/_math/sign.hpp>
10
11namespace etl {
12
15
20template <intmax_t Num, intmax_t Denom = 1>
21struct ratio {
22 static constexpr intmax_t num = detail::sign(Num) * detail::sign(Denom) * abs(Num) / gcd(Num, Denom);
23 static constexpr intmax_t den = abs(Denom) / gcd(Num, Denom);
24
26};
27
28using atto = ratio<1, 1'000'000'000'000'000'000>;
29using femto = ratio<1, 1'000'000'000'000'000>;
30using pico = ratio<1, 1'000'000'000'000>;
31using nano = ratio<1, 1'000'000'000>;
32using micro = ratio<1, 1'000'000>;
33using milli = ratio<1, 1'000>;
38using kilo = ratio<1'000, 1>;
39using mega = ratio<1'000'000, 1>;
40using giga = ratio<1'000'000'000, 1>;
41using tera = ratio<1'000'000'000'000, 1>;
42using peta = ratio<1'000'000'000'000'000, 1>;
43using exa = ratio<1'000'000'000'000'000'000, 1>;
44
46
47} // namespace etl
48
49#endif // TETL_RATIO_RATIO_HPP
constexpr auto abs(complex< T > const &z) -> T
Definition abs.hpp:13
constexpr auto gcd(M m, N n) noexcept -> etl::common_type_t< M, N >
Computes the greatest common divisor of the integers m and n.
Definition gcd.hpp:16
Definition adjacent_find.hpp:8
ratio< 1, 100 > centi
Definition ratio.hpp:34
ratio< 1 '000, 1 > kilo
Definition ratio.hpp:38
ratio< 1, 1 '000 '000 '000 > nano
Definition ratio.hpp:31
ratio< 1, 1 '000 '000 '000 '000 > pico
Definition ratio.hpp:30
ratio< 1, 10 > deci
Definition ratio.hpp:35
ratio< 1, 1 '000 '000 '000 '000 '000 > femto
Definition ratio.hpp:29
TETL_BUILTIN_INTMAX intmax_t
Maximum-width signed integer type.
Definition intmax_t.hpp:11
ratio< 1 '000 '000, 1 > mega
Definition ratio.hpp:39
ratio< 1 '000 '000 '000 '000 '000, 1 > peta
Definition ratio.hpp:42
ratio< 1 '000 '000 '000, 1 > giga
Definition ratio.hpp:40
ratio< 1 '000 '000 '000 '000 '000 '000, 1 > exa
Definition ratio.hpp:43
ratio< 1, 1 '000 > milli
Definition ratio.hpp:33
ratio< 1 '000 '000 '000 '000, 1 > tera
Definition ratio.hpp:41
ratio< 1, 1 '000 '000 '000 '000 '000 '000 > atto
Definition ratio.hpp:28
ratio< 10, 1 > deca
Definition ratio.hpp:36
ratio< 100, 1 > hecto
Definition ratio.hpp:37
ratio< 1, 1 '000 '000 > micro
Definition ratio.hpp:32
The typename template provides compile-time rational arithmetic support. Each instantiation of this t...
Definition ratio.hpp:21
static constexpr intmax_t den
Definition ratio.hpp:23
static constexpr intmax_t num
Definition ratio.hpp:22
ratio< num, den > type
Definition ratio.hpp:25