![]() ![]() Unit/unit operations and integral/rational powers of units : The various algebraic operations between scalars, units, and quantities give Quantity q1 ( 1.0 * u1 ) quantity q2 ( 2.0 * u2 ) If we define a few units and associated quantities,Ĭonst double s1 = 2 const long x1 = 2 const static_rational x2 /// define some unitsįorce u1 = newton energy u2 = joule /// define some quantities It uses the SI unit system defined in boost/units/systems/si.hpp. This example provides a fairly extensive set of tests covering most of theįunctionality. ![]() Quantity > L ( std :: complex ( 3.0, 4.0 )* meters ) quantity > E ( kilograms * pow ( L / seconds )) Īnd find that the code functions exactly as expected with no additional work,ĭelegating operations to std :: complex and performing the appropriate dimensional ![]() The meaningfulness of complex lengths and energies) : L = 2 m L + L = 4 m L - L = 0 m L * L = 4 m ^ 2 L / L = 1 dimensionless L * meter = 2 m ^ 2 kilograms *( L / seconds )*( L / seconds ) = 4 m ^ 2 kg s ^- 2 kilograms *( L / seconds )^ 2 = 4 m ^ 2 kg s ^- 2 L ^ 3 = 8 m ^ 3 L ^( 3 / 2 ) = 2.82843 m ^( 3 / 2 ) 2 vL = 1.41421 m ^( 1 / 2 ) ( 3 / 2 ) vL = 1.5874 m ^( 2 / 3 )Īs a further demonstration of the flexibility of the system, we replace theĭouble value type with a std :: complex value type (ignoring the question of Giving us the basic quantity functionality : Quantity E = kilograms * pow ( L / seconds ) // quantity of energy Quantity L = 2.0 * meters // quantity of length This example demonstrates how to use quantities of our toy unit system : Length_dimension = list >, dimensionless_type > mass_dimension = list >, dimensionless_type > time_dimension = list >, dimensionless_type > energy_dimension = list >, list >, list >, dimensionless_type > LM_type = list >, list >, dimensionless_type > L_T_type = list >, list >, dimensionless_type > V_type = list >, list >, dimensionless_type > Outputting (with symbol demangling, implemented in boost/units/detail/utility.hpp) Typedef mpl :: times :: type LM_type typedef mpl :: divides :: type L_T_type typedef static_root :: type, static_rational >:: type V_type It is possible to perform compile time arithmetic according to the dimensional On composite dimensions (defined in boost/units/dimension.hpp) By using MPL metafunctions and the template specializations for operations ![]()
0 Comments
Leave a Reply. |