-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathratios.cppm
80 lines (71 loc) · 2.44 KB
/
ratios.cppm
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* @brief Definitions for representing the different
* order or magnitudes in a physical quantity
*/
export module physics.quantities:ratios;
import math;
import std;
/**
* @brief Represents a power that can be used as a ratio.
*
* This struct template represents a mathematical power, where the base is an integral number,
* and the exponent is an integer. It's designed to be used as a ratio in the context of units
* of measure, where the power describes how a certain quantity is measured relative to a
* reference unit.
*
* @tparam Base The integral base of the power.
* @tparam Exponent The integer exponent of the power.
* @tparam BaseDenominator The denominator of the base, which can be used to represent fractional
* powers. By default, this is set to 1, indicating an integer base.
*/
template <typename T>
concept RatioV = (std::is_integral_v<T> || std::is_floating_point_v<T>)
&& !std::is_same_v<T, char>;
/**
* Represents a power that will serve as a ratio for compare quantities
* with the same dimension
* @tparam Base
* @tparam Exponent
* @tparam BaseDenominator
*/
template <int Base = 10, int Exponent = 0, int BaseDenominator = 1>
struct ratio {
static constexpr double base = static_cast<double>(Base);
static constexpr double exponent = static_cast<double>(Exponent);
static constexpr double base_denominator = static_cast<double>(BaseDenominator);
static constexpr double value = zero::math::power_of(base, exponent);
};
export namespace zero::physics {
using unit_r = ratio<1, 1>;
using yocto = ratio<10, -24>;
using zepto = ratio<10, -21>;
using atto = ratio<10, -18>;
using femto = ratio<10, -15>;
using pico = ratio<10, -12>;
using nano = ratio<10, -9>;
using micro = ratio<10, -6>;
using milli = ratio<10, -3>;
using centi = ratio<10, -2>;
using deci = ratio<10, -1>;
using root = ratio<10, 0>;
using deca = ratio<10, 1>;
using hecto = ratio<10, 2>;
using kilo = ratio<10, 3>;
using mega = ratio<10, 6>;
using giga = ratio<10, 9>;
using tera = ratio<10, 12>;
using peta = ratio<10, 15>;
using exa = ratio<10, 18>;
using zetta = ratio<10, 21>;
using yotta = ratio<10, 24>;
using second = ratio<60, 0>;
using minute = ratio<60, 1>;
using hour = ratio<60, 2>;
using day = ratio<24, 1, 3600>;
template <typename T>
concept Ratio = requires {
T::base;
T::exponent;
T::value;
};
}