From 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 20:24:20 +0200 Subject: Adding upstream version 14.2.21. Signed-off-by: Daniel Baumann --- src/boost/libs/units/README.md | 38 + src/boost/libs/units/boost.css | 65 ++ src/boost/libs/units/covscan.sh | 38 + src/boost/libs/units/example/Jamfile.v2 | 25 + src/boost/libs/units/example/autoprefixes.cpp | 148 +++ src/boost/libs/units/example/complex.cpp | 421 ++++++++ src/boost/libs/units/example/composite_output.cpp | 116 +++ src/boost/libs/units/example/conversion.cpp | 124 +++ src/boost/libs/units/example/conversion_factor.cpp | 76 ++ src/boost/libs/units/example/dimension.cpp | 117 +++ .../libs/units/example/heterogeneous_unit.cpp | 87 ++ src/boost/libs/units/example/information.cpp | 100 ++ src/boost/libs/units/example/kitchen_sink.cpp | 542 ++++++++++ src/boost/libs/units/example/lambda.cpp | 157 +++ src/boost/libs/units/example/measurement.hpp | 344 +++++++ .../libs/units/example/non_base_dimension.cpp | 78 ++ src/boost/libs/units/example/performance.cpp | 395 ++++++++ src/boost/libs/units/example/quantity.cpp | 128 +++ src/boost/libs/units/example/quaternion.cpp | 232 +++++ src/boost/libs/units/example/radar_beam_height.cpp | 167 +++ .../units/example/runtime_conversion_factor.cpp | 72 ++ src/boost/libs/units/example/runtime_unit.cpp | 116 +++ .../libs/units/example/runtime_unit_input.txt | 13 + src/boost/libs/units/example/systems.cpp | 1072 ++++++++++++++++++++ src/boost/libs/units/example/temperature.cpp | 98 ++ src/boost/libs/units/example/test_system.hpp | 153 +++ src/boost/libs/units/example/tutorial.cpp | 95 ++ src/boost/libs/units/example/unit.cpp | 73 ++ src/boost/libs/units/images/form_0.png | Bin 0 -> 186 bytes src/boost/libs/units/images/form_1.png | Bin 0 -> 482 bytes src/boost/libs/units/images/form_10.png | Bin 0 -> 466 bytes src/boost/libs/units/images/form_11.png | Bin 0 -> 460 bytes src/boost/libs/units/images/form_12.png | Bin 0 -> 313 bytes src/boost/libs/units/images/form_13.png | Bin 0 -> 303 bytes src/boost/libs/units/images/form_14.png | Bin 0 -> 344 bytes src/boost/libs/units/images/form_15.png | Bin 0 -> 380 bytes src/boost/libs/units/images/form_2.png | Bin 0 -> 449 bytes src/boost/libs/units/images/form_3.png | Bin 0 -> 707 bytes src/boost/libs/units/images/form_4.png | Bin 0 -> 192 bytes src/boost/libs/units/images/form_5.png | Bin 0 -> 897 bytes src/boost/libs/units/images/form_6.png | Bin 0 -> 907 bytes src/boost/libs/units/images/form_7.png | Bin 0 -> 367 bytes src/boost/libs/units/images/form_8.png | Bin 0 -> 3868 bytes src/boost/libs/units/images/form_9.png | Bin 0 -> 405 bytes src/boost/libs/units/index.html | 22 + src/boost/libs/units/meta/libraries.json | 16 + src/boost/libs/units/test/Jamfile.v2 | 78 ++ .../libs/units/test/check_conversion_defs.cpp | 159 +++ src/boost/libs/units/test/fail_add_temperature.cpp | 38 + src/boost/libs/units/test/fail_adl_detail.cpp | 48 + src/boost/libs/units/test/fail_base_dimension.cpp | 32 + .../libs/units/test/fail_heterogeneous_unit.cpp | 46 + .../libs/units/test/fail_implicit_conversion.cpp | 36 + src/boost/libs/units/test/fail_quantity_add.cpp | 35 + .../libs/units/test/fail_quantity_add_assign.cpp | 36 + src/boost/libs/units/test/fail_quantity_assign.cpp | 36 + .../libs/units/test/fail_quantity_construct.cpp | 35 + .../libs/units/test/fail_quantity_non_unit.cpp | 37 + .../libs/units/test/fail_quantity_scalar_add.cpp | 35 + .../libs/units/test/fail_quantity_scalar_sub.cpp | 35 + .../libs/units/test/fail_quantity_sub_assign.cpp | 36 + .../libs/units/test/fail_quantity_subtract.cpp | 35 + .../libs/units/test/fail_quantity_unit_add.cpp | 35 + .../units/test/fail_quantity_unit_subtract.cpp | 35 + .../libs/units/test/fail_scalar_quantity_add.cpp | 35 + .../libs/units/test/fail_scalar_quantity_sub.cpp | 35 + .../libs/units/test/fail_unit_quantity_add.cpp | 35 + .../units/test/fail_unit_quantity_subtract.cpp | 35 + src/boost/libs/units/test/test_absolute.cpp | 68 ++ src/boost/libs/units/test/test_base_dimension.cpp | 31 + src/boost/libs/units/test/test_cmath.cpp | 173 ++++ .../libs/units/test/test_complicated_system.cpp | 96 ++ src/boost/libs/units/test/test_constants.cpp | 87 ++ src/boost/libs/units/test/test_conversion.cpp | 110 ++ src/boost/libs/units/test/test_custom_unit.cpp | 84 ++ .../libs/units/test/test_default_conversion.cpp | 78 ++ .../libs/units/test/test_dimensionless_ice1.cpp | 26 + .../libs/units/test/test_dimensionless_ice2.cpp | 25 + .../units/test/test_dimensionless_quantity.cpp | 216 ++++ src/boost/libs/units/test/test_header.hpp | 126 +++ .../libs/units/test/test_implicit_conversion.cpp | 113 +++ .../libs/units/test/test_information_units.cpp | 242 +++++ src/boost/libs/units/test/test_lambda.cpp | 269 +++++ src/boost/libs/units/test/test_limits.cpp | 127 +++ .../libs/units/test/test_mixed_value_types.cpp | 22 + .../libs/units/test/test_negative_denominator.cpp | 32 + src/boost/libs/units/test/test_output.cpp | 499 +++++++++ src/boost/libs/units/test/test_predicates.cpp | 100 ++ src/boost/libs/units/test/test_quantity.cpp | 203 ++++ src/boost/libs/units/test/test_reduce_unit.cpp | 30 + .../libs/units/test/test_scaled_conversion.cpp | 66 ++ src/boost/libs/units/test/test_scaled_unit.cpp | 76 ++ .../libs/units/test/test_sqrt_scaled_unit.cpp | 48 + src/boost/libs/units/test/test_trig.cpp | 79 ++ src/boost/libs/units/test/test_unit.cpp | 67 ++ src/boost/libs/units/test/test_unscale.cpp | 58 ++ src/boost/libs/units/test_headers/Jamfile.v2 | 56 + src/boost/libs/units/test_headers/main.cpp | 12 + src/boost/libs/units/test_headers/test.cpp | 19 + src/boost/libs/units/tutorial/tutorial_1.cpp | 314 ++++++ 100 files changed, 9647 insertions(+) create mode 100644 src/boost/libs/units/README.md create mode 100644 src/boost/libs/units/boost.css create mode 100755 src/boost/libs/units/covscan.sh create mode 100644 src/boost/libs/units/example/Jamfile.v2 create mode 100644 src/boost/libs/units/example/autoprefixes.cpp create mode 100644 src/boost/libs/units/example/complex.cpp create mode 100644 src/boost/libs/units/example/composite_output.cpp create mode 100644 src/boost/libs/units/example/conversion.cpp create mode 100644 src/boost/libs/units/example/conversion_factor.cpp create mode 100644 src/boost/libs/units/example/dimension.cpp create mode 100644 src/boost/libs/units/example/heterogeneous_unit.cpp create mode 100644 src/boost/libs/units/example/information.cpp create mode 100644 src/boost/libs/units/example/kitchen_sink.cpp create mode 100644 src/boost/libs/units/example/lambda.cpp create mode 100644 src/boost/libs/units/example/measurement.hpp create mode 100644 src/boost/libs/units/example/non_base_dimension.cpp create mode 100644 src/boost/libs/units/example/performance.cpp create mode 100644 src/boost/libs/units/example/quantity.cpp create mode 100644 src/boost/libs/units/example/quaternion.cpp create mode 100644 src/boost/libs/units/example/radar_beam_height.cpp create mode 100644 src/boost/libs/units/example/runtime_conversion_factor.cpp create mode 100644 src/boost/libs/units/example/runtime_unit.cpp create mode 100644 src/boost/libs/units/example/runtime_unit_input.txt create mode 100644 src/boost/libs/units/example/systems.cpp create mode 100644 src/boost/libs/units/example/temperature.cpp create mode 100644 src/boost/libs/units/example/test_system.hpp create mode 100644 src/boost/libs/units/example/tutorial.cpp create mode 100644 src/boost/libs/units/example/unit.cpp create mode 100644 src/boost/libs/units/images/form_0.png create mode 100644 src/boost/libs/units/images/form_1.png create mode 100644 src/boost/libs/units/images/form_10.png create mode 100644 src/boost/libs/units/images/form_11.png create mode 100644 src/boost/libs/units/images/form_12.png create mode 100644 src/boost/libs/units/images/form_13.png create mode 100644 src/boost/libs/units/images/form_14.png create mode 100644 src/boost/libs/units/images/form_15.png create mode 100644 src/boost/libs/units/images/form_2.png create mode 100644 src/boost/libs/units/images/form_3.png create mode 100644 src/boost/libs/units/images/form_4.png create mode 100644 src/boost/libs/units/images/form_5.png create mode 100644 src/boost/libs/units/images/form_6.png create mode 100644 src/boost/libs/units/images/form_7.png create mode 100644 src/boost/libs/units/images/form_8.png create mode 100644 src/boost/libs/units/images/form_9.png create mode 100644 src/boost/libs/units/index.html create mode 100644 src/boost/libs/units/meta/libraries.json create mode 100644 src/boost/libs/units/test/Jamfile.v2 create mode 100644 src/boost/libs/units/test/check_conversion_defs.cpp create mode 100644 src/boost/libs/units/test/fail_add_temperature.cpp create mode 100644 src/boost/libs/units/test/fail_adl_detail.cpp create mode 100644 src/boost/libs/units/test/fail_base_dimension.cpp create mode 100644 src/boost/libs/units/test/fail_heterogeneous_unit.cpp create mode 100644 src/boost/libs/units/test/fail_implicit_conversion.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_add.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_add_assign.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_assign.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_construct.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_non_unit.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_scalar_add.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_scalar_sub.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_sub_assign.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_subtract.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_unit_add.cpp create mode 100644 src/boost/libs/units/test/fail_quantity_unit_subtract.cpp create mode 100644 src/boost/libs/units/test/fail_scalar_quantity_add.cpp create mode 100644 src/boost/libs/units/test/fail_scalar_quantity_sub.cpp create mode 100644 src/boost/libs/units/test/fail_unit_quantity_add.cpp create mode 100644 src/boost/libs/units/test/fail_unit_quantity_subtract.cpp create mode 100644 src/boost/libs/units/test/test_absolute.cpp create mode 100644 src/boost/libs/units/test/test_base_dimension.cpp create mode 100644 src/boost/libs/units/test/test_cmath.cpp create mode 100644 src/boost/libs/units/test/test_complicated_system.cpp create mode 100644 src/boost/libs/units/test/test_constants.cpp create mode 100644 src/boost/libs/units/test/test_conversion.cpp create mode 100644 src/boost/libs/units/test/test_custom_unit.cpp create mode 100644 src/boost/libs/units/test/test_default_conversion.cpp create mode 100644 src/boost/libs/units/test/test_dimensionless_ice1.cpp create mode 100644 src/boost/libs/units/test/test_dimensionless_ice2.cpp create mode 100644 src/boost/libs/units/test/test_dimensionless_quantity.cpp create mode 100644 src/boost/libs/units/test/test_header.hpp create mode 100644 src/boost/libs/units/test/test_implicit_conversion.cpp create mode 100644 src/boost/libs/units/test/test_information_units.cpp create mode 100644 src/boost/libs/units/test/test_lambda.cpp create mode 100644 src/boost/libs/units/test/test_limits.cpp create mode 100644 src/boost/libs/units/test/test_mixed_value_types.cpp create mode 100644 src/boost/libs/units/test/test_negative_denominator.cpp create mode 100644 src/boost/libs/units/test/test_output.cpp create mode 100644 src/boost/libs/units/test/test_predicates.cpp create mode 100644 src/boost/libs/units/test/test_quantity.cpp create mode 100644 src/boost/libs/units/test/test_reduce_unit.cpp create mode 100644 src/boost/libs/units/test/test_scaled_conversion.cpp create mode 100644 src/boost/libs/units/test/test_scaled_unit.cpp create mode 100644 src/boost/libs/units/test/test_sqrt_scaled_unit.cpp create mode 100644 src/boost/libs/units/test/test_trig.cpp create mode 100644 src/boost/libs/units/test/test_unit.cpp create mode 100644 src/boost/libs/units/test/test_unscale.cpp create mode 100644 src/boost/libs/units/test_headers/Jamfile.v2 create mode 100644 src/boost/libs/units/test_headers/main.cpp create mode 100644 src/boost/libs/units/test_headers/test.cpp create mode 100644 src/boost/libs/units/tutorial/tutorial_1.cpp (limited to 'src/boost/libs/units') diff --git a/src/boost/libs/units/README.md b/src/boost/libs/units/README.md new file mode 100644 index 00000000..685cb464 --- /dev/null +++ b/src/boost/libs/units/README.md @@ -0,0 +1,38 @@ +Boost.Units +=========== + +Boost.Units, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), +implements dimensional analysis in a general and extensible manner, +treating it as a generic compile-time metaprogramming problem. +With appropriate compiler optimization, no runtime execution cost is introduced, +facilitating the use of this library to provide dimension checking in performance-critical code. + +### Directories + +* **doc** - QuickBook documentation sources +* **example** - examples +* **images** - images for documention +* **include** - Interface headers +* **test** - unit tests +* **test_headers** - unit tests for self containment of headers +* **tutorial** - tutorial + +### Test results + +@ | Travis | AppVeyor +--------|-------------|--------- +master | [![Build Status](https://travis-ci.org/boostorg/units.svg?branch=master)](https://travis-ci.org/boostorg/units) | [![Build Status](https://ci.appveyor.com/api/projects/status/github/boostorg/units?branch=master&svg=true)](https://ci.appveyor.com/project/boostorg/units) +develop | [![Build Status](https://travis-ci.org/boostorg/units.svg)](https://travis-ci.org/boostorg/units) | [![Build Status](https://ci.appveyor.com/api/projects/status/github/boostorg/units?svg=true)](https://ci.appveyor.com/project/boostorg/units) + + + Coverity Scan Build Status + + +### More information + +* [Documentation](http://boost.org/libs/units) + +### License + +Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). diff --git a/src/boost/libs/units/boost.css b/src/boost/libs/units/boost.css new file mode 100644 index 00000000..9f8d4bda --- /dev/null +++ b/src/boost/libs/units/boost.css @@ -0,0 +1,65 @@ +/*============================================================================= + Copyright 2002 William E. Kempf + Distributed under the Boost Software License, Version 1.0. (See accompany- + ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +=============================================================================*/ + +H1 +{ + FONT-SIZE: 200%; + COLOR: #00008B; +} +H2 +{ + FONT-SIZE: 150%; +} +H3 +{ + FONT-SIZE: 125%; +} +H4 +{ + FONT-SIZE: 108%; +} +BODY +{ + FONT-SIZE: 100%; + BACKGROUND-COLOR: #ffffff; +} +PRE +{ + MARGIN-LEFT: 2em; + FONT-FAMILY: Courier, + monospace; +} +CODE +{ + FONT-FAMILY: Courier, + monospace; +} +CODE.as_pre +{ + white-space: pre; +} +.index +{ + TEXT-ALIGN: left; +} +.page-index +{ + TEXT-ALIGN: left; +} +.definition +{ + TEXT-ALIGN: left; +} +.footnote +{ + FONT-SIZE: 66%; + VERTICAL-ALIGN: super; + TEXT-DECORATION: none; +} +.function-semantics +{ + CLEAR: left; +} \ No newline at end of file diff --git a/src/boost/libs/units/covscan.sh b/src/boost/libs/units/covscan.sh new file mode 100755 index 00000000..88e08d3e --- /dev/null +++ b/src/boost/libs/units/covscan.sh @@ -0,0 +1,38 @@ +#! /bin/bash +# +# Copyright 2017 James E. King, III +# 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) +# +# Bash script to run in travis to perform a Coverity Scan build +# + +# +# Environment Variables +# +# COVERITY_SCAN_NOTIFICATION_EMAIL - email address to notify +# COVERITY_SCAN_TOKEN - the Coverity Scan token (should be secure) +# SELF - the boost libs directory name + +set -ex + +pushd /tmp +rm -rf coverity_tool.tgz cov-analysis* +wget -nv https://scan.coverity.com/download/linux64 --post-data "token=$COVERITY_SCAN_TOKEN&project=boostorg/$SELF" -O coverity_tool.tgz +tar xzf coverity_tool.tgz +COVBIN=$(echo $(pwd)/cov-analysis*/bin) +export PATH=$COVBIN:$PATH +popd + +cd libs/$SELF/test +../../../b2 toolset=gcc clean +rm -rf cov-int/ +cov-build --dir cov-int ../../../b2 toolset=gcc -q -j3 +tar cJf cov-int.tar.xz cov-int/ +curl --form token="$COVERITY_SCAN_TOKEN" \ + --form email="$COVERITY_SCAN_NOTIFICATION_EMAIL" \ + --form file=@cov-int.tar.xz \ + --form version="$(git describe --tags)" \ + --form description="boostorg/$SELF" \ + https://scan.coverity.com/builds?project="boostorg/$SELF" diff --git a/src/boost/libs/units/example/Jamfile.v2 b/src/boost/libs/units/example/Jamfile.v2 new file mode 100644 index 00000000..b918205a --- /dev/null +++ b/src/boost/libs/units/example/Jamfile.v2 @@ -0,0 +1,25 @@ +# Jamfile.v2 +# +# Copyright (c) 2007-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 + +import testing ; +import path ; + +project boost/units/example : + : requirements $(BOOST_ROOT) ../../.. all +; + +files = [ path.glob . : *.cpp : performance.* runtime_unit.* ] ; + +for local file in $(files) +{ + run $(file) ; +} + +compile performance.cpp ; +run runtime_unit.cpp : + +#include +#include +#include +#include +#include + +struct byte_base_unit : boost::units::base_unit +{ + static constexpr const char* name() { return("byte"); } + static constexpr const char* symbol() { return("b"); } +}; + +struct thing_base_unit : boost::units::base_unit +{ + static constexpr const char* name() { return("thing"); } + static constexpr const char* symbol() { return(""); } +}; + +struct euro_base_unit : boost::units::base_unit +{ + static constexpr const char* name() { return("EUR"); } + static constexpr const char* symbol() { return("€"); } +}; + +int main() +{ + using std::cout; + using std::endl; + + using namespace boost::units; + using namespace boost::units::si; + + //[autoprefixes_snippet_1 + using boost::units::binary_prefix; + using boost::units::engineering_prefix; + using boost::units::no_prefix; + + quantity l = 2.345 * meters; // A quantity of length, in units of meters. + cout << engineering_prefix << l << endl; // Outputs "2.345 m". + l = 1000.0 * l; // Increase it by 1000, so expect a k prefix. + // Note that a double 1000.0 is required - an integer will fail to compile. + cout << engineering_prefix << l << endl; // Output autoprefixed with k to "2.345 km". + + quantity e = kilograms * pow<2>(l / seconds); // A quantity of energy. + cout << engineering_prefix << e << endl; // 5.49902 MJ + cout << name_format << engineering_prefix << e << endl; // 5.49902 megaJoule + //] [/autoprefixes_snippet_1] + + //[autoprefixes_snippet_2 + // Don't forget that the units name or symbol format specification is persistent. + cout << symbol_format << endl; // Resets the format to the default symbol format. + + quantity b = 2048. * byte_base_unit::unit_type(); + cout << engineering_prefix << b << endl; // 2.048 kb + cout << symbol_format << binary_prefix << b << endl; // "2 Kib" + //] [/autoprefixes_snippet_2] + + // Note that scalar dimensionless values are *not* prefixed automatically by the engineering_prefix or binary_prefix iostream manipulators. + //[autoprefixes_snippet_3 + const double s1 = 2345.6; + const long x1 = 23456; + cout << engineering_prefix << s1 << endl; // 2345.6 + cout << engineering_prefix << x1 << endl; // 23456 + + cout << binary_prefix << s1 << endl; // 2345.6 + cout << binary_prefix << x1 << endl; // 23456 + //] [/autoprefixes_snippet_3] + + //[autoprefixes_snippet_4 + const length L; // A unit of length (but not a quantity of length). + cout << L << endl; // Default length unit is meter, + // but default is symbol format so output is just "m". + cout << name_format << L << endl; // default length name is "meter". + //] [/autoprefixes_snippet_4] + + //[autoprefixes_snippet_5 + no_prefix(cout); // Clear any prefix flag. + cout << no_prefix << endl; // Clear any prefix flag using `no_prefix` manipulator. + //] [/autoprefixes_snippet_5] + + //[autoprefixes_snippet_6 + cout << boost::units::get_autoprefix(cout) << endl; // 8 is `autoprefix_binary` from `enum autoprefix_mode`. + cout << boost::units::get_format(cout) << endl; // 1 is `name_fmt` from `enum format_mode`. + //] [/autoprefixes_snippet_6] + + + quantity t = 2048. * thing_base_unit::unit_type(); + cout << name_format << engineering_prefix << t << endl; // 2.048 kilothing + cout << symbol_format << engineering_prefix << t << endl; // 2.048 k + + cout << binary_prefix << t << endl; // "2 Ki" + + quantity ce = 2048. * euro_base_unit::unit_type(); + cout << name_format << engineering_prefix << ce << endl; // 2.048 kiloEUR + cout << symbol_format << engineering_prefix << ce << endl; // 2.048 k€ + + + return 0; +} // int main() + diff --git a/src/boost/libs/units/example/complex.cpp b/src/boost/libs/units/example/complex.cpp new file mode 100644 index 00000000..d3579a06 --- /dev/null +++ b/src/boost/libs/units/example/complex.cpp @@ -0,0 +1,421 @@ +// 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 complex.cpp + +\details +Demonstrate a complex number class that functions correctly with quantities. + +Output: +@verbatim + +//[complex_output_1 ++L = 2 + 1 i m +-L = -2 + -1 i m +L+L = 4 + 2 i m +L-L = 0 + 0 i m +L*L = 3 + 4 i m^2 +L/L = 1 + 0 i dimensionless +L^3 = 2 + 11 i m^3 +L^(3/2) = 2.56713 + 2.14247 i m^(3/2) +3vL = 1.29207 + 0.201294 i m^(1/3) +(3/2)vL = 1.62894 + 0.520175 i m^(2/3) +//] + +//[complex_output_2 ++L = 2 m + 1 m i +-L = -2 m + -1 m i +L+L = 4 m + 2 m i +L-L = 0 m + 0 m i +L*L = 3 m^2 + 4 m^2 i +L/L = 1 dimensionless + 0 dimensionless i +L^3 = 2 m^3 + 11 m^3 i +L^(3/2) = 2.56713 m^(3/2) + 2.14247 m^(3/2) i +3vL = 1.29207 m^(1/3) + 0.201294 m^(1/3) i +(3/2)vL = 1.62894 m^(2/3) + 0.520175 m^(2/3) i +//] + +@endverbatim +**/ + +#include +#include +#include + +#include + +#include +#include +#include + +#include "test_system.hpp" + +//[complex_class_snippet_1 +namespace boost { + +namespace units { + +/// replacement complex class +template +class complex +{ + public: + typedef complex this_type; + + constexpr complex(const T& r = 0,const T& i = 0) : r_(r),i_(i) { } + constexpr complex(const this_type& source) : r_(source.r_),i_(source.i_) { } + + constexpr this_type& operator=(const this_type& source) + { + if (this == &source) return *this; + + r_ = source.r_; + i_ = source.i_; + + return *this; + } + + constexpr T& real() { return r_; } + constexpr T& imag() { return i_; } + + constexpr const T& real() const { return r_; } + constexpr const T& imag() const { return i_; } + + constexpr this_type& operator+=(const T& val) + { + r_ += val; + return *this; + } + + constexpr this_type& operator-=(const T& val) + { + r_ -= val; + return *this; + } + + constexpr this_type& operator*=(const T& val) + { + r_ *= val; + i_ *= val; + return *this; + } + + constexpr this_type& operator/=(const T& val) + { + r_ /= val; + i_ /= val; + return *this; + } + + constexpr this_type& operator+=(const this_type& source) + { + r_ += source.r_; + i_ += source.i_; + return *this; + } + + constexpr this_type& operator-=(const this_type& source) + { + r_ -= source.r_; + i_ -= source.i_; + return *this; + } + + constexpr this_type& operator*=(const this_type& source) + { + *this = *this * source; + return *this; + } + + constexpr this_type& operator/=(const this_type& source) + { + *this = *this / source; + return *this; + } + + private: + T r_,i_; +}; + +} + +} + +#if BOOST_UNITS_HAS_BOOST_TYPEOF + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::complex, 1) + +#endif + +namespace boost { + +namespace units { + +template +constexpr +complex::type> +operator+(const complex& x) +{ + typedef typename unary_plus_typeof_helper::type type; + + return complex(x.real(),x.imag()); +} + +template +constexpr +complex::type> +operator-(const complex& x) +{ + typedef typename unary_minus_typeof_helper::type type; + + return complex(-x.real(),-x.imag()); +} + +template +constexpr +complex::type> +operator+(const complex& x,const complex& y) +{ + typedef typename boost::units::add_typeof_helper::type type; + + return complex(x.real()+y.real(),x.imag()+y.imag()); +} + +template +constexpr +complex::type> +operator-(const complex& x,const complex& y) +{ + typedef typename boost::units::subtract_typeof_helper::type type; + + return complex(x.real()-y.real(),x.imag()-y.imag()); +} + +template +constexpr +complex::type> +operator*(const complex& x,const complex& y) +{ + typedef typename boost::units::multiply_typeof_helper::type type; + + return complex(x.real()*y.real() - x.imag()*y.imag(), + x.real()*y.imag() + x.imag()*y.real()); + +// fully correct implementation has more complex return type +// +// typedef typename boost::units::multiply_typeof_helper::type xy_type; +// +// typedef typename boost::units::add_typeof_helper< +// xy_type,xy_type>::type xy_plus_xy_type; +// typedef typename +// boost::units::subtract_typeof_helper::type +// xy_minus_xy_type; +// +// BOOST_STATIC_ASSERT((boost::is_same::value == true)); +// +// return complex(x.real()*y.real()-x.imag()*y.imag(), +// x.real()*y.imag()+x.imag()*y.real()); +} + +template +constexpr +complex::type> +operator/(const complex& x,const complex& y) +{ + // naive implementation of complex division + typedef typename boost::units::divide_typeof_helper::type type; + + return complex((x.real()*y.real()+x.imag()*y.imag())/ + (y.real()*y.real()+y.imag()*y.imag()), + (x.imag()*y.real()-x.real()*y.imag())/ + (y.real()*y.real()+y.imag()*y.imag())); + +// fully correct implementation has more complex return type +// +// typedef typename boost::units::multiply_typeof_helper::type xy_type; +// typedef typename boost::units::multiply_typeof_helper::type yy_type; +// +// typedef typename boost::units::add_typeof_helper::type +// xy_plus_xy_type; +// typedef typename boost::units::subtract_typeof_helper< +// xy_type,xy_type>::type xy_minus_xy_type; +// +// typedef typename boost::units::divide_typeof_helper< +// xy_plus_xy_type,yy_type>::type xy_plus_xy_over_yy_type; +// typedef typename boost::units::divide_typeof_helper< +// xy_minus_xy_type,yy_type>::type xy_minus_xy_over_yy_type; +// +// BOOST_STATIC_ASSERT((boost::is_same::value == true)); +// +// return complex( +// (x.real()*y.real()+x.imag()*y.imag())/ +// (y.real()*y.real()+y.imag()*y.imag()), +// (x.imag()*y.real()-x.real()*y.imag())/ +// (y.real()*y.real()+y.imag()*y.imag())); +} + +template +complex +pow(const complex& x,const Y& y) +{ + std::complex tmp(x.real(),x.imag()); + + tmp = std::pow(tmp,y); + + return complex(tmp.real(),tmp.imag()); +} + +template +std::ostream& operator<<(std::ostream& os,const complex& val) +{ + os << val.real() << " + " << val.imag() << " i"; + + return os; +} + +/// specialize power typeof helper for complex +template +struct power_typeof_helper,static_rational > +{ + typedef complex< + typename power_typeof_helper >::type + > type; + + static type value(const complex& x) + { + const static_rational rat; + + const Y m = Y(rat.numerator())/Y(rat.denominator()); + + return boost::units::pow(x,m); + } +}; + +/// specialize root typeof helper for complex +template +struct root_typeof_helper,static_rational > +{ + typedef complex< + typename root_typeof_helper >::type + > type; + + static type value(const complex& x) + { + const static_rational rat; + + const Y m = Y(rat.denominator())/Y(rat.numerator()); + + return boost::units::pow(x,m); + } +}; + +/// specialize power typeof helper for complex > +template +struct power_typeof_helper >,static_rational > +{ + typedef typename + power_typeof_helper >::type value_type; + typedef typename + power_typeof_helper >::type unit_type; + typedef quantity quantity_type; + typedef complex type; + + static type value(const complex >& x) + { + const complex tmp = + pow >(complex(x.real().value(), + x.imag().value())); + + return type(quantity_type::from_value(tmp.real()), + quantity_type::from_value(tmp.imag())); + } +}; + +/// specialize root typeof helper for complex > +template +struct root_typeof_helper >,static_rational > +{ + typedef typename + root_typeof_helper >::type value_type; + typedef typename + root_typeof_helper >::type unit_type; + typedef quantity quantity_type; + typedef complex type; + + static type value(const complex >& x) + { + const complex tmp = + root >(complex(x.real().value(), + x.imag().value())); + + return type(quantity_type::from_value(tmp.real()), + quantity_type::from_value(tmp.imag())); + } +}; + +} // namespace units + +} // namespace boost +//] + +int main(void) +{ + using namespace boost::units; + using namespace boost::units::test; + + { + //[complex_snippet_1 + typedef quantity > length_dimension; + + const length_dimension L(complex(2.0,1.0)*meters); + //] + + std::cout << "+L = " << +L << std::endl + << "-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^3 = " << pow<3>(L) << std::endl + << "L^(3/2) = " << pow< static_rational<3,2> >(L) << std::endl + << "3vL = " << root<3>(L) << std::endl + << "(3/2)vL = " << root< static_rational<3,2> >(L) << std::endl + << std::endl; + } + + { + //[complex_snippet_2 + typedef complex > length_dimension; + + const length_dimension L(2.0*meters,1.0*meters); + //] + + std::cout << "+L = " << +L << std::endl + << "-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^3 = " << pow<3>(L) << std::endl + << "L^(3/2) = " << pow< static_rational<3,2> >(L) << std::endl + << "3vL = " << root<3>(L) << std::endl + << "(3/2)vL = " << root< static_rational<3,2> >(L) << std::endl + << std::endl; + } + + return 0; +} diff --git a/src/boost/libs/units/example/composite_output.cpp b/src/boost/libs/units/example/composite_output.cpp new file mode 100644 index 00000000..022ea4e6 --- /dev/null +++ b/src/boost/libs/units/example/composite_output.cpp @@ -0,0 +1,116 @@ +// 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 composite_output.cpp + +\details An example of textual representations of units. + +Output: +@verbatim + +//[conversion_output_output +2 dyn +2 dyn +2 dyne +cm g s^-1 +centimeter gram second^-1 +dyn +dyne +n +nano +n +nano +F +farad +1 F +1 farad +nF +nanofarad +1 nF +1 nanofarad +n(cm g s^-1) +nano(centimeter gram second^-1) +//] + +@endverbatim +**/ +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include +#include + +namespace boost { + +namespace units { + +//[composite_output_snippet_1 + +std::string name_string(const cgs::force&) +{ + return "dyne"; +} + +std::string symbol_string(const cgs::force&) +{ + return "dyn"; +} + +//] + +} + +} + +int main() +{ + using namespace boost::units; + using boost::units::cgs::centimeter; + using boost::units::cgs::gram; + using boost::units::cgs::second; + using boost::units::cgs::dyne; + + //[composite_output_snippet_2] + std::cout << 2.0 * dyne << std::endl + << symbol_format << 2.0 * dyne << std::endl + << name_format << 2.0 * dyne << std::endl + << symbol_format << gram*centimeter/second << std::endl + << name_format << gram*centimeter/second << std::endl + << symbol_format << gram*centimeter/(second*second) << std::endl + << name_format << gram*centimeter/(second*second) << std::endl + << symbol_string(scale<10,static_rational<-9> >()) << std::endl + << name_string(scale<10,static_rational<-9> >()) << std::endl + << symbol_format << si::nano << std::endl + << name_format << si::nano << std::endl + << symbol_format << si::farad << std::endl + << name_format << si::farad << std::endl + << symbol_format << 1.0*si::farad << std::endl + << name_format << 1.0*si::farad << std::endl + << symbol_format << si::farad*si::nano << std::endl + << name_format << si::farad*si::nano << std::endl + << symbol_format << 1.0*si::farad*si::nano << std::endl + << name_format << 1.0*si::farad*si::nano << std::endl + << symbol_format << si::nano*gram*centimeter/second << std::endl + << name_format << si::nano*gram*centimeter/second << std::endl; + //] + + return 0; +} diff --git a/src/boost/libs/units/example/conversion.cpp b/src/boost/libs/units/example/conversion.cpp new file mode 100644 index 00000000..0299dfdc --- /dev/null +++ b/src/boost/libs/units/example/conversion.cpp @@ -0,0 +1,124 @@ +// 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 conversion.cpp + +\details +Test explicit and implicit unit conversion. + +Output: +@verbatim + +//[conversion_output_1 +L1 = 2 m +L2 = 2 m +L3 = 2 m +L4 = 200 cm +L5 = 5 m +L6 = 4 m +L7 = 200 cm +//] + +//[conversion_output_2 +volume (m^3) = 1 m^3 +volume (cm^3) = 1e+06 cm^3 +volume (m^3) = 1 m^3 + +energy (joules) = 1 J +energy (ergs) = 1e+07 erg +energy (joules) = 1 J + +velocity (2 m/s) = 2 m s^-1 +velocity (2 cm/s) = 0.02 m s^-1 +//] + +@endverbatim +**/ + +#include + +#include +#include +#include +#include +#include +#include + +using namespace boost::units; + +int main() +{ + // test quantity_cast + { + // implicit value_type conversions + //[conversion_snippet_1 + quantity L1 = quantity(int(2.5)*si::meters); + quantity L2(quantity(2.5*si::meters)); + //] + + //[conversion_snippet_3 + quantity L3 = static_cast >(L1); + //] + + //[conversion_snippet_4 + quantity L4 = static_cast >(L1); + //] + + quantity L5(4*si::meters), + L6(5*si::meters); + quantity L7(L1); + + swap(L5,L6); + + std::cout << "L1 = " << L1 << std::endl + << "L2 = " << L2 << std::endl + << "L3 = " << L3 << std::endl + << "L4 = " << L4 << std::endl + << "L5 = " << L5 << std::endl + << "L6 = " << L6 << std::endl + << "L7 = " << L7 << std::endl + << std::endl; + } + + // test explicit unit system conversion + { + //[conversion_snippet_5 + quantity vs(1.0*pow<3>(si::meter)); + quantity vc(vs); + quantity vs2(vc); + + quantity es(1.0*si::joule); + quantity ec(es); + quantity es2(ec); + + quantity v1 = 2.0*si::meters/si::second, + v2(2.0*cgs::centimeters/cgs::second); + //] + + std::cout << "volume (m^3) = " << vs << std::endl + << "volume (cm^3) = " << vc << std::endl + << "volume (m^3) = " << vs2 << std::endl + << std::endl; + + std::cout << "energy (joules) = " << es << std::endl + << "energy (ergs) = " << ec << std::endl + << "energy (joules) = " << es2 << std::endl + << std::endl; + + std::cout << "velocity (2 m/s) = " << v1 << std::endl + << "velocity (2 cm/s) = " << v2 << std::endl + << std::endl; + } + + return 0; +} diff --git a/src/boost/libs/units/example/conversion_factor.cpp b/src/boost/libs/units/example/conversion_factor.cpp new file mode 100644 index 00000000..4401e477 --- /dev/null +++ b/src/boost/libs/units/example/conversion_factor.cpp @@ -0,0 +1,76 @@ +// 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 conversion_factor.cpp + +\details An example of using conversion_factor. + +Output: +@verbatim + +//[conversion_factor_output +1e-005 +100 +1e-005 +100 +0.01 +//] + +@endverbatim +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + using namespace boost; + using namespace boost::units; + + //[conversion_factor_snippet_1 + + double dyne_to_newton = + conversion_factor(cgs::dyne,si::newton); + std::cout << dyne_to_newton << std::endl; + + double force_over_mass_conversion = + conversion_factor(si::newton/si::kilogram,cgs::dyne/cgs::gram); + std::cout << force_over_mass_conversion << std::endl; + + double momentum_conversion = + conversion_factor(cgs::momentum(),si::momentum()); + std::cout << momentum_conversion << std::endl; + + double momentum_over_mass_conversion = + conversion_factor(si::momentum()/si::mass(),cgs::momentum()/cgs::gram); + std::cout << momentum_over_mass_conversion << std::endl; + + double acceleration_conversion = + conversion_factor(cgs::gal,si::meter_per_second_squared); + std::cout << acceleration_conversion << std::endl; + + //] + + return 0; +} diff --git a/src/boost/libs/units/example/dimension.cpp b/src/boost/libs/units/example/dimension.cpp new file mode 100644 index 00000000..7f7ffb6b --- /dev/null +++ b/src/boost/libs/units/example/dimension.cpp @@ -0,0 +1,117 @@ +// 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 dimension.cpp + +\details +Test dimension list manipulation. + +Output: +@verbatim + +//[dimension_output +length_dimension = list >, dimensionless_type> +mass_dimension = list >, dimensionless_type> +time_dimension = list >, dimensionless_type> +energy_dimension = list >, list >, list >, dimensionless_type> > > +LM_type = list >, list >, dimensionless_type> > +L_T_type = list >, list >, dimensionless_type> > +V_type = list >, list >, dimensionless_type> > +//] + +@endverbatim +**/ + +#include +#include + +#include + +#include + +#include "test_system.hpp" + +namespace mpl = boost::mpl; + +int main(void) +{ + using namespace boost::units; + + BOOST_MPL_ASSERT((boost::is_same< + length_dimension, + mpl::push_front< + dimensionless_type, + dim > + >::type + >)); + BOOST_MPL_ASSERT((boost::is_same< + mass_dimension, + mpl::push_front< + dimensionless_type, + dim > + >::type + >)); + BOOST_MPL_ASSERT((boost::is_same > >::type, + dim > >::type, + dim > >::type>)); + + std::cout << "length_dimension = " + << simplify_typename(length_dimension()) << std::endl + << "mass_dimension = " + << simplify_typename(mass_dimension()) << std::endl + << "time_dimension = " + << simplify_typename(time_dimension()) << std::endl + << "energy_dimension = " + << simplify_typename(energy_dimension()) << std::endl; + + //[dimension_snippet_1 + typedef mpl::times::type LM_type; + typedef mpl::divides::type L_T_type; + typedef static_root< + mpl::divides::type, + static_rational<2> + >::type V_type; + //] + + BOOST_MPL_ASSERT((boost::is_same > >::type, + dim > >::type>)); + + BOOST_MPL_ASSERT((boost::is_same > >::type, + dim > >::type>)); + + BOOST_MPL_ASSERT((boost::is_same > >::type, + dim > >::type>)); + + std::cout << "LM_type = " << simplify_typename(LM_type()) << std::endl + << "L_T_type = " << simplify_typename(L_T_type()) << std::endl + << "V_type = " << simplify_typename(V_type()) << std::endl; + + return 0; +} diff --git a/src/boost/libs/units/example/heterogeneous_unit.cpp b/src/boost/libs/units/example/heterogeneous_unit.cpp new file mode 100644 index 00000000..7a4f1123 --- /dev/null +++ b/src/boost/libs/units/example/heterogeneous_unit.cpp @@ -0,0 +1,87 @@ +// 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 heterogeneous_unit.cpp + +\details +Test heterogeneous units and quantities. + +Output: +@verbatim + +//[heterogeneous_unit_output_1 +1.5 m +1 g +1.5 m g +1.5 m g^-1 + +1 N +1 kg s^-2 + +1 cm kg s^-2 +1 cm m^-1 kg s^-2 +//] + +//[heterogeneous_unit_output_2 +1.5 cm m +0.015 m^2 +//] + +@endverbatim +**/ + +#define MCS_USE_DEMANGLING +//#define MCS_USE_BOOST_REGEX_DEMANGLING + +#include + +#include +#include +#include +#include +#include +#include + +using namespace boost::units; + +int main() +{ + //[heterogeneous_unit_snippet_1 + quantity L(1.5*si::meter); + quantity M(1.0*cgs::gram); + + std::cout << L << std::endl + << M << std::endl + << L*M << std::endl + << L/M << std::endl + << std::endl; + + std::cout << 1.0*si::meter*si::kilogram/pow<2>(si::second) << std::endl + << 1.0*si::meter*si::kilogram/pow<2>(si::second)/si::meter + << std::endl << std::endl; + + std::cout << 1.0*cgs::centimeter*si::kilogram/pow<2>(si::second) << std::endl + << 1.0*cgs::centimeter*si::kilogram/pow<2>(si::second)/si::meter + << std::endl << std::endl; + //] + + //[heterogeneous_unit_snippet_2 + quantity A(1.5*si::meter*cgs::centimeter); + + std::cout << 1.5*si::meter*cgs::centimeter << std::endl + << A << std::endl + << std::endl; + //] + + return 0; +} diff --git a/src/boost/libs/units/example/information.cpp b/src/boost/libs/units/example/information.cpp new file mode 100644 index 00000000..21ae3f91 --- /dev/null +++ b/src/boost/libs/units/example/information.cpp @@ -0,0 +1,100 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2014 Erik Erlandson +// +// 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) + +//#include + +/** +\file + +\brief information.cpp + +\details +Demonstrate information unit system. + +Output: +@verbatim +bytes= 1.25e+08 B +bits= 8e+06 b +nats= 4605.17 nat +1024 bytes in a kibi-byte +8.38861e+06 bits in a mebi-byte +0.000434294 hartleys in a milli-nat +entropy in bits= 1 b +entropy in nats= 0.693147 nat +entropy in hartleys= 0.30103 Hart +entropy in shannons= 1 Sh +entropy in bytes= 0.125 B +@endverbatim +**/ + +#include +#include +using std::cout; +using std::endl; +using std::log; + +#include +#include +#include +namespace bu = boost::units; +using bu::quantity; +using bu::conversion_factor; + +// SI prefixes +#include +namespace si = boost::units::si; + +// information unit system +#include +using namespace bu::information; + +// Define a function for the entropy of a bernoulli trial. +// The formula is computed using natural log, so the units are in nats. +// The user provides the desired return unit, the only restriction being that it +// must be a unit of information. Conversion to the requested return unit is +// accomplished automatically by the boost::units library. +template +constexpr +quantity > +bernoulli_entropy(double p, const bu::unit&) { + typedef bu::unit requested_unit; + return quantity((-(p*log(p) + (1-p)*log(1-p)))*nats); +} + +int main(int argc, char** argv) { + // a quantity of information (default in units of bytes) + quantity nbytes(1 * si::giga * bit); + cout << "bytes= " << nbytes << endl; + + // a quantity of information, stored as bits + quantity nbits(1 * si::mega * byte); + cout << "bits= " << nbits << endl; + + // a quantity of information, stored as nats + quantity nnats(2 * si::kilo * hartleys); + cout << "nats= " << nnats << endl; + + // how many bytes are in a kibi-byte? + cout << conversion_factor(kibi * byte, byte) << " bytes in a kibi-byte" << endl; + + // how many bits are in a mebi-byte? + cout << conversion_factor(mebi * byte, bit) << " bits in a mebi-byte" << endl; + + // how many hartleys are in a milli-nat? + cout << conversion_factor(si::milli * nat, hartley) << " hartleys in a milli-nat" << endl; + + // compute the entropy of a fair coin flip, in various units of information: + cout << "entropy in bits= " << bernoulli_entropy(0.5, bits) << endl; + cout << "entropy in nats= " << bernoulli_entropy(0.5, nats) << endl; + cout << "entropy in hartleys= " << bernoulli_entropy(0.5, hartleys) << endl; + cout << "entropy in shannons= " << bernoulli_entropy(0.5, shannons) << endl; + cout << "entropy in bytes= " << bernoulli_entropy(0.5, bytes) << endl; + + return 0; +} diff --git a/src/boost/libs/units/example/kitchen_sink.cpp b/src/boost/libs/units/example/kitchen_sink.cpp new file mode 100644 index 00000000..ece126bc --- /dev/null +++ b/src/boost/libs/units/example/kitchen_sink.cpp @@ -0,0 +1,542 @@ +// 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 + +\details +More extensive quantity tests. + +Output: +@verbatim + +//[kitchen_sink_output_1 +S1 : 2 +X1 : 2 +X2 : (4/3) +U1 : N +U2 : J +Q1 : 1 N +Q2 : 2 J +//] + +//[kitchen_sink_output_2 +U1*S1 : 2 N +S1*U1 : 2 N +U1/S1 : 0.5 N +S1/U1 : 2 m^-1 kg^-1 s^2 +//] + +//[kitchen_sink_output_3 +U1+U1 : N +U1-U1 : N +U1*U1 : m^2 kg^2 s^-4 +U1/U1 : dimensionless +U1*U2 : m^3 kg^2 s^-4 +U1/U2 : m^-1 +U1^X : m^2 kg^2 s^-4 +X1vU1 : m^(1/2) kg^(1/2) s^-1 +U1^X2 : m^(4/3) kg^(4/3) s^(-8/3) +X2vU1 : m^(3/4) kg^(3/4) s^(-3/2) +//] + +//[kitchen_sink_output_4 +Q1*S1 : 2 N +S1*Q1 : 2 N +Q1/S1 : 0.5 N +S1/Q1 : 2 m^-1 kg^-1 s^2 +//] + +//[kitchen_sink_output_5 +U1*Q1 : 1 m^2 kg^2 s^-4 +Q1*U1 : 1 m^2 kg^2 s^-4 +U1/Q1 : 1 dimensionless +Q1/U1 : 1 dimensionless +//] + +//[kitchen_sink_output_6 ++Q1 : 1 N +-Q1 : -1 N +Q1+Q1 : 2 N +Q1-Q1 : 0 N +Q1*Q1 : 1 m^2 kg^2 s^-4 +Q1/Q1 : 1 dimensionless +Q1*Q2 : 2 m^3 kg^2 s^-4 +Q1/Q2 : 0.5 m^-1 +Q1^X1 : 1 m^2 kg^2 s^-4 +X1vQ1 : 1 m^(1/2) kg^(1/2) s^-1 +Q1^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_7 +l1 == l2 false +l1 != l2 true +l1 <= l2 true +l1 < l2 true +l1 >= l2 false +l1 > l2 false +//] + +dimless = 1 + +//[kitchen_sink_output_8 +v1 = 2 m s^-1 +//] + +//[kitchen_sink_output_9 +F = 1 N +dx = 1 m +E = 1 J +//] + +//[kitchen_sink_output_10 +r = 5e-07 m +P = 101325 Pa +V = 5.23599e-19 m^3 +T = 310 K +n = 2.05835e-17 mol +R = 8.314472 m^2 kg s^-2 K^-1 mol^-1 (rel. unc. = 1.8e-06) +//] + +//[kitchen_sink_output_11 +theta = 0.375 rd +sin(theta) = 0.366273 dimensionless +asin(sin(theta)) = 0.375 rd +//] + +//[kitchen_sink_output_12 +V = (12.5,0) V +I = (3,4) A +Z = (1.5,-2) Ohm +I*Z = (12.5,0) V +//] + +//[kitchen_sink_output_13 +x+y-w = 0.48(+/-0.632772) m +w*x = 9.04(+/-0.904885) m^2 +x/y = 0.666667(+/-0.149071) dimensionless +//] + +//[kitchen_sink_output_14 +w*y^2/(u*x)^2 = 10.17(+/-3.52328) m^-1 +w/(u*x)^(1/2) = 3.19612(+/-0.160431) dimensionless +//] + +//[kitchen_sink_output_15 +I*w = m^2 kg s^-1 rad^-1 +I*w/L = dimensionless +I*w^2 = J +//] + +//[kitchen_sink_output_16 +1 F +1 kat +1 S +1 C +1 V +1 J +1 N +1 Hz +1 lx +1 H +1 lm +1 Wb +1 T +1 W +1 Pa +1 Ohm +//] + +//[kitchen_sink_output_18 +1 farad +1 katal +1 siemen +1 coulomb +1 volt +1 joule +1 newton +1 hertz +1 lux +1 henry +1 lumen +1 weber +1 tesla +1 watt +1 pascal +1 ohm +//] + +@endverbatim +**/ + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#include "measurement.hpp" + +namespace boost { + +namespace units { + +//[kitchen_sink_function_snippet_3 +/// the physical definition of work - computed for an arbitrary unit system +template +constexpr +quantity,Y> +work(quantity,Y> F, + quantity,Y> dx) +{ + return F*dx; +} +//] + +//[kitchen_sink_function_snippet_4 +/// the ideal gas law in si units +template +constexpr +quantity +idealGasLaw(const quantity& P, + const quantity& V, + const quantity& T) +{ + using namespace boost::units::si; + + using namespace constants::codata; + return (P*V/(R*T)); +} +//] + +} // namespace units + +} // namespace boost + +int 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 q1(1.0*u1); + quantity 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 + << "S1/U1 : " << s1/u1 << std::endl + << std::endl; + + /// check unit-unit algebra + std::cout << "U1+U1 : " << u1+u1 << std::endl + << "U1-U1 : " << u1-u1 << std::endl + << "U1*U1 : " << u1*u1 << std::endl + << "U1/U1 : " << u1/u1 << std::endl + //<< "U1+U2 : " << u1+u2 << std::endl // illegal + //<< "U1-U2 : " << u1-u2 << std::endl // illegal + << "U1*U2 : " << u1*u2 << std::endl + << "U1/U2 : " << u1/u2 << std::endl + << "U1^X : " << pow<2>(u1) << std::endl + << "X1vU1 : " << root<2>(u1) << std::endl + << "U1^X2 : " << pow >(u1) << std::endl + << "X2vU1 : " << root >(u1) << std::endl + << std::endl; + + /// check scalar-quantity algebra + std::cout //<< "Q1+S1 : " << q1+s1 << std::endl // illegal + //<< "S1+Q1 : " << s1+q1 << std::endl // illegal + //<< "Q1-S1 : " << q1-s1 << std::endl // illegal + //<< "S1-Q1 : " << s1-q1 << std::endl // illegal + << "Q1*S1 : " << q1*s1 << std::endl + << "S1*Q1 : " << s1*q1 << std::endl + << "Q1/S1 : " << q1/s1 << std::endl + << "S1/Q1 : " << s1/q1 << std::endl + << std::endl; + + /// check unit-quantity algebra + std::cout //<< "U1+Q1 : " << u1+q1 << std::endl // illegal + //<< "Q1+U1 : " << q1+u1 << std::endl // illegal + //<< "U1-Q1 : " << u1-q1 << std::endl // illegal + //<< "Q1-U1 : " << q1-u1 << std::endl // illegal + << "U1*Q1 : " << u1*q1 << std::endl + << "Q1*U1 : " << q1*u1 << std::endl + << "U1/Q1 : " << u1/q1 << std::endl + << "Q1/U1 : " << q1/u1 << std::endl + << std::endl; + + /// check quantity-quantity algebra + std::cout << "+Q1 : " << +q1 << std::endl + << "-Q1 : " << -q1 << std::endl + << "Q1+Q1 : " << q1+q1 << std::endl + << "Q1-Q1 : " << q1-q1 << std::endl + << "Q1*Q1 : " << q1*q1 << std::endl + << "Q1/Q1 : " << q1/q1 << std::endl + //<< "Q1+Q2 : " << q1+q2 << std::endl // illegal + //<< "Q1-Q2 : " << q1-q2 << std::endl // illegal + << "Q1*Q2 : " << q1*q2 << std::endl + << "Q1/Q2 : " << q1/q2 << std::endl + << "Q1^X1 : " << pow<2>(q1) << std::endl + << "X1vQ1 : " << root<2>(q1) << std::endl + << "Q1^X2 : " << pow >(q1) << std::endl + << "X2vQ1 : " << root >(q1) << std::endl + << std::endl; + + //[kitchen_sink_snippet_2 + /// check comparison tests + quantity l1(1.0*meter), + l2(2.0*meters); + //] + + std::cout << std::boolalpha + << "l1 == l2" << "\t" << (l1 == l2) << std::endl + << "l1 != l2" << "\t" << (l1 != l2) << std::endl + << "l1 <= l2" << "\t" << (l1 <= l2) << std::endl + << "l1 < l2 " << "\t" << (l1 < l2) << std::endl + << "l1 >= l2" << "\t" << (l1 >= l2) << std::endl + << "l1 > l2 " << "\t" << (l1 > l2) << std::endl + << std::endl; + + //[kitchen_sink_snippet_3 + /// check implicit unit conversion from dimensionless to value_type + const double dimless = (q1/q1); + //] + + std::cout << "dimless = " << dimless << std::endl + << std::endl; + + quantity v1 = 2.0*meters/second; + + std::cout << "v1 = " << v1 << std::endl + << std::endl; + + //[kitchen_sink_snippet_4 + /// test calcuation of work + quantity F(1.0*newton); + quantity dx(1.0*meter); + quantity E(work(F,dx)); + //] + + std::cout << "F = " << F << std::endl + << "dx = " << dx << std::endl + << "E = " << E << std::endl + << std::endl; + + { + //[kitchen_sink_snippet_5 + /// test ideal gas law + quantity T = (273.+37.)*kelvin; + quantity P = 1.01325e5*pascals; + quantity r = 0.5e-6*meters; + quantity V = (4.0/3.0)*3.141592*pow<3>(r); + quantity n(idealGasLaw(P,V,T)); + //] + + std::cout << "r = " << r << std::endl + << "P = " << P << std::endl + << "V = " << V << std::endl + << "T = " << T << std::endl + << "n = " << n << std::endl + #if BOOST_UNITS_HAS_TYPEOF + << "R = " << constants::codata::R << std::endl + #else + << "no typeof" << std::endl + #endif // BOOST_UNITS_HAS_TYPEOF + << std::endl; + } + + //[kitchen_sink_snippet_6 + /// test trig stuff + quantity theta = 0.375*radians; + quantity sin_theta = sin(theta); + quantity thetap = asin(sin_theta); + //] + + std::cout << "theta = " << theta << std::endl + << "sin(theta) = " << sin_theta << std::endl + << "asin(sin(theta)) = " << thetap << std::endl + << std::endl; + + /// test implicit conversion of dimensionless to value + double tmp = sin_theta; + + tmp = sin_theta; + + /// test implicit conversion from value to dimensionless + quantity tmpp = tmp; + + tmpp = tmp; + + /// check complex quantities + typedef std::complex complex_type; + + //[kitchen_sink_snippet_7 + quantity v = complex_type(12.5,0.0)*volts; + quantity i = complex_type(3.0,4.0)*amperes; + quantity z = complex_type(1.5,-2.0)*ohms; + //] + + std::cout << "V = " << v << std::endl + << "I = " << i << std::endl + << "Z = " << z << std::endl + << "I*Z = " << i*z << std::endl + << std::endl; + + /// check quantities using user-defined type encapsulating error propagation + + //[kitchen_sink_snippet_8 + quantity > + u(measurement(1.0,0.0)*meters), + w(measurement(4.52,0.02)*meters), + x(measurement(2.0,0.2)*meters), + y(measurement(3.0,0.6)*meters); + //] + + std::cout << "x+y-w = " << x+y-w << std::endl + << "w*x = " << w*x << std::endl + << "x/y = " << x/y << std::endl + << "w*y^2/(u*x)^2 = " << w*y*y/pow<2>(u*x) << std::endl + << "w/(u*x)^(1/2) = " << w/pow< static_rational<1,2> >(u*x) + << std::endl << std::endl; + } + + /// check moment of inertia/angular momentum/rotational energy + + //[kitchen_sink_snippet_9 + std::cout << symbol_format + << "I*w = " << moment_of_inertia()*angular_velocity() << std::endl + << "I*w/L = " << moment_of_inertia()*angular_velocity()/angular_momentum() << std::endl + << "I*w^2 = " << moment_of_inertia()*pow<2>(angular_velocity()) << std::endl + << std::endl; + //] + + //[kitchen_sink_snippet_10 +// std::cout << typename_format +// << quantity(1.0*farad) << std::endl +// << quantity(1.0*katal) << std::endl +// << quantity(1.0*siemen) << std::endl +// << quantity(1.0*coulomb) << std::endl +// << quantity(1.0*volt) << std::endl +// << quantity(1.0*joule) << std::endl +// << quantity(1.0*newton) << std::endl +// << quantity(1.0*hertz) << std::endl +// << quantity(1.0*lux) << std::endl +// << quantity(1.0*henry) << std::endl +// << quantity(1.0*lumen) << std::endl +// << quantity(1.0*weber) << std::endl +// << quantity(1.0*tesla) << std::endl +// << quantity(1.0*watt) << std::endl +// << quantity(1.0*pascals) << std::endl +// << quantity(1.0*ohm) << std::endl +// << std::endl; + //] + + //[kitchen_sink_snippet_11 +// std::cout << raw_format +// << quantity(1.0*farad) << std::endl +// << quantity(1.0*katal) << std::endl +// << quantity(1.0*siemen) << std::endl +// << quantity(1.0*coulomb) << std::endl +// << quantity(1.0*volt) << std::endl +// << quantity(1.0*joule) << std::endl +// << quantity(1.0*newton) << std::endl +// << quantity(1.0*hertz) << std::endl +// << quantity(1.0*lux) << std::endl +// << quantity(1.0*henry) << std::endl +// << quantity(1.0*lumen) << std::endl +// << quantity(1.0*weber) << std::endl +// << quantity(1.0*tesla) << std::endl +// << quantity(1.0*watt) << std::endl +// << quantity(1.0*pascals) << std::endl +// << quantity(1.0*ohm) << std::endl +// << std::endl; + //] + + //[kitchen_sink_snippet_12 + std::cout << symbol_format + << quantity(1.0*farad) << std::endl + << quantity(1.0*katal) << std::endl + << quantity(1.0*siemen) << std::endl + << quantity(1.0*coulomb) << std::endl + << quantity(1.0*volt) << std::endl + << quantity(1.0*joule) << std::endl + << quantity(1.0*newton) << std::endl + << quantity(1.0*hertz) << std::endl + << quantity(1.0*lux) << std::endl + << quantity(1.0*henry) << std::endl + << quantity(1.0*lumen) << std::endl + << quantity(1.0*weber) << std::endl + << quantity(1.0*tesla) << std::endl + << quantity(1.0*watt) << std::endl + << quantity(1.0*pascals) << std::endl + << quantity(1.0*ohm) << std::endl + << std::endl; + //] + + //[kitchen_sink_snippet_13 + std::cout << name_format + << quantity(1.0*farad) << std::endl + << quantity(1.0*katal) << std::endl + << quantity(1.0*siemen) << std::endl + << quantity(1.0*coulomb) << std::endl + << quantity(1.0*volt) << std::endl + << quantity(1.0*joule) << std::endl + << quantity(1.0*newton) << std::endl + << quantity(1.0*hertz) << std::endl + << quantity(1.0*lux) << std::endl + << quantity(1.0*henry) << std::endl + << quantity(1.0*lumen) << std::endl + << quantity(1.0*weber) << std::endl + << quantity(1.0*tesla) << std::endl + << quantity(1.0*watt) << std::endl + << quantity(1.0*pascals) << std::endl + << quantity(1.0*ohm) << std::endl + << std::endl; + //] + + return 0; +} diff --git a/src/boost/libs/units/example/lambda.cpp b/src/boost/libs/units/example/lambda.cpp new file mode 100644 index 00000000..0fbac916 --- /dev/null +++ b/src/boost/libs/units/example/lambda.cpp @@ -0,0 +1,157 @@ +// 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) + +// $Id: lambda.cpp 27 2008-06-16 14:50:58Z maehne $ + +//////////////////////////////////////////////////////////////////////// +/// +/// \file lambda.cpp +/// +/// \brief Example demonstrating the usage of Boost.Units' quantity, +/// unit, and absolute types in functors created with the +/// Boost.Lambda library and stored in Boost.Function objects. +/// +/// \author Torsten Maehne +/// \date 2008-06-04 +/// +/// A mechanical, electrical, geometrical, and thermal example +/// demonstrate how to use Boost.Units' quantity, unit, and absolute +/// types in lambda expressions. The resulting functors can be stored +/// in boost::function objects. It is also shown how to work around a +/// limitation of Boost.Lambda's bind() to help it to find the correct +/// overloaded function by specifying its signature with a +/// static_cast. +/// +//////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include + +// Include boost/units/lambda.hpp instead of boost/lambda/lambda.hpp +// for a convenient usage of Boost.Units' quantity, unit, and absolute +// types in lambda expressions. The header augments Boost.Lambda's +// return type detuction system to recognize the new types so that not +// for each arithmetic operation the return type needs to be +// explicitely specified. +#include + +#include + +static const double pi = 3.14159265358979323846; + +//[lambda_snippet_1 + +int main(int argc, char **argv) { + + using namespace std; + namespace bl = boost::lambda; + namespace bu = boost::units; + namespace si = boost::units::si; + + + //////////////////////////////////////////////////////////////////////// + // Mechanical example: linear accelerated movement + //////////////////////////////////////////////////////////////////////// + + // Initial condition variables for acceleration, speed, and displacement + bu::quantity a = 2.0 * si::meters_per_second_squared; + bu::quantity v = 1.0 * si::meters_per_second; + bu::quantity s0 = 0.5 * si::meter; + + // Displacement over time + boost::function (bu::quantity) > + s = 0.5 * bl::var(a) * bl::_1 * bl::_1 + + bl::var(v) * bl::_1 + + bl::var(s0); + + cout << "Linear accelerated movement:" << endl + << "a = " << a << ", v = " << v << ", s0 = " << s0 << endl + << "s(1.0 * si::second) = " << s(1.0 * si::second) << endl + << endl; + + // Change initial conditions + a = 1.0 * si::meters_per_second_squared; + v = 2.0 * si::meters_per_second; + s0 = -1.5 * si::meter; + + cout << "a = " << a << ", v = " << v << ", s0 = " << s0 << endl + << "s(1.0 * si::second) = " << s(1.0 * si::second) << endl + << endl; + + + //////////////////////////////////////////////////////////////////////// + // Electrical example: oscillating current + //////////////////////////////////////////////////////////////////////// + + // Constants for the current amplitude, frequency, and offset current + const bu::quantity iamp = 1.5 * si::ampere; + const bu::quantity f = 1.0e3 * si::hertz; + const bu::quantity i0 = 0.5 * si::ampere; + + // The invocation of the sin function needs to be postponed using + // bind to specify the oscillation function. A lengthy static_cast + // to the function pointer referencing boost::units::sin() is needed + // to avoid an "unresolved overloaded function type" error. + boost::function (bu::quantity) > + i = iamp + * bl::bind(static_cast::type (*)(const bu::quantity&)>(bu::sin), + 2.0 * pi * si::radian * f * bl::_1) + + i0; + + cout << "Oscillating current:" << endl + << "iamp = " << iamp << ", f = " << f << ", i0 = " << i0 << endl + << "i(1.25e-3 * si::second) = " << i(1.25e-3 * si::second) << endl + << endl; + + + //////////////////////////////////////////////////////////////////////// + // Geometric example: area calculation for a square + //////////////////////////////////////////////////////////////////////// + + // Length constant + const bu::quantity l = 1.5 * si::meter; + + // Again an ugly static_cast is needed to bind pow<2> to the first + // function argument. + boost::function (bu::quantity) > + A = bl::bind(static_cast (*)(const bu::quantity&)>(bu::pow<2>), + bl::_1); + + cout << "Area of a square:" << endl + << "A(" << l <<") = " << A(l) << endl << endl; + + + //////////////////////////////////////////////////////////////////////// + // Thermal example: temperature difference of two absolute temperatures + //////////////////////////////////////////////////////////////////////// + + // Absolute temperature constants + const bu::quantity > + Tref = 273.15 * bu::absolute(); + const bu::quantity > + Tamb = 300.00 * bu::absolute(); + + boost::function (bu::quantity >, + bu::quantity >)> + dT = bl::_2 - bl::_1; + + cout << "Temperature difference of two absolute temperatures:" << endl + << "dT(" << Tref << ", " << Tamb << ") = " << dT(Tref, Tamb) << endl + << endl; + + + return 0; +} +//] diff --git a/src/boost/libs/units/example/measurement.hpp b/src/boost/libs/units/example/measurement.hpp new file mode 100644 index 00000000..72063023 --- /dev/null +++ b/src/boost/libs/units/example/measurement.hpp @@ -0,0 +1,344 @@ +// 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) + +#ifndef BOOST_UNITS_MEASUREMENT_HPP +#define BOOST_UNITS_MEASUREMENT_HPP + +#include +#include +#include +#include + +#include +#include + +namespace boost { + +namespace units { + +namespace sqr_namespace /**/ { + +template +constexpr +Y sqr(Y val) +{ return val*val; } + +} // namespace + +using sqr_namespace::sqr; + +template +class measurement +{ + public: + typedef measurement this_type; + typedef Y value_type; + + constexpr measurement(const value_type& val = value_type(), + const value_type& err = value_type()) : + value_(val), + uncertainty_(std::abs(err)) + { } + + constexpr measurement(const this_type& source) : + value_(source.value_), + uncertainty_(source.uncertainty_) + { } + + //~measurement() { } + + constexpr this_type& operator=(const this_type& source) + { + if (this == &source) return *this; + + value_ = source.value_; + uncertainty_ = source.uncertainty_; + + return *this; + } + + constexpr operator value_type() const { return value_; } + + constexpr value_type value() const { return value_; } + constexpr value_type uncertainty() const { return uncertainty_; } + constexpr value_type lower_bound() const { return value_-uncertainty_; } + constexpr value_type upper_bound() const { return value_+uncertainty_; } + + constexpr this_type& operator+=(const value_type& val) + { + value_ += val; + return *this; + } + + constexpr this_type& operator-=(const value_type& val) + { + value_ -= val; + return *this; + } + + constexpr this_type& operator*=(const value_type& val) + { + value_ *= val; + uncertainty_ *= val; + return *this; + } + + constexpr this_type& operator/=(const value_type& val) + { + value_ /= val; + uncertainty_ /= val; + return *this; + } + + constexpr this_type& operator+=(const this_type& /*source*/); + constexpr this_type& operator-=(const this_type& /*source*/); + constexpr this_type& operator*=(const this_type& /*source*/); + constexpr this_type& operator/=(const this_type& /*source*/); + + private: + value_type value_, + uncertainty_; +}; + +} + +} + +#if BOOST_UNITS_HAS_BOOST_TYPEOF + +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::measurement, 1) + +#endif + +namespace boost { + +namespace units { + +template +inline +constexpr +measurement& +measurement::operator+=(const this_type& source) +{ + uncertainty_ = std::sqrt(sqr(uncertainty_)+sqr(source.uncertainty_)); + value_ += source.value_; + + return *this; +} + +template +inline +constexpr +measurement& +measurement::operator-=(const this_type& source) +{ + uncertainty_ = std::sqrt(sqr(uncertainty_)+sqr(source.uncertainty_)); + value_ -= source.value_; + + return *this; +} + +template +inline +constexpr +measurement& +measurement::operator*=(const this_type& source) +{ + uncertainty_ = (value_*source.value_)* + std::sqrt(sqr(uncertainty_/value_)+ + sqr(source.uncertainty_/source.value_)); + value_ *= source.value_; + + return *this; +} + +template +inline +constexpr +measurement& +measurement::operator/=(const this_type& source) +{ + uncertainty_ = (value_/source.value_)* + std::sqrt(sqr(uncertainty_/value_)+ + sqr(source.uncertainty_/source.value_)); + value_ /= source.value_; + + return *this; +} + +// value_type op measurement +template +inline +constexpr +measurement +operator+(Y lhs,const measurement& rhs) +{ + return (measurement(lhs,Y(0))+=rhs); +} + +template +inline +constexpr +measurement +operator-(Y lhs,const measurement& rhs) +{ + return (measurement(lhs,Y(0))-=rhs); +} + +template +inline +constexpr +measurement +operator*(Y lhs,const measurement& rhs) +{ + return (measurement(lhs,Y(0))*=rhs); +} + +template +inline +constexpr +measurement +operator/(Y lhs,const measurement& rhs) +{ + return (measurement(lhs,Y(0))/=rhs); +} + +// measurement op value_type +template +inline +constexpr +measurement +operator+(const measurement& lhs,Y rhs) +{ + return (measurement(lhs)+=measurement(rhs,Y(0))); +} + +template +inline +constexpr +measurement +operator-(const measurement& lhs,Y rhs) +{ + return (measurement(lhs)-=measurement(rhs,Y(0))); +} + +template +inline +constexpr +measurement +operator*(const measurement& lhs,Y rhs) +{ + return (measurement(lhs)*=measurement(rhs,Y(0))); +} + +template +inline +constexpr +measurement +operator/(const measurement& lhs,Y rhs) +{ + return (measurement(lhs)/=measurement(rhs,Y(0))); +} + +// measurement op measurement +template +inline +constexpr +measurement +operator+(const measurement& lhs,const measurement& rhs) +{ + return (measurement(lhs)+=rhs); +} + +template +inline +constexpr +measurement +operator-(const measurement& lhs,const measurement& rhs) +{ + return (measurement(lhs)-=rhs); +} + +template +inline +constexpr +measurement +operator*(const measurement& lhs,const measurement& rhs) +{ + return (measurement(lhs)*=rhs); +} + +template +inline +constexpr +measurement +operator/(const measurement& lhs,const measurement& rhs) +{ + return (measurement(lhs)/=rhs); +} + +/// specialize power typeof helper +template +struct power_typeof_helper,static_rational > +{ + typedef measurement< + typename power_typeof_helper >::type + > type; + + static constexpr type value(const measurement& x) + { + const static_rational rat; + + const Y m = Y(rat.numerator())/Y(rat.denominator()), + newval = std::pow(x.value(),m), + err = newval*std::sqrt(std::pow(m*x.uncertainty()/x.value(),2)); + + return type(newval,err); + } +}; + +/// specialize root typeof helper +template +struct root_typeof_helper,static_rational > +{ + typedef measurement< + typename root_typeof_helper >::type + > type; + + static constexpr type value(const measurement& x) + { + const static_rational rat; + + const Y m = Y(rat.denominator())/Y(rat.numerator()), + newval = std::pow(x.value(),m), + err = newval*std::sqrt(std::pow(m*x.uncertainty()/x.value(),2)); + + return type(newval,err); + } +}; + +// stream output +template +inline +std::ostream& operator<<(std::ostream& os,const measurement& val) +{ + boost::io::ios_precision_saver precision_saver(os); + boost::io::ios_flags_saver flags_saver(os); + + os << val.value() << "(+/-" << val.uncertainty() << ")"; + + return os; +} + +} // namespace units + +} // namespace boost + +#endif // BOOST_UNITS_MEASUREMENT_HPP diff --git a/src/boost/libs/units/example/non_base_dimension.cpp b/src/boost/libs/units/example/non_base_dimension.cpp new file mode 100644 index 00000000..4476a34e --- /dev/null +++ b/src/boost/libs/units/example/non_base_dimension.cpp @@ -0,0 +1,78 @@ +// 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) 2007-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 non_base_dimension.cpp + +\details +Another example of user-defined units with conversions. + +Output: +@verbatim + +//[non_base_dimension_output +//] + +@endverbatim +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace boost { + +namespace units { + +//[non_base_dimension_snippet_1 + +struct imperial_gallon_tag : + base_unit { }; + +typedef make_system::type imperial; + +typedef unit imperial_gallon; + +struct us_gallon_tag : base_unit { }; + +typedef make_system::type us; + +typedef unit us_gallon; + +//] + +} // namespace units + +} // namespace boost + +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial_gallon_tag, + boost::units::us_gallon_tag, + double, 1.2009499255); + +using namespace boost::units; + +int main(void) +{ + quantity ig1(1.0*imperial_gallon()); + quantity ug1(1.0*us_gallon()); + + quantity ig2(ug1); + quantity ug2(ig1); + + return 0; +} diff --git a/src/boost/libs/units/example/performance.cpp b/src/boost/libs/units/example/performance.cpp new file mode 100644 index 00000000..fd2abe10 --- /dev/null +++ b/src/boost/libs/units/example/performance.cpp @@ -0,0 +1,395 @@ +// 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 performance.cpp + +\details +Test runtime performance. + +Output: +@verbatim + +multiplying ublas::matrix(1000, 1000) : 25.03 seconds +multiplying ublas::matrix(1000, 1000) : 24.49 seconds +tiled_matrix_multiply(1000, 1000) : 1.12 seconds +tiled_matrix_multiply(1000, 1000) : 1.16 seconds +solving y' = 1 - x + 4 * y with double: 1.97 seconds +solving y' = 1 - x + 4 * y with quantity: 1.84 seconds + +@endverbatim +**/ + +#define _SCL_SECURE_NO_WARNINGS + +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4267; disable:4127; disable:4244; disable:4100) +#endif + +#include + +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif + +#include +#include +#include +#include + +enum { + tile_block_size = 24 +}; + +template +void tiled_multiply_carray_inner(T0* first, + T1* second, + Out* out, + int totalwidth, + int width2, + int height1, + int common) { + for(int j = 0; j < height1; ++j) { + for(int i = 0; i < width2; ++i) { + Out value = out[j * totalwidth + i]; + for(int k = 0; k < common; ++k) { + value += first[k + totalwidth * j] * second[k * totalwidth + i]; + } + out[j * totalwidth + i] = value; + } + } +} + +template +void tiled_multiply_carray_outer(T0* first, + T1* second, + Out* out, + int width2, + int height1, + int common) { + std::fill_n(out, width2 * height1, Out()); + int j = 0; + for(; j < height1 - tile_block_size; j += tile_block_size) { + int i = 0; + for(; i < width2 - tile_block_size; i += tile_block_size) { + int k = 0; + for(; k < common - tile_block_size; k += tile_block_size) { + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, + tile_block_size, + tile_block_size, + tile_block_size); + } + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, + tile_block_size, + tile_block_size, + common - k); + } + int k = 0; + for(; k < common - tile_block_size; k += tile_block_size) { + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, width2 - i, + tile_block_size, + tile_block_size); + } + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, width2 - i, + tile_block_size, + common - k); + } + int i = 0; + for(; i < width2 - tile_block_size; i += tile_block_size) { + int k = 0; + for(; k < common - tile_block_size; k += tile_block_size) { + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, + tile_block_size, + height1 - j, + tile_block_size); + } + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, + tile_block_size, + height1 - j, + common - k); + } + int k = 0; + for(; k < common - tile_block_size; k += tile_block_size) { + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, + width2 - i, + height1 - j, + tile_block_size); + } + tiled_multiply_carray_inner( + &first[k + width2 * j], + &second[k * width2 + i], + &out[j * width2 + i], + width2, + width2 - i, + height1 - j, + common - k); +} + +enum { max_value = 1000}; + +template +BOOST_CXX14_CONSTEXPR +R solve_differential_equation(F f, T lower, T upper, N steps, R start) { + typedef typename F::template result::type f_result; + T h = (upper - lower) / (1.0*steps); + for(N i = N(); i < steps; ++i) { + R y = start; + T x = lower + h * (1.0*i); + f_result k1 = f(x, y); + f_result k2 = f(x + h / 2.0, y + h * k1 / 2.0); + f_result k3 = f(x + h / 2.0, y + h * k2 / 2.0); + f_result k4 = f(x + h, y + h * k3); + start = y + h * (k1 + 2.0 * k2 + 2.0 * k3 + k4) / 6.0; + } + return(start); +} + +using namespace boost::units; + +//y' = 1 - x + 4 * y +struct f { + template struct result; + + BOOST_CONSTEXPR double operator()(const double& x, const double& y) const { + return(1.0 - x + 4.0 * y); + } + + boost::units::quantity + BOOST_CONSTEXPR operator()(const quantity& x, + const quantity& y) const { + using namespace boost::units; + using namespace si; + return(1.0 * meters / second - + x * meters / pow<2>(seconds) + + 4.0 * y / seconds ); + } +}; + +template<> +struct f::result { + typedef double type; +}; + +template<> +struct f::result, quantity > { + typedef quantity type; +}; + + + +//y' = 1 - x + 4 * y +//y' - 4 * y = 1 - x +//e^(-4 * x) * (dy - 4 * y * dx) = e^(-4 * x) * (1 - x) * dx +//d/dx(y * e ^ (-4 * x)) = e ^ (-4 * x) (1 - x) * dx + +//d/dx(y * e ^ (-4 * x)) = e ^ (-4 * x) * dx - x * e ^ (-4 * x) * dx +//d/dx(y * e ^ (-4 * x)) = d/dx((-3/16 + 1/4 * x) * e ^ (-4 * x)) +//y * e ^ (-4 * x) = (-3/16 + 1/4 * x) * e ^ (-4 * x) + C +//y = (-3/16 + 1/4 * x) + C/e ^ (-4 * x) +//y = 1/4 * x - 3/16 + C * e ^ (4 * x) + +//y(0) = 1 +//1 = - 3/16 + C +//C = 19/16 +//y(x) = 1/4 * x - 3/16 + 19/16 * e ^ (4 * x) + + + +int main() { + boost::numeric::ublas::matrix ublas_result; + { + boost::numeric::ublas::matrix m1(max_value, max_value); + boost::numeric::ublas::matrix m2(max_value, max_value); + std::srand(1492); + for(int i = 0; i < max_value; ++i) { + for(int j = 0; j < max_value; ++j) { + m1(i,j) = std::rand(); + m2(i,j) = std::rand(); + } + } + std::cout << "multiplying ublas::matrix(" + << max_value << ", " << max_value << ") : "; + boost::timer timer; + ublas_result = (prod(m1, m2)); + std::cout << timer.elapsed() << " seconds" << std::endl; + } + typedef boost::numeric::ublas::matrix< + boost::units::quantity + > matrix_type; + matrix_type ublas_resultq; + { + matrix_type m1(max_value, max_value); + matrix_type m2(max_value, max_value); + std::srand(1492); + for(int i = 0; i < max_value; ++i) { + for(int j = 0; j < max_value; ++j) { + m1(i,j) = std::rand(); + m2(i,j) = std::rand(); + } + } + std::cout << "multiplying ublas::matrix(" + << max_value << ", " << max_value << ") : "; + boost::timer timer; + ublas_resultq = (prod(m1, m2)); + std::cout << timer.elapsed() << " seconds" << std::endl; + } + std::vector cresult(max_value * max_value); + { + std::vector m1(max_value * max_value); + std::vector m2(max_value * max_value); + std::srand(1492); + for(int i = 0; i < max_value * max_value; ++i) { + m1[i] = std::rand(); + m2[i] = std::rand(); + } + std::cout << "tiled_matrix_multiply(" + << max_value << ", " << max_value << ") : "; + boost::timer timer; + tiled_multiply_carray_outer( + &m1[0], + &m2[0], + &cresult[0], + max_value, + max_value, + max_value); + std::cout << timer.elapsed() << " seconds" << std::endl; + } + std::vector< + boost::units::quantity + > cresultq(max_value * max_value); + { + std::vector< + boost::units::quantity + > m1(max_value * max_value); + std::vector< + boost::units::quantity + > m2(max_value * max_value); + std::srand(1492); + for(int i = 0; i < max_value * max_value; ++i) { + m1[i] = std::rand() * boost::units::si::newtons; + m2[i] = std::rand() * boost::units::si::meters; + } + std::cout << "tiled_matrix_multiply(" + << max_value << ", " << max_value << ") : "; + boost::timer timer; + tiled_multiply_carray_outer( + &m1[0], + &m2[0], + &cresultq[0], + max_value, + max_value, + max_value); + std::cout << timer.elapsed() << " seconds" << std::endl; + } + for(int i = 0; i < max_value; ++i) { + for(int j = 0; j < max_value; ++j) { + const double diff = + std::abs(ublas_result(i,j) - cresult[i * max_value + j]); + if(diff > ublas_result(i,j) /1e14) { + std::cout << std::setprecision(15) << "Uh Oh. ublas_result(" + << i << "," << j << ") = " << ublas_result(i,j) + << std::endl + << "cresult[" << i << " * " << max_value << " + " + << j << "] = " << cresult[i * max_value + j] + << std::endl; + return(EXIT_FAILURE); + } + } + } + { + std::vector values(1000); + std::cout << "solving y' = 1 - x + 4 * y with double: "; + boost::timer timer; + for(int i = 0; i < 1000; ++i) { + const double x = .1 * i; + values[i] = solve_differential_equation(f(), 0.0, x, i * 100, 1.0); + } + std::cout << timer.elapsed() << " seconds" << std::endl; + for(int i = 0; i < 1000; ++i) { + const double x = .1 * i; + const double value = 1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x); + if(std::abs(values[i] - value) > value / 1e9) { + std::cout << std::setprecision(15) << "i = : " << i + << ", value = " << value << " approx = " << values[i] + << std::endl; + return(EXIT_FAILURE); + } + } + } + { + using namespace boost::units; + using namespace si; + std::vector > values(1000); + std::cout << "solving y' = 1 - x + 4 * y with quantity: "; + boost::timer timer; + for(int i = 0; i < 1000; ++i) { + const quantity x = .1 * i * seconds; + values[i] = solve_differential_equation( + f(), + 0.0 * seconds, + x, + i * 100, + 1.0 * meters); + } + std::cout << timer.elapsed() << " seconds" << std::endl; + for(int i = 0; i < 1000; ++i) { + const double x = .1 * i; + const quantity value = + (1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x)) * meters; + if(abs(values[i] - value) > value / 1e9) { + std::cout << std::setprecision(15) << "i = : " << i + << ", value = " << value << " approx = " + << values[i] << std::endl; + return(EXIT_FAILURE); + } + } + } +} diff --git a/src/boost/libs/units/example/quantity.cpp b/src/boost/libs/units/example/quantity.cpp new file mode 100644 index 00000000..e3d3f18a --- /dev/null +++ b/src/boost/libs/units/example/quantity.cpp @@ -0,0 +1,128 @@ +// 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 + +\details +Test quantity algebra. + +Output: +@verbatim + +//[quantity_output_double +L = 2 m +L+L = 4 m +L-L = 0 m +L*L = 4 m^2 +L/L = 1 dimensionless +L*meter = 2 m^2 +kilograms*(L/seconds)*(L/seconds) = 4 m^2 kg s^-2 +kilograms*(L/seconds)^2 = 4 m^2 kg s^-2 +L^3 = 8 m^3 +L^(3/2) = 2.82843 m^(3/2) +2vL = 1.41421 m^(1/2) +(3/2)vL = 1.5874 m^(2/3) +//] + +//[quantity_output_complex +L = (3,4) m +L+L = (6,8) m +L-L = (0,0) m +L*L = (-7,24) m^2 +L/L = (1,0) dimensionless +L*meter = (3,4) m^2 +kilograms*(L/seconds)*(L/seconds) = (-7,24) m^2 kg s^-2 +kilograms*(L/seconds)^2 = (-7,24) m^2 kg s^-2 +L^3 = (-117,44) m^3 +L^(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 +#include + +#include + +#include + +#include +#include +#include + +#include "test_system.hpp" + +int main(void) +{ + using namespace boost::units; + using namespace boost::units::test; + + { + //[quantity_snippet_1 + quantity L = 2.0*meters; // quantity of length + quantity 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 >(L) << std::endl + << "2vL = " + << root<2>(L) << std::endl + << "(3/2)vL = " + << root >(L) << std::endl + << std::endl; + } + + { + //[quantity_snippet_2 + quantity > L(std::complex(3.0,4.0)*meters); + quantity > 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 >(L) << std::endl + << "2vL = " + << root<2>(L) << std::endl + << "(3/2)vL = " + << root >(L) << std::endl + << std::endl; + } + + return 0; +} diff --git a/src/boost/libs/units/example/quaternion.cpp b/src/boost/libs/units/example/quaternion.cpp new file mode 100644 index 00000000..a2e3e91b --- /dev/null +++ b/src/boost/libs/units/example/quaternion.cpp @@ -0,0 +1,232 @@ +// 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) 2007-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 quaternion.cpp + +\details +Demonstrate interoperability with Boost.Quaternion. + +Output: +@verbatim + +//[quaternion_output_1 ++L = (4,3,2,1) m +-L = (-4,-3,-2,-1) m +L+L = (8,6,4,2) m +L-L = (0,0,0,0) m +L*L = (2,24,16,8) m^2 +L/L = (1,0,0,0) dimensionless +L^3 = (-104,102,68,34) m^3 +//] + +//[quaternion_output_2 ++L = (4 m,3 m,2 m,1 m) +-L = (-4 m,-3 m,-2 m,-1 m) +L+L = (8 m,6 m,4 m,2 m) +L-L = (0 m,0 m,0 m,0 m) +L^3 = (-104 m^3,102 m^3,68 m^3,34 m^3) +//] + +@endverbatim +**/ + +#include + +#include +#include + +#include +#include +#include + +#include "test_system.hpp" + +#if BOOST_UNITS_HAS_BOOST_TYPEOF + +#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() + +BOOST_TYPEOF_REGISTER_TEMPLATE(boost::math::quaternion, 1) + +#endif + +namespace boost { + +namespace units { + +//[quaternion_class_snippet_1a +/// specialize power typeof helper +template +struct power_typeof_helper,static_rational > +{ + // boost::math::quaternion only supports integer powers + BOOST_STATIC_ASSERT(D==1); + + typedef boost::math::quaternion< + typename power_typeof_helper >::type + > type; + + static type value(const boost::math::quaternion& x) + { + return boost::math::pow(x,static_cast(N)); + } +}; +//] + +//[quaternion_class_snippet_1b +/// specialize root typeof helper +template +struct root_typeof_helper,static_rational > +{ + // boost::math::quaternion only supports integer powers + BOOST_STATIC_ASSERT(N==1); + + typedef boost::math::quaternion< + typename root_typeof_helper >::type + > type; + + static type value(const boost::math::quaternion& x) + { + return boost::math::pow(x,static_cast(D)); + } +}; +//] + +//[quaternion_class_snippet_2a +/// specialize power typeof helper for quaternion > +template +struct power_typeof_helper< + boost::math::quaternion >, + static_rational > +{ + typedef typename power_typeof_helper< + Y, + static_rational + >::type value_type; + + typedef typename power_typeof_helper< + Unit, + static_rational + >::type unit_type; + + typedef quantity quantity_type; + typedef boost::math::quaternion type; + + static type value(const boost::math::quaternion >& x) + { + const boost::math::quaternion tmp = + pow >(boost::math::quaternion( + x.R_component_1().value(), + x.R_component_2().value(), + x.R_component_3().value(), + x.R_component_4().value())); + + return type(quantity_type::from_value(tmp.R_component_1()), + quantity_type::from_value(tmp.R_component_2()), + quantity_type::from_value(tmp.R_component_3()), + quantity_type::from_value(tmp.R_component_4())); + } +}; +//] + +//[quaternion_class_snippet_2b +/// specialize root typeof helper for quaternion > +template +struct root_typeof_helper< + boost::math::quaternion >, + static_rational > +{ + typedef typename root_typeof_helper< + Y, + static_rational + >::type value_type; + + typedef typename root_typeof_helper< + Unit, + static_rational + >::type unit_type; + + typedef quantity quantity_type; + typedef boost::math::quaternion type; + + static type value(const boost::math::quaternion >& x) + { + const boost::math::quaternion tmp = + root >(boost::math::quaternion( + x.R_component_1().value(), + x.R_component_2().value(), + x.R_component_3().value(), + x.R_component_4().value())); + + return type(quantity_type::from_value(tmp.R_component_1()), + quantity_type::from_value(tmp.R_component_2()), + quantity_type::from_value(tmp.R_component_3()), + quantity_type::from_value(tmp.R_component_4())); + } +}; +//] + +} // namespace units + +} // namespace boost + +int main(void) +{ + using boost::math::quaternion; + using namespace boost::units; + using namespace boost::units::test; + using boost::units::pow; + + { + //[quaternion_snippet_1 + typedef quantity > length_dimension; + + length_dimension L(quaternion(4.0,3.0,2.0,1.0)*meters); + //] + + std::cout << "+L = " << +L << std::endl + << "-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 + // unfortunately, without qualification msvc still + // finds boost::math::pow by ADL. + << "L^3 = " << boost::units::pow<3>(L) << std::endl +// << "L^(3/2) = " << pow< static_rational<3,2> >(L) << std::endl +// << "3vL = " << root<3>(L) << std::endl +// << "(3/2)vL = " << root< static_rational<3,2> >(L) << std::endl + << std::endl; + } + + { + //[quaternion_snippet_2 + typedef quaternion > length_dimension; + + length_dimension L(4.0*meters,3.0*meters,2.0*meters,1.0*meters); + //] + + std::cout << "+L = " << +L << std::endl + << "-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^3 = " << boost::units::pow<3>(L) << std::endl +// << "L^(3/2) = " << pow< static_rational<3,2> >(L) << std::endl +// << "3vL = " << root<3>(L) << std::endl +// << "(3/2)vL = " << root< static_rational<3,2> >(L) << std::endl + << std::endl; + } + + return 0; +} diff --git a/src/boost/libs/units/example/radar_beam_height.cpp b/src/boost/libs/units/example/radar_beam_height.cpp new file mode 100644 index 00000000..00f1f902 --- /dev/null +++ b/src/boost/libs/units/example/radar_beam_height.cpp @@ -0,0 +1,167 @@ +// 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 radar_beam_height.cpp + +\details +Demonstrate library usage for user test cases suggested by Michael Fawcett. + +Output: +@verbatim + +//[radar_beam_height_output +radar range : 300 nmi +earth radius : 6.37101e+06 m +beam height 1 : 18169.7 m +beam height 2 : 9.81085 nmi +beam height 3 : 18169.7 m +beam height 4 : 9.81085 nmi +beam height approx : 59488.4 ft +beam height approx : 18132.1 m +//] + +@endverbatim +**/ + +#include + +#include +#include +#include +#include +#include + +using boost::units::length_dimension; +using boost::units::pow; +using boost::units::root; +using boost::units::quantity; +using boost::units::unit; + +//[radar_beam_height_class_snippet_1 +namespace nautical { + +struct length_base_unit : + boost::units::base_unit +{ + static std::string name() { return "nautical mile"; } + static std::string symbol() { return "nmi"; } +}; + +typedef boost::units::make_system::type system; + +/// unit typedefs +typedef unit length; + +static const length mile,miles; + +} // namespace nautical + +// helper for conversions between nautical length and si length +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(nautical::length_base_unit, + boost::units::si::meter_base_unit, + double, 1.852e3); +//] + +//[radar_beam_height_class_snippet_2 +namespace imperial { + +struct length_base_unit : + boost::units::base_unit +{ + static std::string name() { return "foot"; } + static std::string symbol() { return "ft"; } +}; + +typedef boost::units::make_system::type system; + +/// unit typedefs +typedef unit length; + +static const length foot,feet; + +} // imperial + +// helper for conversions between imperial length and si length +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(imperial::length_base_unit, + boost::units::si::meter_base_unit, + double, 1.0/3.28083989501312); +//] + +// radar beam height functions +//[radar_beam_height_function_snippet_1 +template +constexpr +quantity,T> +radar_beam_height(const quantity,T>& radar_range, + const quantity,T>& earth_radius, + T k = 4.0/3.0) +{ + return quantity,T> + (pow<2>(radar_range)/(2.0*k*earth_radius)); +} +//] + +//[radar_beam_height_function_snippet_2 +template +constexpr +return_type +radar_beam_height(const quantity,T>& radar_range, + const quantity,T>& earth_radius, + T k = 4.0/3.0) +{ + // need to decide which system to use for calculation + return pow<2>(static_cast(radar_range)) + / (2.0*k*static_cast(earth_radius)); +} +//] + +//[radar_beam_height_function_snippet_3 +constexpr +quantity +radar_beam_height(const quantity& range) +{ + return quantity + (pow<2>(range/(1.23*nautical::miles/root<2>(imperial::feet)))); +} +//] + +int main(void) +{ + using namespace boost::units; + using namespace boost::units::si; + using namespace nautical; + + //[radar_beam_height_snippet_1 + const quantity radar_range(300.0*miles); + const quantity earth_radius(6371.0087714*kilo*meters); + + const quantity beam_height_1(radar_beam_height(quantity(radar_range),earth_radius)); + const quantity beam_height_2(radar_beam_height(radar_range,quantity(earth_radius))); + const quantity beam_height_3(radar_beam_height< quantity >(radar_range,earth_radius)); + const quantity beam_height_4(radar_beam_height< quantity >(radar_range,earth_radius)); + //] + + std::cout << "radar range : " << radar_range << std::endl + << "earth radius : " << earth_radius << std::endl + << "beam height 1 : " << beam_height_1 << std::endl + << "beam height 2 : " << beam_height_2 << std::endl + << "beam height 3 : " << beam_height_3 << std::endl + << "beam height 4 : " << beam_height_4 << std::endl + << "beam height approx : " << radar_beam_height(radar_range) + << std::endl + << "beam height approx : " + << quantity(radar_beam_height(radar_range)) + << std::endl << std::endl; + + return 0; +} diff --git a/src/boost/libs/units/example/runtime_conversion_factor.cpp b/src/boost/libs/units/example/runtime_conversion_factor.cpp new file mode 100644 index 00000000..f814c884 --- /dev/null +++ b/src/boost/libs/units/example/runtime_conversion_factor.cpp @@ -0,0 +1,72 @@ +// 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) + +#include +#include +#include +#include + +//[runtime_conversion_factor_snippet_1 + +using boost::units::base_dimension; +using boost::units::base_unit; + +static const long currency_base = 1; + +struct currency_base_dimension : base_dimension {}; + +typedef currency_base_dimension::dimension_type currency_type; + +template +struct currency_base_unit : + base_unit, currency_type, currency_base + N> {}; + +typedef currency_base_unit<0> us_dollar_base_unit; +typedef currency_base_unit<1> euro_base_unit; + +typedef us_dollar_base_unit::unit_type us_dollar; +typedef euro_base_unit::unit_type euro; + +// an array of all possible conversions +double conversion_factors[2][2] = { + {1.0, 1.0}, + {1.0, 1.0} +}; + +double get_conversion_factor(long from, long to) { + return(conversion_factors[from][to]); +} + +void set_conversion_factor(long from, long to, double value) { + conversion_factors[from][to] = value; + conversion_factors[to][from] = 1.0 / value; +} + +BOOST_UNITS_DEFINE_CONVERSION_FACTOR_TEMPLATE((long N1)(long N2), + currency_base_unit, + currency_base_unit, + double, get_conversion_factor(N1, N2)); + +//] + +int main() { + boost::units::quantity dollars = 2.00 * us_dollar(); + boost::units::quantity euros(dollars); + set_conversion_factor(0, 1, 2.0); + dollars = static_cast >(euros); + set_conversion_factor(0, 1, .5); + euros = static_cast >(dollars); + double value = euros.value(); // = .5 + if(value != .5) { + return(1); + } else { + return(0); + } +} diff --git a/src/boost/libs/units/example/runtime_unit.cpp b/src/boost/libs/units/example/runtime_unit.cpp new file mode 100644 index 00000000..5777facd --- /dev/null +++ b/src/boost/libs/units/example/runtime_unit.cpp @@ -0,0 +1,116 @@ +// 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) + +#include +#include +#include +#include +#include +#include +#include + +//[runtime_unit_snippet_1 + +namespace { + +using namespace boost::units; +using imperial::foot_base_unit; + +std::map > known_units; + +} + +quantity calculate(const quantity& t) +{ + return(boost::units::hypot(t, 2.0 * si::meters)); +} + +int main() +{ + known_units["meter"] = 1.0 * si::meters; + known_units["centimeter"] = .01 * si::meters; + known_units["foot"] = + conversion_factor(foot_base_unit::unit_type(), si::meter) * si::meter; + + std::string output_type("meter"); + std::string input; + + while((std::cout << "> ") && (std::cin >> input)) + { + if(!input.empty() && input[0] == '#') + { + std::getline(std::cin, input); + } + else if(input == "exit") + { + break; + } + else if(input == "help") + { + std::cout << "type \"exit\" to exit\n" + "type \"return 'unit'\" to set the return units\n" + "type \"'number' 'unit'\" to do a simple calculation" + << std::endl; + } + else if(input == "return") + { + if(std::cin >> input) + { + if(known_units.find(input) != known_units.end()) + { + output_type = input; + std::cout << "Done." << std::endl; + } + else + { + std::cout << "Unknown unit \"" << input << "\"" + << std::endl; + } + } + else + { + break; + } + } + else + { + try + { + double value = boost::lexical_cast(input); + + if(std::cin >> input) + { + if(known_units.find(input) != known_units.end()) + { + std::cout << static_cast( + calculate(value * known_units[input]) / + known_units[output_type]) + << ' ' << output_type << std::endl; + } + else + { + std::cout << "Unknown unit \"" << input << "\"" + << std::endl; + } + } + else + { + break; + } + } + catch(...) + { + std::cout << "Input error" << std::endl; + } + } + } +} + +//] diff --git a/src/boost/libs/units/example/runtime_unit_input.txt b/src/boost/libs/units/example/runtime_unit_input.txt new file mode 100644 index 00000000..6c109e6c --- /dev/null +++ b/src/boost/libs/units/example/runtime_unit_input.txt @@ -0,0 +1,13 @@ +# runtime_unit_input.txt +# +# Copyright (c) 2007-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) + +return foot +2.0 centimeter +return centimeter +3.0 meter +exit diff --git a/src/boost/libs/units/example/systems.cpp b/src/boost/libs/units/example/systems.cpp new file mode 100644 index 00000000..cbbce743 --- /dev/null +++ b/src/boost/libs/units/example/systems.cpp @@ -0,0 +1,1072 @@ +// 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 systems.cpp + +\details +Test various non-si units + +Output: +@verbatim + +@endverbatim +**/ + +#define BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(namespace_,unit_name_,dimension_) \ +namespace boost { \ +namespace units { \ +namespace namespace_ { \ +typedef make_system::type unit_name_ ## system_; \ +typedef unit unit_name_ ## _ ## dimension_; \ +static constexpr unit_name_ ## _ ## dimension_ unit_name_ ## s; \ +} \ +} \ +} \ + +#include +#include +#include + +#include +#include +#include + +#include +#include + +// angle base units +#include +#include +#include +#include +#include +#include +#include + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(angle,arcminute,plane_angle) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(angle,arcsecond,plane_angle) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(angle,degree,plane_angle) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(angle,gradian,plane_angle) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(angle,radian,plane_angle) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(angle,revolution,plane_angle) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(angle,steradian,solid_angle) + +// astronomical base units +#include +#include +#include +#include +#include +#include +#include + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(astronomical,astronomical_unit,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(astronomical,light_second,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(astronomical,light_minute,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(astronomical,light_hour,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(astronomical,light_day,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(astronomical,light_year,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(astronomical,parsec,length) + +// imperial base units +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,thou,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,inch,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,foot,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,yard,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,furlong,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,mile,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,league,length) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,grain,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,drachm,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,ounce,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,pound,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,stone,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,quarter,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,hundredweight,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,ton,mass) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,fluid_ounce,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,gill,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,pint,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,quart,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(imperial,gallon,volume) + +// metric base units +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,angstrom,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,fermi,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,micron,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,nautical_mile,length) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,ton,mass) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,day,time) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,hour,time) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,minute,time) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,year,time) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,knot,velocity) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,are,area) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,barn,area) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,hectare,area) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,liter,volume) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,atmosphere,pressure) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,bar,pressure) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,mmHg,pressure) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(metric,torr,pressure) + +// us base units + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,mil,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,inch,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,foot,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,yard,length) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,mile,length) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,grain,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,dram,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,ounce,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,pound,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,hundredweight,mass) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,ton,mass) + +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,minim,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,fluid_dram,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,teaspoon,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,tablespoon,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,fluid_ounce,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,gill,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,cup,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,pint,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,quart,volume) +BOOST_UNITS_DEFINE_SINGLE_UNIT_SYSTEM(us,gallon,volume) + +int main(void) +{ + using namespace boost::units; + + { + using namespace boost::units::angle; + + std::cout << "Testing angle base units..." << std::endl; + + quantity as(1.0*arcseconds); + quantity am(1.0*arcminutes); + quantity d(1.0*degrees); + quantity g(1.0*gradians); + quantity r(1.0*radians); + quantity rev(1.0*revolutions); + + std::cout << as << " = " << quantity(as) << std::endl + << am << " = " << quantity(am) << std::endl + << d << " = " << quantity(d) << std::endl + << g << " = " << quantity(g) << std::endl + << r << " = " << quantity(r) << std::endl + << rev << " = " << quantity(rev) << std::endl + << std::endl; + + std::cout << rev << "/" << as << " = " << quantity(rev/as) << std::endl + << rev << "/" << am << " = " << quantity(rev/am) << std::endl + << rev << "/" << d << " = " << quantity(rev/d) << std::endl + << rev << "/" << g << " = " << quantity(rev/g) << std::endl + << rev << "/" << r << " = " << quantity(rev/r) << std::endl + << std::endl; + + // conversions only work with exponent of +/- 1 in scaled_base_unit? + std::cout << as << " = " << quantity(as) << std::endl + << am << " = " << quantity(am) << std::endl + << d << " = " << quantity(d) << std::endl + << rev << " = " << quantity(rev) << std::endl + << std::endl; + + // conversions only work with exponent of +/- 1 in scaled_base_unit? see arcsecond.hpp + std::cout << as << " = " << quantity(as) << std::endl + << am << " = " << quantity(am) << std::endl + << d << " = " << quantity(d) << std::endl + << rev << " = " << quantity(rev) << std::endl + << std::endl; + + std::cout << as << " = " << quantity(as) << std::endl + << am << " = " << quantity(am) << std::endl + << d << " = " << quantity(d) << std::endl + << rev << " = " << quantity(rev) << std::endl + << std::endl; + + std::cout << as << " = " << quantity(as) << std::endl + << am << " = " << quantity(am) << std::endl + << d << " = " << quantity(d) << std::endl + << rev << " = " << quantity(rev) << std::endl + << std::endl; + + quantity sa1(1.0*steradians); + + std::cout << sa1 << std::endl + << std::endl; + } + + { + using namespace boost::units::astronomical; + + std::cout << "Testing astronomical base units..." << std::endl; + + quantity ls(1.0*light_seconds); + quantity lm(1.0*light_minutes); + quantity au(1.0*astronomical_units); + quantity lh(1.0*light_hours); + quantity ld(1.0*light_days); + quantity ly(1.0*light_years); + quantity ps(1.0*parsecs); + + std::cout << ls << " = " << quantity(ls) << std::endl + << lm << " = " << quantity(lm) << std::endl + << au << " = " << quantity(au) << std::endl + << lh << " = " << quantity(lh) << std::endl + << ld << " = " << quantity(ld) << std::endl + << ly << " = " << quantity(ly) << std::endl + << ps << " = " << quantity(ps) << std::endl + << std::endl; + + std::cout << ly << "/" << ls << " = " << quantity(ly/ls) << std::endl + << ly << "/" << lm << " = " << quantity(ly/lm) << std::endl + << ly << "/" << au << " = " << quantity(ly/au) << std::endl + << ly << "/" << lh << " = " << quantity(ly/ld) << std::endl + << ly << "/" << ld << " = " << quantity(ly/lh) << std::endl + << ly << "/" << ps << " = " << quantity(ly/ps) << std::endl + << std::endl; + + std::cout << ls << " = " << quantity(ls) << std::endl + << lm << " = " << quantity(lm) << std::endl + << lh << " = " << quantity(lh) << std::endl + << ld << " = " << quantity(ld) << std::endl + << ly << " = " << quantity(ly) << std::endl + << std::endl; + + std::cout << ls << " = " << quantity(ls) << std::endl + << lm << " = " << quantity(lm) << std::endl + << lh << " = " << quantity(lh) << std::endl + << ld << " = " << quantity(ld) << std::endl + << ly << " = " << quantity(ly) << std::endl + << std::endl; + + std::cout << ls << " = " << quantity(ls) << std::endl + << lm << " = " << quantity(lm) << std::endl + << lh << " = " << quantity(lh) << std::endl + << ld << " = " << quantity(ld) << std::endl + << ly << " = " << quantity(ly) << std::endl + << std::endl; + + std::cout << ls << " = " << quantity(ls) << std::endl + << lm << " = " << quantity(lm) << std::endl + << lh << " = " << quantity(lh) << std::endl + << ld << " = " << quantity(ld) << std::endl + << ly << " = " << quantity(ly) << std::endl + << std::endl; + + std::cout << ls << " = " << quantity(ls) << std::endl + << lm << " = " << quantity(lm) << std::endl + << lh << " = " << quantity(ld) << std::endl + << ld << " = " << quantity(lh) << std::endl + << ly << " = " << quantity(ly) << std::endl + << std::endl; + } + + { + using namespace boost::units::imperial; + + std::cout << "Testing imperial base units..." << std::endl; + + quantity iml1(1.0*thous); + quantity iml2(1.0*inchs); + quantity iml3(1.0*foots); + quantity iml4(1.0*yards); + quantity iml5(1.0*furlongs); + quantity iml6(1.0*miles); + quantity iml7(1.0*leagues); + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + std::cout << iml7 << "/" << iml1 << " = " << quantity(iml7/iml1) << std::endl + << iml7 << "/" << iml2 << " = " << quantity(iml7/iml2) << std::endl + << iml7 << "/" << iml3 << " = " << quantity(iml7/iml3) << std::endl + << iml7 << "/" << iml4 << " = " << quantity(iml7/iml4) << std::endl + << iml7 << "/" << iml5 << " = " << quantity(iml7/iml5) << std::endl + << iml7 << "/" << iml6 << " = " << quantity(iml7/iml6) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << iml6 << " = " << quantity(iml6) << std::endl + << iml7 << " = " << quantity(iml7) << std::endl + << std::endl; + + quantity imm1(1.0*grains); + quantity imm2(1.0*drachms); + quantity imm3(1.0*ounces); + quantity imm4(1.0*pounds); + quantity imm5(1.0*stones); + quantity imm6(1.0*quarters); + quantity imm7(1.0*hundredweights); + quantity imm8(1.0*tons); + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm8 << "/" << imm1 << " = " << quantity(imm8/imm1) << std::endl + << imm8 << "/" << imm2 << " = " << quantity(imm8/imm2) << std::endl + << imm8 << "/" << imm3 << " = " << quantity(imm8/imm3) << std::endl + << imm8 << "/" << imm4 << " = " << quantity(imm8/imm4) << std::endl + << imm8 << "/" << imm5 << " = " << quantity(imm8/imm5) << std::endl + << imm8 << "/" << imm6 << " = " << quantity(imm8/imm6) << std::endl + << imm8 << "/" << imm7 << " = " << quantity(imm8/imm7) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << imm7 << " = " << quantity(imm7) << std::endl + << imm8 << " = " << quantity(imm8) << std::endl + << std::endl; + + quantity imv1(1.0*fluid_ounces); + quantity imv2(1.0*gills); + quantity imv3(1.0*pints); + quantity imv4(1.0*quarts); + quantity imv5(1.0*gallons); + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << std::endl; + + std::cout << imv5 << "/" << imv1 << " = " << quantity(imv5/imv1) << std::endl + << imv5 << "/" << imv2 << " = " << quantity(imv5/imv2) << std::endl + << imv5 << "/" << imv3 << " = " << quantity(imv5/imv3) << std::endl + << imv5 << "/" << imv4 << " = " << quantity(imv5/imv4) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << std::endl; + } + + { + using namespace boost::units::metric; + + std::cout << "Testing metric base units..." << std::endl; + + quantity ml1(1.0*fermis); + quantity ml2(1.0*angstroms); + quantity ml3(1.0*microns); + quantity ml4(1.0*nautical_miles); + + std::cout << ml1 << " = " << quantity(ml1) << std::endl + << ml2 << " = " << quantity(ml2) << std::endl + << ml3 << " = " << quantity(ml3) << std::endl + << ml4 << " = " << quantity(ml4) << std::endl + << std::endl; + + std::cout << ml4 << "/" << ml1 << " = " << quantity(ml4/ml1) << std::endl + << ml4 << "/" << ml2 << " = " << quantity(ml4/ml2) << std::endl + << ml4 << "/" << ml3 << " = " << quantity(ml4/ml3) << std::endl + << std::endl; + + std::cout << ml1 << " = " << quantity(ml1) << std::endl + << ml2 << " = " << quantity(ml2) << std::endl + << ml3 << " = " << quantity(ml3) << std::endl + << ml4 << " = " << quantity(ml4) << std::endl + << std::endl; + + std::cout << ml1 << " = " << quantity(ml1) << std::endl + << ml2 << " = " << quantity(ml2) << std::endl + << ml3 << " = " << quantity(ml3) << std::endl + << ml4 << " = " << quantity(ml4) << std::endl + << std::endl; + + std::cout << ml1 << " = " << quantity(ml1) << std::endl + << ml2 << " = " << quantity(ml2) << std::endl + << ml3 << " = " << quantity(ml3) << std::endl + << ml4 << " = " << quantity(ml4) << std::endl + << std::endl; + + std::cout << ml1 << " = " << quantity(ml1) << std::endl + << ml2 << " = " << quantity(ml2) << std::endl + << ml3 << " = " << quantity(ml3) << std::endl + << ml4 << " = " << quantity(ml4) << std::endl + << std::endl; + + quantity mm1(1.0*tons); + + std::cout << mm1 << " = " << quantity(mm1) << std::endl + //<< quantity(mm1) << std::endl // this should work... + << std::endl; + + quantity mt1(1.0*minutes); + quantity mt2(1.0*hours); + quantity mt3(1.0*days); + quantity mt4(1.0*years); + + std::cout << mt1 << " = " << quantity(mt1) << std::endl + << mt2 << " = " << quantity(mt2) << std::endl + << mt3 << " = " << quantity(mt3) << std::endl + << mt4 << " = " << quantity(mt4) << std::endl + << std::endl; + + std::cout << mt4 << "/" << mt1 << " = " << quantity(mt4/mt1) << std::endl + << mt4 << "/" << mt2 << " = " << quantity(mt4/mt2) << std::endl + << mt4 << "/" << mt3 << " = " << quantity(mt4/mt3) << std::endl + << std::endl; + + std::cout << mt1 << " = " << quantity(mt1) << std::endl + << mt2 << " = " << quantity(mt2) << std::endl + << mt3 << " = " << quantity(mt3) << std::endl + << mt4 << " = " << quantity(mt4) << std::endl + << std::endl; + + std::cout << mt1 << " = " << quantity(mt1) << std::endl + << mt2 << " = " << quantity(mt2) << std::endl + << mt3 << " = " << quantity(mt3) << std::endl + << mt4 << " = " << quantity(mt4) << std::endl + << std::endl; + + std::cout << mt1 << " = " << quantity(mt1) << std::endl + << mt2 << " = " << quantity(mt2) << std::endl + << mt3 << " = " << quantity(mt3) << std::endl + << mt4 << " = " << quantity(mt4) << std::endl + << std::endl; + + std::cout << mt1 << " = " << quantity(mt1) << std::endl + << mt2 << " = " << quantity(mt2) << std::endl + << mt3 << " = " << quantity(mt3) << std::endl + << mt4 << " = " << quantity(mt4) << std::endl + << std::endl; + + quantity ms1(1.0*knots); + + std::cout << ms1 << " = " << quantity(ms1) << std::endl + << std::endl; + + quantity ma1(1.0*barns); + quantity ma2(1.0*ares); + quantity ma3(1.0*hectares); + + std::cout << ma1 << " = " << quantity(ma1) << std::endl + << ma2 << " = " << quantity(ma2) << std::endl + << ma3 << " = " << quantity(ma3) << std::endl + << std::endl; + + std::cout << ma3 << "/" << ma1 << " = " << quantity(ma3/ma1) << std::endl + << ma3 << "/" << ma2 << " = " << quantity(ma3/ma2) << std::endl + << std::endl; + + std::cout << ma1 << " = " << quantity(ma1) << std::endl + << ma2 << " = " << quantity(ma2) << std::endl + << ma3 << " = " << quantity(ma3) << std::endl + << std::endl; + + std::cout << ma1 << " = " << quantity(ma1) << std::endl + << ma2 << " = " << quantity(ma2) << std::endl + << ma3 << " = " << quantity(ma3) << std::endl + << std::endl; + + std::cout << ma1 << " = " << quantity(ma1) << std::endl + << ma2 << " = " << quantity(ma2) << std::endl + << ma3 << " = " << quantity(ma3) << std::endl + << std::endl; + + quantity mv1(1.0*liters); + + std::cout << mv1 << " = " << quantity(mv1) << std::endl + << std::endl; + + quantity mp1(1.0*mmHgs); + quantity mp2(1.0*torrs); + quantity mp3(1.0*bars); + quantity mp4(1.0*atmospheres); + + std::cout << mp1 << " = " << quantity(mp1) << std::endl + << mp2 << " = " << quantity(mp2) << std::endl + << mp3 << " = " << quantity(mp3) << std::endl + << mp4 << " = " << quantity(mp4) << std::endl + << std::endl; + + std::cout << mp4 << "/" << mp1 << " = " << quantity(mp4/mp1) << std::endl + << mp4 << "/" << mp2 << " = " << quantity(mp4/mp2) << std::endl + << mp4 << "/" << mp3 << " = " << quantity(mp4/mp3) << std::endl + << std::endl; + + std::cout << mp1 << " = " << quantity(mp1) << std::endl + << mp2 << " = " << quantity(mp2) << std::endl + << mp3 << " = " << quantity(mp3) << std::endl + << mp4 << " = " << quantity(mp4) << std::endl + << std::endl; + + std::cout << mp1 << " = " << quantity(mp1) << std::endl + << mp2 << " = " << quantity(mp2) << std::endl + << mp3 << " = " << quantity(mp3) << std::endl + << mp4 << " = " << quantity(mp4) << std::endl + << std::endl; + + std::cout << mp1 << " = " << quantity(mp1) << std::endl + << mp2 << " = " << quantity(mp2) << std::endl + << mp3 << " = " << quantity(mp3) << std::endl + << mp4 << " = " << quantity(mp4) << std::endl + << std::endl; + + std::cout << mp1 << " = " << quantity(mp1) << std::endl + << mp2 << " = " << quantity(mp2) << std::endl + << mp3 << " = " << quantity(mp3) << std::endl + << mp4 << " = " << quantity(mp4) << std::endl + << std::endl; + } + + { + using namespace boost::units::us; + + std::cout << "Testing U.S. customary base units..." << std::endl; + + quantity iml1(1.0*mils); + quantity iml2(1.0*inchs); + quantity iml3(1.0*foots); + quantity iml4(1.0*yards); + quantity iml5(1.0*miles); + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << std::endl; + + std::cout << iml5 << "/" << iml1 << " = " << quantity(iml5/iml1) << std::endl + << iml5 << "/" << iml2 << " = " << quantity(iml5/iml2) << std::endl + << iml5 << "/" << iml3 << " = " << quantity(iml5/iml3) << std::endl + << iml5 << "/" << iml4 << " = " << quantity(iml5/iml4) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << std::endl; + + std::cout << iml1 << " = " << quantity(iml1) << std::endl + << iml2 << " = " << quantity(iml2) << std::endl + << iml3 << " = " << quantity(iml3) << std::endl + << iml4 << " = " << quantity(iml4) << std::endl + << iml5 << " = " << quantity(iml5) << std::endl + << std::endl; + + quantity imm1(1.0*grains); + quantity imm2(1.0*drams); + quantity imm3(1.0*ounces); + quantity imm4(1.0*pounds); + quantity imm5(1.0*hundredweights); + quantity imm6(1.0*tons); + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << std::endl; + + std::cout << imm6 << "/" << imm1 << " = " << quantity(imm6/imm1) << std::endl + << imm6 << "/" << imm2 << " = " << quantity(imm6/imm2) << std::endl + << imm6 << "/" << imm3 << " = " << quantity(imm6/imm3) << std::endl + << imm6 << "/" << imm4 << " = " << quantity(imm6/imm4) << std::endl + << imm6 << "/" << imm5 << " = " << quantity(imm6/imm5) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << std::endl; + + std::cout << imm1 << " = " << quantity(imm1) << std::endl + << imm2 << " = " << quantity(imm2) << std::endl + << imm3 << " = " << quantity(imm3) << std::endl + << imm4 << " = " << quantity(imm4) << std::endl + << imm5 << " = " << quantity(imm5) << std::endl + << imm6 << " = " << quantity(imm6) << std::endl + << std::endl; + + quantity imv1(1.0*minims); + quantity imv2(1.0*fluid_drams); + quantity imv3(1.0*teaspoons); + quantity imv4(1.0*tablespoons); + quantity imv5(1.0*fluid_ounces); + quantity imv6(1.0*gills); + quantity imv7(1.0*cups); + quantity imv8(1.0*pints); + quantity imv9(1.0*quarts); + quantity imv10(1.0*gallons); + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv10 << "/" << imv1 << " = " << quantity(imv10/imv1) << std::endl + << imv10 << "/" << imv2 << " = " << quantity(imv10/imv2) << std::endl + << imv10 << "/" << imv3 << " = " << quantity(imv10/imv3) << std::endl + << imv10 << "/" << imv4 << " = " << quantity(imv10/imv4) << std::endl + << imv10 << "/" << imv5 << " = " << quantity(imv10/imv5) << std::endl + << imv10 << "/" << imv6 << " = " << quantity(imv10/imv6) << std::endl + << imv10 << "/" << imv7 << " = " << quantity(imv10/imv7) << std::endl + << imv10 << "/" << imv8 << " = " << quantity(imv10/imv8) << std::endl + << imv10 << "/" << imv9 << " = " << quantity(imv10/imv9) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + + std::cout << imv1 << " = " << quantity(imv1) << std::endl + << imv2 << " = " << quantity(imv2) << std::endl + << imv3 << " = " << quantity(imv3) << std::endl + << imv4 << " = " << quantity(imv4) << std::endl + << imv5 << " = " << quantity(imv5) << std::endl + << imv6 << " = " << quantity(imv6) << std::endl + << imv7 << " = " << quantity(imv7) << std::endl + << imv8 << " = " << quantity(imv8) << std::endl + << imv9 << " = " << quantity(imv9) << std::endl + << imv10 << " = " << quantity(imv10) << std::endl + << std::endl; + } + + return 0; +} diff --git a/src/boost/libs/units/example/temperature.cpp b/src/boost/libs/units/example/temperature.cpp new file mode 100644 index 00000000..f6b43421 --- /dev/null +++ b/src/boost/libs/units/example/temperature.cpp @@ -0,0 +1,98 @@ +// 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 temperature.cpp + +\details +Conversions between Fahrenheit and Kelvin for absolute temperatures and +temperature differences. + +Output: +@verbatim + +//[ temperature_output_1 +{ 32 } F +{ 273.15 } K +{ 273.15 } K +[ 32 ] F +[ 17.7778 ] K +[ 17.7778 ] K +//] + +@endverbatim +**/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace boost::units; + +namespace boost { + +namespace units { + +namespace fahrenheit { + +//[temperature_snippet_1 +typedef temperature::fahrenheit_base_unit::unit_type temperature; +typedef get_system::type system; + +BOOST_UNITS_STATIC_CONSTANT(degree,temperature); +BOOST_UNITS_STATIC_CONSTANT(degrees,temperature); +//] + +} // fahrenheit + +} // namespace units + +} // namespace boost + +int main() +{ + //[temperature_snippet_3 + quantity > T1p( + 32.0*absolute()); + quantity T1v( + 32.0*fahrenheit::degrees); + + quantity > T2p(T1p); + quantity T2v(T1v); + //] + + typedef conversion_helper< + quantity >, + quantity > > absolute_conv_type; + typedef conversion_helper< + quantity, + quantity > relative_conv_type; + + std::cout << T1p << std::endl + << absolute_conv_type::convert(T1p) << std::endl + << T2p << std::endl + << T1v << std::endl + << relative_conv_type::convert(T1v) << std::endl + << T2v << std::endl + << std::endl; + + return 0; +} diff --git a/src/boost/libs/units/example/test_system.hpp b/src/boost/libs/units/example/test_system.hpp new file mode 100644 index 00000000..0eaaa973 --- /dev/null +++ b/src/boost/libs/units/example/test_system.hpp @@ -0,0 +1,153 @@ +// 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) + +#ifndef MCS_TEST_SYSTEM_HPP +#define MCS_TEST_SYSTEM_HPP + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { + +namespace units { + +//[test_system_snippet_1 + +/// base dimension of length +struct length_base_dimension : base_dimension { }; +/// base dimension of mass +struct mass_base_dimension : base_dimension { }; +/// base dimension of time +struct time_base_dimension : base_dimension { }; + +//] + +#if 0 +//[test_system_snippet_2 + +typedef make_dimension_list< + boost::mpl::list< dim< length_base_dimension,static_rational<1> > > +>::type length_dimension; + +typedef make_dimension_list< + boost::mpl::list< dim< mass_base_dimension,static_rational<1> > > +>::type mass_dimension; + +typedef make_dimension_list< + boost::mpl::list< dim< time_base_dimension,static_rational<1> > > +>::type time_dimension; + +//] +#endif + +//[test_system_snippet_3 +typedef length_base_dimension::dimension_type length_dimension; +typedef mass_base_dimension::dimension_type mass_dimension; +typedef time_base_dimension::dimension_type time_dimension; +//] + +#if 0 +//[test_system_snippet_4 + +typedef make_dimension_list< + boost::mpl::list< dim< length_base_dimension,static_rational<2> > > +>::type area_dimension; + +typedef make_dimension_list< + boost::mpl::list< dim< mass_base_dimension,static_rational<1> >, + dim< length_base_dimension,static_rational<2> >, + dim< time_base_dimension,static_rational<-2> > > +>::type energy_dimension; + +//] +#endif + +//[test_system_snippet_5 +typedef derived_dimension::type area_dimension; +typedef derived_dimension::type energy_dimension; +//] + +namespace test { + +//[test_system_snippet_6 + +struct meter_base_unit : base_unit { }; +struct kilogram_base_unit : base_unit { }; +struct second_base_unit : base_unit { }; + +typedef make_system< + meter_base_unit, + kilogram_base_unit, + second_base_unit>::type mks_system; + +/// unit typedefs +typedef unit dimensionless; + +typedef unit length; +typedef unit mass; +typedef unit time; + +typedef unit area; +typedef unit energy; +//] + +//[test_system_snippet_7 +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(meter,length); +BOOST_UNITS_STATIC_CONSTANT(meters,length); +BOOST_UNITS_STATIC_CONSTANT(kilogram,mass); +BOOST_UNITS_STATIC_CONSTANT(kilograms,mass); +BOOST_UNITS_STATIC_CONSTANT(second,time); +BOOST_UNITS_STATIC_CONSTANT(seconds,time); + +BOOST_UNITS_STATIC_CONSTANT(square_meter,area); +BOOST_UNITS_STATIC_CONSTANT(square_meters,area); +BOOST_UNITS_STATIC_CONSTANT(joule,energy); +BOOST_UNITS_STATIC_CONSTANT(joules,energy); +//] + +} // namespace test + +//[test_system_snippet_8 +template<> struct base_unit_info +{ + static std::string name() { return "meter"; } + static std::string symbol() { return "m"; } +}; +//] + +template<> struct base_unit_info +{ + static std::string name() { return "kilogram"; } + static std::string symbol() { return "kg"; } +}; + +template<> struct base_unit_info +{ + static std::string name() { return "second"; } + static std::string symbol() { return "s"; } +}; + +} // namespace units + +} // namespace boost + +#endif // MCS_TEST_SYSTEM_HPP diff --git a/src/boost/libs/units/example/tutorial.cpp b/src/boost/libs/units/example/tutorial.cpp new file mode 100644 index 00000000..acda5ee9 --- /dev/null +++ b/src/boost/libs/units/example/tutorial.cpp @@ -0,0 +1,95 @@ +// 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 tutorial.cpp + +\brief Basic tutorial using SI units. + +\details +Tutorial +Defines a function that computes the work, in joules, +done by exerting a force in newtons over a specified distance +in meters and outputs the result to std::cout. + +Also code for computing the complex impedance +using std::complex as the value type. + +Output: +@verbatim +//[tutorial_output +F = 2 N +dx = 2 m +E = 4 J + +V = (12.5,0) V +I = (3,4) A +Z = (1.5,-2) Ohm +I*Z = (12.5,0) V +I*Z == V? true +//] +@endverbatim +*/ + +//[tutorial_code +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace boost::units; +using namespace boost::units::si; + +constexpr +quantity +work(const quantity& F, const quantity& dx) +{ + return F * dx; // Defines the relation: work = force * distance. +} + +int main() +{ + /// Test calculation of work. + quantity F(2.0 * newton); // Define a quantity of force. + quantity dx(2.0 * meter); // and a distance, + quantity E(work(F,dx)); // and calculate the work done. + + std::cout << "F = " << F << std::endl + << "dx = " << dx << std::endl + << "E = " << E << std::endl + << std::endl; + + /// Test and check complex quantities. + typedef std::complex complex_type; // double real and imaginary parts. + + // Define some complex electrical quantities. + quantity v = complex_type(12.5, 0.0) * volts; + quantity i = complex_type(3.0, 4.0) * amperes; + quantity z = complex_type(1.5, -2.0) * ohms; + + std::cout << "V = " << v << std::endl + << "I = " << i << std::endl + << "Z = " << z << std::endl + // Calculate from Ohm's law voltage = current * resistance. + << "I * Z = " << i * z << std::endl + // Check defined V is equal to calculated. + << "I * Z == V? " << std::boolalpha << (i * z == v) << std::endl + << std::endl; + return 0; +} +//] diff --git a/src/boost/libs/units/example/unit.cpp b/src/boost/libs/units/example/unit.cpp new file mode 100644 index 00000000..934d5573 --- /dev/null +++ b/src/boost/libs/units/example/unit.cpp @@ -0,0 +1,73 @@ +// 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 unit.cpp + +\details +Test unit algebra. + +Output: +@verbatim + +//[unit_output +L = m +L+L = m +L-L = m +L/L = dimensionless +meter*meter = m^2 +M*(L/T)*(L/T) = m^2 kg s^-2 +M*(L/T)^2 = m^2 kg s^-2 +L^3 = m^3 +L^(3/2) = m^(3/2) +2vM = kg^(1/2) +(3/2)vM = kg^(2/3) +//] + +@endverbatim +**/ + +#include + +#include "test_system.hpp" + +#include + +int main() +{ + using namespace boost::units; + using namespace boost::units::test; + + //[unit_snippet_1 + const length L; + const mass M; + // needs to be namespace-qualified because of global time definition + const boost::units::test::time T; + const energy E; + //] + + std::cout << "L = " << L << std::endl + << "L+L = " << L+L << std::endl + << "L-L = " << L-L << std::endl + << "L/L = " << L/L << std::endl + << "meter*meter = " << meter*meter << std::endl + << "M*(L/T)*(L/T) = " << M*(L/T)*(L/T) << std::endl + << "M*(L/T)^2 = " << M*pow<2>(L/T) << std::endl + << "L^3 = " << pow<3>(L) << std::endl + << "L^(3/2) = " << pow >(L) + << std::endl + << "2vM = " << root<2>(M) << std::endl + << "(3/2)vM = " << root >(M) + << std::endl; + + return 0; +} diff --git a/src/boost/libs/units/images/form_0.png b/src/boost/libs/units/images/form_0.png new file mode 100644 index 00000000..7a8b61e2 Binary files /dev/null and b/src/boost/libs/units/images/form_0.png differ diff --git a/src/boost/libs/units/images/form_1.png b/src/boost/libs/units/images/form_1.png new file mode 100644 index 00000000..aa6ec914 Binary files /dev/null and b/src/boost/libs/units/images/form_1.png differ diff --git a/src/boost/libs/units/images/form_10.png b/src/boost/libs/units/images/form_10.png new file mode 100644 index 00000000..debfc1d7 Binary files /dev/null and b/src/boost/libs/units/images/form_10.png differ diff --git a/src/boost/libs/units/images/form_11.png b/src/boost/libs/units/images/form_11.png new file mode 100644 index 00000000..86792044 Binary files /dev/null and b/src/boost/libs/units/images/form_11.png differ diff --git a/src/boost/libs/units/images/form_12.png b/src/boost/libs/units/images/form_12.png new file mode 100644 index 00000000..1e92526b Binary files /dev/null and b/src/boost/libs/units/images/form_12.png differ diff --git a/src/boost/libs/units/images/form_13.png b/src/boost/libs/units/images/form_13.png new file mode 100644 index 00000000..d4fe5724 Binary files /dev/null and b/src/boost/libs/units/images/form_13.png differ diff --git a/src/boost/libs/units/images/form_14.png b/src/boost/libs/units/images/form_14.png new file mode 100644 index 00000000..8e2e2823 Binary files /dev/null and b/src/boost/libs/units/images/form_14.png differ diff --git a/src/boost/libs/units/images/form_15.png b/src/boost/libs/units/images/form_15.png new file mode 100644 index 00000000..ef47182b Binary files /dev/null and b/src/boost/libs/units/images/form_15.png differ diff --git a/src/boost/libs/units/images/form_2.png b/src/boost/libs/units/images/form_2.png new file mode 100644 index 00000000..06bb0ec0 Binary files /dev/null and b/src/boost/libs/units/images/form_2.png differ diff --git a/src/boost/libs/units/images/form_3.png b/src/boost/libs/units/images/form_3.png new file mode 100644 index 00000000..5a59744e Binary files /dev/null and b/src/boost/libs/units/images/form_3.png differ diff --git a/src/boost/libs/units/images/form_4.png b/src/boost/libs/units/images/form_4.png new file mode 100644 index 00000000..4b1c9b2d Binary files /dev/null and b/src/boost/libs/units/images/form_4.png differ diff --git a/src/boost/libs/units/images/form_5.png b/src/boost/libs/units/images/form_5.png new file mode 100644 index 00000000..a641eb61 Binary files /dev/null and b/src/boost/libs/units/images/form_5.png differ diff --git a/src/boost/libs/units/images/form_6.png b/src/boost/libs/units/images/form_6.png new file mode 100644 index 00000000..0075f7af Binary files /dev/null and b/src/boost/libs/units/images/form_6.png differ diff --git a/src/boost/libs/units/images/form_7.png b/src/boost/libs/units/images/form_7.png new file mode 100644 index 00000000..66b89ac5 Binary files /dev/null and b/src/boost/libs/units/images/form_7.png differ diff --git a/src/boost/libs/units/images/form_8.png b/src/boost/libs/units/images/form_8.png new file mode 100644 index 00000000..f272bead Binary files /dev/null and b/src/boost/libs/units/images/form_8.png differ diff --git a/src/boost/libs/units/images/form_9.png b/src/boost/libs/units/images/form_9.png new file mode 100644 index 00000000..cbf21704 Binary files /dev/null and b/src/boost/libs/units/images/form_9.png differ diff --git a/src/boost/libs/units/index.html b/src/boost/libs/units/index.html new file mode 100644 index 00000000..d03ad5c7 --- /dev/null +++ b/src/boost/libs/units/index.html @@ -0,0 +1,22 @@ + + + + + +Automatic redirection failed, please go to +../../doc/html/boost_units.html +
+ +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) 2007-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)
+
+
+ + diff --git a/src/boost/libs/units/meta/libraries.json b/src/boost/libs/units/meta/libraries.json new file mode 100644 index 00000000..4e8bdb9a --- /dev/null +++ b/src/boost/libs/units/meta/libraries.json @@ -0,0 +1,16 @@ +{ + "key": "units", + "name": "Units", + "authors": [ + "Matthias Schabel", + "Steven Watanabe" + ], + "description": "Zero-overhead dimensional analysis and unit/quantity manipulation and conversion.", + "category": [ + "Domain" + ], + "maintainers": [ + "Jürgen Hunold ", + "Steven Watanabe " + ] +} diff --git a/src/boost/libs/units/test/Jamfile.v2 b/src/boost/libs/units/test/Jamfile.v2 new file mode 100644 index 00000000..5dae5562 --- /dev/null +++ b/src/boost/libs/units/test/Jamfile.v2 @@ -0,0 +1,78 @@ +# Jamfile.v2 +# +# Copyright (c) 2007-2009 +# 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 + +import testing ; + +warning-options = all on ; +warning-compilers = + msvc +; + +project boost/units/test : + requirements + /boost//headers + msvc:on + $(warning-compilers)\:$(warning-options) + # This warning comes from the test library. + msvc:"/wd4701" + # The comes from the exception library + msvc,7.1:"/wd4800" +; + +alias test_framework : /boost//unit_test_framework/off ; + +compile test_predicates.cpp ; +compile test_negative_denominator.cpp ; +compile test_dimensionless_ice1.cpp ; +compile test_dimensionless_ice2.cpp ; +compile test_mixed_value_types.cpp ; +compile test_complicated_system.cpp ; +compile test_reduce_unit.cpp ; +compile test_unscale.cpp ; +compile test_constants.cpp ; + +run test_dimensionless_quantity.cpp ; +run test_implicit_conversion.cpp ; +run test_quantity.cpp ; +run test_unit.cpp ; +run test_conversion.cpp test_framework ; +run test_base_dimension.cpp ; +run test_absolute.cpp ; +run test_default_conversion.cpp ; +run test_cmath.cpp ; +run test_limits.cpp ; +run test_custom_unit.cpp ; +run test_scaled_conversion.cpp ; +run test_lambda.cpp ; +run test_sqrt_scaled_unit.cpp ; +run test_scaled_unit.cpp test_framework ; +run test_output.cpp test_framework /boost//regex/off : : : always_show_run_output ; +run test_trig.cpp test_framework ; +run test_information_units.cpp test_framework ; + +compile-fail fail_implicit_conversion.cpp ; +compile-fail fail_quantity_construct.cpp ; +compile-fail fail_quantity_assign.cpp ; +compile-fail fail_quantity_add.cpp ; +compile-fail fail_quantity_subtract.cpp ; +compile-fail fail_quantity_add_assign.cpp ; +compile-fail fail_quantity_sub_assign.cpp ; +compile-fail fail_quantity_scalar_add.cpp ; +compile-fail fail_quantity_scalar_sub.cpp ; +compile-fail fail_quantity_unit_add.cpp ; +compile-fail fail_quantity_unit_subtract.cpp ; +compile-fail fail_scalar_quantity_add.cpp ; +compile-fail fail_scalar_quantity_sub.cpp ; +compile-fail fail_unit_quantity_add.cpp ; +compile-fail fail_unit_quantity_subtract.cpp ; +compile-fail fail_adl_detail.cpp ; +compile-fail fail_heterogeneous_unit.cpp ; +compile-fail fail_base_dimension.cpp ; +compile-fail fail_add_temperature.cpp ; +compile-fail fail_quantity_non_unit.cpp ; diff --git a/src/boost/libs/units/test/check_conversion_defs.cpp b/src/boost/libs/units/test/check_conversion_defs.cpp new file mode 100644 index 00000000..cb7ff56b --- /dev/null +++ b/src/boost/libs/units/test/check_conversion_defs.cpp @@ -0,0 +1,159 @@ +// 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) 2007-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) + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace filesystem = boost::filesystem; + +//struct stop { +// stop() { char c; std::cin >> c; } +//} stop_; + +boost::regex whitespace("\\s*"); +boost::regex blank_line("\\A(?://.*$|\\s)*"); + +boost::regex include_guard("#ifndef (\\w+)\n#define \\1\n"); +boost::regex base_unit("(\\w*_base_unit)(?:;| :)"); + +std::pair get_base_unit_and_include_guard(const filesystem::path& path) { + filesystem::ifstream in(path); + std::string contents(std::istreambuf_iterator(in.rdbuf()), std::istreambuf_iterator()); + in.close(); + boost::smatch include_guard_match; + boost::regex_search(contents, include_guard_match, include_guard); + boost::smatch base_unit_match; + boost::regex_search(contents, base_unit_match, base_unit); + std::cout << "creating map entry: " << base_unit_match[1].str() << " -> "<< include_guard_match[1].str() << std::endl; + return(std::make_pair(base_unit_match[1].str(), include_guard_match[1].str())); +} + +int main() { + std::cout << "In main" << std::endl; + std::map include_guards; + for(filesystem::directory_iterator begin(filesystem::path("../../../boost/units/systems/base_units")), end; begin != end; ++begin) { + if(begin->status().type() == filesystem::regular_file) { + std::cout << "reading file: " << begin->path() << std::endl; + include_guards.insert(get_base_unit_and_include_guard(begin->path())); + } + } + + std::cout << "reading conversions file" << std::endl; + filesystem::ifstream conversions_file(filesystem::path("../../../boost/units/systems/base_units/detail/conversions.hpp")); + + std::string line; + int line_count = 0; + + boost::smatch match; + + std::set conversion_guards; + + try { + +boost::regex include_guard_regex("#if defined\\((\\w+)\\) && defined\\((\\w+)\\) &&\\\\"); +std::cout << __LINE__ << std::endl; +boost::regex conversion_guard_regex(" !defined\\((\\w+)\\)"); +std::cout << __LINE__ << std::endl; +boost::regex set_conversion_guard(" #define (\\w+)"); +std::cout << __LINE__ << std::endl; +boost::regex include_conversion(" #include "); +std::cout << __LINE__ << std::endl; +boost::regex include_absolute(" #include "); +std::cout << __LINE__ << std::endl; +boost::regex define_conversion_factor(" BOOST_UNITS_DEFINE_CONVERSION_FACTOR\\(boost::units::(\\w+_base_unit), boost::units::(\\w+_base_unit), \\w+, (?:[\\d\\.e\\-/ ]*|one\\(\\))\\);"); +std::cout << __LINE__ << std::endl; +boost::regex define_conversion_offset(" BOOST_UNITS_DEFINE_CONVERSION_OFFSET\\(boost::units::(\\w+_base_unit), boost::units::(\\w+_base_unit), \\w+, [\\d\\.e+\\* \\-/]*\\);"); +std::cout << __LINE__ << std::endl; +boost::regex endif("#endif"); +std::cout << __LINE__ << std::endl; + + while(std::getline(conversions_file, line)) { + ++line_count; + std::cout << "on line: " << line_count << std::endl; + if(boost::regex_match(line, match, blank_line)) { + continue; + } else if(boost::regex_match(line, match, include_guard_regex)) { + std::string guard1, guard2, unit1, unit2, conversion_guard; + bool uses_absolute = false; + + guard1 = match[1].str(); + guard2 = match[2].str(); + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(!boost::regex_match(line, match, conversion_guard_regex)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + + conversion_guard = match[1].str(); + if(!conversion_guards.insert(conversion_guard).second){ std::cerr << "error on line: " << line_count << std::endl; return(1); } + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(!boost::regex_match(line, match, set_conversion_guard)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } +std::cout << __LINE__ << std::endl; + + if(match[1].str() != conversion_guard) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(!boost::regex_match(line, match, include_conversion)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } +std::cout << __LINE__ << std::endl; + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + if(boost::regex_match(line, match, include_absolute)) { + uses_absolute = true; + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + } + +std::cout << __LINE__ << std::endl; + if(!boost::regex_match(line, match, define_conversion_factor)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + +std::cout << __LINE__ << ": " << line << std::endl; + unit1 = match[1].str(); + unit2 = match[2].str(); + if(!((include_guards[unit1] == guard1 && include_guards[unit2] == guard2) || + (include_guards[unit1] == guard2 && include_guards[unit2] == guard1))) { + std::cerr << "guard1: " << guard1 << std::endl; + std::cerr << "guard2: " << guard2 << std::endl; + std::cerr << "unit1: " << unit1 << std::endl; + std::cerr << "unit2: " << unit2 << std::endl; + std::cerr << "include_guards[unit1]: " << include_guards[unit1] << std::endl; + std::cerr << "include_guards[unit2]: " << include_guards[unit2] << std::endl; + { std::cerr << "error on line: " << line_count << std::endl; return(1); } + } +std::cout << __LINE__ << std::endl; + + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; +std::cout << __LINE__ << std::endl; + if(boost::regex_match(line, match, define_conversion_offset)) { + if(!uses_absolute) { std::cerr << "error on line: " << line_count << std::endl; return(1); } +std::cout << __LINE__ << std::endl; + if(match[1].str() != unit1 || match[2].str() != unit2) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + if(!std::getline(conversions_file, line)) { std::cerr << "unexpected end of file." << std::endl; return(1); } ++line_count; + } else { + if(uses_absolute) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + } +std::cout << __LINE__ << std::endl; + + + if(!boost::regex_match(line, match, endif)) { std::cerr << "error on line: " << line_count << std::endl; return(1); } + + } + } + + } catch(std::exception& e) { + std::cerr << e.what() << std::endl; + return(1); + } + +} diff --git a/src/boost/libs/units/test/fail_add_temperature.cpp b/src/boost/libs/units/test/fail_add_temperature.cpp new file mode 100644 index 00000000..979b2363 --- /dev/null +++ b/src/boost/libs/units/test/fail_add_temperature.cpp @@ -0,0 +1,38 @@ +// 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 fail_add_temperature.cpp + +\details +Verify that adding two absolute temeratures fails miserably. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity > q(2.0 * bu::absolute()); + + q += q; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_adl_detail.cpp b/src/boost/libs/units/test/fail_adl_detail.cpp new file mode 100644 index 00000000..b44788df --- /dev/null +++ b/src/boost/libs/units/test/fail_adl_detail.cpp @@ -0,0 +1,48 @@ +// 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 fail_adl_detail.cpp + +\details +make sure that namespace detail is not pulled in by ADL. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +namespace boost { +namespace units { +namespace detail { + + template + void this_function_should_not_be_found_by_adl(const T&) {}; + +} +} +} + +int main(int argc,char *argv[]) +{ + + bu::quantity q; + + this_function_should_not_be_found_by_adl(q); + + return 0; +} diff --git a/src/boost/libs/units/test/fail_base_dimension.cpp b/src/boost/libs/units/test/fail_base_dimension.cpp new file mode 100644 index 00000000..1dd7a4a0 --- /dev/null +++ b/src/boost/libs/units/test/fail_base_dimension.cpp @@ -0,0 +1,32 @@ +// 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 fail_base_dimension.cpp + +\details +make sure that trying to use the same ordinal for multiple +base dimensions fails. + +Output: +@verbatim +@endverbatim +**/ + +#include + +struct dim1 : boost::units::base_dimension {}; +struct dim2 : boost::units::base_dimension {}; + +int main() +{ +} diff --git a/src/boost/libs/units/test/fail_heterogeneous_unit.cpp b/src/boost/libs/units/test/fail_heterogeneous_unit.cpp new file mode 100644 index 00000000..c0f7692e --- /dev/null +++ b/src/boost/libs/units/test/fail_heterogeneous_unit.cpp @@ -0,0 +1,46 @@ +// 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 fail_heterogeneous_unit.cpp + +\details +make sure that trying to bind a heterogeneous system to a different dimension fails. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include +#include +//#include +//#include + +namespace bu = boost::units; + +template +bu::quantity > f(bu::quantity > l) { + return(static_cast > >(f(static_cast >(l)))); +} +bu::quantity f(bu::quantity l) { + return(l * l * 2.0 * bu::si::kilograms / bu::pow<2>(bu::si::seconds)); +} + +int main() { + + f(1.0 * bu::pow<2>(bu::si::meters) / bu::cgs::centimeters); + + return(0); +} diff --git a/src/boost/libs/units/test/fail_implicit_conversion.cpp b/src/boost/libs/units/test/fail_implicit_conversion.cpp new file mode 100644 index 00000000..bedef1b5 --- /dev/null +++ b/src/boost/libs/units/test/fail_implicit_conversion.cpp @@ -0,0 +1,36 @@ +// 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 fail_implicit_conversion.cpp + +\details +Test implicit conversions for quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include + +namespace bu = boost::units; + +int main(int,char *[]) +{ + const bu::quantity T1(2.0 * bu::si::meters); + const bu::quantity T2 = T1; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_add.cpp b/src/boost/libs/units/test/fail_quantity_add.cpp new file mode 100644 index 00000000..e7e37d48 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_add.cpp @@ -0,0 +1,35 @@ +// 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 fail_quantity_add.cpp + +\details +Test addition of quantities with different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::seconds + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_add_assign.cpp b/src/boost/libs/units/test/fail_quantity_add_assign.cpp new file mode 100644 index 00000000..f31df615 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_add_assign.cpp @@ -0,0 +1,36 @@ +// 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 fail_quantity_add_assign.cpp + +\details +Test += of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity T1; + T1 += 2.0 * bu::si::seconds; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_assign.cpp b/src/boost/libs/units/test/fail_quantity_assign.cpp new file mode 100644 index 00000000..0f48bf21 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_assign.cpp @@ -0,0 +1,36 @@ +// 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 fail_quantity_assign.cpp + +\details +Test assignment of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + const bu::quantity T1; + T1 = 2.0 * bu::si::seconds; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_construct.cpp b/src/boost/libs/units/test/fail_quantity_construct.cpp new file mode 100644 index 00000000..94506583 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_construct.cpp @@ -0,0 +1,35 @@ +// 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 fail_quantity_construct.cpp + +\details +Test construction of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + const bu::quantity T1(2.0 * bu::si::seconds); + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_non_unit.cpp b/src/boost/libs/units/test/fail_quantity_non_unit.cpp new file mode 100644 index 00000000..646160d6 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_non_unit.cpp @@ -0,0 +1,37 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// 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 fail_quantity_non_unit.cpp + +\details + +Make sure that trying to use a base_unit as though +it were a unit fails. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity q; + + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_scalar_add.cpp b/src/boost/libs/units/test/fail_quantity_scalar_add.cpp new file mode 100644 index 00000000..94cc8f27 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_scalar_add.cpp @@ -0,0 +1,35 @@ +// 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 fail_quantity_scalar_add.cpp + +\details +Test addition of quantity and scalar. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters + 2.0; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_scalar_sub.cpp b/src/boost/libs/units/test/fail_quantity_scalar_sub.cpp new file mode 100644 index 00000000..a4b93f13 --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_scalar_sub.cpp @@ -0,0 +1,35 @@ +// 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 fail_quantity_scalar_sub.cpp + +\details +Test subtraction of quantity and scalar. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters - 2.0; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_sub_assign.cpp b/src/boost/libs/units/test/fail_quantity_sub_assign.cpp new file mode 100644 index 00000000..65ea62fe --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_sub_assign.cpp @@ -0,0 +1,36 @@ +// 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 fail_quantity_sub_assign.cpp + +\details +Test -= of quantity from different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int,char *[]) +{ + + bu::quantity T1; + T1 -= 2.0 * bu::si::seconds; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_subtract.cpp b/src/boost/libs/units/test/fail_quantity_subtract.cpp new file mode 100644 index 00000000..65f71e9b --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_subtract.cpp @@ -0,0 +1,35 @@ +// 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 fail_quantity_subtract.cpp + +\details +Test subtraction of quantities with different dimensions. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::seconds - 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_unit_add.cpp b/src/boost/libs/units/test/fail_quantity_unit_add.cpp new file mode 100644 index 00000000..537656bc --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_unit_add.cpp @@ -0,0 +1,35 @@ +// 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 fail_quantity_unit_add.cpp + +\details +Test addition of quantity and unit. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters + bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_quantity_unit_subtract.cpp b/src/boost/libs/units/test/fail_quantity_unit_subtract.cpp new file mode 100644 index 00000000..bcd9260c --- /dev/null +++ b/src/boost/libs/units/test/fail_quantity_unit_subtract.cpp @@ -0,0 +1,35 @@ +// 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 fail_quantity_unit_subtract.cpp + +\details +Test subtraction of quantity and unit. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 * bu::si::meters - bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_scalar_quantity_add.cpp b/src/boost/libs/units/test/fail_scalar_quantity_add.cpp new file mode 100644 index 00000000..07225248 --- /dev/null +++ b/src/boost/libs/units/test/fail_scalar_quantity_add.cpp @@ -0,0 +1,35 @@ +// 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 fail_scalar_quantity_add.cpp + +\details +Test addition of scalar and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_scalar_quantity_sub.cpp b/src/boost/libs/units/test/fail_scalar_quantity_sub.cpp new file mode 100644 index 00000000..44e6a7d1 --- /dev/null +++ b/src/boost/libs/units/test/fail_scalar_quantity_sub.cpp @@ -0,0 +1,35 @@ +// 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 fail_scalar_quantity_sub.cpp + +\details +Test subtraction of scalar and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + 2.0 - 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_unit_quantity_add.cpp b/src/boost/libs/units/test/fail_unit_quantity_add.cpp new file mode 100644 index 00000000..512d3329 --- /dev/null +++ b/src/boost/libs/units/test/fail_unit_quantity_add.cpp @@ -0,0 +1,35 @@ +// 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 fail_unit_quantity_add.cpp + +\details +Test addition of unit and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + bu::si::meters + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/fail_unit_quantity_subtract.cpp b/src/boost/libs/units/test/fail_unit_quantity_subtract.cpp new file mode 100644 index 00000000..512d3329 --- /dev/null +++ b/src/boost/libs/units/test/fail_unit_quantity_subtract.cpp @@ -0,0 +1,35 @@ +// 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 fail_unit_quantity_add.cpp + +\details +Test addition of unit and quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +namespace bu = boost::units; + +int main(int argc,char *argv[]) +{ + + bu::si::meters + 2.0 * bu::si::meters; + + return 0; +} diff --git a/src/boost/libs/units/test/test_absolute.cpp b/src/boost/libs/units/test/test_absolute.cpp new file mode 100644 index 00000000..2908612f --- /dev/null +++ b/src/boost/libs/units/test/test_absolute.cpp @@ -0,0 +1,68 @@ +// 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 test_absolute.cpp + +\details +Test absolute units. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001))) + +namespace bu = boost::units; +using bu::si::kelvin_base_unit; +using bu::temperature::celsius_base_unit; +using bu::temperature::fahrenheit_base_unit; + +typedef bu::unit::type> kelvin_type; + +typedef bu::unit::type> celsius_type; + +typedef bu::unit::type> fahrenheit_type; + +int test_main(int,char *[]) +{ + BOOST_CONSTEXPR_OR_CONST bu::quantity > q1(212.0 * bu::absolute()); + BOOST_CONSTEXPR_OR_CONST bu::quantity > q2(0.0 * bu::absolute()); + BOOST_CONSTEXPR_OR_CONST bu::quantity > q3(q2); + BOOST_CONSTEXPR_OR_CONST bu::quantity q4(q1 - q3); + + BOOST_UNITS_CHECK_CLOSE(q4.value(), 180.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity > q5(static_cast >(q4) + static_cast > >(q2)); + + BOOST_UNITS_CHECK_CLOSE(q5.value(), 373.15); + + BOOST_CONSTEXPR_OR_CONST bu::quantity > q6(q5); + + BOOST_UNITS_CHECK_CLOSE(q6.value(), 212.0); + + return(0); +} diff --git a/src/boost/libs/units/test/test_base_dimension.cpp b/src/boost/libs/units/test/test_base_dimension.cpp new file mode 100644 index 00000000..27cc6dcd --- /dev/null +++ b/src/boost/libs/units/test/test_base_dimension.cpp @@ -0,0 +1,31 @@ +// 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 test_base_dimension.cpp + +\details +Test base_dimension class. + +Output: +@verbatim +@endverbatim +**/ + +#include + +struct dimension : boost::units::base_dimension { + typedef boost::units::base_dimension base; +}; + +int main() { +} diff --git a/src/boost/libs/units/test/test_cmath.cpp b/src/boost/libs/units/test/test_cmath.cpp new file mode 100644 index 00000000..85a5119c --- /dev/null +++ b/src/boost/libs/units/test/test_cmath.cpp @@ -0,0 +1,173 @@ +// 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 test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include + +#include + +#include "test_header.hpp" + +namespace bu = boost::units; + +int test_main(int,char *[]) +{ + BOOST_CONSTEXPR_OR_CONST double inf = std::numeric_limits::infinity(), + nan = std::numeric_limits::quiet_NaN(); + + // default constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity E1(0.0*bu::joules), + E2(inf*bu::joules), + E3(nan*bu::joules); + + BOOST_CHECK((bu::isfinite)(E1) == true); + BOOST_CHECK((bu::isfinite)(E2) == false); + BOOST_CHECK((bu::isfinite)(E3) == false); + + BOOST_CHECK((bu::isinf)(E1) == false); + BOOST_CHECK((bu::isinf)(E2) == true); + BOOST_CHECK((bu::isinf)(E3) == false); + + BOOST_CHECK((bu::isnan)(E1) == false); + BOOST_CHECK((bu::isnan)(E2) == false); + BOOST_CHECK((bu::isnan)(E3) == true); + + BOOST_CHECK((bu::isnormal)(E1) == false); + BOOST_CHECK((bu::isnormal)(E2) == false); + BOOST_CHECK((bu::isnormal)(E3) == false); + + BOOST_CONSTEXPR_OR_CONST bu::quantity E4(-2.5*bu::joules), + E5(2.5*bu::joules); + + BOOST_CHECK((bu::isgreater)(E4,E5) == false); + BOOST_CHECK((bu::isgreater)(E5,E4) == true); + BOOST_CHECK((bu::isgreater)(E4,E4) == false); + BOOST_CHECK((bu::isgreater)(E3,E4) == false); + BOOST_CHECK((bu::isgreater)(E4,E3) == false); + + BOOST_CHECK((bu::isgreaterequal)(E4,E5) == false); + BOOST_CHECK((bu::isgreaterequal)(E5,E4) == true); + BOOST_CHECK((bu::isgreaterequal)(E4,E4) == true); + BOOST_CHECK((bu::isgreaterequal)(E3,E4) == false); + BOOST_CHECK((bu::isgreaterequal)(E4,E3) == false); + + BOOST_CHECK((bu::isless)(E4,E5) == true); + BOOST_CHECK((bu::isless)(E5,E4) == false); + BOOST_CHECK((bu::isless)(E4,E4) == false); + BOOST_CHECK((bu::isless)(E3,E4) == false); + BOOST_CHECK((bu::isless)(E4,E3) == false); + + BOOST_CHECK((bu::islessequal)(E4,E5) == true); + BOOST_CHECK((bu::islessequal)(E5,E4) == false); + BOOST_CHECK((bu::islessequal)(E4,E4) == true); + BOOST_CHECK((bu::islessequal)(E3,E4) == false); + BOOST_CHECK((bu::islessequal)(E4,E3) == false); + + BOOST_CHECK((bu::islessgreater)(E4,E5) == true); + BOOST_CHECK((bu::islessgreater)(E5,E4) == true); + BOOST_CHECK((bu::islessgreater)(E4,E4) == false); + BOOST_CHECK((bu::islessgreater)(E3,E4) == false); + BOOST_CHECK((bu::islessgreater)(E4,E3) == false); + + BOOST_CHECK((bu::isunordered)(E4,E5) == false); + BOOST_CHECK((bu::isunordered)(E5,E4) == false); + BOOST_CHECK((bu::isunordered)(E4,E4) == false); + BOOST_CHECK((bu::isunordered)(E3,E4) == true); + BOOST_CHECK((bu::isunordered)(E4,E3) == true); + + BOOST_CHECK((bu::abs)(E4) == E5); + BOOST_CHECK((bu::ceil)(E4) == -2.0*bu::joules); + BOOST_CHECK((bu::copysign)(E4,E5) == E5); + BOOST_CHECK((bu::fabs)(E4) == E5); + BOOST_CHECK((bu::floor)(E4) == -3.0*bu::joules); + BOOST_CHECK((bu::fdim)(E4,E5) == 0.0*bu::joules); + BOOST_CHECK((bu::fdim)(E5,E4) == E5-E4); + + BOOST_CONSTEXPR_OR_CONST bu::quantity L1(3.0*bu::meters), + L2(4.0*bu::meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity A1(4.0*bu::square_meters), + A2(L1*L2+A1); + +#if 0 + BOOST_CHECK((bu::fma)(L1,L2,A1) == A2); +#endif + + BOOST_CHECK((bu::fmax)(E4,E5) == E5); + BOOST_CHECK((bu::fmin)(E4,E5) == E4); + + // need to test fpclassify + + BOOST_CHECK(bu::hypot(L1,L2) == 5.0*bu::meters); + +#if 0 + +// BOOST_CHECK(bu::llrint(E4).value() == bu::detail::llrint(E4.value())); +// BOOST_CHECK(bu::llround(E4).value() == bu::detail::llround(E4.value())); + BOOST_CHECK((bu::nearbyint)(E4).value() == (bu::detail::nearbyint)(E4.value())); + BOOST_CHECK((bu::rint)(E4).value() == (bu::detail::rint)(E4.value())); + +#endif + + BOOST_CHECK((bu::nextafter)(E4,E5).value() == (boost::math::nextafter)(E4.value(),E5.value())); + BOOST_CHECK((bu::nextafter)(E5,E4).value() == (boost::math::nextafter)(E5.value(),E4.value())); + + BOOST_CHECK((bu::nexttoward)(E4,E5).value() == (boost::math::nextafter)(E4.value(),E5.value())); + BOOST_CHECK((bu::nexttoward)(E5,E4).value() == (boost::math::nextafter)(E5.value(),E4.value())); + + BOOST_CHECK((bu::round)(E4 - 0.00000000001 * bu::joules) == -3.0*bu::joules); + BOOST_CHECK((bu::round)(E5 + 0.00000000001 * bu::joules) == 3.0*bu::joules); + BOOST_CHECK((bu::signbit)(E4) != 0); + BOOST_CHECK((bu::signbit)(E5) == 0); + BOOST_CHECK((bu::trunc)(E4) == -2.0*bu::joules); + BOOST_CHECK((bu::trunc)(E5) == 2.0*bu::joules); + + BOOST_CHECK((bu::fmod)(E4,E5) == -0.0*bu::joules); + + bu::quantity pint; + + BOOST_CHECK((bu::modf)(E4,&pint) == -0.5*bu::joules); + BOOST_CHECK(pint == -2.0*bu::joules); + + int ex; + const bu::quantity E6((bu::frexp)(E4,&ex)); + + BOOST_CHECK(E6 == -0.625*bu::joules); + BOOST_CHECK(ex == 2); + BOOST_CHECK((bu::ldexp)(E6,ex) == E4); + + BOOST_CONSTEXPR_OR_CONST bu::quantity E7(1.0); + + BOOST_CHECK(bu::pow(E7,E7) == 1.0*1.0); + + const bu::quantity E8((bu::exp)(E7)); + + BOOST_CHECK(std::abs(E8 - std::exp(1.0)) < .000001); + BOOST_CHECK(bu::log(E8) == E7); + + BOOST_CONSTEXPR_OR_CONST bu::quantity E9(100.0); + + BOOST_CHECK(bu::log10(E9) == 2.0); + + BOOST_CHECK(bu::sqrt(A1) == 2.0*bu::meters); + + return 0; +} diff --git a/src/boost/libs/units/test/test_complicated_system.cpp b/src/boost/libs/units/test/test_complicated_system.cpp new file mode 100644 index 00000000..4ac3a82d --- /dev/null +++ b/src/boost/libs/units/test/test_complicated_system.cpp @@ -0,0 +1,96 @@ +// 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) 2007-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) + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace test_system1 { + +// the base units in the system will be: +// +// volts = m^2 kg s^-2 C^-1 +// newtons = m kg s^-2 +// joules = m^2 kg s^-2 + +// we will find the representation of m^-1 C^-1 = V N J^-2 = m^-1 C^-1 + +// reducing the system should generate the matrix equation +// 2 1 2 +// 1 1 1 x = c +// -2 -2 -2 +// -1 0 0 + +struct volt : boost::units::base_unit {}; +struct newton : boost::units::base_unit {}; +struct joule : boost::units::base_unit {}; + +typedef boost::units::make_system::type complicated_system; + +typedef boost::units::derived_dimension< + boost::units::length_base_dimension, -1, + boost::units::time_base_dimension, -1, + boost::units::current_base_dimension, -1 +>::type dimension; + +typedef boost::units::reduce_unit >::type reduced; + +typedef boost::units::divide_typeof_helper< + boost::units::multiply_typeof_helper::type, + boost::units::power_typeof_helper >::type +>::type expected; + +void test() { + BOOST_MPL_ASSERT((boost::is_same)); +} + +} + +namespace test_system2 { + +// the base units in the system will be: +// +// kilograms = kg +// meters = m + +// we will find the representation of m and kg + +// reducing the system should generate the matrix equation +// 0 1 +// 1 0 x = c + +struct kilogram : boost::units::base_unit {}; +struct meter : boost::units::base_unit {}; + +typedef boost::units::make_system::type mk_system; + +typedef boost::units::reduce_unit >::type mass_unit; +typedef boost::units::reduce_unit >::type length_unit; + +void test() { + BOOST_MPL_ASSERT((boost::is_same)); + BOOST_MPL_ASSERT((boost::is_same)); +} + +} diff --git a/src/boost/libs/units/test/test_constants.cpp b/src/boost/libs/units/test/test_constants.cpp new file mode 100644 index 00000000..55b45a1c --- /dev/null +++ b/src/boost/libs/units/test/test_constants.cpp @@ -0,0 +1,87 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2003-2009 Matthias Christian Schabel +// Copyright (C) 2007-2009 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 test_constants.cpp + +\details +Test all combinations of operators with the constants. + +**/ + +#include +#include +#include +#include +#include + +using boost::units::quantity; +using boost::units::si::length; +using boost::units::si::meters; +using boost::units::si::seconds; +using boost::units::static_rational; +using boost::units::pow; +using boost::units::root; + +BOOST_UNITS_PHYSICAL_CONSTANT(length_constant, quantity, 2.0 * meters, 0.5 * meters); + +template +void check_same(const T&, const T&); + +template +typename T::value_type unwrap(const boost::units::constant&); + +template +T unwrap(const T&); + +#define BOOST_UNITS_CHECK_RESULT(arg1, op, arg2) check_same((arg1) op (arg2), unwrap(arg1) op unwrap(arg2)); + +void test_add() { + BOOST_UNITS_CHECK_RESULT(length_constant, +, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, +, 1.0 * meters); + BOOST_UNITS_CHECK_RESULT(1.0* meters, +, length_constant); +} + +void test_subtract() { + BOOST_UNITS_CHECK_RESULT(length_constant, -, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, -, 1.0 * meters); + BOOST_UNITS_CHECK_RESULT(1.0* meters, -, length_constant); +} + +void test_multiply() { + BOOST_UNITS_CHECK_RESULT(length_constant, *, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0 * seconds); + BOOST_UNITS_CHECK_RESULT(1.0 * seconds, *, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, *, 1.0); + BOOST_UNITS_CHECK_RESULT(1.0, *, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, *, seconds); + BOOST_UNITS_CHECK_RESULT(seconds, *, length_constant); +} + +void test_divide() { + BOOST_UNITS_CHECK_RESULT(length_constant, /, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0 * seconds); + BOOST_UNITS_CHECK_RESULT(1.0 * seconds, /, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, /, 1.0); + BOOST_UNITS_CHECK_RESULT(1.0, /, length_constant); + BOOST_UNITS_CHECK_RESULT(length_constant, /, seconds); + BOOST_UNITS_CHECK_RESULT(seconds, /, length_constant); +} + +void test_pow() { + check_same(pow<2>(length_constant), pow<2>(unwrap(length_constant))); + check_same(root<2>(length_constant), root<2>(unwrap(length_constant))); + check_same(pow<5>(length_constant), pow<5>(unwrap(length_constant))); + check_same(root<5>(length_constant), root<5>(unwrap(length_constant))); + check_same(pow >(length_constant), pow >(unwrap(length_constant))); + check_same(root >(length_constant), root >(unwrap(length_constant))); +} diff --git a/src/boost/libs/units/test/test_conversion.cpp b/src/boost/libs/units/test/test_conversion.cpp new file mode 100644 index 00000000..17015245 --- /dev/null +++ b/src/boost/libs/units/test/test_conversion.cpp @@ -0,0 +1,110 @@ +// 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 test_conversion.cpp + +\details +Test conversion between quantities. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include + +#include + +#define BOOST_TEST_MAIN + +#include + +#define BOOST_UNITS_CHECK_CLOSE(a, b) BOOST_CHECK_CLOSE_FRACTION(a, b, .0000001) + +namespace bu = boost::units; + +typedef bu::si::length si_length; +typedef bu::si::time si_time; +typedef bu::si::mass si_mass; +typedef bu::si::area si_area; + +typedef bu::cgs::length cgs_length; +typedef bu::cgs::time cgs_time; +typedef bu::cgs::mass cgs_mass; +typedef bu::cgs::area cgs_area; + +typedef bu::multiply_typeof_helper::type mixed_length; +typedef bu::multiply_typeof_helper::type mixed_time; + +typedef bu::divide_typeof_helper::type, mixed_time>::type mixed_energy_1; +typedef bu::divide_typeof_helper::type, + bu::multiply_typeof_helper::type >::type mixed_energy_2; + +BOOST_AUTO_TEST_CASE(test_conversion) { + BOOST_CHECK_EQUAL(1, 1); + BOOST_CONSTEXPR_OR_CONST bu::quantity a1(2.0 * mixed_length()); + BOOST_CONSTEXPR_OR_CONST bu::quantity a2(a1); + + BOOST_UNITS_CHECK_CLOSE(a2.value(), .02); + + BOOST_CONSTEXPR_OR_CONST bu::quantity a3(a2); + + BOOST_UNITS_CHECK_CLOSE(a3.value(), 2.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity e1(2.0 * mixed_energy_1()); + BOOST_CONSTEXPR_OR_CONST bu::quantity e2(e1); + + BOOST_UNITS_CHECK_CLOSE(e2.value(), 20.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity e3(e1); + BOOST_UNITS_CHECK_CLOSE(e3.value(), .0002); + BOOST_CONSTEXPR_OR_CONST bu::quantity e4(e3); + BOOST_UNITS_CHECK_CLOSE(e4.value(), 20.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity F0 = 20 * bu::cgs::dyne; + BOOST_UNITS_CHECK_CLOSE(F0.value(), 20.0); + + BOOST_CONSTEXPR_OR_CONST bu::quantity F3(F0); + BOOST_UNITS_CHECK_CLOSE(F3.value(), 2.0e-4); + + BOOST_CONSTEXPR_OR_CONST bu::quantity F5(20 * bu::cgs::dyne); + BOOST_UNITS_CHECK_CLOSE(F5.value(), 2.0e-4); + + // same type + BOOST_CHECK_EQUAL(boost::units::conversion_factor(si_length(), si_length()), 1.0); +} + +BOOST_AUTO_TEST_CASE(test_dimensionless_conversions) { + typedef bu::divide_typeof_helper::type mixed_dimensionless; + + BOOST_CONSTEXPR_OR_CONST bu::quantity dimensionless_test1(1.0*bu::cgs::dyne/bu::si::newton); + BOOST_CHECK(dimensionless_test1 == 1e-5); + + typedef bu::multiply_typeof_helper::type m_cm; + typedef bu::divide_typeof_helper::type heterogeneous_dimensionless; + BOOST_CONSTEXPR_OR_CONST bu::quantity dimensionless_test2(1.0*bu::cgs::dyne/bu::si::newton); + BOOST_CHECK(dimensionless_test2.value() == 1e-5); + BOOST_CONSTEXPR_OR_CONST bu::quantity::type> dimensionless_test3(dimensionless_test2); + BOOST_UNITS_CHECK_CLOSE(dimensionless_test3.value(), 1.0); + + BOOST_UNITS_CHECK_CLOSE(boost::units::conversion_factor(mixed_dimensionless(), heterogeneous_dimensionless()), 1e-5); + BOOST_UNITS_CHECK_CLOSE(boost::units::conversion_factor(heterogeneous_dimensionless(), mixed_dimensionless()), 1e5); + + + //m/cm -> g/kg + BOOST_CONSTEXPR_OR_CONST bu::quantity::type> dimensionless_test4(2.0 * bu::si::meters / bu::cgs::centimeters); + BOOST_CONSTEXPR_OR_CONST bu::quantity::type> dimensionless_test5(dimensionless_test4); + BOOST_UNITS_CHECK_CLOSE(dimensionless_test5.value(), 2e5); +} diff --git a/src/boost/libs/units/test/test_custom_unit.cpp b/src/boost/libs/units/test/test_custom_unit.cpp new file mode 100644 index 00000000..42e7d6e8 --- /dev/null +++ b/src/boost/libs/units/test/test_custom_unit.cpp @@ -0,0 +1,84 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 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 test_custom_unit.cpp + +\details +Make sure that a minimal + - * / unit class is fully functional. + +Output: +@verbatim +@endverbatim +**/ + +#include + +#include + +namespace bu = boost::units; + +template +struct simple_unit {}; + +BOOST_TYPEOF_REGISTER_TEMPLATE(simple_unit, (int)(int)(int)) + +template +simple_unit operator+(const simple_unit&, + const simple_unit&) +{ + return simple_unit(); +} + +template +simple_unit operator-(const simple_unit&, + const simple_unit&) +{ + return simple_unit(); +} + +template +simple_unit +operator*(const simple_unit&, + const simple_unit&) +{ + return simple_unit(); +} + +template +simple_unit +operator/(const simple_unit&, + const simple_unit&) +{ + return simple_unit(); +} + +int test_main(int,char *[]) +{ + bu::quantity > mass = bu::quantity >::from_value(2); + bu::quantity > length = bu::quantity >::from_value(4); + + bu::quantity > ml = mass * length; + bu::quantity > m_per_l = mass/length; + + BOOST_CHECK(ml.value() == 8); + BOOST_CHECK(m_per_l.value() == 0.5); + + mass += mass; + + BOOST_CHECK(mass.value() == 4); + + length -= length; + BOOST_CHECK(length.value() == 0); + + return 0; +} diff --git a/src/boost/libs/units/test/test_default_conversion.cpp b/src/boost/libs/units/test/test_default_conversion.cpp new file mode 100644 index 00000000..f05aac69 --- /dev/null +++ b/src/boost/libs/units/test/test_default_conversion.cpp @@ -0,0 +1,78 @@ +// 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) + +#include + +#include +#include +#include +#include +#include +#include + +struct dimension1_tag : boost::units::base_dimension {}; +struct dimension2_tag : boost::units::base_dimension {}; + +typedef dimension1_tag::dimension_type dimension1; +typedef dimension2_tag::dimension_type dimension2; +typedef boost::mpl::times::type dimension12; + +struct unit1_tag : boost::units::base_unit {}; +struct unit2_tag : boost::units::base_unit {}; +struct unit3_tag : boost::units::base_unit {}; +struct unit4_tag : boost::units::base_unit {}; +struct unit5_tag : boost::units::base_unit {}; +struct unit6_tag : boost::units::base_unit {}; +struct unit7_tag : boost::units::base_unit {}; + +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit1_tag, unit2_tag, double, 2.0); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit2_tag, unit3_tag, double, 3.0); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit6_tag, unit3_tag, double, 5.0); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit7_tag, unit1_tag, double, 7.0); + +typedef boost::units::multiply_typeof_helper::type unit34_type; +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(unit5_tag, unit34_type , double, 5.0); + +template +struct make_unit { + typedef boost::units::unit< + typename BaseUnit::dimension_type, + typename boost::units::make_system::type> type; +}; + +BOOST_UNITS_DEFAULT_CONVERSION(unit1_tag, unit2_tag); +BOOST_UNITS_DEFAULT_CONVERSION(unit3_tag, unit2_tag); +BOOST_UNITS_DEFAULT_CONVERSION(unit5_tag, unit34_type); +BOOST_UNITS_DEFAULT_CONVERSION(unit6_tag, make_unit::type); +BOOST_UNITS_DEFAULT_CONVERSION(unit7_tag, make_unit::type); + +int test_main(int, char*[]) { + BOOST_CONSTEXPR_OR_CONST double value1 = boost::units::conversion_factor(unit3_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value1 - 1.0/6.0) < .0000000001); + BOOST_CONSTEXPR_OR_CONST double value2 = boost::units::conversion_factor(unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value2 - 5.0/6.0) < .0000000001); + typedef boost::units::scaled_base_unit > > scaled_unit5_tag; + BOOST_CONSTEXPR_OR_CONST double value3 = boost::units::conversion_factor(scaled_unit5_tag::unit_type() / unit4_tag::unit_type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value3 - 10.0/6.0) < .0000000001); + + // check homogeneous unit conversions + BOOST_CONSTEXPR_OR_CONST double value4 = boost::units::conversion_factor(make_unit::type(), make_unit::type()); + BOOST_CHECK(std::abs(value4 - 1.0/6.0) < .0000000001); + BOOST_CONSTEXPR_OR_CONST double value5 = boost::units::conversion_factor(unit3_tag::unit_type(), make_unit::type()); + BOOST_CHECK(std::abs(value5 - 1.0/6.0) < .0000000001); + BOOST_CONSTEXPR_OR_CONST double value6 = boost::units::conversion_factor(make_unit::type(), unit1_tag::unit_type()); + BOOST_CHECK(std::abs(value6 - 1.0/6.0) < .0000000001); + + // check chained homogeneous conversions + BOOST_CONSTEXPR_OR_CONST double value7 = boost::units::conversion_factor(unit6_tag::unit_type(), unit7_tag::unit_type()); + BOOST_CHECK(std::abs(value7 - 5.0/42.0) < .0000000001); + + return(0); +} diff --git a/src/boost/libs/units/test/test_dimensionless_ice1.cpp b/src/boost/libs/units/test/test_dimensionless_ice1.cpp new file mode 100644 index 00000000..06ab61ee --- /dev/null +++ b/src/boost/libs/units/test/test_dimensionless_ice1.cpp @@ -0,0 +1,26 @@ +// 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) + +#include +#include +#include + +void foo() +{ + BOOST_CONSTEXPR_OR_CONST boost::units::quantity d = boost::units::quantity< boost::units::si::dimensionless >(); + boost::ignore_unused(d); +} + +#include + +int main() +{ + BOOST_CHECK( 1 == 2 ); +} diff --git a/src/boost/libs/units/test/test_dimensionless_ice2.cpp b/src/boost/libs/units/test/test_dimensionless_ice2.cpp new file mode 100644 index 00000000..b04e6544 --- /dev/null +++ b/src/boost/libs/units/test/test_dimensionless_ice2.cpp @@ -0,0 +1,25 @@ +// 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) + +#include +#include +#include + +void foo() +{ + BOOST_CONSTEXPR_OR_CONST boost::units::quantity d(1.0 * boost::units::si::meters / boost::units::cgs::centimeters); +} + +#include + +int main() +{ + BOOST_CHECK( 1 == 2 ); +} diff --git a/src/boost/libs/units/test/test_dimensionless_quantity.cpp b/src/boost/libs/units/test/test_dimensionless_quantity.cpp new file mode 100644 index 00000000..197d7c9d --- /dev/null +++ b/src/boost/libs/units/test/test_dimensionless_quantity.cpp @@ -0,0 +1,216 @@ +// 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 test_dimensionless_quantity.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include + +namespace bu = boost::units; + +BOOST_STATIC_CONSTEXPR double E_ = 2.718281828459045235360287471352662497757; + +int test_main(int,char *[]) +{ + // default constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity E1; + BOOST_CHECK(E1.value() == double()); + + // value_type constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity E2(E_); + BOOST_CHECK(E2.value() == E_); + + // copy constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity E3(E2); + BOOST_CHECK(E3.value() == E_); + + // operator= + BOOST_CONSTEXPR_OR_CONST bu::quantity E4 = E2; + BOOST_CHECK(E4.value() == E_); + + // implicit copy constructor value_type conversion + BOOST_CONSTEXPR_OR_CONST bu::quantity E5(E2); + BOOST_UNITS_CHECK_CLOSE(E5.value(), float(E_)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity E6(E2); + BOOST_CHECK(E6.value() == long(E_)); + + // implicit operator= value_type conversion + // narrowing conversion disallowed +// BOOST_CONSTEXPR_OR_CONST bu::quantity E7 = E2; +// BOOST_UNITS_CHECK_CLOSE(E7.value(),float(E_)); + + // narrowing conversion disallowed +// BOOST_CONSTEXPR_OR_CONST bu::quantity E8 = E2; +// BOOST_CHECK(E8.value() == long(E_)); + + // const construction + bu::quantity E9(E2); + BOOST_CHECK(E9.value() == E_); + +// // value assignment +// E9.value() = 1.5*bu::dimensionless(); +// BOOST_CHECK(E9.value() == 1.5); +// +// // value assignment with implicit conversion +// E9.value() = 1.5; +// BOOST_CHECK(E9.value() == 1.5); +// +// // value assignment with implicit value_type conversion +// E9.value() = 2*bu::dimensionless(); +// BOOST_CHECK(E9.value() == double(2)); +// +// // value assignment with implicit value_type conversion +// E9.value() = 2; +// BOOST_CHECK(E9.value() == double(2)); + + // operator+=(this_type) + E9 = 2.0; + E9 += E9; + BOOST_CHECK(E9.value() == 4.0); + + // operator-=(this_type) + E9 = 2.0; + E9 -= E9; + BOOST_CHECK(E9.value() == 0.0); + + // operator*=(value_type) + E9 = 2.0; + E9 *= 2.0; + BOOST_CHECK(E9.value() == 4.0); + + // operator/=(value_type) + E9 = 2.0; + E9 /= 2.0; + BOOST_CHECK(E9.value() == 1.0); + + // static construct quantity from value_type + BOOST_CONSTEXPR_OR_CONST bu::quantity E(bu::quantity::from_value(2.5)); + BOOST_CHECK(E.value() == 2.5); + + // implicit conversion to value_type + const double V1(E9); + BOOST_CHECK(V1 == E9.value()); + + const double V2 = E9; + BOOST_CHECK(V2 == E9.value()); + + // unit * scalar + BOOST_CHECK(bu::dimensionless()*2.0 == bu::quantity::from_value(2.0)); + + // unit / scalar + BOOST_CHECK(bu::dimensionless()/2.0 == bu::quantity::from_value(0.5)); + + // scalar * unit + BOOST_CHECK(2.0*bu::dimensionless() == bu::quantity::from_value(2.0)); + + // scalar / unit + BOOST_CHECK(2.0/bu::dimensionless() == bu::quantity::from_value(2.0)); + + // quantity * scalar + BOOST_CHECK(E*2.0 == bu::quantity::from_value(5.0)); + + // quantity / scalar + BOOST_CHECK(E/2.0 == bu::quantity::from_value(1.25)); + + // scalar * quantity + BOOST_CHECK(2.0*E == bu::quantity::from_value(5.0)); + + // scalar / quantity + BOOST_CHECK(2.0/E == bu::quantity::from_value(0.8)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity D1(1.0), + D2(2.0); + + // unit * quantity + BOOST_CHECK(bu::dimensionless()*D1 == D1); + + // unit / quantity + BOOST_CHECK(bu::dimensionless()/D1 == D1); + + // quantity * unit + BOOST_CHECK(D1*bu::dimensionless() == D1); + + // quantity / unit + BOOST_CHECK(D1*bu::dimensionless() == D1); + + // +quantity + BOOST_CHECK(+D1 == 1.0*bu::dimensionless()); + + // -quantity + BOOST_CHECK(-D1 == -1.0*bu::dimensionless()); + + // quantity + quantity + BOOST_CHECK(D2+D1 == 3.0*bu::dimensionless()); + + // quantity - quantity + BOOST_CHECK(D2-D1 == 1.0*bu::dimensionless()); + + // quantity * quantity + BOOST_CHECK(D1*D2 == 2.0*bu::dimensionless()); + + // quantity / quantity + BOOST_CHECK(D2/D1 == 2.0*bu::dimensionless()); + + // integer power of quantity + BOOST_CHECK(2.0*bu::pow<2>(D2) == 2.0*std::pow(2.0,2.0)*bu::dimensionless()); + + // rational power of quantity + BOOST_CHECK((2.0*bu::pow< bu::static_rational<2,3> >(D2) == 2.0*std::pow(2.0,2.0/3.0)*bu::dimensionless())); + + // integer root of quantity + BOOST_CHECK(2.0*bu::root<2>(D2) == 2.0*std::pow(2.0,1.0/2.0)*bu::dimensionless()); + + // rational root of quantity + BOOST_CHECK((2.0*bu::root< bu::static_rational<3,2> >(D2) == 2.0*std::pow(2.0,2.0/3.0)*bu::dimensionless())); + + BOOST_CONSTEXPR_OR_CONST bu::quantity A1(0.0), + A2(0.0), + A3(1.0), + A4(-1.0); + + // operator== + BOOST_CHECK((A1 == A2) == true); + BOOST_CHECK((A1 == A3) == false); + + // operator!= + BOOST_CHECK((A1 != A2) == false); + BOOST_CHECK((A1 != A3) == true); + + // operator< + BOOST_CHECK((A1 < A2) == false); + BOOST_CHECK((A1 < A3) == true); + + // operator<= + BOOST_CHECK((A1 <= A2) == true); + BOOST_CHECK((A1 <= A3) == true); + + // operator> + BOOST_CHECK((A1 > A2) == false); + BOOST_CHECK((A1 > A4) == true); + + // operator>= + BOOST_CHECK((A1 >= A2) == true); + BOOST_CHECK((A1 >= A4) == true); + + return 0; +} diff --git a/src/boost/libs/units/test/test_header.hpp b/src/boost/libs/units/test/test_header.hpp new file mode 100644 index 00000000..bc2ec439 --- /dev/null +++ b/src/boost/libs/units/test/test_header.hpp @@ -0,0 +1,126 @@ +// 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 test_header.hpp + +\details +Unit system for test purposes. + +Output: +@verbatim +@endverbatim +**/ + +#ifndef BOOST_UNITS_TEST_HEADER_HPP +#define BOOST_UNITS_TEST_HEADER_HPP + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001))) + +namespace boost { + +namespace units { + +//struct length_base_dimension : boost::units::base_dimension { }; ///> base dimension of length +//struct mass_base_dimension : boost::units::base_dimension { }; ///> base dimension of mass +//struct time_base_dimension : boost::units::base_dimension { }; ///> base dimension of time + +typedef length_base_dimension::dimension_type length_dimension; +typedef mass_base_dimension::dimension_type mass_dimension; +typedef time_base_dimension::dimension_type time_dimension; + +typedef derived_dimension::type area_dimension; +typedef derived_dimension::type energy_dimension; +typedef derived_dimension::type inverse_energy_dim; +typedef derived_dimension::type velocity_dimension; +typedef derived_dimension::type volume_dimension; + +/// placeholder class defining test unit system +struct length_unit : base_unit {}; +struct mass_unit : base_unit {}; +struct time_unit : base_unit {}; + +typedef make_system::type system; + +/// unit typedefs +typedef unit dimensionless; + +typedef unit length; +typedef unit mass; +typedef unit time; + +typedef unit area; +typedef unit energy; +typedef unit inverse_energy; +typedef unit velocity; +typedef unit volume; + +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(meter,length); +BOOST_UNITS_STATIC_CONSTANT(meters,length); +BOOST_UNITS_STATIC_CONSTANT(kilogram,mass); +BOOST_UNITS_STATIC_CONSTANT(kilograms,mass); +BOOST_UNITS_STATIC_CONSTANT(second,time); +BOOST_UNITS_STATIC_CONSTANT(seconds,time); + +BOOST_UNITS_STATIC_CONSTANT(square_meter,area); +BOOST_UNITS_STATIC_CONSTANT(square_meters,area); +BOOST_UNITS_STATIC_CONSTANT(joule,energy); +BOOST_UNITS_STATIC_CONSTANT(joules,energy); +BOOST_UNITS_STATIC_CONSTANT(meter_per_second,velocity); +BOOST_UNITS_STATIC_CONSTANT(meters_per_second,velocity); +BOOST_UNITS_STATIC_CONSTANT(cubic_meter,volume); +BOOST_UNITS_STATIC_CONSTANT(cubic_meters,volume); + +template<> struct base_unit_info +{ + static std::string name() { return "meter"; } + static std::string symbol() { return "m"; } +}; +//] + +template<> struct base_unit_info +{ + static std::string name() { return "kilogram"; } + static std::string symbol() { return "kg"; } +}; + +template<> struct base_unit_info +{ + static std::string name() { return "second"; } + static std::string symbol() { return "s"; } +}; + +} // namespace units + +} // namespace boost + +#endif // BOOST_UNITS_TEST_HEADER_HPP diff --git a/src/boost/libs/units/test/test_implicit_conversion.cpp b/src/boost/libs/units/test/test_implicit_conversion.cpp new file mode 100644 index 00000000..41dfca03 --- /dev/null +++ b/src/boost/libs/units/test/test_implicit_conversion.cpp @@ -0,0 +1,113 @@ +// 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 test_implicit_conversion.cpp + +\details +Test implicit conversions for quantity. + +Output: +@verbatim +@endverbatim +**/ + +#include + +#include +#include +#include +#include + +namespace bu = boost::units; + +int test_main(int,char *[]) +{ + //// si->si always true + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + + //// cgs->cgs always true + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + + //// si->cgs + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == true)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + + //// cgs->si + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == false)); + //BOOST_CHECK((bu::base_unit_is_implicitly_convertible::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == true)); + + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == true)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + BOOST_CHECK((bu::is_implicitly_convertible::value == false)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity S1(2.0*bu::si::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity S2 = S1; + + BOOST_CHECK((S1.value() == S2.value())); + + BOOST_CONSTEXPR_OR_CONST bu::quantity S3(2.0*bu::si::catalytic_activity()); + + + BOOST_CONSTEXPR_OR_CONST bu::quantity C1(2.0*bu::cgs::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity C2 = C1; + + BOOST_CHECK((C1.value() == C2.value())); + + return 0; +} diff --git a/src/boost/libs/units/test/test_information_units.cpp b/src/boost/libs/units/test/test_information_units.cpp new file mode 100644 index 00000000..80eb04f2 --- /dev/null +++ b/src/boost/libs/units/test/test_information_units.cpp @@ -0,0 +1,242 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2014 Erik Erlandson +// +// 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) + +#include +#include + +#include +#include +#include + +#include +#include + +// All information systems definitions +#include + +using std::cout; +using std::cerr; +using std::endl; +using std::stringstream; + +namespace bu = boost::units; +namespace si = boost::units::si; + +using bu::quantity; + +using bu::information::bit_base_unit; +using bu::information::byte_base_unit; +using bu::information::nat_base_unit; +using bu::information::hartley_base_unit; +using bu::information::shannon_base_unit; + + +#define BOOST_TEST_MAIN +#include + + +#include + +const double close_fraction = 0.0000001; + +// checks that cf(u2,u1) == expected +// also checks invariant property that cf(u2,u1) * cf(u1,u2) == 1 +#define CHECK_DIRECT_CF(u1, u2, expected) \ + BOOST_CHECK_CLOSE_FRACTION(bu::conversion_factor((u2), (u1)), (expected), close_fraction); \ + BOOST_CHECK_CLOSE_FRACTION(bu::conversion_factor((u2), (u1)) * bu::conversion_factor((u1), (u2)), 1.0, close_fraction); + +// check transitive conversion factors +// invariant: cf(u1,u3) = cf(u1,u2)*cf(u2,u3) +#define CHECK_TRANSITIVE_CF(u1, u2, u3) { \ + BOOST_CONSTEXPR_OR_CONST double cf12 = bu::conversion_factor((u2), (u1)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf23 = bu::conversion_factor((u3), (u2)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf13 = bu::conversion_factor((u3), (u1)) ; \ + BOOST_CHECK_CLOSE_FRACTION(cf13, cf12*cf23, close_fraction); \ + BOOST_CONSTEXPR_OR_CONST double cf32 = bu::conversion_factor((u2), (u3)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf21 = bu::conversion_factor((u1), (u2)) ; \ + BOOST_CONSTEXPR_OR_CONST double cf31 = bu::conversion_factor((u1), (u3)) ; \ + BOOST_CHECK_CLOSE_FRACTION(cf31, cf32*cf21, close_fraction); \ +} + + +BOOST_AUTO_TEST_CASE(test_cf_bit_byte) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), byte_base_unit::unit_type(), 8.0); +} + +BOOST_AUTO_TEST_CASE(test_cf_bit_nat) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), nat_base_unit::unit_type(), 1.442695040888964); +} + +BOOST_AUTO_TEST_CASE(test_cf_bit_hartley) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), hartley_base_unit::unit_type(), 3.321928094887363); +} + +BOOST_AUTO_TEST_CASE(test_cf_bit_shannon) { + CHECK_DIRECT_CF(bit_base_unit::unit_type(), shannon_base_unit::unit_type(), 1.0); +} + +///////////////////////////////////////////////////////////////////////////////////// +// spot-check that these are automatically transitive, thru central "hub unit" bit: +// basic pattern is to test invariant property: cf(c,a) = cf(c,b)*cf(b,a) + +BOOST_AUTO_TEST_CASE(test_transitive_byte_nat) { + CHECK_TRANSITIVE_CF(byte_base_unit::unit_type(), bit_base_unit::unit_type(), nat_base_unit::unit_type()); +} +BOOST_AUTO_TEST_CASE(test_transitive_nat_hartley) { + CHECK_TRANSITIVE_CF(nat_base_unit::unit_type(), bit_base_unit::unit_type(), hartley_base_unit::unit_type()); +} +BOOST_AUTO_TEST_CASE(test_transitive_hartley_shannon) { + CHECK_TRANSITIVE_CF(hartley_base_unit::unit_type(), bit_base_unit::unit_type(), shannon_base_unit::unit_type()); +} +BOOST_AUTO_TEST_CASE(test_transitive_shannon_byte) { + CHECK_TRANSITIVE_CF(shannon_base_unit::unit_type(), bit_base_unit::unit_type(), byte_base_unit::unit_type()); +} + +// test transitive factors, none of which are bit, just for good measure +BOOST_AUTO_TEST_CASE(test_transitive_byte_nat_hartley) { + CHECK_TRANSITIVE_CF(byte_base_unit::unit_type(), nat_base_unit::unit_type(), hartley_base_unit::unit_type()); +} + +BOOST_AUTO_TEST_CASE(test_byte_quantity_is_default) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * byte); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * byte); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_byte_quantity_explicit) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * byte); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * byte); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_bit_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * bit); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * bit); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_nat_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * nat); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * nat); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_hartley_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * hartley); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * hartley); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_shannon_quantity) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity qd(2 * shannon); + BOOST_CHECK_EQUAL(qd.value(), double(2)); + BOOST_CONSTEXPR_OR_CONST quantity ql(2 * shannon); + BOOST_CHECK_EQUAL(ql.value(), long(2)); +} + +BOOST_AUTO_TEST_CASE(test_mixed_hu) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST double cf = 0.001; + BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 1.0, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 1.0/8.0, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 0.69315, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 0.30102, cf); + BOOST_CHECK_CLOSE_FRACTION((quantity(1.0 * bits)).value(), 1.0, cf); +} + +BOOST_AUTO_TEST_CASE(test_info_prefixes) { + using namespace bu::information; + BOOST_CONSTEXPR_OR_CONST quantity q10(1LL * kibi * byte); + BOOST_CHECK_EQUAL(q10.value(), 1024LL); + + BOOST_CONSTEXPR_OR_CONST quantity q20(1LL * mebi * byte); + BOOST_CHECK_EQUAL(q20.value(), 1048576LL); + + BOOST_CONSTEXPR_OR_CONST quantity q30(1LL * gibi * byte); + BOOST_CHECK_EQUAL(q30.value(), 1073741824LL); + + BOOST_CONSTEXPR_OR_CONST quantity q40(1LL * tebi * byte); + BOOST_CHECK_EQUAL(q40.value(), 1099511627776LL); + + BOOST_CONSTEXPR_OR_CONST quantity q50(1LL * pebi * byte); + BOOST_CHECK_EQUAL(q50.value(), 1125899906842624LL); + + BOOST_CONSTEXPR_OR_CONST quantity q60(1LL * exbi * byte); + BOOST_CHECK_EQUAL(q60.value(), 1152921504606846976LL); + + using boost::multiprecision::int128_t; + + const quantity q70(1LL * zebi * byte); + BOOST_CHECK_EQUAL(q70.value(), int128_t("1180591620717411303424")); + + const quantity q80(1LL * yobi * byte); + BOOST_CHECK_EQUAL(q80.value(), int128_t("1208925819614629174706176")); + + // sanity check: si prefixes should also operate + BOOST_CONSTEXPR_OR_CONST quantity q1e3(1LL * si::kilo * byte); + BOOST_CHECK_EQUAL(q1e3.value(), 1000LL); + + BOOST_CONSTEXPR_OR_CONST quantity q1e6(1LL * si::mega * byte); + BOOST_CHECK_EQUAL(q1e6.value(), 1000000LL); +} + +BOOST_AUTO_TEST_CASE(test_unit_constant_io) { + using namespace bu::information; + + std::stringstream ss; + ss << bu::symbol_format << bytes; + BOOST_CHECK_EQUAL(ss.str(), "B"); + + ss.str(""); + ss << bu::name_format << bytes; + BOOST_CHECK_EQUAL(ss.str(), "byte"); + + ss.str(""); + ss << bu::symbol_format << bits; + BOOST_CHECK_EQUAL(ss.str(), "b"); + + ss.str(""); + ss << bu::name_format << bits; + BOOST_CHECK_EQUAL(ss.str(), "bit"); + + ss.str(""); + ss << bu::symbol_format << nats; + BOOST_CHECK_EQUAL(ss.str(), "nat"); + + ss.str(""); + ss << bu::name_format << nats; + BOOST_CHECK_EQUAL(ss.str(), "nat"); + + ss.str(""); + ss << bu::symbol_format << hartleys; + BOOST_CHECK_EQUAL(ss.str(), "Hart"); + + ss.str(""); + ss << bu::name_format << hartleys; + BOOST_CHECK_EQUAL(ss.str(), "hartley"); + + ss.str(""); + ss << bu::symbol_format << shannons; + BOOST_CHECK_EQUAL(ss.str(), "Sh"); + + ss.str(""); + ss << bu::name_format << shannons; + BOOST_CHECK_EQUAL(ss.str(), "shannon"); +} diff --git a/src/boost/libs/units/test/test_lambda.cpp b/src/boost/libs/units/test/test_lambda.cpp new file mode 100644 index 00000000..8c3642c7 --- /dev/null +++ b/src/boost/libs/units/test/test_lambda.cpp @@ -0,0 +1,269 @@ +// 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) + +// $Id: test_lambda.cpp 27 2008-06-16 14:50:58Z maehne $ + +//////////////////////////////////////////////////////////////////////// +/// +/// \file test_lambda.hpp +/// +/// \brief Unit test for checking the usage of Boost.Units' quantity, +/// unit, and absolute types in functors created with the +/// Boost.Lambda library. +/// +/// \author Torsten Maehne +/// \date 2008-06-16 +/// +/// This unit test contains a check for each operator action, for +/// which a specialization of Boost.Lambda's return type deduction +/// system is made in lambda.hpp, i.e., for the operators defined for +/// Boost.Units' quantity, unit, and absolute types. +/// +//////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include "test_header.hpp" + + +namespace bl = boost::lambda; +namespace bu = boost::units; +namespace si = boost::units::si; + + +int test_main(int, char *[]) +{ + + //////////////////////////////////////////////////////////////////////// + // Test for Boost.Lambda working with overloaded operators defined + // in + //////////////////////////////////////////////////////////////////////// + + bu::quantity lvar = 0.0 * bu::meter; + + bu::quantity dlvar = 3.0; + + // quantity += quantity + boost::function (bu::quantity)> + f = (bl::var(lvar) += bl::_1); + + lvar = 1.0 * bu::meter; + BOOST_CHECK((f(2.0 * bu::meter) == 3.0 * bu::meter)); + BOOST_CHECK((f(6.0 * bu::meter) == 9.0 * bu::meter)); + + // quantity += quantity + dlvar = 4.0; + BOOST_CHECK(((bl::var(dlvar) += bl::_1)(3.0) == 7.0)); + + // quantity -= quantity + lvar = 3.0 * bu::meter; + BOOST_CHECK((f(-2.0 * bu::meter) == 1.0 * bu::meter)); + BOOST_CHECK((f(6.0 * bu::meter) == 7.0 * bu::meter)); + + // quantity -= quantity + dlvar = 4.0; + BOOST_CHECK(((bl::var(dlvar) -= bl::_1)(3.0) == 1.0)); + + // quantity *= quantity + dlvar = 2.0; + BOOST_CHECK(((bl::var(dlvar) *= bl::_1)(3.0) == 6.0)); + + // quantity /= quantity + dlvar = 6.0; + BOOST_CHECK(((bl::var(dlvar) /= bl::_1)(3.0) == 2.0)); + + // quantity *= Y + lvar = 3.0 * bu::meter; + BOOST_CHECK(((bl::var(lvar) *= bl::_1)(2.0) == 6.0 * bu::meter)); + + // quantity /= Y + lvar = 6.0 * bu::meter; + BOOST_CHECK(((bl::var(lvar) /= bl::_1)(3.0) == 2.0 * bu::meter)); + + // unit * Y + BOOST_CHECK(((bl::_1 * bl::_2)(bu::meter, 2.0) == 2.0 * bu::meter)); + BOOST_CHECK(((bu::meter * bl::_1)(2.0) == 2.0 * bu::meter)); + + // unit / Y + BOOST_CHECK(((bl::_1 / bl::_2)(bu::meter, 0.5) == 2.0 * bu::meter)); + BOOST_CHECK(((bu::meter / bl::_1)(0.5 * bu::second) == 2.0 * bu::meter_per_second)); + + // Y * unit + BOOST_CHECK(((bl::_1 * bl::_2)(2.0, bu::meter) == 2.0 * bu::meter)); + BOOST_CHECK(((bl::_1 * bu::meter)(2.0 / bu::second) == 2.0 * bu::meter_per_second)); + + // Y / unit + BOOST_CHECK(((bl::_1 / bl::_2)(3.5, bu::second) == 3.5 / bu::second)); + BOOST_CHECK(((bl::_1 / bu::second)(3.5 * bu::meter) == 3.5 * bu::meter_per_second)); + + // quantity * X + BOOST_CHECK(((bl::_1 * bl::_2)(2.0, 3.0 * bu::meter) == 6.0 * bu::meter)); + + // X * quantity + BOOST_CHECK(((bl::_1 * bl::_2)(4.0 * bu::joule, 2.0) == 8.0 * bu::joule)); + + // quantity / X + BOOST_CHECK(((bl::_1 / bl::_2)(4.0 * bu::joule, 2.0) == 2.0 * bu::joule)); + + // X / quantity + BOOST_CHECK(((3.0 / bl::_1)(2.0 * bu::second) == 1.5 / bu::second)); + + // unit * quantity + BOOST_CHECK(((bl::_1 * bl::_2)(bu::meter, 12.0 / bu::second) == 12.0 * bu::meter_per_second)); + BOOST_CHECK(((bu::meter * bl::_1)(12.0 / bu::second) == 12.0 * bu::meter_per_second)); + + // unit / quantity + BOOST_CHECK(((bl::_1 / bl::_2)(bu::meter, 0.5 * bu::second) == 2.0 * bu::meter_per_second)); + BOOST_CHECK(((bu::meter / bl::_1)(0.25 * bu::second) == 4.0 * bu::meter_per_second)); + + // quantity * unit + BOOST_CHECK(((bl::_1 * bl::_2)(2.0 / bu::second, bu::meter) == 2.0 * bu::meter_per_second)); + BOOST_CHECK(((bl::_1 * bu::meter)(12.0 / bu::second) == 12.0 * bu::meter_per_second)); + + // quantity / unit + BOOST_CHECK(((bl::_1 / bl::_2)(3.5 * bu::meter, bu::second) == 3.5 * bu::meter_per_second)); + BOOST_CHECK(((bl::_1 / bu::second)(5.0 * bu::second) == 5.0)); + + // +quantity + BOOST_CHECK(((+bl::_1)(5.0 * bu::second) == 5.0 * bu::second)); + + // -quantity + BOOST_CHECK(((-bl::_1)(5.0 * bu::second) == -5.0 * bu::second)); + + // quantity + quantity + BOOST_CHECK(((bl::_1 + bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == 6.0 * bu::meter)); + + // quantity + Y + BOOST_CHECK(((bl::_1 + 1.0f)(bu::quantity(2.0)) == 3.0)); + + // X + quantity + BOOST_CHECK(((1.0f + bl::_1)(bu::quantity(1.0)) == 2.0)); + + // quantity - quantity + BOOST_CHECK(((bl::_1 - bl::_2)(2.0 * bu::meter, 4.0 * bu::meter) == -2.0 * bu::meter)); + + // quantity - Y + BOOST_CHECK(((bl::_1 - 2.0f)(bu::quantity(1.0)) == -1.0)); + + // X - quantity + BOOST_CHECK(((2.0f - bl::_1)(bu::quantity(1.0)) == 1.0)); + + // quantity * quantity + BOOST_CHECK(((bl::_1 * bl::_2)(2.0 * bu::kilogram, 4.0 * bu::meter_per_second) == 8.0 * bu::kilogram * bu::meter_per_second)); + + // quantity / quantity + BOOST_CHECK(((bl::_1 / bl::_2)(2.0 * bu::meter_per_second, 4.0 * bu::meter_per_second) == 0.5)); + + // quantity == quantity + BOOST_CHECK(((bl::_1 == bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 == bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == false)); + + // quantity != quantity + BOOST_CHECK(((bl::_1 != bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 != bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == true)); + + // quantity < quantity + BOOST_CHECK(((bl::_1 < bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 < bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == true)); + + // quantity <= quantity + BOOST_CHECK(((bl::_1 <= bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 <= bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 <= bl::_2)(4.0 * bu::meter, 3.0 * bu::meter) == false)); + + // quantity > quantity + BOOST_CHECK(((bl::_1 > bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 > bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 > bl::_2)(4.0 * bu::meter, 3.0 * bu::meter) == true)); + + // quantity >= quantity + BOOST_CHECK(((bl::_1 >= bl::_2)(2.0 * bu::meter, 2.0 * bu::meter) == true)); + BOOST_CHECK(((bl::_1 >= bl::_2)(2.0 * bu::meter, 3.0 * bu::meter) == false)); + BOOST_CHECK(((bl::_1 >= bl::_2)(4.0 * bu::meter, 3.0 * bu::meter) == true)); + + + //////////////////////////////////////////////////////////////////////// + // Test for Boost.Lambda working with overloaded operators defined + // in + //////////////////////////////////////////////////////////////////////// + + // +unit + BOOST_CHECK(((+bl::_1)(bu::meter) == bu::meter)); + + // -unit + BOOST_CHECK(((-bl::_1)(bu::meter) == bu::meter)); + + // unit + unit + BOOST_CHECK(((bl::_1 + bu::meter)(bu::meter) == bu::meter)); + BOOST_CHECK(((bu::meter + bl::_1)(bu::meter) == bu::meter)); + BOOST_CHECK(((bl::_1 + bl::_2)(bu::meter, bu::meter) == bu::meter)); + + // unit - unit + BOOST_CHECK(((bl::_1 - bl::_2)(bu::meter, bu::meter) == bu::meter)); + BOOST_CHECK(((bl::_1 - bu::meter)(bu::meter) == bu::meter)); + BOOST_CHECK(((bu::meter - bl::_1)(bu::meter) == bu::meter)); + + // unit * unit + BOOST_CHECK(((bl::_1 * bl::_2)(bu::meter, bu::meter) == bu::meter * bu::meter)); + BOOST_CHECK(((bl::_1 * bu::meter)(bu::meter) == bu::meter * bu::meter)); + + // unit / unit + BOOST_CHECK(((bl::_1 / bl::_2)(bu::meter, bu::second) == bu::meter_per_second)); + BOOST_CHECK(((bl::_1 / bu::second)(bu::meter) == bu::meter_per_second)); + + // unit == unit + BOOST_CHECK(((bl::_1 == bu::meter)(bu::meter) == true)); + BOOST_CHECK(((bl::_1 == bu::meter)(bu::second) == false)); + + // unit != unit + BOOST_CHECK(((bl::_1 != bu::meter)(bu::meter) == false)); + BOOST_CHECK(((bl::_1 != bu::meter)(bu::second) == true)); + + + //////////////////////////////////////////////////////////////////////// + // Test for Boost.Lambda working with overloaded operators defined + // in + //////////////////////////////////////////////////////////////////////// + + // absolute += Y + bu::quantity > Ta = 270.0 * bu::absolute(); + (Ta += bl::_1)(30.0 * si::kelvin); + BOOST_CHECK(( Ta == 300.0 * bu::absolute())); + + // absolute -= Y + Ta = 270 * bu::absolute(); + (Ta -= bl::_1)(-30.0 * si::kelvin); + BOOST_CHECK(( Ta == 300.0 * bu::absolute())); + + // absolute + Y + BOOST_CHECK(((270.0 * bu::absolute() + bl::_1)(30.0 * si::kelvin) == 300.0 * bu::absolute())); + + // Y + absolute + BOOST_CHECK(((bl::_1 + 270.0 * bu::absolute())(30.0 * si::kelvin) == 300.0 * bu::absolute())); + + // absolute - Y + BOOST_CHECK(((270.0 * bu::absolute() - bl::_1)(30.0 * si::kelvin) == 240.0 * bu::absolute())); + + // absolute - absolute + BOOST_CHECK(((bl::_1 - 270.0 * bu::absolute())(300.0 * bu::absolute()) == 30.0 * si::kelvin)); + + // T * absolute > + BOOST_CHECK(((bl::_1 * bu::absolute())(300.0) == 300.0 * bu::absolute())); + BOOST_CHECK(((bl::_1 * bl::_2)(300.0, bu::absolute()) == 300.0 * bu::absolute())); + + // absolute > * T + BOOST_CHECK(((bu::absolute() * bl::_1)(300.0) == 300.0 * bu::absolute())); + BOOST_CHECK(((bl::_1 * bl::_2)(bu::absolute(), 300.0) == 300.0 * bu::absolute())); + + + return 0; +} diff --git a/src/boost/libs/units/test/test_limits.cpp b/src/boost/libs/units/test/test_limits.cpp new file mode 100644 index 00000000..6057cf94 --- /dev/null +++ b/src/boost/libs/units/test/test_limits.cpp @@ -0,0 +1,127 @@ +// 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 test_limits.cpp + +\details +Test numeric_limits specialization. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +#include +#include + +#include "test_header.hpp" + +typedef boost::units::length unit_type; +using boost::units::quantity; + +template +struct check_quiet_NaN; + +template<> +struct check_quiet_NaN { + template + static void apply() { + quantity q((std::numeric_limits >::quiet_NaN)()); + bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); + BOOST_CHECK(test); + } +}; + +template<> +struct check_quiet_NaN { + template + static void apply() {} +}; + +template +struct check_signaling_NaN; + +template<> +struct check_signaling_NaN { + template + static void apply() { + quantity q((std::numeric_limits >::signaling_NaN)()); + bool test = isnan BOOST_PREVENT_MACRO_SUBSTITUTION (q); + BOOST_CHECK(test); + } +}; + +template<> +struct check_signaling_NaN { + template + static void apply() {} +}; + +template +void do_check() { + #define CHECK_FUNCTION(name) BOOST_CHECK(((std::numeric_limits::name)() == (std::numeric_limits >::name)().value())) + #define CHECK_CONSTANT(name) BOOST_CHECK((std::numeric_limits::name == std::numeric_limits >::name)) + CHECK_FUNCTION(min); + CHECK_FUNCTION(max); + CHECK_FUNCTION(epsilon); + CHECK_FUNCTION(round_error); + CHECK_FUNCTION(infinity); + CHECK_FUNCTION(denorm_min); + #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS + CHECK_FUNCTION(lowest); + #endif + + CHECK_CONSTANT(is_specialized); + CHECK_CONSTANT(digits); + CHECK_CONSTANT(digits10); + #ifndef BOOST_NO_CXX11_NUMERIC_LIMITS + CHECK_CONSTANT(max_digits10); + #endif + CHECK_CONSTANT(is_signed); + CHECK_CONSTANT(is_integer); + CHECK_CONSTANT(is_exact); + CHECK_CONSTANT(radix); + CHECK_CONSTANT(min_exponent); + CHECK_CONSTANT(min_exponent10); + CHECK_CONSTANT(max_exponent); + CHECK_CONSTANT(max_exponent10); + CHECK_CONSTANT(has_infinity); + CHECK_CONSTANT(has_quiet_NaN); + CHECK_CONSTANT(has_signaling_NaN); + CHECK_CONSTANT(has_denorm); + CHECK_CONSTANT(has_denorm_loss); + CHECK_CONSTANT(is_iec559); + CHECK_CONSTANT(is_bounded); + CHECK_CONSTANT(is_modulo); + CHECK_CONSTANT(traps); + CHECK_CONSTANT(tinyness_before); + CHECK_CONSTANT(round_style); + + check_quiet_NaN >::has_quiet_NaN>::template apply(); + check_signaling_NaN >::has_signaling_NaN>::template apply(); +} + +int test_main(int,char *[]) +{ + do_check(); + do_check(); + do_check(); + do_check(); + do_check(); + do_check >(); + + return(0); +} diff --git a/src/boost/libs/units/test/test_mixed_value_types.cpp b/src/boost/libs/units/test/test_mixed_value_types.cpp new file mode 100644 index 00000000..7d86362c --- /dev/null +++ b/src/boost/libs/units/test/test_mixed_value_types.cpp @@ -0,0 +1,22 @@ +// 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) 2007-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) + +#include +#include +#include + +namespace bu = boost::units; + +int main() { + bu::quantity q1; + BOOST_CONSTEXPR_OR_CONST bu::quantity q2; + q1 + q2; + q1 -= q2; +} diff --git a/src/boost/libs/units/test/test_negative_denominator.cpp b/src/boost/libs/units/test/test_negative_denominator.cpp new file mode 100644 index 00000000..e9b638ab --- /dev/null +++ b/src/boost/libs/units/test/test_negative_denominator.cpp @@ -0,0 +1,32 @@ +// 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 test_negative_denominator.cpp + +\details +Test negative denominator for static_rational class. + +Output: +@verbatim +@endverbatim +**/ + +#include + +#include +#include + +BOOST_MPL_ASSERT((boost::is_same::type, boost::units::static_rational<2, -1>::type>)); + +int main() { +} diff --git a/src/boost/libs/units/test/test_output.cpp b/src/boost/libs/units/test/test_output.cpp new file mode 100644 index 00000000..abc39d85 --- /dev/null +++ b/src/boost/libs/units/test/test_output.cpp @@ -0,0 +1,499 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2009 Steven Watanabe +// Copyright Paul A. Bristow 2010 +// +// 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 test_output.cpp + +\brief +Test unit and quantity printing +\details +Tests for output from various units, name, symbol and raw formats, and automatic prefixing in engineering and binary units. +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#define BOOST_TEST_MAIN +#include + +struct meter_base_unit : boost::units::base_unit { + static BOOST_CONSTEXPR const char* name() { return("meter"); } + static BOOST_CONSTEXPR const char* symbol() { return("m"); } +}; + +struct second_base_unit : boost::units::base_unit { + static BOOST_CONSTEXPR const char* name() { return("second"); } + static BOOST_CONSTEXPR const char* symbol() { return("s"); } +}; + +struct byte_base_unit : boost::units::base_unit { + static BOOST_CONSTEXPR const char* name() { return("byte"); } + static BOOST_CONSTEXPR const char* symbol() { return("b"); } +}; + +typedef boost::units::make_system::type my_system; + +typedef boost::units::unit length; +typedef boost::units::unit velocity; + +typedef boost::units::make_scaled_unit > >::type scaled_length; +typedef boost::units::make_scaled_unit > >::type scaled_velocity1; + +typedef boost::units::scaled_base_unit > > millisecond_base_unit; + +typedef boost::units::make_system::type scaled_system; + +typedef boost::units::unit scaled_time; +typedef boost::units::unit scaled_velocity2; + +typedef boost::units::unit area; +typedef boost::units::make_scaled_unit > >::type scaled_area; + +typedef boost::units::make_scaled_unit > >::type double_scaled_length; + +typedef boost::units::scaled_base_unit > > scaled_length_base_unit; +namespace boost { +namespace units { +template<> +struct base_unit_info { + static BOOST_CONSTEXPR const char* symbol() { return("scm"); } + static BOOST_CONSTEXPR const char* name() { return("scaled_meter"); } +}; +} +} +typedef boost::units::scaled_base_unit > > double_scaled_length_base_unit; +typedef double_scaled_length_base_unit::unit_type double_scaled_length2; + +typedef boost::units::reduce_unit >::type custom1; + +std::string name_string(const custom1&) { return("custom1"); } +std::string symbol_string(const custom1&) { return("c1"); } + +typedef boost::units::reduce_unit >::type custom2; + +BOOST_CONSTEXPR const char* name_string(const custom2&) { return("custom2"); } +BOOST_CONSTEXPR const char* symbol_string(const custom2&) { return("c2"); } + +typedef boost::units::make_scaled_unit > >::type scaled_custom1; +typedef boost::units::make_scaled_unit > >::type scaled_custom2; + +#ifndef BOOST_NO_CWCHAR + +#define BOOST_UNITS_TEST_OUTPUT(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + BOOST_CHECK_EQUAL(ss.str(), expected); \ +} \ +{ \ + std::wostringstream ss; \ + ss FORMATTERS << v; \ + BOOST_CHECK(ss.str() == BOOST_PP_CAT(L, expected)); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_REGEX(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + boost::regex r(expected); \ + BOOST_CHECK_MESSAGE(boost::regex_match(ss.str(), r), \ + ss.str() + " does not match " + expected); \ +} \ +{ \ + std::wostringstream ss; \ + ss FORMATTERS << v; \ + boost::wregex r(BOOST_PP_CAT(L, expected)); \ + BOOST_CHECK(boost::regex_match(ss.str(), r)); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_DISPLAY(v) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + std::cout << #v << ": " << ss.str() << std::endl; \ +} \ +{ \ + std::wostringstream ss; \ + ss FORMATTERS << v; \ + std::wcout << #v << ": " << ss.str() << std::endl; \ +} + +#else + +#define BOOST_UNITS_TEST_OUTPUT(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + BOOST_CHECK_EQUAL(ss.str(), expected); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_REGEX(v, expected) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + boost::regex r(expected); \ + BOOST_CHECK_MESSAGE(boost::regex_match(ss.str(), r), \ + ss.str() + " does not match " + expected); \ +} + +#define BOOST_UNITS_TEST_OUTPUT_DISPLAY(v) \ +{ \ + std::ostringstream ss; \ + ss FORMATTERS << v; \ + std::cout << #v << ": " << ss.str() << std::endl; \ +} + +#endif + +BOOST_AUTO_TEST_CASE(test_output_unit_symbol) +{ // base units using default symbol_format (no format specified) and no auto prefixing. +#define FORMATTERS + BOOST_UNITS_TEST_OUTPUT(meter_base_unit::unit_type(), "m"); + BOOST_UNITS_TEST_OUTPUT(velocity(), "m s^-1"); + BOOST_UNITS_TEST_OUTPUT(scaled_length(), "km"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity1(), "k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(millisecond_base_unit::unit_type(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_time(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity2(), "m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(area(), "m^2"); + BOOST_UNITS_TEST_OUTPUT(scaled_area(), "k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "Kikm"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kscm"); + BOOST_UNITS_TEST_OUTPUT(custom1(), "c1"); + BOOST_UNITS_TEST_OUTPUT(custom2(), "c2"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kc1"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "kc2"); + BOOST_UNITS_TEST_OUTPUT(boost::units::absolute(), "absolute m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_unit_raw) +{ // raw format specified +#define FORMATTERS << boost::units::raw_format + BOOST_UNITS_TEST_OUTPUT(meter_base_unit::unit_type(), "m"); + BOOST_UNITS_TEST_OUTPUT(velocity(), "m s^-1"); + BOOST_UNITS_TEST_OUTPUT(scaled_length(), "km"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity1(), "k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(millisecond_base_unit::unit_type(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_time(), "ms"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity2(), "m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(area(), "m^2"); + BOOST_UNITS_TEST_OUTPUT(scaled_area(), "k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "Kikm"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kscm"); + // when using raw format, we ignore the user defined overloads + BOOST_UNITS_TEST_OUTPUT(custom1(), "m^3"); + BOOST_UNITS_TEST_OUTPUT(custom2(), "m s^-2"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "k(m^3)"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "k(m s^-2)"); + BOOST_UNITS_TEST_OUTPUT(boost::units::absolute(), "absolute m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_unit_name) +{ // name format specified. +#define FORMATTERS << boost::units::name_format + BOOST_UNITS_TEST_OUTPUT(meter_base_unit::unit_type(), "meter"); + BOOST_UNITS_TEST_OUTPUT(velocity(), "meter second^-1"); + BOOST_UNITS_TEST_OUTPUT(scaled_length(), "kilometer"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity1(), "kilo(meter second^-1)"); + BOOST_UNITS_TEST_OUTPUT(millisecond_base_unit::unit_type(), "millisecond"); + BOOST_UNITS_TEST_OUTPUT(scaled_time(), "millisecond"); + BOOST_UNITS_TEST_OUTPUT(scaled_velocity2(), "meter millisecond^-1"); + BOOST_UNITS_TEST_OUTPUT(area(), "meter^2"); + BOOST_UNITS_TEST_OUTPUT(scaled_area(), "kilo(meter^2)"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length(), "kibikilometer"); + BOOST_UNITS_TEST_OUTPUT(double_scaled_length2(), "kiloscaled_meter"); + BOOST_UNITS_TEST_OUTPUT(custom1(), "custom1"); + BOOST_UNITS_TEST_OUTPUT(custom2(), "custom2"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom1(), "kilocustom1"); + BOOST_UNITS_TEST_OUTPUT(scaled_custom2(), "kilocustom2"); + BOOST_UNITS_TEST_OUTPUT(boost::units::absolute(), "absolute meter"); +#undef FORMATTERS +} + + +BOOST_AUTO_TEST_CASE(test_output_quantity_symbol) +{ // quantity symbols using default format. +#define FORMATTERS + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 m s^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 Kikm"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 c1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 c2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kc1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kc2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute(), "1.5 absolute m"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 10) * byte_base_unit::unit_type(), "1024 b"); + +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_quantity_raw) +{ // quantity symbols using raw format. +#define FORMATTERS << boost::units::raw_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 m s^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 Kikm"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm"); + // when using raw format, we ignore the user defined overloads + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 m^3"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 m s^-2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 k(m^3)"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 k(m s^-2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute(), "1.5 absolute m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_quantity_name) +{ // // quantity symbols using name format. +#define FORMATTERS << boost::units::name_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 meter"); + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 meter second^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 kilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 kilo(meter second^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 meter millisecond^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 meter^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 kilo(meter^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.5 kibikilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kiloscaled_meter"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 custom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 custom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kilocustom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kilocustom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute(), "1.5 absolute meter"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_autoprefixed_quantity_name) +{ // Engineering autoprefix, with name format. +#define FORMATTERS << boost::units::name_format << boost::units::engineering_prefix + // Single base unit like meter. + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 meter"); + BOOST_UNITS_TEST_OUTPUT(1500.0*meter_base_unit::unit_type(), "1.5 kilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5e7*meter_base_unit::unit_type(), "15 megameter"); + BOOST_UNITS_TEST_OUTPUT(1.5e-3*meter_base_unit::unit_type(), "1.5 millimeter"); + BOOST_UNITS_TEST_OUTPUT(1.5e-9*meter_base_unit::unit_type(), "1.5 nanometer"); + BOOST_UNITS_TEST_OUTPUT(1.5e-8*meter_base_unit::unit_type(), "15 nanometer"); + BOOST_UNITS_TEST_OUTPUT(1.5e-10*meter_base_unit::unit_type(), "150 picometer"); + BOOST_UNITS_TEST_OUTPUT(0.0000000012345 * meter_base_unit::unit_type(), "1.2345 nanometer"); + + // Too small or large for a multiple name. + BOOST_UNITS_TEST_OUTPUT_REGEX(9.99999e-25 * meter_base_unit::unit_type(), "9\\.99999e-0?25 meter"); // Just too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1e+28 * meter_base_unit::unit_type(), "1e\\+0?28 meter"); // Just too large for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e-25 * meter_base_unit::unit_type(), "1\\.5e-0?25 meter"); // Too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e+28 * meter_base_unit::unit_type(), "1\\.5e\\+0?28 meter"); // Too large for multiple. + // Too 'biggest or too smallest'. + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits::max)()*meter_base_unit::unit_type(), "3\\.40282e\\+0?38 meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits::min)()*meter_base_unit::unit_type(), "1\\.17549e-0?38 meter"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits::max)()*meter_base_unit::unit_type(), "1.79769e+308 meter"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits::min)()*meter_base_unit::unit_type(), "2.22507e-308 meter"); + // Infinity and NaN + BOOST_UNITS_TEST_OUTPUT_REGEX(std::numeric_limits::infinity()*meter_base_unit::unit_type(), "(1\\.#INF|inf|INF|Inf) meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX(-std::numeric_limits::infinity()*meter_base_unit::unit_type(), "-(1\\.#INF|inf|INF|Inf) meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX(std::numeric_limits::quiet_NaN()*meter_base_unit::unit_type(), "(1\\.#QNAN|nan|NaNQ|NaN) meter"); + BOOST_UNITS_TEST_OUTPUT_REGEX(-std::numeric_limits::quiet_NaN()*meter_base_unit::unit_type(), "-?(1\\.#IND|nan|nan\\(ind\\)|NaNQ|NaN) meter"); + + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 meter second^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 kilometer"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 kilo(meter second^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 millisecond"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 meter millisecond^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 meter^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 kilo(meter^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.536 megameter"); // 1.5 * 2^10 = 1.5 * 1024 = 1.536 + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kiloscaled_meter"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 custom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 custom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kilocustom1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kilocustom2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute(), "1.5 absolute meter"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 10) * byte_base_unit::unit_type(), "1.024 kilobyte"); + + BOOST_UNITS_TEST_OUTPUT(1.5, "1.5"); // scalar. + BOOST_UNITS_TEST_OUTPUT(1567., "1567"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(0.00015, "0.00015"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-1.5, "-1.5"); // scalar. + BOOST_UNITS_TEST_OUTPUT(-1567., "-1567"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-0.00015, "-0.00015"); // scalars are *not* autoprefixed. +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_autoprefixed_quantity_symbol) +{ // Engineering autoprefix, with symbol format. +#define FORMATTERS << boost::units::symbol_format << boost::units::engineering_prefix + // Single base unit like m. + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); + BOOST_UNITS_TEST_OUTPUT(1500.0*meter_base_unit::unit_type(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5e7*meter_base_unit::unit_type(), "15 Mm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-3*meter_base_unit::unit_type(), "1.5 mm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-9*meter_base_unit::unit_type(), "1.5 nm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-8*meter_base_unit::unit_type(), "15 nm"); + BOOST_UNITS_TEST_OUTPUT(1.5e-10*meter_base_unit::unit_type(), "150 pm"); + // Too small or large for a multiple name. + BOOST_UNITS_TEST_OUTPUT_REGEX(9.99999e-25 * meter_base_unit::unit_type(), "9\\.99999e-0?25 m"); // Just too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1e+28 * meter_base_unit::unit_type(), "1e\\+0?28 m"); // Just too large for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e-25 * meter_base_unit::unit_type(), "1\\.5e-0?25 m"); // Too small for multiple. + BOOST_UNITS_TEST_OUTPUT_REGEX(1.5e+28 * meter_base_unit::unit_type(), "1\\.5e\\+0?28 m"); // Too large for multiple. + // + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits::max)()*meter_base_unit::unit_type(), "3\\.40282e\\+0?38 m"); + BOOST_UNITS_TEST_OUTPUT_REGEX((std::numeric_limits::min)()*meter_base_unit::unit_type(), "1\\.17549e-0?38 m"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits::max)()*meter_base_unit::unit_type(), "1.79769e+308 m"); + BOOST_UNITS_TEST_OUTPUT((std::numeric_limits::min)()*meter_base_unit::unit_type(), "2.22507e-308 m"); + + BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 m s^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 km"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity1(), "1.5 k(m s^-1)"); + BOOST_UNITS_TEST_OUTPUT(1.5*millisecond_base_unit::unit_type(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_time(), "1.5 ms"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_velocity2(), "1.5 m ms^-1"); + BOOST_UNITS_TEST_OUTPUT(1.5*area(), "1.5 m^2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_area(), "1.5 k(m^2)"); + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length(), "1.536 Mm"); // 1.5 * 2^10 = 1.5 * 1024 = 1.536 + BOOST_UNITS_TEST_OUTPUT(1.5*double_scaled_length2(), "1.5 kscm"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom1(), "1.5 c1"); + BOOST_UNITS_TEST_OUTPUT(1.5*custom2(), "1.5 c2"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom1(), "1.5 kc1"); + BOOST_UNITS_TEST_OUTPUT(1.5*scaled_custom2(), "1.5 kc2"); + BOOST_UNITS_TEST_OUTPUT(1.5*boost::units::absolute(), "1.5 absolute m"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 10) * byte_base_unit::unit_type(), "1.024 kb"); + +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_symbol) +{ // Binary prefix with symbol format. +#define FORMATTERS << boost::units::symbol_format << boost::units::binary_prefix + BOOST_UNITS_TEST_OUTPUT(1024 * byte_base_unit::unit_type(), "1 Kib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 20) * byte_base_unit::unit_type(), "1 Mib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 30) * byte_base_unit::unit_type(), "1 Gib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 40) * byte_base_unit::unit_type(), "1 Tib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 50) * byte_base_unit::unit_type(), "1 Pib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 60) * byte_base_unit::unit_type(), "1 Eib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 70) * byte_base_unit::unit_type(), "1 Zib"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 80) * byte_base_unit::unit_type(), "1 Yib"); + BOOST_UNITS_TEST_OUTPUT(42, "42"); // integer scalar. + BOOST_UNITS_TEST_OUTPUT(-42, "-42"); // integer scalar. + BOOST_UNITS_TEST_OUTPUT(1567, "1567"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-1567, "-1567"); // scalars are *not* autoprefixed. +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_name) +{ // Binary prefix with name format. + // http://physics.nist.gov/cuu/Units/binary.html + // 1998 the International Electrotechnical Commission (IEC) approved + // IEC 60027-2, Second edition, 2000-11, Letter symbols to be used in electrical technology + // - Part 2: Telecommunications and electronics. + // IEC 80000-13:2008, Quantities and units + // - Part 13: Information science and technology +#define FORMATTERS << boost::units::name_format << boost::units::binary_prefix + BOOST_UNITS_TEST_OUTPUT(2048 * byte_base_unit::unit_type(), "2 kibibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 32) *byte_base_unit::unit_type(), "4 gibibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 41) *byte_base_unit::unit_type(), "2 tebibyte"); // http://en.wikipedia.org/wiki/Tebibyte + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 50) *byte_base_unit::unit_type(), "1 pebibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 60) *byte_base_unit::unit_type(), "1 exbibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 70) *byte_base_unit::unit_type(), "1 zebibyte"); + BOOST_UNITS_TEST_OUTPUT(std::pow(2., 80) *byte_base_unit::unit_type(), "1 yobibyte"); + BOOST_UNITS_TEST_OUTPUT(2048, "2048"); // scalars are *not* autoprefixed. + BOOST_UNITS_TEST_OUTPUT(-4096, "-4096"); // scalars are *not* autoprefixed. +#undef FORMATTERS +} + +// Tests on using more than one format or prefix - only the last specified should be used. +// (This may indicate a programming mistake, but it is ignored). +BOOST_AUTO_TEST_CASE(test_output_quantity_name_duplicate) +{ // Ensure that if more than one format specified, only the last is used. +#define FORMATTERS << boost::units::symbol_format << boost::units::name_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 meter"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_quantity_symbol_duplicate) +{ // Ensure that if more than one format specified, only the last is used. +#define FORMATTERS << boost::units::name_format << boost::units::symbol_format + BOOST_UNITS_TEST_OUTPUT(1.5*meter_base_unit::unit_type(), "1.5 m"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_name_duplicate) +{ // Ensure that if more than one auto prefix specified, only the last is used. +#define FORMATTERS << boost::units::name_format << boost::units::binary_prefix << boost::units::engineering_prefix + BOOST_UNITS_TEST_OUTPUT(2048 * byte_base_unit::unit_type(), "2.048 kilobyte"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_symbol_duplicate) +{ // Ensure that if more than one auto prefix specified, only the last is used. +#define FORMATTERS << boost::units::symbol_format << boost::units::engineering_prefix << boost::units::binary_prefix + BOOST_UNITS_TEST_OUTPUT(2048 * byte_base_unit::unit_type(), "2 Kib"); +#undef FORMATTERS +} + +BOOST_AUTO_TEST_CASE(test_output_typename_format) +{ // Displays typename formatting result. The test doesn't check the formatting result + // and thus doesn't fail because the formatting result is platform-dependent. +#define FORMATTERS << boost::units::typename_format + BOOST_UNITS_TEST_OUTPUT_DISPLAY(meter_base_unit::unit_type()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(velocity()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_length()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_velocity1()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(millisecond_base_unit::unit_type()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_time()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_velocity2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(area()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_area()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(double_scaled_length()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(double_scaled_length2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(custom1()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(custom2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_custom1()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(scaled_custom2()); + BOOST_UNITS_TEST_OUTPUT_DISPLAY(boost::units::absolute()); +#undef FORMATTERS +} diff --git a/src/boost/libs/units/test/test_predicates.cpp b/src/boost/libs/units/test/test_predicates.cpp new file mode 100644 index 00000000..d05c4eaf --- /dev/null +++ b/src/boost/libs/units/test/test_predicates.cpp @@ -0,0 +1,100 @@ +// 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 test_predicates.cpp + +\details +Test metafunctions is_unit, is_quantity, is_dimension_list .... + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace bu = boost::units; + +struct dimension_tag : boost::units::base_dimension { }; + +typedef dimension_tag::dimension_type dimension; + +struct base_unit1 : bu::base_unit {}; +struct base_unit2 : bu::base_unit {}; + +typedef bu::make_system::type system1; +typedef bu::make_system::type system2; + +int main(int,char *[]) +{ + BOOST_MPL_ASSERT((bu::is_dimension_list)); + BOOST_MPL_ASSERT((bu::is_dimension_list)); + BOOST_MPL_ASSERT_NOT((bu::is_dimension_list >)); + BOOST_MPL_ASSERT_NOT((bu::is_dimension_list)); + + BOOST_MPL_ASSERT((bu::is_unit >)); + BOOST_MPL_ASSERT((bu::is_unit >)); + BOOST_MPL_ASSERT_NOT((bu::is_unit)); + + BOOST_MPL_ASSERT((bu::is_unit_of_system, system1>)); + BOOST_MPL_ASSERT((bu::is_unit_of_system, system1>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_system)); + + BOOST_MPL_ASSERT((bu::is_unit_of_dimension, bu::dimensionless_type>)); + BOOST_MPL_ASSERT((bu::is_unit_of_dimension, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension, bu::dimensionless_type>)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension)); + BOOST_MPL_ASSERT_NOT((bu::is_unit_of_dimension)); + + BOOST_MPL_ASSERT((bu::is_quantity > >)); + BOOST_MPL_ASSERT((bu::is_quantity > >)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity)); + + BOOST_MPL_ASSERT((bu::is_quantity, int> >)); + BOOST_MPL_ASSERT((bu::is_quantity, int> >)); + + BOOST_MPL_ASSERT((bu::is_quantity_of_system >, system1>)); + BOOST_MPL_ASSERT((bu::is_quantity_of_system >, system1>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system >, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system >, system2>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_system)); + + BOOST_MPL_ASSERT((bu::is_quantity_of_dimension >, bu::dimensionless_type>)); + BOOST_MPL_ASSERT((bu::is_quantity_of_dimension >, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension >, dimension>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension >, bu::dimensionless_type>)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension)); + BOOST_MPL_ASSERT_NOT((bu::is_quantity_of_dimension)); + + return 0; +} diff --git a/src/boost/libs/units/test/test_quantity.cpp b/src/boost/libs/units/test/test_quantity.cpp new file mode 100644 index 00000000..b6461bf2 --- /dev/null +++ b/src/boost/libs/units/test/test_quantity.cpp @@ -0,0 +1,203 @@ +// 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 test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include + +namespace bu = boost::units; + +BOOST_STATIC_CONSTEXPR double E_ = 2.718281828459045235360287471352662497757; + +int test_main(int,char *[]) +{ + // default constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity E1; + BOOST_CHECK(E1.value() == double()); + + // value_type constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity E2(E_*bu::joules); + BOOST_CHECK(E2.value() == E_); + + // copy constructor + BOOST_CONSTEXPR_OR_CONST bu::quantity E3(E2); + BOOST_CHECK(E3.value() == E_); + + // operator= + BOOST_CONSTEXPR_OR_CONST bu::quantity E4 = E2; + BOOST_CHECK(E4.value() == E_); + + // implicit copy constructor value_type conversion + BOOST_CONSTEXPR_OR_CONST bu::quantity E5(E2); + BOOST_UNITS_CHECK_CLOSE(E5.value(),float(E_)); + + // implicit operator= value_type conversion + //BOOST_CONSTEXPR_OR_CONST bu::quantity E7 = E2; + //BOOST_UNITS_CHECK_CLOSE(E7.value(),float(E_)); + + //BOOST_CONSTEXPR_OR_CONST bu::quantity E8 = E2; + //BOOST_CHECK(E8.value() == long(E_)); + + // const construction + bu::quantity E9(E2); + BOOST_CHECK(E9.value() == E_); + + // value assignment + bu::quantity_cast(E9) = 1.5; + BOOST_CHECK(E9.value() == 1.5); + + // value assignment with implicit value_type conversion + bu::quantity_cast(E9) = 2; + BOOST_CHECK(E9.value() == double(2)); + + // operator+=(this_type) + E9 = 2.0*bu::joules; + E9 += E9; + BOOST_CHECK(E9.value() == 4.0); + + // operator-=(this_type) + E9 = 2.0*bu::joules; + E9 -= E9; + BOOST_CHECK(E9.value() == 0.0); + + // operator*=(value_type) + E9 = 2.0*bu::joules; + E9 *= 2.0; + BOOST_CHECK(E9.value() == 4.0); + + // operator/=(value_type) + E9 = 2.0*bu::joules; + E9 /= 2.0; + BOOST_CHECK(E9.value() == 1.0); + + // static construct quantity from value_type + BOOST_CONSTEXPR_OR_CONST bu::quantity E(bu::quantity::from_value(2.5)); + BOOST_CHECK(E.value() == 2.5); + + // quantity_cast + + // unit * scalar + BOOST_CHECK(bu::joules*2.0 == bu::quantity::from_value(2.0)); + + // unit / scalar + BOOST_CHECK(bu::joules/2.0 == bu::quantity::from_value(0.5)); + + // scalar * unit + BOOST_CHECK(2.0*bu::joules == bu::quantity::from_value(2.0)); + + // scalar / unit + BOOST_CHECK(2.0/bu::joules == bu::quantity::from_value(2.0)); + + // quantity * scalar + BOOST_CHECK(E*2.0 == bu::quantity::from_value(5.0)); + + // quantity / scalar + BOOST_CHECK(E/2.0 == bu::quantity::from_value(1.25)); + + // scalar * quantity + BOOST_CHECK(2.0*E == bu::quantity::from_value(5.0)); + + // scalar / quantity + BOOST_CHECK(2.0/E == bu::quantity::from_value(0.8)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity L(1.0*bu::meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity M(2.0*bu::kilograms); + BOOST_CONSTEXPR_OR_CONST bu::quantity T(3.0*bu::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity V(bu::quantity::from_value(4.0)); + + // unit * quantity + BOOST_CHECK(bu::seconds*V == 4.0*bu::meters); + + // unit / quantity + BOOST_CHECK(bu::meters/V == 0.25*bu::seconds); + + // quantity * unit + BOOST_CHECK(V*bu::seconds == 4.0*bu::meters); + + // quantity / unit + BOOST_CHECK(V/bu::meters == 4.0/bu::seconds); + + // +quantity + BOOST_CHECK(+V == 4.0*bu::meters_per_second); + + // -quantity + BOOST_CHECK(-V == -4.0*bu::meters_per_second); + + // quantity + quantity + BOOST_CHECK(V+V == 8.0*bu::meters_per_second); + + // quantity - quantity + BOOST_CHECK(V-V == 0.0*bu::meters_per_second); + + // quantity * quantity + BOOST_CHECK(V*T == 12.0*bu::meters); + + // quantity / quantity + BOOST_CHECK(L/V == 0.25*bu::seconds); + + BOOST_CONSTEXPR_OR_CONST bu::quantity A(2.0*bu::square_meters); + BOOST_CONSTEXPR_OR_CONST bu::quantity VL(1.0*bu::cubic_meters); + + // integer power of quantity + BOOST_CHECK(2.0*bu::pow<2>(L) == A); + + // rational power of quantity + BOOST_CHECK((bu::pow< bu::static_rational<2,3> >(VL) == 0.5*A)); + + // integer root of quantity + BOOST_CHECK(bu::root<2>(A) == std::sqrt(2.0)*L); + + // rational root of quantity + BOOST_CHECK((bu::root< bu::static_rational<3,2> >(VL) == 0.5*A)); + + BOOST_CONSTEXPR_OR_CONST bu::quantity A1(0.0*bu::square_meters), + A2(0.0*bu::square_meters), + A3(1.0*bu::square_meters), + A4(-1.0*bu::square_meters); + + // operator== + BOOST_CHECK((A1 == A2) == true); + BOOST_CHECK((A1 == A3) == false); + + // operator!= + BOOST_CHECK((A1 != A2) == false); + BOOST_CHECK((A1 != A3) == true); + + // operator< + BOOST_CHECK((A1 < A2) == false); + BOOST_CHECK((A1 < A3) == true); + + // operator<= + BOOST_CHECK((A1 <= A2) == true); + BOOST_CHECK((A1 <= A3) == true); + + // operator> + BOOST_CHECK((A1 > A2) == false); + BOOST_CHECK((A1 > A4) == true); + + // operator>= + BOOST_CHECK((A1 >= A2) == true); + BOOST_CHECK((A1 >= A4) == true); + + return 0; +} diff --git a/src/boost/libs/units/test/test_reduce_unit.cpp b/src/boost/libs/units/test/test_reduce_unit.cpp new file mode 100644 index 00000000..c9daed09 --- /dev/null +++ b/src/boost/libs/units/test/test_reduce_unit.cpp @@ -0,0 +1,30 @@ +// 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) 2007-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 test_reduce_unit.cpp + +\details +Test that reduce_unit works correctly by itself to try to isolate problems. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include + +#include +#include + +BOOST_MPL_ASSERT((boost::is_same::type, boost::units::si::kelvin_base_unit::unit_type>)); diff --git a/src/boost/libs/units/test/test_scaled_conversion.cpp b/src/boost/libs/units/test/test_scaled_conversion.cpp new file mode 100644 index 00000000..c9da8fcf --- /dev/null +++ b/src/boost/libs/units/test/test_scaled_conversion.cpp @@ -0,0 +1,66 @@ +// 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) 2007-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 test_scaled_conversion.cpp + +\details +Test unit scaling + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define BOOST_UNITS_CHECK_CLOSE(a, b) (BOOST_CHECK((std::abs((a) - (b)) < .0000001))) + +namespace bu = boost::units; + +struct base_dimension1 : bu::base_dimension {}; +struct base_dimension2 : bu::base_dimension {}; +struct base_dimension3 : bu::base_dimension {}; + +typedef bu::derived_dimension::type dimension4; + +struct base_unit1 : bu::base_unit {}; +struct base_unit2 : bu::base_unit {}; +struct base_unit3 : bu::base_unit {}; +struct base_unit4 : bu::base_unit {}; +struct base_unit5 : bu::base_unit {}; + +typedef bu::scaled_base_unit > > scaled_base_unit2; +typedef bu::scaled_base_unit > > scaled_base_unit4; + +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(base_unit1, scaled_base_unit2, double, 5); +BOOST_UNITS_DEFINE_CONVERSION_FACTOR(scaled_base_unit2, base_unit3, double, 3); + +int test_main(int,char *[]) +{ + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(base_unit1::unit_type(), base_unit2::unit_type()), 5000); + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(base_unit2::unit_type(), base_unit3::unit_type()), 0.003); + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(scaled_base_unit2::unit_type(), base_unit2::unit_type()), 1000); + + BOOST_UNITS_CHECK_CLOSE(bu::conversion_factor(base_unit4::unit_type()/base_unit5::unit_type(), scaled_base_unit4::unit_type()/base_unit5::unit_type()), 1e-3); + + return(0); +} diff --git a/src/boost/libs/units/test/test_scaled_unit.cpp b/src/boost/libs/units/test/test_scaled_unit.cpp new file mode 100644 index 00000000..2357a98d --- /dev/null +++ b/src/boost/libs/units/test/test_scaled_unit.cpp @@ -0,0 +1,76 @@ +// 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) 2007-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 test_scaled_conversion.cpp + +\details +Test unit scaling + +Output: +@verbatim +@endverbatim +**/ + +#define BOOST_TEST_MAIN + +#include +#include +#include +#include + +#include + +#include +#include + +namespace bu = boost::units; +namespace si = boost::units::si; + +BOOST_AUTO_TEST_CASE(test_scaled_to_plain) { + BOOST_CONSTEXPR_OR_CONST bu::quantity s1 = 12.5 * si::seconds; + BOOST_CONSTEXPR_OR_CONST bu::quantity s2(si::nano * s1); + BOOST_CHECK_CLOSE_FRACTION(1e-9 * s1.value(), s2.value(), 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_plain_to_scaled) { + BOOST_CONSTEXPR_OR_CONST bu::quantity s1 = 12.5 * si::seconds; + typedef bu::multiply_typeof_helper::type time_unit; + BOOST_CONSTEXPR_OR_CONST bu::quantity s2(s1); + BOOST_CHECK_CLOSE_FRACTION(1e9 * s1.value(), s2.value(), 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_scaled_to_scaled) { + typedef bu::multiply_typeof_helper::type mega_time_unit; + typedef bu::multiply_typeof_helper::type micro_time_unit; + BOOST_CONSTEXPR_OR_CONST bu::quantity s1(12.5 * si::seconds); + BOOST_CONSTEXPR_OR_CONST bu::quantity s2(s1); + BOOST_CHECK_CLOSE_FRACTION(1e12 * s1.value(), s2.value(), 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_conversion_factor) { + BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::nano*si::seconds, si::seconds), 1e-9, 0.000000001); + BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::seconds, si::nano*si::seconds), 1e9, 0.000000001); + BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::mega*si::seconds, si::micro*si::seconds), 1e12, 0.000000001); +} + +BOOST_AUTO_TEST_CASE(test_output) { + std::stringstream stream; + stream << si::nano * 12.5 * si::seconds; + BOOST_CHECK_EQUAL(stream.str(), "12.5 ns"); +} + +BOOST_AUTO_TEST_CASE(test_output_name) { + std::stringstream stream; + stream << bu::name_format << si::nano * 12.5 * si::seconds; + BOOST_CHECK_EQUAL(stream.str(), "12.5 nanosecond"); +} diff --git a/src/boost/libs/units/test/test_sqrt_scaled_unit.cpp b/src/boost/libs/units/test/test_sqrt_scaled_unit.cpp new file mode 100644 index 00000000..8224fa25 --- /dev/null +++ b/src/boost/libs/units/test/test_sqrt_scaled_unit.cpp @@ -0,0 +1,48 @@ +// 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 test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include +#include +#include + +namespace bu = boost::units; + +static const double E_ = 2.718281828459045235360287471352662497757; + +typedef bu::make_scaled_unit > >::type milli_meter_unit; + +typedef bu::make_scaled_unit > >::type micro_meter2_unit; + +int test_main(int,char *[]) +{ + const bu::quantity E1 = E_*micro_meter2_unit(); + const bu::quantity E2 = sqrt(E1); + + BOOST_CHECK(E1.value() == E_); + BOOST_CHECK(E2.value() == sqrt(E_)); + return 0; +} diff --git a/src/boost/libs/units/test/test_trig.cpp b/src/boost/libs/units/test/test_trig.cpp new file mode 100644 index 00000000..574c460a --- /dev/null +++ b/src/boost/libs/units/test/test_trig.cpp @@ -0,0 +1,79 @@ +// Boost.Units - A C++ library for zero-overhead dimensional analysis and +// unit/quantity manipulation and conversion +// +// Copyright (C) 2009 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 test_trig.cpp + +\details +Test trigonometric functions. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include +#include +#include +#include +#include + +#define BOOST_TEST_MAIN +#include + +using boost::units::si::radians; +using boost::units::si::si_dimensionless; +using boost::units::degree::degrees; +BOOST_UNITS_STATIC_CONSTANT(degree_dimensionless, boost::units::degree::dimensionless); +using boost::units::si::meters; +BOOST_UNITS_STATIC_CONSTANT(heterogeneous_dimensionless, boost::units::reduce_unit::type); + +BOOST_AUTO_TEST_CASE(test_sin) { + BOOST_CHECK_EQUAL(boost::units::sin(2.0 * radians), std::sin(2.0) * si_dimensionless); + BOOST_CHECK_CLOSE_FRACTION(static_cast(boost::units::sin(15.0 * degrees)), 0.2588, 0.0004); +} + +BOOST_AUTO_TEST_CASE(test_cos) { + BOOST_CHECK_EQUAL(boost::units::cos(2.0 * radians), std::cos(2.0) * si_dimensionless); + BOOST_CHECK_CLOSE_FRACTION(static_cast(boost::units::cos(75.0 * degrees)), 0.2588, 0.0004); +} + +BOOST_AUTO_TEST_CASE(test_tan) { + BOOST_CHECK_EQUAL(boost::units::tan(2.0 * radians), std::tan(2.0) * si_dimensionless); + BOOST_CHECK_CLOSE_FRACTION(static_cast(boost::units::tan(45.0 * degrees)), 1.0, 0.0001); +} + +BOOST_AUTO_TEST_CASE(test_asin) { + BOOST_CHECK_EQUAL(boost::units::asin(0.2 * si_dimensionless), std::asin(0.2) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::asin(0.5 * degree_dimensionless).value(), 30.0, 0.0001); + BOOST_CHECK_EQUAL(boost::units::asin(0.2 * heterogeneous_dimensionless).value(), std::asin(0.2)); +} + +BOOST_AUTO_TEST_CASE(test_acos) { + BOOST_CHECK_EQUAL(boost::units::acos(0.2 * si_dimensionless), std::acos(0.2) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::acos(0.5 * degree_dimensionless).value(), 60.0, 0.0001); + BOOST_CHECK_EQUAL(boost::units::acos(0.2 * heterogeneous_dimensionless).value(), std::acos(0.2)); +} + +BOOST_AUTO_TEST_CASE(test_atan) { + BOOST_CHECK_EQUAL(boost::units::atan(0.2 * si_dimensionless), std::atan(0.2) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::atan(1.0 * degree_dimensionless).value(), 45.0, 0.0001); + BOOST_CHECK_EQUAL(boost::units::atan(0.2 * heterogeneous_dimensionless).value(), std::atan(0.2)); +} + +BOOST_AUTO_TEST_CASE(test_atan2) { + BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * si_dimensionless, 0.3 * si_dimensionless), std::atan2(0.2, 0.3) * radians); + BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * meters, 0.3 * meters), std::atan2(0.2, 0.3) * radians); + BOOST_CHECK_CLOSE_FRACTION(boost::units::atan2(0.8660*degree_dimensionless,0.5*degree_dimensionless).value(), 60., 0.0002); + BOOST_CHECK_EQUAL(boost::units::atan2(0.2 * heterogeneous_dimensionless, 0.3 * heterogeneous_dimensionless).value(), std::atan2(0.2, 0.3)); +} diff --git a/src/boost/libs/units/test/test_unit.cpp b/src/boost/libs/units/test/test_unit.cpp new file mode 100644 index 00000000..ed80430f --- /dev/null +++ b/src/boost/libs/units/test/test_unit.cpp @@ -0,0 +1,67 @@ +// 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 test_units_1.cpp + +\details +Test unit class. + +Output: +@verbatim +@endverbatim +**/ + +#include "test_header.hpp" + +#include + +namespace bu = boost::units; + +int test_main(int,char *[]) +{ + BOOST_CONSTEXPR_OR_CONST bu::dimensionless D; + + BOOST_CONSTEXPR_OR_CONST bu::length L; + BOOST_CONSTEXPR_OR_CONST bu::mass M; + BOOST_CONSTEXPR_OR_CONST bu::time T; + + BOOST_CHECK(+L == L); + BOOST_CHECK(-L == L); + BOOST_CHECK(L+L == L); + BOOST_CHECK(L-L == L); + + BOOST_CHECK(+M == M); + BOOST_CHECK(-M == M); + BOOST_CHECK(M+M == M); + BOOST_CHECK(M-M == M); + + BOOST_CONSTEXPR_OR_CONST bu::area A; + BOOST_CONSTEXPR_OR_CONST bu::energy E; + BOOST_CONSTEXPR_OR_CONST bu::velocity V; + + BOOST_CHECK(L*L == A); + BOOST_CHECK(A == L*L); + + BOOST_CHECK(L/L == D); + BOOST_CHECK(D == L/L); + + BOOST_CHECK(L/T == V); + BOOST_CHECK(V == L/T); + + BOOST_CHECK(M*L*L/T/T == E); + BOOST_CHECK(M*(L/T)*(L/T) == E); + BOOST_CHECK(M*bu::pow<2>(L/T) == E); + BOOST_CHECK(bu::root<2>(E/M) == V); + + return 0; +} diff --git a/src/boost/libs/units/test/test_unscale.cpp b/src/boost/libs/units/test/test_unscale.cpp new file mode 100644 index 00000000..d81a144d --- /dev/null +++ b/src/boost/libs/units/test/test_unscale.cpp @@ -0,0 +1,58 @@ +// 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) 2007-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 test_unscale.cpp + +\details +Test that unscale works in an attempt to isolate the sun problems. + +Output: +@verbatim +@endverbatim +**/ + +#include +#include +#include + +#include +#include + +BOOST_MPL_ASSERT((boost::is_same::type, + boost::units::temperature::fahrenheit_base_unit::unit_type::system_type>)); + +BOOST_MPL_ASSERT((boost::is_same::type, + boost::units::temperature::fahrenheit_base_unit::unit_type>)); + +BOOST_MPL_ASSERT((boost::is_same::type>::type, + boost::units::temperature::fahrenheit_base_unit::unit_type>)); + +BOOST_MPL_ASSERT((boost::is_same< + boost::units::temperature::fahrenheit_base_unit::unit_type, + boost::units::unit< + boost::units::temperature_dimension, + boost::units::heterogeneous_system< + boost::units::heterogeneous_system_impl< + boost::units::list< + boost::units::heterogeneous_system_dim< + boost::units::temperature::fahrenheit_base_unit, + boost::units::static_rational<1> + >, + boost::units::dimensionless_type + >, + boost::units::temperature_dimension, + boost::units::dimensionless_type + > + > + > +>)); diff --git a/src/boost/libs/units/test_headers/Jamfile.v2 b/src/boost/libs/units/test_headers/Jamfile.v2 new file mode 100644 index 00000000..8bcd8322 --- /dev/null +++ b/src/boost/libs/units/test_headers/Jamfile.v2 @@ -0,0 +1,56 @@ +# Jamfile.v2 +# +# Copyright (c) 2007-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 + +import testing ; +import path ; +import regex ; +import print ; +import sequence ; +import feature ; + +project boost/units/test_headers : + requirements $(BOOST_ROOT) ../../.. +; + +headers = [ path.glob-tree ../../../boost/units : *.hpp : detail ] ; + +for local file in $(headers) +{ + compile test.cpp + : # requirements + BOOST_UNITS_HEADER_NAME=$(file) + $(file) + : # test name + [ regex.replace [ path.relative-to ../../.. $(file) ] "/" "_" ] ; +} + +feature.feature : forward reverse : incidental ; + +rule generate-include-all ( target : sources * : properties * ) +{ + print.output $(target) ; + + if reverse in $(properties) + { + sources = [ sequence.reverse $(sources) ] ; + } + + for local file in $(sources) + { + print.text "#include <$(file:G=)> +" : overwrite ; + } + +} + +make include_all1.cpp : $(headers) : @generate-include-all ; +make include_all2.cpp : $(headers) : @generate-include-all : reverse ; + +# this ought to catch non-inlined functions and other duplicate definitions +link include_all1.cpp include_all2.cpp main.cpp : . : include_all_headers ; diff --git a/src/boost/libs/units/test_headers/main.cpp b/src/boost/libs/units/test_headers/main.cpp new file mode 100644 index 00000000..a7746ff4 --- /dev/null +++ b/src/boost/libs/units/test_headers/main.cpp @@ -0,0 +1,12 @@ +// 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) 2007-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) + +int main() { +} diff --git a/src/boost/libs/units/test_headers/test.cpp b/src/boost/libs/units/test_headers/test.cpp new file mode 100644 index 00000000..589e974c --- /dev/null +++ b/src/boost/libs/units/test_headers/test.cpp @@ -0,0 +1,19 @@ +// 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) 2007-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) + +#define BOOST_UNITS_STRINGIZE_IMPL(x) #x +#define BOOST_UNITS_STRINGIZE(x) BOOST_UNITS_STRINGIZE_IMPL(x) + +#define BOOST_UNITS_HEADER BOOST_UNITS_STRINGIZE(BOOST_UNITS_HEADER_NAME) + +#include BOOST_UNITS_HEADER +#include BOOST_UNITS_HEADER + +int main() {} diff --git a/src/boost/libs/units/tutorial/tutorial_1.cpp b/src/boost/libs/units/tutorial/tutorial_1.cpp new file mode 100644 index 00000000..f7508a6c --- /dev/null +++ b/src/boost/libs/units/tutorial/tutorial_1.cpp @@ -0,0 +1,314 @@ +// 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) + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { + +namespace units { + +struct length_base_dimension : boost::units::base_dimension { }; ///> base dimension of length +struct time_base_dimension : boost::units::base_dimension { }; ///> base dimension of time + +typedef length_base_dimension::dimension_type length_dimension; +typedef time_base_dimension::dimension_type time_dimension; + +struct length1_base_unit : base_unit +{ + static std::string name() { return "length 1"; } + static std::string symbol() { return "l1"; } +}; + +struct length2_base_unit : base_unit +{ + static std::string name() { return "length2"; } + static std::string symbol() { return "l2"; } +}; + +struct time1_base_unit : base_unit +{ + static std::string name() { return "time1"; } + static std::string symbol() { return "t1"; } +}; + +struct time2_base_unit : base_unit +{ + static std::string name() { return "time2"; } + static std::string symbol() { return "t2"; } +}; + +namespace s1 { + +typedef make_system::type system; + +/// unit typedefs +typedef unit dimensionless; + +typedef unit length; +typedef unit time; + +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(length1,length); +BOOST_UNITS_STATIC_CONSTANT(time1,time); + +} // namespace s1 + +namespace s2 { + +typedef make_system::type system; + +/// unit typedefs +typedef unit dimensionless; + +typedef unit length; +typedef unit time; + +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(length2,length); +BOOST_UNITS_STATIC_CONSTANT(time2,time); + +} // namespace s2 + +template +struct conversion_helper< quantity,quantity > +{ + static quantity convert(const quantity& source) + { + return quantity::from_value(2.5*source.value()); + } +}; + +template +struct conversion_helper< quantity,quantity > +{ + static quantity convert(const quantity& source) + { + return quantity::from_value((1.0/2.5)*source.value()); + } +}; + +template +struct conversion_helper< quantity,quantity > +{ + static quantity convert(const quantity& source) + { + return quantity::from_value(0.5*source.value()); + } +}; + +} // namespace units + +} // namespace boost + +int main(void) +{ + using namespace boost::units; + + quantity l1(1.0*s1::length1); + quantity l2(1.5*l1); + quantity l3(2.0*l2/3.0); + + quantity t1(1.0*s1::time1); + quantity t2(1.5*t1); +// quantity t3(2.0*t2/3.0); + + return 0; +} + +/* +// 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) + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace boost { + +namespace units { + +struct length_base_dimension : boost::units::base_dimension { }; ///> base dimension of length +struct mass_base_dimension : boost::units::base_dimension { }; ///> base dimension of mass +struct time_base_dimension : boost::units::base_dimension { }; ///> base dimension of time + +typedef length_base_dimension::dimension_type length_dimension; +typedef mass_base_dimension::dimension_type mass_dimension; +typedef time_base_dimension::dimension_type time_dimension; + +struct centimeter_base_unit : base_unit +{ + static std::string name() { return "centimeter"; } + static std::string symbol() { return "cm"; } +}; + +struct gram_base_unit : base_unit +{ + static std::string name() { return "gram"; } + static std::string symbol() { return "g"; } +}; + +struct second_base_unit : base_unit +{ + static std::string name() { return "second"; } + static std::string symbol() { return "s"; } +}; + +namespace CG { + +typedef make_system::type system; + +/// unit typedefs +typedef unit dimensionless; + +typedef unit length; +typedef unit mass; + +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(centimeter,length); +BOOST_UNITS_STATIC_CONSTANT(gram,mass); + +} // namespace CG + +namespace cgs { + +typedef make_system::type system; + +/// unit typedefs +typedef unit dimensionless; + +typedef unit length; +typedef unit mass; +typedef unit time; + +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(centimeter,length); +BOOST_UNITS_STATIC_CONSTANT(gram,mass); +BOOST_UNITS_STATIC_CONSTANT(second,time); + +} // namespace cgs + +namespace esu { + +typedef make_system::type system; + +/// derived dimension for force in electrostatic units : L M T^-2 +typedef derived_dimension::type force_dimension; + +/// derived dimension for charge in electrostatic units : L^3/2 M^1/2 T^-1 +typedef make_dimension_list< mpl::list< dim >, + dim >, + dim > > >::type charge_dimension; + +/// derived dimension for current in electrostatic units : L^3/2 M^1/2 T^-2 +typedef make_dimension_list< mpl::list< dim >, + dim >, + dim > > >::type current_dimension; + +/// derived dimension for electric potential in electrostatic units : L^1/2 M^1/2 T^-1 +typedef make_dimension_list< mpl::list< dim >, + dim >, + dim > > >::type electric_potential_dimension; + +/// derived dimension for electric field in electrostatic units : L^-1/2 M^1/2 T^-1 +typedef make_dimension_list< mpl::list< dim >, + dim >, + dim > > >::type electric_field_dimension; + +/// unit typedefs +typedef unit dimensionless; + +typedef unit length; +typedef unit mass; +typedef unit time; + +typedef unit force; + +typedef unit charge; +typedef unit current; +typedef unit electric_potential; +typedef unit electric_field; + +/// unit constants +BOOST_UNITS_STATIC_CONSTANT(centimeter,length); +BOOST_UNITS_STATIC_CONSTANT(gram,mass); +BOOST_UNITS_STATIC_CONSTANT(second,time); + +BOOST_UNITS_STATIC_CONSTANT(dyne,force); + +BOOST_UNITS_STATIC_CONSTANT(esu,charge); +BOOST_UNITS_STATIC_CONSTANT(statvolt,electric_potential); + +} // namespace esu + +template +quantity coulombLaw(const quantity& q1, + const quantity& q2, + const quantity& r) +{ + return q1*q2/(r*r); +} + +} // namespace units + +} // namespace boost + +int main(void) +{ + using namespace boost::units; + + quantity cg_length(1.0*CG::centimeter); + quantity cgs_length(1.0*cgs::centimeter); + + std::cout << cg_length/cgs_length << std::endl; + + std::cout << esu::gram*pow<2>(esu::centimeter/esu::second)/esu::esu << std::endl; + std::cout << esu::statvolt/esu::centimeter << std::endl; + + quantity q1 = 1.0*esu::esu, + q2 = 2.0*esu::esu; + quantity r = 1.0*esu::centimeter; + + std::cout << coulombLaw(q1,q2,r) << std::endl; + std::cout << coulombLaw(q1,q2,cgs_length) << std::endl; + + return 0; +} +*/ -- cgit v1.2.3