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 conversion_factor.cpp 15 16 \details An example of using conversion_factor. 17 18 Output: 19 @verbatim 20 21 //[conversion_factor_output 22 1e-005 23 100 24 1e-005 25 100 26 0.01 27 //] 28 29 @endverbatim 30 **/ 31 32 #include <iostream> 33 34 #include <boost/units/cmath.hpp> 35 #include <boost/units/io.hpp> 36 #include <boost/units/quantity.hpp> 37 #include <boost/units/systems/cgs/acceleration.hpp> 38 #include <boost/units/systems/si/acceleration.hpp> 39 #include <boost/units/systems/si/force.hpp> 40 #include <boost/units/systems/cgs/force.hpp> 41 #include <boost/units/systems/si/mass.hpp> 42 #include <boost/units/systems/cgs/mass.hpp> 43 #include <boost/units/systems/si/momentum.hpp> 44 #include <boost/units/systems/cgs/momentum.hpp> 45 main()46int main() 47 { 48 using namespace boost; 49 using namespace boost::units; 50 51 //[conversion_factor_snippet_1 52 53 double dyne_to_newton = 54 conversion_factor(cgs::dyne,si::newton); 55 std::cout << dyne_to_newton << std::endl; 56 57 double force_over_mass_conversion = 58 conversion_factor(si::newton/si::kilogram,cgs::dyne/cgs::gram); 59 std::cout << force_over_mass_conversion << std::endl; 60 61 double momentum_conversion = 62 conversion_factor(cgs::momentum(),si::momentum()); 63 std::cout << momentum_conversion << std::endl; 64 65 double momentum_over_mass_conversion = 66 conversion_factor(si::momentum()/si::mass(),cgs::momentum()/cgs::gram); 67 std::cout << momentum_over_mass_conversion << std::endl; 68 69 double acceleration_conversion = 70 conversion_factor(cgs::gal,si::meter_per_second_squared); 71 std::cout << acceleration_conversion << std::endl; 72 73 //] 74 75 return 0; 76 } 77