Go to the documentation of this file.
9 #ifndef EAGINE_UNITS_SCALES_HPP
10 #define EAGINE_UNITS_SCALES_HPP
12 #include "../math/constants.hpp"
13 #include "../nothing.hpp"
17 EAGINE_DIAG_OFF(
double-promotion)
20 namespace eagine::units {
29 using scale_of_t =
typename scale_of<X>::type;
35 static constexpr
auto to_base(T v) {
40 static constexpr
auto from_base(T v) {
46 struct scale_of<nothing_t> : one {};
50 using type = constant;
53 static constexpr
auto to_base(T v) {
58 static constexpr
auto from_base(T v) {
63 template <
int Num,
int Den>
65 using type = rational;
68 static constexpr
auto to_base(T v) {
69 return (v * Num) / float(Den);
73 static constexpr
auto from_base(T v) {
74 return (v * Den) / float(Num);
78 template <
int X,
int Y>
83 static constexpr
auto to_base(T v) {
89 static constexpr
auto from_base(T v) {
97 using type = inverted;
100 static constexpr
auto to_base(T v) {
101 return S::from_base(v);
104 template <
typename T>
105 static constexpr
auto from_base(T v) {
106 return S::to_base(v);
110 template <
typename S1,
typename S2>
112 using type = multiplied;
114 template <
typename T>
115 static constexpr
auto to_base(T v) {
116 return S2::to_base(S1::to_base(v));
119 template <
typename T>
120 static constexpr
auto from_base(T v) {
121 return S2::from_base(S1::from_base(v));
125 template <
typename S1,
typename S2>
127 using type = divided;
129 template <
typename T>
130 static constexpr
auto to_base(T v) {
131 return S2::from_base(S1::to_base(v));
134 template <
typename T>
135 static constexpr
auto from_base(T v) {
136 return S2::to_base(S1::from_base(v));
140 template <
typename S1,
typename S2>
141 struct recombined : multiplied<S1, S2> {
142 using type = recombined;
146 using nano = power<1000, -3>;
148 using micro = power<1000, -2>;
150 using milli = power<1000, -1>;
152 using centi = power<10, -2>;
154 using deci = power<10, -1>;
156 using deca = power<10, 1>;
158 using hecto = power<10, 2>;
160 using kilo = power<1000, 1>;
162 using mega = power<1000, 2>;
164 using giga = power<1000, 3>;
166 using tera = power<1000, 4>;
168 using kibi = power<1024, 1>;
170 using mebi = power<1024, 2>;
172 using gibi = power<1024, 3>;
174 using tebi = power<1024, 4>;
179 template <
typename T>
180 static constexpr
auto to_base(T v) {
184 template <
typename T>
185 static constexpr
auto from_base(T v) {
193 struct name_of<scales::one> {
194 static constexpr
const char mp_str[] =
"";
197 struct symbol_of<scales::one> {
198 static constexpr
const char mp_str[] =
"";
202 struct name_of<scales::nano> {
203 static constexpr
const char mp_str[] =
"nano";
206 struct symbol_of<scales::nano> {
207 static constexpr
const char mp_str[] =
"n";
211 struct name_of<scales::micro> {
212 static constexpr
const char mp_str[] =
"micro";
215 struct symbol_of<scales::micro> {
216 static constexpr
const char mp_str[3] = {char(0xCE), char(0xBC),
'\0'};
220 struct name_of<scales::milli> {
221 static constexpr
const char mp_str[] =
"milli";
224 struct symbol_of<scales::milli> {
225 static constexpr
const char mp_str[] =
"m";
229 struct name_of<scales::centi> {
230 static constexpr
const char mp_str[] =
"centi";
233 struct symbol_of<scales::centi> {
234 static constexpr
const char mp_str[] =
"c";
238 struct name_of<scales::deci> {
239 static constexpr
const char mp_str[] =
"deci";
242 struct symbol_of<scales::deci> {
243 static constexpr
const char mp_str[] =
"d";
247 struct name_of<scales::deca> {
248 static constexpr
const char mp_str[] =
"deca";
251 struct symbol_of<scales::deca> {
252 static constexpr
const char mp_str[] =
"dc";
256 struct name_of<scales::hecto> {
257 static constexpr
const char mp_str[] =
"hecto";
260 struct symbol_of<scales::hecto> {
261 static constexpr
const char mp_str[] =
"h";
265 struct name_of<scales::kilo> {
266 static constexpr
const char mp_str[] =
"kilo";
269 struct symbol_of<scales::kilo> {
270 static constexpr
const char mp_str[] =
"k";
274 struct name_of<scales::mega> {
275 static constexpr
const char mp_str[] =
"mega";
278 struct symbol_of<scales::mega> {
279 static constexpr
const char mp_str[] =
"M";
283 struct name_of<scales::giga> {
284 static constexpr
const char mp_str[] =
"giga";
287 struct symbol_of<scales::giga> {
288 static constexpr
const char mp_str[] =
"G";
292 struct name_of<scales::tera> {
293 static constexpr
const char mp_str[] =
"tera";
296 struct symbol_of<scales::tera> {
297 static constexpr
const char mp_str[] =
"T";
301 struct name_of<scales::kibi> {
302 static constexpr
const char mp_str[] =
"kibi";
305 struct symbol_of<scales::kibi> {
306 static constexpr
const char mp_str[] =
"Ki";
310 struct name_of<scales::mebi> {
311 static constexpr
const char mp_str[] =
"mebi";
314 struct symbol_of<scales::mebi> {
315 static constexpr
const char mp_str[] =
"Mi";
319 struct name_of<scales::gibi> {
320 static constexpr
const char mp_str[] =
"gibi";
323 struct symbol_of<scales::gibi> {
324 static constexpr
const char mp_str[] =
"Gi";
328 struct name_of<scales::tebi> {
329 static constexpr
const char mp_str[] =
"tebi";
332 struct symbol_of<scales::tebi> {
333 static constexpr
const char mp_str[] =
"Ti";
337 struct name_of<scales::
pi> {
338 static constexpr
const char mp_str[3] = {char(0xCF), char(0x80),
'\0'};
341 struct symbol_of<scales::
pi> {
342 static constexpr
const char mp_str[] = {char(0xCF), char(0x80),
'\0'};
351 #endif // EAGINE_UNITS_SCALES_HPP
static auto scale(std::shared_ptr< generator > gen, std::array< float, 3 > s) noexcept
Constructs instances of scaled_gen modifier.
Definition: scaled.hpp:41
static constexpr const auto pi
The pi constant.
Definition: constants.hpp:23