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 unit.cpp 15 16 \details 17 Test unit algebra. 18 19 Output: 20 @verbatim 21 22 //[unit_output 23 L = m 24 L+L = m 25 L-L = m 26 L/L = dimensionless 27 meter*meter = m^2 28 M*(L/T)*(L/T) = m^2 kg s^-2 29 M*(L/T)^2 = m^2 kg s^-2 30 L^3 = m^3 31 L^(3/2) = m^(3/2) 32 2vM = kg^(1/2) 33 (3/2)vM = kg^(2/3) 34 //] 35 36 @endverbatim 37 **/ 38 39 #include <iostream> 40 41 #include "test_system.hpp" 42 43 #include <boost/units/pow.hpp> 44 main()45int main() 46 { 47 using namespace boost::units; 48 using namespace boost::units::test; 49 50 //[unit_snippet_1 51 const length L; 52 const mass M; 53 // needs to be namespace-qualified because of global time definition 54 const boost::units::test::time T; 55 const energy E; 56 //] 57 58 std::cout << "L = " << L << std::endl 59 << "L+L = " << L+L << std::endl 60 << "L-L = " << L-L << std::endl 61 << "L/L = " << L/L << std::endl 62 << "meter*meter = " << meter*meter << std::endl 63 << "M*(L/T)*(L/T) = " << M*(L/T)*(L/T) << std::endl 64 << "M*(L/T)^2 = " << M*pow<2>(L/T) << std::endl 65 << "L^3 = " << pow<3>(L) << std::endl 66 << "L^(3/2) = " << pow<static_rational<3,2> >(L) 67 << std::endl 68 << "2vM = " << root<2>(M) << std::endl 69 << "(3/2)vM = " << root<static_rational<3,2> >(M) 70 << std::endl; 71 72 return 0; 73 } 74