Project
Loading...
Searching...
No Matches
units.h
Go to the documentation of this file.
1
4
5#pragma once
6#include <SI/datatypes.h>
7#define UNIT(_name) inline constexpr auto _name
8
9namespace SI {
10
11 // 1. SI Base Units
12 // ----------------
13 UNIT(meters) = unit<length>();
14 UNIT(seconds) = unit<time>();
15 UNIT(kilograms) = unit<mass>();
16 UNIT(kelvins) = unit<temperature>();
20
21 // 2. SI Prefixes
22 // --------------
37
38 // 3. SI Derived Units
39 // -------------------
40 UNIT(kilometers) = kilo * meters;
41 UNIT(millimeters) = milli * meters;
42 UNIT(per_meter) = unit<per_length>();
43 UNIT(minutes) = unit<time, 60>();
46 // area in...
47 UNIT(meters2) = unit<area>(); // (square meter)
48 UNIT(kilometers2) = kilo * kilo * meters2;
49 UNIT(per_meter2) = unit<per_area>();
50 UNIT(meter_kelvins)= meters * kelvins;
51 UNIT(meters2_per_second) = meters2 / seconds;
52 UNIT(kilograms_per_meter2) = kilograms / meters2;
53 // volume in...
54 UNIT(meters3) = unit<volume>(); // (cubic meter)
55 UNIT(kilometers3) = kilo * kilo * kilo * meters3;
56 UNIT(meters3_per_second) = meters3 / seconds;
57 UNIT(meters3_per_mol) = meters3 / moles;
58 UNIT(meters3_per_second2) = meters3 / (seconds * seconds);
59 UNIT(meters3_per_kilogram_per_second2) = meters3 / kilograms / (seconds * seconds);
60 UNIT(kilograms_per_meter3) = kilograms / meters3;
61 // velocity in...
62 UNIT(meters_per_second) = unit<velocity>();
63 UNIT(meters_per_hour) = meters / hours;
64 // acceleration in...
65 UNIT(meters_per_second2) = unit<acceleration>();
66 // force in...
67 UNIT(newtons) = unit<force>();
68 UNIT(newtonmeters) = newtons * meters;
69 UNIT(newtonseconds) = newtons * seconds;
70 UNIT(newtons_per_ampere2) = newtons / (amperes * amperes);
71 // energy in...
72 UNIT(joules) = unit<energy>();
73 UNIT(jouleseconds) = joules * seconds;
74 UNIT(joules_per_second) = joules / seconds;
75 UNIT(joules_per_kelvin) = joules / kelvins;
76 UNIT(joules_per_second_per_kilogram) = joules / seconds / kilograms;
77 UNIT(joules_per_kilogram_per_kelvin) = joules / kilograms / kelvins;
78 UNIT(joules_per_mol) = unit<energy_per_mol>();
79 UNIT(joules_per_kelvin_per_mol) = joules / kelvins / moles;
80 // pressure in...
81 UNIT(pascals) = unit<pressure>();
82
83 UNIT(grays) = joules / kilograms;
84 UNIT(sieverts) = joules / kilograms;
85
86 UNIT(watts) = unit<power>();
87 UNIT(wattmeters2) = watts * meters2;
88 UNIT(watts_per_meter2) = watts / meters2;
89
90 UNIT(amperes_per_meter) = amperes / meters;
91 UNIT(amperes_per_meter2) = amperes / (meters * meters);
92 UNIT(ampere_hours) = amperes * hours;
93
95 UNIT(coulombs_per_mol) = coulombs / moles;
96
98 UNIT(farads) = coulombs / volts;
99 UNIT(hertz_per_volt) = hertz / volts;
100 UNIT(farads_per_meter) = farads / meters;
101 UNIT(ohms) = volts / amperes;
102 UNIT(ohm_meters) = ohms * meters;
103 UNIT(siemens) = amperes / volts;
104 UNIT(siemens_per_meter) = siemens / meters;
105 UNIT(henrys) = volts * seconds / amperes;
106 UNIT(webers) = volts * seconds;
107 UNIT(teslas) = kilograms / (amperes * seconds * seconds);
108 UNIT(joules_per_tesla) = joules / teslas;
109
111
112 UNIT(lumens) = candelas * steradians;
113 UNIT(lumenseconds) = lumens * seconds;
114 UNIT(lumens_per_watt) = lumens / watts;
115 UNIT(lux) = lumens / meters2;
116
117 UNIT(kilograms_per_mol) = kilograms / moles;
118 UNIT(mols_per_meter3) = moles / meters3;
119 UNIT(mols_per_kilogram) = moles / kilograms;
120 UNIT(mols_per_second) = moles / seconds;
122
123 UNIT(kilograms_per_watt) = kilograms / watts;
124
125 // 4. Imperial Units
126 // -----------------
129 UNIT(nautical_miles) = unit<length, 1852, 100>();
133 UNIT(miles_per_hour) = statute_miles / hours;
134 UNIT(knots) = nautical_miles / hours;
135
136 // 5. Various Units
137 // ----------------
140 UNIT(bytes_per_second) = bytes / seconds;
141
142 // 6. Basic Functions & Templates
143 // ------------------------------
145 [[nodiscard]] SI_INLINE angle sin(angle a)
146 {
147 return std::sin(radians(a));
148 }
149
151 [[nodiscard]] SI_INLINE angle cos(angle a)
152 {
153 return std::cos(radians(a));
154 }
155
157 [[nodiscard]] SI_INLINE angle tan(angle a)
158 {
159 return std::tan(radians(a));
160 }
161
163 [[nodiscard]] SI_INLINE angle atan2(angle y, angle x)
164 {
165 return std::atan2(radians(y), radians(x));
166 }
167
169 [[nodiscard]] SI_INLINE angle sin2(angle x)
170 {
171 return 0.5 * (1. - std::cos(2. * x));
172 }
173
175 [[nodiscard]] SI_INLINE angle cos2(angle x)
176 {
177 return 0.5 * (1. + std::cos(2. * x));
178 }
179
180 [[nodiscard]] SI_INLINE angle sqrt(angle a)
181 {
182 return std::sqrt(radians(a));
183 }
184
185 [[nodiscard]] SI_INLINE angle atan2(length y, length x)
186 {
187 return std::atan2(meters(y), meters(x));
188 }
189
191 template <typename T>
192 [[nodiscard]] SI_INLINE_CONSTEXPR auto square(T x) { return x * x; }
193
195 template <typename T>
196 [[nodiscard]] SI_INLINE_CONSTEXPR auto cube(T x) { return x * x * x; }
197
199 template <typename T>
200 [[nodiscard]] SI_INLINE_CONSTEXPR auto clamp(T x, T min, T max) {
201 if (x < min) return min;
202 if (x > max) return max;
203 return x;
204 }
205
206 // 7. References
207 // -------------
208 // 1. https://en.wikipedia.org/wiki/International_System_of_Units
209
210} // end of namespace SI
211
212#undef UNIT
213#undef SI_RETURN_QUANTITY
214#undef SI_INLINE_CONSTEXPR
215#undef SI_INLINE
Defines the dimensionless, the SI base, and the derived SI datatypes, e.g. SI::length.
#define SI_INLINE_CONSTEXPR
Definition internal.h:10
#define SI_INLINE
Definition internal.h:9
Definition constants.h:12
SI_INLINE_CONSTEXPR auto cube(T x)
Raise any number <x> to power of 3 (x³ or x*x*x).
Definition units.h:196
detail::unit< detail::dimension_of_t< Dimension >, detail::ratio< numerator, denumerator > > unit
Definition internal.h:829
SI_INLINE angle sin(angle a)
Calculates the sinus of an angle (a).
Definition units.h:145
SI_INLINE_CONSTEXPR auto clamp(T x, T min, T max)
Clamp any number <x> between <min> and <max> value.
Definition units.h:200
SI_INLINE angle cos(angle a)
Calculates the cosinus of an angle (a).
Definition units.h:151
SI_INLINE angle sqrt(angle a)
Definition units.h:180
SI_INLINE angle tan(angle a)
Calculates the tangens of an angle (a).
Definition units.h:157
SI_INLINE angle sin2(angle x)
Calculates sin²x.
Definition units.h:169
angle radians
basic unit of radians for angle
Definition internal.h:15
SI_INLINE angle atan2(angle y, angle x)
Calculates the atangens of two angles.
Definition units.h:163
long double angle
basic datatype to hold a dimensionless angle, e.g. 3.1415
Definition internal.h:14
SI_INLINE angle cos2(angle x)
Calculates cos²x.
Definition units.h:175
SI_INLINE_CONSTEXPR auto square(T x)
Raise any number <x> to power of 2 (x² or x*x).
Definition units.h:192
Definition internal.h:673
#define UNIT(_name)
Definition units.h:7