📄 kitchen_sink.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 kitchen_sink.cpp\detailedMore extensive quantity tests.Output:@verbatim//[kitchen_sink_output_1S1 : 2X1 : 2X2 : (4/3)U1 : NU2 : JQ1 : 1 NQ2 : 2 J//]//[kitchen_sink_output_2U1*S1 : 2 NS1*U1 : 2 NU1/S1 : 0.5 NS1/U1 : 2 m^-1 kg^-1 s^2//]//[kitchen_sink_output_3U1+U1 : NU1-U1 : NU1*U1 : m^2 kg^2 s^-4U1/U1 : dimensionlessU1*U2 : m^3 kg^2 s^-4U1/U2 : m^-1U1^X : m^2 kg^2 s^-4X1vU1 : m^(1/2) kg^(1/2) s^-1U1^X2 : m^(4/3) kg^(4/3) s^(-8/3)X2vU1 : m^(3/4) kg^(3/4) s^(-3/2)//]//[kitchen_sink_output_4Q1*S1 : 2 NS1*Q1 : 2 NQ1/S1 : 0.5 NS1/Q1 : 2 m^-1 kg^-1 s^2//]//[kitchen_sink_output_5U1*Q1 : 1 m^2 kg^2 s^-4Q1*U1 : 1 m^2 kg^2 s^-4U1/Q1 : 1 dimensionlessQ1/U1 : 1 dimensionless//]//[kitchen_sink_output_6+Q1 : 1 N-Q1 : -1 NQ1+Q1 : 2 NQ1-Q1 : 0 NQ1*Q1 : 1 m^2 kg^2 s^-4Q1/Q1 : 1 dimensionlessQ1*Q2 : 2 m^3 kg^2 s^-4Q1/Q2 : 0.5 m^-1Q1^X1 : 1 m^2 kg^2 s^-4X1vQ1 : 1 m^(1/2) kg^(1/2) s^-1Q1^X2 : 1 m^(4/3) kg^(4/3) s^(-8/3)X2vQ1 : 1 m^(3/4) kg^(3/4) s^(-3/2)//]//[kitchen_sink_output_7l1 == l2 falsel1 != l2 truel1 <= l2 truel1 < l2 truel1 >= l2 falsel1 > l2 false//]dimless = 1//[kitchen_sink_output_8v1 = 2 m s^-1//]//[kitchen_sink_output_9F = 1 Ndx = 1 mE = 1 J//]//[kitchen_sink_output_10r = 5e-07 mP = 101325 PaV = 5.23599e-19 m^3T = 310 Kn = 2.05835e-17 molR = 8.314472 m^2 kg s^-2 K^-1 mol^-1 (rel. unc. = 1.8e-06)//]//[kitchen_sink_output_11theta = 0.375 rdsin(theta) = 0.366273 dimensionlessasin(sin(theta)) = 0.375 rd//]//[kitchen_sink_output_12V = (12.5,0) VI = (3,4) AZ = (1.5,-2) OhmI*Z = (12.5,0) V//]//[kitchen_sink_output_13x+y-w = 0.48(+/-0.632772) mw*x = 9.04(+/-0.904885) m^2x/y = 0.666667(+/-0.149071) dimensionless//]//[kitchen_sink_output_14w*y^2/(u*x)^2 = 10.17(+/-3.52328) m^-1w/(u*x)^(1/2) = 3.19612(+/-0.160431) dimensionless//]//[kitchen_sink_output_15I*w = m^2 kg s^-1 rad^-1I*w/L = dimensionlessI*w^2 = J//]//[kitchen_sink_output_161 F1 kat1 S1 C1 V1 J1 N1 Hz1 lx1 H1 lm1 Wb1 T1 W1 Pa1 Ohm//]//[kitchen_sink_output_181 farad1 katal1 siemen1 coulomb1 volt1 joule1 newton1 hertz1 lux1 henry1 lumen1 weber1 tesla1 watt1 pascal1 ohm//]@endverbatim**/#include <cmath>#include <complex>#include <iostream>#include <boost/typeof/std/complex.hpp>#include <boost/units/cmath.hpp>#include <boost/units/io.hpp>#include <boost/units/systems/si.hpp>#include <boost/units/systems/si/codata/physico-chemical_constants.hpp>#include <boost/units/systems/si/io.hpp>#include "measurement.hpp"namespace boost {namespace units {//[kitchen_sink_function_snippet_3/// the physical definition of work - computed for an arbitrary unit system template<class System,class Y>quantity<unit<energy_dimension,System>,Y> work(quantity<unit<force_dimension,System>,Y> F, quantity<unit<length_dimension,System>,Y> dx){ return F*dx;}//]//[kitchen_sink_function_snippet_4/// the ideal gas law in si unitstemplate<class Y>quantity<si::amount,Y> idealGasLaw(const quantity<si::pressure,Y>& P, const quantity<si::volume,Y>& V, const quantity<si::temperature,Y>& T){ using namespace boost::units::si; #if BOOST_UNITS_HAS_TYPEOF using namespace constants::codata; return (P*V/(R*T)); #else return P*V/(8.314472*(joules/(kelvin*mole))*T); #endif // BOOST_UNITS_HAS_TYPEOF}//]} // namespace units} // namespace boostint main(){ using namespace boost::units; using namespace boost::units::si; { //[kitchen_sink_snippet_1 /// scalar const double s1 = 2; const long x1 = 2; const static_rational<4,3> x2; /// define some units force u1 = newton; energy u2 = joule; /// define some quantities quantity<force> q1(1.0*u1); quantity<energy> q2(2.0*u2); //] /// check scalar, unit, and quantity io std::cout << "S1 : " << s1 << std::endl << "X1 : " << x1 << std::endl << "X2 : " << x2 << std::endl << "U1 : " << u1 << std::endl << "U2 : " << u2 << std::endl << "Q1 : " << q1 << std::endl << "Q2 : " << q2 << std::endl << std::endl; /// check scalar-unit algebra std::cout //<< "U1+S1 : " << u1+s1 << std::endl // illegal //<< "S1+U1 : " << s1+u1 << std::endl // illegal //<< "U1-S1 : " << u1-s1 << std::endl // illegal //<< "S1-U1 : " << s1-u1 << std::endl // illegal << "U1*S1 : " << u1*s1 << std::endl << "S1*U1 : " << s1*u1 << std::endl << "U1/S1 : " << u1/s1 << std::endl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -