📄 quantity.cpp
字号:
// Boost.Units - A C++ library for zero-overhead dimensional analysis and // unit/quantity manipulation and conversion//// Copyright (C) 2003-2008 Matthias Christian Schabel// Copyright (C) 2008 Steven Watanabe//// Distributed under the Boost Software License, Version 1.0. (See// accompanying file LICENSE_1_0.txt or copy at// http://www.boost.org/LICENSE_1_0.txt)/** \file \brief quantity.cpp\detailedTest quantity algebra.Output:@verbatim//[quantity_output_doubleL = 2 mL+L = 4 mL-L = 0 mL*L = 4 m^2L/L = 1 dimensionless L*meter = 2 m^2kilograms*(L/seconds)*(L/seconds) = 4 m^2 kg s^-2kilograms*(L/seconds)^2 = 4 m^2 kg s^-2L^3 = 8 m^3L^(3/2) = 2.82843 m^(3/2)2vL = 1.41421 m^(1/2)(3/2)vL = 1.5874 m^(2/3)//]//[quantity_output_complexL = (3,4) mL+L = (6,8) mL-L = (0,0) mL*L = (-7,24) m^2L/L = (1,0) dimensionless L*meter = (3,4) m^2kilograms*(L/seconds)*(L/seconds) = (-7,24) m^2 kg s^-2kilograms*(L/seconds)^2 = (-7,24) m^2 kg s^-2L^3 = (-117,44) m^3L^(3/2) = (2,11) m^(3/2)2vL = (2,1) m^(1/2)(3/2)vL = (2.38285,1.69466) m^(2/3)//]@endverbatim**/#include <complex>#include <iostream>#include <boost/mpl/list.hpp>#include <boost/typeof/std/complex.hpp>#include <boost/units/pow.hpp>#include <boost/units/quantity.hpp>#include <boost/units/io.hpp>#include "test_system.hpp"int main(void){ using namespace boost::units; using namespace boost::units::test; { //[quantity_snippet_1 quantity<length> L = 2.0*meters; // quantity of length quantity<energy> E = kilograms*pow<2>(L/seconds); // quantity of energy //] std::cout << "L = " << L << std::endl << "L+L = " << L+L << std::endl << "L-L = " << L-L << std::endl << "L*L = " << L*L << std::endl << "L/L = " << L/L << std::endl << "L*meter = " << L*meter << std::endl << "kilograms*(L/seconds)*(L/seconds) = " << kilograms*(L/seconds)*(L/seconds) << std::endl << "kilograms*(L/seconds)^2 = " << kilograms*pow<2>(L/seconds) << std::endl << "L^3 = " << pow<3>(L) << std::endl << "L^(3/2) = " << pow<static_rational<3,2> >(L) << std::endl << "2vL = " << root<2>(L) << std::endl << "(3/2)vL = " << root<static_rational<3,2> >(L) << std::endl << std::endl; } { //[quantity_snippet_2 quantity<length,std::complex<double> > L(std::complex<double>(3.0,4.0)*meters); quantity<energy,std::complex<double> > E(kilograms*pow<2>(L/seconds)); //] std::cout << "L = " << L << std::endl << "L+L = " << L+L << std::endl << "L-L = " << L-L << std::endl << "L*L = " << L*L << std::endl << "L/L = " << L/L << std::endl << "L*meter = " << L*meter << std::endl << "kilograms*(L/seconds)*(L/seconds) = " << kilograms*(L/seconds)*(L/seconds) << std::endl << "kilograms*(L/seconds)^2 = " << kilograms*pow<2>(L/seconds) << std::endl << "L^3 = " << pow<3>(L) << std::endl << "L^(3/2) = " << pow<static_rational<3,2> >(L) << std::endl << "2vL = " << root<2>(L) << std::endl << "(3/2)vL = " << root<static_rational<3,2> >(L) << std::endl << std::endl; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -