Warning: Can't synchronize with repository "(default)" (/home/git/ome.git does not appear to be a Git repository.). Look in the Trac log for more information.
File units.cpp,
1.2 KB
(added by rleigh, 10 years ago) |
Units in C++ using Boost.Units
|
Line | |
---|
1 | #include <iostream> |
---|
2 | |
---|
3 | #include <boost/units/unit.hpp> |
---|
4 | #include <boost/units/quantity.hpp> |
---|
5 | #include <boost/units/systems/si.hpp> |
---|
6 | #include <boost/units/systems/si/prefixes.hpp> |
---|
7 | #include <boost/units/io.hpp> |
---|
8 | #include <boost/units/base_units/metric/angstrom.hpp> |
---|
9 | |
---|
10 | using namespace boost::units; |
---|
11 | using namespace boost::units::si; |
---|
12 | |
---|
13 | typedef quantity<si::length, double> length_type; |
---|
14 | |
---|
15 | typedef make_scaled_unit <si::length,scale<10,static_rational<-3> > >::type millimeter; |
---|
16 | typedef make_scaled_unit <si::length,scale<10,static_rational<-6> > >::type micrometer; |
---|
17 | typedef make_scaled_unit <si::length,scale<10,static_rational<-9> > >::type nanometer; |
---|
18 | |
---|
19 | namespace boost { namespace units |
---|
20 | { |
---|
21 | typedef metric::angstrom_base_unit::unit_type angstrom_unit; |
---|
22 | BOOST_UNITS_STATIC_CONSTANT(angstrom, angstrom_unit); |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | int |
---|
27 | main (void) |
---|
28 | { |
---|
29 | length_type x1(24.25 * micro * meter); |
---|
30 | // length_type x2(2.0 * mm); |
---|
31 | quantity<micrometer> x2(24.25 * micro * meter); |
---|
32 | quantity<nanometer> x3(2.425 * angstrom); |
---|
33 | length_type x4(x2); |
---|
34 | |
---|
35 | std::cout << "Length x1 = " << x1 << std::endl; |
---|
36 | std::cout << "Length x2 = " << x2 << std::endl; |
---|
37 | std::cout << "Length x3 = " << x3 << std::endl; |
---|
38 | std::cout << "Length x4 = " << x4 << std::endl; |
---|
39 | |
---|
40 | } |
---|
Download in other formats:
1.3.13-PRO © 2008-2011
Agilo Software all
rights reserved
(this page was served in: 0.71369 sec.)