]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/units/example/quantity.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / units / example / quantity.cpp
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and
2 // unit/quantity manipulation and conversion
3 //
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 /**
12 \file
13
14 \brief quantity.cpp
15
16 \details
17 Test quantity algebra.
18
19 Output:
20 @verbatim
21
22 //[quantity_output_double
23 L = 2 m
24 L+L = 4 m
25 L-L = 0 m
26 L*L = 4 m^2
27 L/L = 1 dimensionless
28 L*meter = 2 m^2
29 kilograms*(L/seconds)*(L/seconds) = 4 m^2 kg s^-2
30 kilograms*(L/seconds)^2 = 4 m^2 kg s^-2
31 L^3 = 8 m^3
32 L^(3/2) = 2.82843 m^(3/2)
33 2vL = 1.41421 m^(1/2)
34 (3/2)vL = 1.5874 m^(2/3)
35 //]
36
37 //[quantity_output_complex
38 L = (3,4) m
39 L+L = (6,8) m
40 L-L = (0,0) m
41 L*L = (-7,24) m^2
42 L/L = (1,0) dimensionless
43 L*meter = (3,4) m^2
44 kilograms*(L/seconds)*(L/seconds) = (-7,24) m^2 kg s^-2
45 kilograms*(L/seconds)^2 = (-7,24) m^2 kg s^-2
46 L^3 = (-117,44) m^3
47 L^(3/2) = (2,11) m^(3/2)
48 2vL = (2,1) m^(1/2)
49 (3/2)vL = (2.38285,1.69466) m^(2/3)
50 //]
51
52 @endverbatim
53 **/
54
55 #include <complex>
56 #include <iostream>
57
58 #include <boost/mpl/list.hpp>
59
60 #include <boost/typeof/std/complex.hpp>
61
62 #include <boost/units/pow.hpp>
63 #include <boost/units/quantity.hpp>
64 #include <boost/units/io.hpp>
65
66 #include "test_system.hpp"
67
68 int main(void)
69 {
70 using namespace boost::units;
71 using namespace boost::units::test;
72
73 {
74 //[quantity_snippet_1
75 quantity<length> L = 2.0*meters; // quantity of length
76 quantity<energy> E = kilograms*pow<2>(L/seconds); // quantity of energy
77 //]
78
79 std::cout << "L = " << L << std::endl
80 << "L+L = " << L+L << std::endl
81 << "L-L = " << L-L << std::endl
82 << "L*L = " << L*L << std::endl
83 << "L/L = " << L/L << std::endl
84 << "L*meter = " << L*meter << std::endl
85 << "kilograms*(L/seconds)*(L/seconds) = "
86 << kilograms*(L/seconds)*(L/seconds) << std::endl
87 << "kilograms*(L/seconds)^2 = "
88 << kilograms*pow<2>(L/seconds) << std::endl
89 << "L^3 = "
90 << pow<3>(L) << std::endl
91 << "L^(3/2) = "
92 << pow<static_rational<3,2> >(L) << std::endl
93 << "2vL = "
94 << root<2>(L) << std::endl
95 << "(3/2)vL = "
96 << root<static_rational<3,2> >(L) << std::endl
97 << std::endl;
98 }
99
100 {
101 //[quantity_snippet_2
102 quantity<length,std::complex<double> > L(std::complex<double>(3.0,4.0)*meters);
103 quantity<energy,std::complex<double> > E(kilograms*pow<2>(L/seconds));
104 //]
105
106 std::cout << "L = " << L << std::endl
107 << "L+L = " << L+L << std::endl
108 << "L-L = " << L-L << std::endl
109 << "L*L = " << L*L << std::endl
110 << "L/L = " << L/L << std::endl
111 << "L*meter = " << L*meter << std::endl
112 << "kilograms*(L/seconds)*(L/seconds) = "
113 << kilograms*(L/seconds)*(L/seconds) << std::endl
114 << "kilograms*(L/seconds)^2 = "
115 << kilograms*pow<2>(L/seconds) << std::endl
116 << "L^3 = "
117 << pow<3>(L) << std::endl
118 << "L^(3/2) = "
119 << pow<static_rational<3,2> >(L) << std::endl
120 << "2vL = "
121 << root<2>(L) << std::endl
122 << "(3/2)vL = "
123 << root<static_rational<3,2> >(L) << std::endl
124 << std::endl;
125 }
126
127 return 0;
128 }