]>
git.proxmox.com Git - ceph.git/blob - 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
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
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)
17 Test quantity algebra.
22 //[quantity_output_double
29 kilograms*(L/seconds)*(L/seconds) = 4 m^2 kg s^-2
30 kilograms*(L/seconds)^2 = 4 m^2 kg s^-2
32 L^(3/2) = 2.82843 m^(3/2)
34 (3/2)vL = 1.5874 m^(2/3)
37 //[quantity_output_complex
42 L/L = (1,0) dimensionless
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
47 L^(3/2) = (2,11) m^(3/2)
49 (3/2)vL = (2.38285,1.69466) m^(2/3)
58 #include <boost/mpl/list.hpp>
60 #include <boost/typeof/std/complex.hpp>
62 #include <boost/units/pow.hpp>
63 #include <boost/units/quantity.hpp>
64 #include <boost/units/io.hpp>
66 #include "test_system.hpp"
70 using namespace boost::units
;
71 using namespace boost::units::test
;
75 quantity
<length
> L
= 2.0*meters
; // quantity of length
76 quantity
<energy
> E
= kilograms
*pow
<2>(L
/seconds
); // quantity of energy
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
90 << pow
<3>(L
) << std::endl
92 << pow
<static_rational
<3,2> >(L
) << std::endl
94 << root
<2>(L
) << std::endl
96 << root
<static_rational
<3,2> >(L
) << std::endl
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
));
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
117 << pow
<3>(L
) << std::endl
119 << pow
<static_rational
<3,2> >(L
) << std::endl
121 << root
<2>(L
) << std::endl
123 << root
<static_rational
<3,2> >(L
) << std::endl