| 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 test_absolute.cpp |
| 15 | |
| 16 | \details |
| 17 | Test absolute units. |
| 18 | |
| 19 | Output: |
| 20 | @verbatim |
| 21 | @endverbatim |
| 22 | **/ |
| 23 | |
| 24 | #include <boost/units/quantity.hpp> |
| 25 | #include <boost/units/absolute.hpp> |
| 26 | #include <boost/units/unit.hpp> |
| 27 | #include <boost/units/make_system.hpp> |
| 28 | #include <boost/units/physical_dimensions.hpp> |
| 29 | #include <boost/units/base_units/si/kelvin.hpp> |
| 30 | #include <boost/units/base_units/temperature/celsius.hpp> |
| 31 | #include <boost/units/base_units/temperature/fahrenheit.hpp> |
| 32 | |
| 33 | #include <iostream> |
| 34 | |
| 35 | #include <boost/core/lightweight_test.hpp> |
| 36 | |
| 37 | #define BOOST_UNITS_CHECK_CLOSE(a, b) BOOST_TEST(std::abs((a) - (b)) < .0000001) |
| 38 | |
| 39 | namespace bu = boost::units; |
| 40 | using bu::si::kelvin_base_unit; |
| 41 | using bu::temperature::celsius_base_unit; |
| 42 | using bu::temperature::fahrenheit_base_unit; |
| 43 | |
| 44 | typedef bu::unit<bu::temperature_dimension,bu::make_system<kelvin_base_unit>::type> kelvin_type; |
| 45 | |
| 46 | typedef bu::unit<bu::temperature_dimension,bu::make_system<celsius_base_unit>::type> celsius_type; |
| 47 | |
| 48 | typedef bu::unit<bu::temperature_dimension,bu::make_system<fahrenheit_base_unit>::type> fahrenheit_type; |
| 49 | |
| 50 | int main() |
| 51 | { |
| 52 | BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q1(212.0 * bu::absolute<fahrenheit_type>()); |
| 53 | BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<celsius_type> > q2(0.0 * bu::absolute<celsius_type>()); |
| 54 | BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q3(q2); |
| 55 | BOOST_CONSTEXPR_OR_CONST bu::quantity<fahrenheit_type> q4(q1 - q3); |
| 56 | |
| 57 | BOOST_UNITS_CHECK_CLOSE(q4.value(), 180.0); |
| 58 | |
| 59 | BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<kelvin_type> > q5(static_cast<bu::quantity<kelvin_type> >(q4) + static_cast<bu::quantity<bu::absolute<kelvin_type> > >(q2)); |
| 60 | |
| 61 | BOOST_UNITS_CHECK_CLOSE(q5.value(), 373.15); |
| 62 | |
| 63 | BOOST_CONSTEXPR_OR_CONST bu::quantity<bu::absolute<fahrenheit_type> > q6(q5); |
| 64 | |
| 65 | BOOST_UNITS_CHECK_CLOSE(q6.value(), 212.0); |
| 66 | |
| 67 | return boost::report_errors(); |
| 68 | } |
| 69 |
