summaryrefslogtreecommitdiff
path: root/libs/units
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2014-12-11 18:55:56 +0900
committerChanho Park <chanho61.park@samsung.com>2014-12-11 18:55:56 +0900
commit08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch)
tree7a7053ceb8874b28ec4b868d4c49b500008a102e /libs/units
parentbb4dd8289b351fae6b55e303f189127a394a1edd (diff)
downloadboost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2
boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'libs/units')
-rw-r--r--libs/units/README.md26
-rw-r--r--libs/units/example/information.cpp98
-rw-r--r--libs/units/example/performance.cpp1
-rw-r--r--libs/units/example/systems.cpp28
-rw-r--r--libs/units/meta/libraries.json16
-rw-r--r--libs/units/test/Jamfile.v25
-rw-r--r--libs/units/test/test_dimensionless_ice1.cpp2
-rw-r--r--libs/units/test/test_information_units.cpp242
-rw-r--r--libs/units/test/test_limits.cpp6
-rw-r--r--libs/units/test/test_output.cpp51
10 files changed, 444 insertions, 31 deletions
diff --git a/libs/units/README.md b/libs/units/README.md
new file mode 100644
index 0000000000..555467722e
--- /dev/null
+++ b/libs/units/README.md
@@ -0,0 +1,26 @@
+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
+
+### 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/libs/units/example/information.cpp b/libs/units/example/information.cpp
new file mode 100644
index 0000000000..0efc01a174
--- /dev/null
+++ b/libs/units/example/information.cpp
@@ -0,0 +1,98 @@
+// 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 <boost/units/systems/information.hpp>
+
+/**
+\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 <cmath>
+#include <iostream>
+using std::cout;
+using std::endl;
+
+#include <boost/units/quantity.hpp>
+#include <boost/units/io.hpp>
+#include <boost/units/conversion.hpp>
+namespace bu = boost::units;
+using bu::quantity;
+using bu::conversion_factor;
+
+// SI prefixes
+#include <boost/units/systems/si/prefixes.hpp>
+namespace si = boost::units::si;
+
+// information unit system
+#include <boost/units/systems/information.hpp>
+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 <typename Sys>
+quantity<bu::unit<bu::information_dimension, Sys> >
+bernoulli_entropy(double p, const bu::unit<bu::information_dimension, Sys>&) {
+ typedef bu::unit<bu::information_dimension, Sys> requested_unit;
+ return quantity<requested_unit>((-(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<info> nbytes(1 * si::giga * bit);
+ cout << "bytes= " << nbytes << endl;
+
+ // a quantity of information, stored as bits
+ quantity<hu::bit::info> nbits(1 * si::mega * byte);
+ cout << "bits= " << nbits << endl;
+
+ // a quantity of information, stored as nats
+ quantity<hu::nat::info> 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/libs/units/example/performance.cpp b/libs/units/example/performance.cpp
index 0dce3cef78..3407c13714 100644
--- a/libs/units/example/performance.cpp
+++ b/libs/units/example/performance.cpp
@@ -55,6 +55,7 @@ solving y' = 1 - x + 4 * y with quantity: 1.84 seconds
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si.hpp>
#include <boost/units/cmath.hpp>
+#include <boost/units/io.hpp>
enum {
tile_block_size = 24
diff --git a/libs/units/example/systems.cpp b/libs/units/example/systems.cpp
index 9c34804198..877b2fa768 100644
--- a/libs/units/example/systems.cpp
+++ b/libs/units/example/systems.cpp
@@ -229,34 +229,6 @@ 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)
-#ifdef __GNUC__
-#include <cxxabi.h>
-#endif
-
-inline std::string demangle(const char* name)
-{
- #ifdef __GNUC__
- // need to demangle C++ symbols
- char* realname;
- std::size_t len;
- int stat;
-
- realname = abi::__cxa_demangle(name,NULL,&len,&stat);
-
- if (realname != NULL)
- {
- const std::string out(realname);
- free(realname);
-
- return out;
- }
-
- return std::string("demangle :: error - unable to demangle specified symbol");
- #else
- return name;
- #endif
-}
-
int main(void)
{
using namespace boost::units;
diff --git a/libs/units/meta/libraries.json b/libs/units/meta/libraries.json
new file mode 100644
index 0000000000..4e8bdb9adf
--- /dev/null
+++ b/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 <jhunold -at- gmx.eu>",
+ "Steven Watanabe <steven -at- providere-consulting.com>"
+ ]
+}
diff --git a/libs/units/test/Jamfile.v2 b/libs/units/test/Jamfile.v2
index c75a4edb21..8913e2b6f1 100644
--- a/libs/units/test/Jamfile.v2
+++ b/libs/units/test/Jamfile.v2
@@ -16,7 +16,7 @@ warning-compilers =
project boost/units/test :
requirements
- <source>/boost//headers
+ <implicit-dependency>/boost//headers
<include>../../..
<toolset>msvc:<asynch-exceptions>on
$(warning-compilers):$(warning-options)
@@ -52,8 +52,9 @@ run test_custom_unit.cpp ;
run test_scaled_conversion.cpp ;
run test_lambda.cpp ;
run test_scaled_unit.cpp test_framework ;
-run test_output.cpp test_framework /boost//regex ;
+run test_output.cpp test_framework /boost//regex : : : <test-info>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 ;
diff --git a/libs/units/test/test_dimensionless_ice1.cpp b/libs/units/test/test_dimensionless_ice1.cpp
index 469cb4cf22..8fb9867833 100644
--- a/libs/units/test/test_dimensionless_ice1.cpp
+++ b/libs/units/test/test_dimensionless_ice1.cpp
@@ -8,12 +8,14 @@
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
+#include <boost/core/ignore_unused.hpp>
#include <boost/units/systems/si/base.hpp>
#include <boost/units/quantity.hpp>
void foo()
{
boost::units::quantity<boost::units::si::dimensionless> d = boost::units::quantity< boost::units::si::dimensionless >();
+ boost::ignore_unused(d);
}
#include <boost/test/test_tools.hpp>
diff --git a/libs/units/test/test_information_units.cpp b/libs/units/test/test_information_units.cpp
new file mode 100644
index 0000000000..6bb1ab5960
--- /dev/null
+++ b/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 <iostream>
+#include <sstream>
+
+#include <boost/units/quantity.hpp>
+#include <boost/units/conversion.hpp>
+#include <boost/units/io.hpp>
+
+#include <boost/units/systems/si/prefixes.hpp>
+#include <boost/units/systems/si/time.hpp>
+
+// All information systems definitions
+#include <boost/units/systems/information.hpp>
+
+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 <boost/test/unit_test.hpp>
+
+
+#include <boost/multiprecision/cpp_int.hpp>
+
+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) { \
+ double cf12 = bu::conversion_factor((u2), (u1)) ; \
+ double cf23 = bu::conversion_factor((u3), (u2)) ; \
+ double cf13 = bu::conversion_factor((u3), (u1)) ; \
+ BOOST_CHECK_CLOSE_FRACTION(cf13, cf12*cf23, close_fraction); \
+ double cf32 = bu::conversion_factor((u2), (u3)) ; \
+ double cf21 = bu::conversion_factor((u1), (u2)) ; \
+ 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;
+ quantity<info, double> qd(2 * byte);
+ BOOST_CHECK_EQUAL(qd.value(), double(2));
+ quantity<info, long> ql(2 * byte);
+ BOOST_CHECK_EQUAL(ql.value(), long(2));
+}
+
+BOOST_AUTO_TEST_CASE(test_byte_quantity_explicit) {
+ using namespace bu::information;
+ quantity<hu::byte::info, double> qd(2 * byte);
+ BOOST_CHECK_EQUAL(qd.value(), double(2));
+ quantity<hu::byte::info, long> ql(2 * byte);
+ BOOST_CHECK_EQUAL(ql.value(), long(2));
+}
+
+BOOST_AUTO_TEST_CASE(test_bit_quantity) {
+ using namespace bu::information;
+ quantity<hu::bit::info, double> qd(2 * bit);
+ BOOST_CHECK_EQUAL(qd.value(), double(2));
+ quantity<hu::bit::info, long> ql(2 * bit);
+ BOOST_CHECK_EQUAL(ql.value(), long(2));
+}
+
+BOOST_AUTO_TEST_CASE(test_nat_quantity) {
+ using namespace bu::information;
+ quantity<hu::nat::info, double> qd(2 * nat);
+ BOOST_CHECK_EQUAL(qd.value(), double(2));
+ quantity<hu::nat::info, long> ql(2 * nat);
+ BOOST_CHECK_EQUAL(ql.value(), long(2));
+}
+
+BOOST_AUTO_TEST_CASE(test_hartley_quantity) {
+ using namespace bu::information;
+ quantity<hu::hartley::info, double> qd(2 * hartley);
+ BOOST_CHECK_EQUAL(qd.value(), double(2));
+ quantity<hu::hartley::info, long> ql(2 * hartley);
+ BOOST_CHECK_EQUAL(ql.value(), long(2));
+}
+
+BOOST_AUTO_TEST_CASE(test_shannon_quantity) {
+ using namespace bu::information;
+ quantity<hu::shannon::info, double> qd(2 * shannon);
+ BOOST_CHECK_EQUAL(qd.value(), double(2));
+ quantity<hu::shannon::info, long> ql(2 * shannon);
+ BOOST_CHECK_EQUAL(ql.value(), long(2));
+}
+
+BOOST_AUTO_TEST_CASE(test_mixed_hu) {
+ using namespace bu::information;
+ const double cf = 0.001;
+ BOOST_CHECK_CLOSE_FRACTION((quantity<hu::bit::info>(1.0 * bits)).value(), 1.0, cf);
+ BOOST_CHECK_CLOSE_FRACTION((quantity<hu::byte::info>(1.0 * bits)).value(), 1.0/8.0, cf);
+ BOOST_CHECK_CLOSE_FRACTION((quantity<hu::nat::info>(1.0 * bits)).value(), 0.69315, cf);
+ BOOST_CHECK_CLOSE_FRACTION((quantity<hu::hartley::info>(1.0 * bits)).value(), 0.30102, cf);
+ BOOST_CHECK_CLOSE_FRACTION((quantity<hu::shannon::info>(1.0 * bits)).value(), 1.0, cf);
+}
+
+BOOST_AUTO_TEST_CASE(test_info_prefixes) {
+ using namespace bu::information;
+ quantity<info, long long> q10(1LL * kibi * byte);
+ BOOST_CHECK_EQUAL(q10.value(), 1024LL);
+
+ quantity<info, long long> q20(1LL * mebi * byte);
+ BOOST_CHECK_EQUAL(q20.value(), 1048576LL);
+
+ quantity<info, long long> q30(1LL * gibi * byte);
+ BOOST_CHECK_EQUAL(q30.value(), 1073741824LL);
+
+ quantity<info, long long> q40(1LL * tebi * byte);
+ BOOST_CHECK_EQUAL(q40.value(), 1099511627776LL);
+
+ quantity<info, long long> q50(1LL * pebi * byte);
+ BOOST_CHECK_EQUAL(q50.value(), 1125899906842624LL);
+
+ quantity<info, long long> q60(1LL * exbi * byte);
+ BOOST_CHECK_EQUAL(q60.value(), 1152921504606846976LL);
+
+ using boost::multiprecision::int128_t;
+
+ quantity<info, int128_t> q70(1LL * zebi * byte);
+ BOOST_CHECK_EQUAL(q70.value(), int128_t("1180591620717411303424"));
+
+ quantity<info, int128_t> q80(1LL * yobi * byte);
+ BOOST_CHECK_EQUAL(q80.value(), int128_t("1208925819614629174706176"));
+
+ // sanity check: si prefixes should also operate
+ quantity<info, long long> q1e3(1LL * si::kilo * byte);
+ BOOST_CHECK_EQUAL(q1e3.value(), 1000LL);
+
+ quantity<info, long long> 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/libs/units/test/test_limits.cpp b/libs/units/test/test_limits.cpp
index 458feefdbd..6057cf94d3 100644
--- a/libs/units/test/test_limits.cpp
+++ b/libs/units/test/test_limits.cpp
@@ -80,10 +80,16 @@ void do_check() {
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);
diff --git a/libs/units/test/test_output.cpp b/libs/units/test/test_output.cpp
index 95c3a21ce7..7404bc60b4 100644
--- a/libs/units/test/test_output.cpp
+++ b/libs/units/test/test_output.cpp
@@ -35,6 +35,7 @@ Tests for output from various units, name, symbol and raw formats, and automatic
#include <boost/regex.hpp>
+#include <iostream>
#include <sstream>
#include <boost/config.hpp>
#include <limits>
@@ -132,6 +133,18 @@ typedef boost::units::make_scaled_unit<custom2, boost::units::scale<10, boost::u
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) \
@@ -150,6 +163,13 @@ typedef boost::units::make_scaled_unit<custom2, boost::units::scale<10, boost::u
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)
@@ -316,7 +336,7 @@ BOOST_AUTO_TEST_CASE(test_output_autoprefixed_quantity_name)
BOOST_UNITS_TEST_OUTPUT_REGEX(std::numeric_limits<float>::infinity()*meter_base_unit::unit_type(), "(1\\.#INF|inf|INF) meter");
BOOST_UNITS_TEST_OUTPUT_REGEX(-std::numeric_limits<float>::infinity()*meter_base_unit::unit_type(), "-(1\\.#INF|inf|INF) meter");
BOOST_UNITS_TEST_OUTPUT_REGEX(std::numeric_limits<double>::quiet_NaN()*meter_base_unit::unit_type(), "(1\\.#QNAN|nan|NaNQ) meter");
- BOOST_UNITS_TEST_OUTPUT_REGEX(-std::numeric_limits<double>::quiet_NaN()*meter_base_unit::unit_type(), "-?(1\\.#IND|nan|NaNQ) meter");
+ BOOST_UNITS_TEST_OUTPUT_REGEX(-std::numeric_limits<double>::quiet_NaN()*meter_base_unit::unit_type(), "-?(1\\.#IND|nan|nan\\(ind\\)|NaNQ) meter");
BOOST_UNITS_TEST_OUTPUT(1.5*velocity(), "1.5 meter second^-1");
BOOST_UNITS_TEST_OUTPUT(1.5*scaled_length(), "1.5 kilometer");
@@ -395,6 +415,8 @@ BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_symbol)
BOOST_UNITS_TEST_OUTPUT(pow(2., 40) * byte_base_unit::unit_type(), "1 Tib");
BOOST_UNITS_TEST_OUTPUT(pow(2., 50) * byte_base_unit::unit_type(), "1 Pib");
BOOST_UNITS_TEST_OUTPUT(pow(2., 60) * byte_base_unit::unit_type(), "1 Eib");
+ BOOST_UNITS_TEST_OUTPUT(pow(2., 70) * byte_base_unit::unit_type(), "1 Zib");
+ BOOST_UNITS_TEST_OUTPUT(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.
@@ -408,12 +430,16 @@ BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_name)
// 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(pow(2., 32) *byte_base_unit::unit_type(), "4 gibibyte");
BOOST_UNITS_TEST_OUTPUT(pow(2., 41) *byte_base_unit::unit_type(), "2 tebibyte"); // http://en.wikipedia.org/wiki/Tebibyte
BOOST_UNITS_TEST_OUTPUT(pow(2., 50) *byte_base_unit::unit_type(), "1 pebibyte");
BOOST_UNITS_TEST_OUTPUT(pow(2., 60) *byte_base_unit::unit_type(), "1 exbibyte");
+ BOOST_UNITS_TEST_OUTPUT(pow(2., 70) *byte_base_unit::unit_type(), "1 zebibyte");
+ BOOST_UNITS_TEST_OUTPUT(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
@@ -448,3 +474,26 @@ BOOST_AUTO_TEST_CASE(test_output_auto_binary_prefixed_quantity_symbol_duplicate)
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<meter_base_unit::unit_type>());
+#undef FORMATTERS
+}