diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/boost/libs/integer | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/integer')
30 files changed, 2048 insertions, 0 deletions
diff --git a/src/boost/libs/integer/CMakeLists.txt b/src/boost/libs/integer/CMakeLists.txt new file mode 100644 index 00000000..93bb5144 --- /dev/null +++ b/src/boost/libs/integer/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright 2018 Peter Dimov +# Copyright 2018 Andrey Semashev +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +# Partial (add_subdirectory only) and experimental CMake support +# Subject to change; please do not rely on the contents of this file yet. + +cmake_minimum_required(VERSION 3.5) + +project(BoostInteger LANGUAGES CXX) + +add_library(boost_integer INTERFACE) +add_library(Boost::integer ALIAS boost_integer) + +target_include_directories(boost_integer INTERFACE include) + +target_link_libraries(boost_integer + INTERFACE + Boost::assert + Boost::config + Boost::core + Boost::static_assert + Boost::throw_exception +) diff --git a/src/boost/libs/integer/README.md b/src/boost/libs/integer/README.md new file mode 100644 index 00000000..05c1270e --- /dev/null +++ b/src/boost/libs/integer/README.md @@ -0,0 +1,30 @@ +# Boost.Integer + +Boost.Integer, part of collection of the [Boost C++ Libraries](https://github.com/boostorg), provides +integer type support, particularly helpful in generic programming. It provides the means to select +an integer type based upon its properties, like the number of bits or the maximum supported value, +as well as compile-time bit mask selection. There is a derivative of `std::numeric_limits` that provides +integral constant expressions for `min` and `max`... +Finally, it provides two compile-time algorithms: determining the highest power of two in a +compile-time value; and computing min and max of constant expressions. + +### Directories + +* **doc** - QuickBook documentation sources +* **include** - Interface headers of Boost.Integer +* **test** - Boost.Integer unit tests + +### More information + +* [Documentation](https://boost.org/libs/integer) +* [Report bugs](https://github.com/boostorg/integer/issues/new). Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well. +* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). + +### Build status + +Master: [![AppVeyor](https://ci.appveyor.com/api/projects/status/iugyf5rf51n99g3w?svg=true)](https://ci.appveyor.com/project/Lastique/integer/branch/master) [![Travis CI](https://travis-ci.org/boostorg/integer.svg?branch=master)](https://travis-ci.org/boostorg/integer) +Develop: [![AppVeyor](https://ci.appveyor.com/api/projects/status/iugyf5rf51n99g3w/branch/develop?svg=true)](https://ci.appveyor.com/project/Lastique/integer/branch/develop) [![Travis CI](https://travis-ci.org/boostorg/integer.svg?branch=develop)](https://travis-ci.org/boostorg/integer) + +### License + +Distributed under the [Boost Software License, Version 1.0](https://www.boost.org/LICENSE_1_0.txt). diff --git a/src/boost/libs/integer/index.html b/src/boost/libs/integer/index.html new file mode 100644 index 00000000..dfc23cc1 --- /dev/null +++ b/src/boost/libs/integer/index.html @@ -0,0 +1,16 @@ +<html> +<head> +<meta http-equiv="refresh" content="0; URL=doc/html/index.html"> +</head> +<body> +Automatic redirection failed, please go to +<a href="doc/html/index.html">doc/html/index.html</a>. + <P>Copyright Beman Dawes, Daryle Walker, Gennaro Prota and John Maddock 2001-2009</P> + <P>Distributed under the Boost Software License, Version 1.0. (See accompanying file <A href="../../LICENSE_1_0.txt"> + LICENSE_1_0.txt</A> or copy at <A href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</A>).</P> +</body> +</html> + + + + diff --git a/src/boost/libs/integer/meta/libraries.json b/src/boost/libs/integer/meta/libraries.json new file mode 100644 index 00000000..1a259233 --- /dev/null +++ b/src/boost/libs/integer/meta/libraries.json @@ -0,0 +1,13 @@ +{ + "key": "integer", + "name": "Integer", + "description": "The organization of boost integer headers and classes is designed to take advantage of <stdint.h> types from the 1999 C standard without resorting to undefined behavior in terms of the 1998 C++ standard. The header <boost/cstdint.hpp> makes the standard integer types safely available in namespace boost without placing any names in namespace std.", + "category": [ + "Math" + ], + "authors": "", + "maintainers": [ + "Daryle Walker <darylew -at- hotmail.com>", + "Andrey Semashev <andrey.semashev -at- gmail.com>" + ] +} diff --git a/src/boost/libs/integer/test/Jamfile.v2 b/src/boost/libs/integer/test/Jamfile.v2 new file mode 100644 index 00000000..b1057d66 --- /dev/null +++ b/src/boost/libs/integer/test/Jamfile.v2 @@ -0,0 +1,38 @@ +#~ Copyright Rene Rivera 2008 +#~ 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 ../../config/checks/config : requires ; + +project : requirements <warnings>all <toolset>gcc:<cxxflags>-Wextra ; + +obj has_gmpxx : has_gmpxx.cpp ; +explicit has_gmpxx ; + +test-suite integer + : + [ run integer_traits_test.cpp ] + [ run integer_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long <toolset>sun:<cxxflags>"-Qoption ccfe -tmpldepth=128" ] + [ run integer_mask_test.cpp ] + [ run static_log2_test.cpp ] + [ run static_min_max_test.cpp ] + [ run extended_euclidean_test.cpp ] + [ run mod_inverse_test.cpp ] + [ compile integer_traits_include_test.cpp ] + [ compile integer_include_test.cpp ] + [ compile integer_mask_include_test.cpp ] + [ compile static_log2_include_test.cpp ] + [ compile static_min_max_include_test.cpp ] + [ compile integer_fwd_include_test.cpp ] + [ compile gcd_constexpr14_test.cpp ] + [ compile gcd_noexcept_test.cpp ] + [ compile-fail fail_int_exact.cpp ] + [ compile-fail fail_int_fast.cpp ] + [ compile-fail fail_int_least.cpp ] + [ compile-fail fail_uint_exact.cpp ] + [ compile-fail fail_uint_fast.cpp ] + [ compile-fail fail_uint_least.cpp ] + [ compile-fail fail_uint_65.cpp ] + [ run common_factor_test.cpp : : : [ check-target-builds has_gmpxx "Checking for gmpxx.h" : <define>BOOST_INTEGER_HAS_GMPXX_H=1 <linkflags>-lgmp <linkflags>-lgmpxx ] ] + ; diff --git a/src/boost/libs/integer/test/common_factor_test.cpp b/src/boost/libs/integer/test/common_factor_test.cpp new file mode 100644 index 00000000..9edb0801 --- /dev/null +++ b/src/boost/libs/integer/test/common_factor_test.cpp @@ -0,0 +1,652 @@ +// Boost GCD & LCM common_factor.hpp test program --------------------------// + +// (C) Copyright Daryle Walker 2001, 2006. +// 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) + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 01 Dec 2006 Various fixes for old compilers (Joaquin M Lopez Munoz) +// 10 Nov 2006 Make long long and __int64 mutually exclusive (Daryle Walker) +// 04 Nov 2006 Use more built-in numeric types, binary-GCD (Daryle Walker) +// 03 Nov 2006 Use custom numeric types (Daryle Walker) +// 02 Nov 2006 Change to Boost.Test's unit test system (Daryle Walker) +// 07 Nov 2001 Initial version (Daryle Walker) + +#define BOOST_TEST_MAIN "Boost.integer GCD & LCM unit tests" + +#include <boost/config.hpp> // for BOOST_MSVC, etc. +#include <boost/detail/workaround.hpp> +#include <boost/integer/common_factor.hpp> // for boost::integer::gcd, etc. +#include <boost/mpl/list.hpp> // for boost::mpl::list +#include <boost/operators.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/random.hpp> +#include <boost/rational.hpp> + +#include <istream> // for std::basic_istream +#include <limits> // for std::numeric_limits +#include <ostream> // for std::basic_ostream + +#ifdef BOOST_INTEGER_HAS_GMPXX_H +#include <gmpxx.h> +#endif + +#include "multiprecision_config.hpp" + +#ifndef DISABLE_MP_TESTS +#include <boost/multiprecision/cpp_int.hpp> +#endif + +namespace { + +// TODO: add polynominal/non-real type; especially after any switch to the +// binary-GCD algorithm for built-in types + +// Custom integer class (template) +template < typename IntType, int ID = 0 > +class my_wrapped_integer + : private ::boost::shiftable1<my_wrapped_integer<IntType, ID>, + ::boost::operators<my_wrapped_integer<IntType, ID> > > +{ + // Helper type-aliases + typedef my_wrapped_integer self_type; + typedef IntType self_type::* bool_type; + + // Member data + IntType v_; + +public: + // Template parameters + typedef IntType int_type; + + BOOST_STATIC_CONSTANT(int,id = ID); + + // Lifetime management (use automatic destructor and copy constructor) + my_wrapped_integer( int_type const &v = int_type() ) : v_( v ) {} + + // Accessors + int_type value() const { return this->v_; } + + // Operators (use automatic copy assignment) + operator bool_type() const { return this->v_ ? &self_type::v_ : 0; } + + self_type & operator ++() { ++this->v_; return *this; } + self_type & operator --() { --this->v_; return *this; } + + self_type operator ~() const { return self_type( ~this->v_ ); } + self_type operator !() const { return self_type( !this->v_ ); } + self_type operator +() const { return self_type( +this->v_ ); } + self_type operator -() const { return self_type( -this->v_ ); } + + bool operator <( self_type const &r ) const { return this->v_ < r.v_; } + bool operator ==( self_type const &r ) const { return this->v_ == r.v_; } + + self_type &operator *=(self_type const &r) {this->v_ *= r.v_; return *this;} + self_type &operator /=(self_type const &r) {this->v_ /= r.v_; return *this;} + self_type &operator %=(self_type const &r) {this->v_ %= r.v_; return *this;} + self_type &operator +=(self_type const &r) {this->v_ += r.v_; return *this;} + self_type &operator -=(self_type const &r) {this->v_ -= r.v_; return *this;} + self_type &operator<<=(self_type const &r){this->v_ <<= r.v_; return *this;} + self_type &operator>>=(self_type const &r){this->v_ >>= r.v_; return *this;} + self_type &operator &=(self_type const &r) {this->v_ &= r.v_; return *this;} + self_type &operator |=(self_type const &r) {this->v_ |= r.v_; return *this;} + self_type &operator ^=(self_type const &r) {this->v_ ^= r.v_; return *this;} + + // Input & output + friend std::istream & operator >>( std::istream &i, self_type &x ) + { return i >> x.v_; } + + friend std::ostream & operator <<( std::ostream &o, self_type const &x ) + { return o << x.v_; } + +}; // my_wrapped_integer + +template < typename IntType, int ID > +my_wrapped_integer<IntType, ID> abs( my_wrapped_integer<IntType, ID> const &x ) +{ return ( x < my_wrapped_integer<IntType, ID>(0) ) ? -x : +x; } + +typedef my_wrapped_integer<int> MyInt1; +typedef my_wrapped_integer<unsigned> MyUnsigned1; +typedef my_wrapped_integer<int, 1> MyInt2; +typedef my_wrapped_integer<unsigned, 1> MyUnsigned2; + +// Without these explicit instantiations, MSVC++ 6.5/7.0 does not find +// some friend operators in certain contexts. +MyInt1 dummy1; +MyUnsigned1 dummy2; +MyInt2 dummy3; +MyUnsigned2 dummy4; + +// Various types to test with each GCD/LCM +typedef ::boost::mpl::list<signed char, short, int, long, +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1500) +#elif defined(BOOST_HAS_LONG_LONG) + boost::long_long_type, +#elif defined(BOOST_HAS_MS_INT64) + __int64, +#endif + MyInt1 +#ifndef DISABLE_MP_TESTS + , boost::multiprecision::cpp_int +#endif +> signed_test_types; +typedef ::boost::mpl::list<unsigned char, unsigned short, unsigned, + unsigned long, +#if BOOST_WORKAROUND(BOOST_MSVC, <= 1500) +#elif defined(BOOST_HAS_LONG_LONG) + boost::ulong_long_type, +#elif defined(BOOST_HAS_MS_INT64) + unsigned __int64, +#endif + MyUnsigned1, MyUnsigned2 /*, boost::multiprecision::uint256_t*/> unsigned_test_types; + +} // namespace + +#define BOOST_NO_MACRO_EXPAND /**/ + +// Specialize numeric_limits for _some_ of our types +namespace std +{ + +template < > +class numeric_limits< MyInt1 > +{ + typedef MyInt1::int_type int_type; + typedef numeric_limits<int_type> limits_type; + +public: + BOOST_STATIC_CONSTANT(bool, is_specialized = limits_type::is_specialized); + + static MyInt1 min BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::min)(); } + static MyInt1 max BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::max)(); } + + BOOST_STATIC_CONSTANT(int, digits = limits_type::digits); + BOOST_STATIC_CONSTANT(int, digits10 = limits_type::digits10); +#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS + BOOST_STATIC_CONSTANT(int, max_digits10 = limits_type::max_digits10); +#endif + BOOST_STATIC_CONSTANT(bool, is_signed = limits_type::is_signed); + BOOST_STATIC_CONSTANT(bool, is_integer = limits_type::is_integer); + BOOST_STATIC_CONSTANT(bool, is_exact = limits_type::is_exact); + BOOST_STATIC_CONSTANT(int, radix = limits_type::radix); + static MyInt1 epsilon() throw() { return limits_type::epsilon(); } + static MyInt1 round_error() throw() { return limits_type::round_error(); } + + BOOST_STATIC_CONSTANT(int, min_exponent = limits_type::min_exponent); + BOOST_STATIC_CONSTANT(int, min_exponent10 = limits_type::min_exponent10); + BOOST_STATIC_CONSTANT(int, max_exponent = limits_type::max_exponent); + BOOST_STATIC_CONSTANT(int, max_exponent10 = limits_type::max_exponent10); + + BOOST_STATIC_CONSTANT(bool, has_infinity = limits_type::has_infinity); + BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = limits_type::has_quiet_NaN); + BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = limits_type::has_signaling_NaN); + BOOST_STATIC_CONSTANT(float_denorm_style, has_denorm = limits_type::has_denorm); + BOOST_STATIC_CONSTANT(bool, has_denorm_loss = limits_type::has_denorm_loss); + + static MyInt1 infinity() throw() { return limits_type::infinity(); } + static MyInt1 quiet_NaN() throw() { return limits_type::quiet_NaN(); } + static MyInt1 signaling_NaN() throw() {return limits_type::signaling_NaN();} + static MyInt1 denorm_min() throw() { return limits_type::denorm_min(); } + + BOOST_STATIC_CONSTANT(bool, is_iec559 = limits_type::is_iec559); + BOOST_STATIC_CONSTANT(bool, is_bounded = limits_type::is_bounded); + BOOST_STATIC_CONSTANT(bool, is_modulo = limits_type::is_modulo); + + BOOST_STATIC_CONSTANT(bool, traps = limits_type::traps); + BOOST_STATIC_CONSTANT(bool, tinyness_before = limits_type::tinyness_before); + BOOST_STATIC_CONSTANT(float_round_style, round_style = limits_type::round_style); + +}; // std::numeric_limits<MyInt1> + +template < > +class numeric_limits< MyUnsigned1 > +{ + typedef MyUnsigned1::int_type int_type; + typedef numeric_limits<int_type> limits_type; + +public: + BOOST_STATIC_CONSTANT(bool, is_specialized = limits_type::is_specialized); + + static MyUnsigned1 min BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::min)(); } + static MyUnsigned1 max BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::max)(); } + + BOOST_STATIC_CONSTANT(int, digits = limits_type::digits); + BOOST_STATIC_CONSTANT(int, digits10 = limits_type::digits10); +#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS + BOOST_STATIC_CONSTANT(int, max_digits10 = limits_type::max_digits10); +#endif + BOOST_STATIC_CONSTANT(bool, is_signed = limits_type::is_signed); + BOOST_STATIC_CONSTANT(bool, is_integer = limits_type::is_integer); + BOOST_STATIC_CONSTANT(bool, is_exact = limits_type::is_exact); + BOOST_STATIC_CONSTANT(int, radix = limits_type::radix); + static MyUnsigned1 epsilon() throw() { return limits_type::epsilon(); } + static MyUnsigned1 round_error() throw(){return limits_type::round_error();} + + BOOST_STATIC_CONSTANT(int, min_exponent = limits_type::min_exponent); + BOOST_STATIC_CONSTANT(int, min_exponent10 = limits_type::min_exponent10); + BOOST_STATIC_CONSTANT(int, max_exponent = limits_type::max_exponent); + BOOST_STATIC_CONSTANT(int, max_exponent10 = limits_type::max_exponent10); + + BOOST_STATIC_CONSTANT(bool, has_infinity = limits_type::has_infinity); + BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = limits_type::has_quiet_NaN); + BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = limits_type::has_signaling_NaN); + BOOST_STATIC_CONSTANT(float_denorm_style, has_denorm = limits_type::has_denorm); + BOOST_STATIC_CONSTANT(bool, has_denorm_loss = limits_type::has_denorm_loss); + + static MyUnsigned1 infinity() throw() { return limits_type::infinity(); } + static MyUnsigned1 quiet_NaN() throw() { return limits_type::quiet_NaN(); } + static MyUnsigned1 signaling_NaN() throw() + { return limits_type::signaling_NaN(); } + static MyUnsigned1 denorm_min() throw(){ return limits_type::denorm_min(); } + + BOOST_STATIC_CONSTANT(bool, is_iec559 = limits_type::is_iec559); + BOOST_STATIC_CONSTANT(bool, is_bounded = limits_type::is_bounded); + BOOST_STATIC_CONSTANT(bool, is_modulo = limits_type::is_modulo); + + BOOST_STATIC_CONSTANT(bool, traps = limits_type::traps); + BOOST_STATIC_CONSTANT(bool, tinyness_before = limits_type::tinyness_before); + BOOST_STATIC_CONSTANT(float_round_style, round_style = limits_type::round_style); + +}; // std::numeric_limits<MyUnsigned1> + +#if BOOST_WORKAROUND(BOOST_MSVC,<1300) +// MSVC 6.0 lacks operator<< for __int64, see +// https://support.microsoft.com/kb/168440/ + +inline ostream& operator<<(ostream& os, __int64 i) +{ + char buf[20]; + sprintf(buf,"%I64d", i); + os << buf; + return os; +} + +inline ostream& operator<<(ostream& os, unsigned __int64 i) +{ + char buf[20]; + sprintf(buf,"%I64u", i); + os << buf; + return os; +} +#endif + +} // namespace std + +// GCD tests + +// GCD on signed integer types +template< class T > void gcd_int_test() // signed_test_types +{ +#ifndef BOOST_MSVC + using boost::integer::gcd; + using boost::integer::gcd_evaluator; +#else + using namespace boost::integer; +#endif + + // Originally from Boost.Rational tests + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(1), static_cast<T>(-1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(-1), static_cast<T>(1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(1), static_cast<T>(1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(-1), static_cast<T>(-1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(0), static_cast<T>(0)), static_cast<T>( 0) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(7), static_cast<T>(0)), static_cast<T>( 7) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(0), static_cast<T>(9)), static_cast<T>( 9) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(-7), static_cast<T>(0)), static_cast<T>( 7) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(0), static_cast<T>(-9)), static_cast<T>( 9) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(42), static_cast<T>(30)), static_cast<T>( 6) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(6), static_cast<T>(-9)), static_cast<T>( 3) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(-10), static_cast<T>(-10)), static_cast<T>(10) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(-25), static_cast<T>(-10)), static_cast<T>( 5) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(3), static_cast<T>(7)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(8), static_cast<T>(9)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(7), static_cast<T>(49)), static_cast<T>( 7) ); + // Again with function object: + BOOST_TEST_EQ(gcd_evaluator<T>()(1, -1), static_cast<T>(1)); + BOOST_TEST_EQ(gcd_evaluator<T>()(-1, 1), static_cast<T>(1)); + BOOST_TEST_EQ(gcd_evaluator<T>()(1, 1), static_cast<T>(1)); + BOOST_TEST_EQ(gcd_evaluator<T>()(-1, -1), static_cast<T>(1)); + BOOST_TEST_EQ(gcd_evaluator<T>()(0, 0), static_cast<T>(0)); + BOOST_TEST_EQ(gcd_evaluator<T>()(7, 0), static_cast<T>(7)); + BOOST_TEST_EQ(gcd_evaluator<T>()(0, 9), static_cast<T>(9)); + BOOST_TEST_EQ(gcd_evaluator<T>()(-7, 0), static_cast<T>(7)); + BOOST_TEST_EQ(gcd_evaluator<T>()(0, -9), static_cast<T>(9)); + BOOST_TEST_EQ(gcd_evaluator<T>()(42, 30), static_cast<T>(6)); + BOOST_TEST_EQ(gcd_evaluator<T>()(6, -9), static_cast<T>(3)); + BOOST_TEST_EQ(gcd_evaluator<T>()(-10, -10), static_cast<T>(10)); + BOOST_TEST_EQ(gcd_evaluator<T>()(-25, -10), static_cast<T>(5)); + BOOST_TEST_EQ(gcd_evaluator<T>()(3, 7), static_cast<T>(1)); + BOOST_TEST_EQ(gcd_evaluator<T>()(8, 9), static_cast<T>(1)); + BOOST_TEST_EQ(gcd_evaluator<T>()(7, 49), static_cast<T>(7)); +} + +// GCD on unmarked signed integer type +void gcd_unmarked_int_test() +{ +#ifndef BOOST_MSVC + using boost::integer::gcd; +#else + using namespace boost::integer; +#endif + + // The regular signed-integer GCD function performs the unsigned version, + // then does an absolute-value on the result. Signed types that are not + // marked as such (due to no std::numeric_limits specialization) may be off + // by a sign. + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(1), static_cast<MyInt2>(-1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(-1), static_cast<MyInt2>(1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(1), static_cast<MyInt2>(1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(-1), static_cast<MyInt2>(-1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(0), static_cast<MyInt2>(0) )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(7), static_cast<MyInt2>(0) )), MyInt2( 7) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(0), static_cast<MyInt2>(9) )), MyInt2( 9) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(-7), static_cast<MyInt2>(0) )), MyInt2( 7) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(0), static_cast<MyInt2>(-9) )), MyInt2( 9) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(42), static_cast<MyInt2>(30))), MyInt2( 6) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(6), static_cast<MyInt2>(-9) )), MyInt2( 3) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(-10), static_cast<MyInt2>(-10) )), MyInt2(10) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(-25), static_cast<MyInt2>(-10) )), MyInt2( 5) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(3), static_cast<MyInt2>(7) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(8), static_cast<MyInt2>(9) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::gcd(static_cast<MyInt2>(7), static_cast<MyInt2>(49) )), MyInt2( 7) ); +} + +// GCD on unsigned integer types +template< class T > void gcd_unsigned_test() // unsigned_test_types +{ +#ifndef BOOST_MSVC + using boost::integer::gcd; +#else + using namespace boost::integer; +#endif + + // Note that unmarked types (i.e. have no std::numeric_limits + // specialization) are treated like non/unsigned types + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(1u), static_cast<T>(1u)), static_cast<T>( 1u) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(0u), static_cast<T>(0u)), static_cast<T>( 0u) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(7u), static_cast<T>(0u)), static_cast<T>( 7u) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(0u), static_cast<T>(9u)), static_cast<T>( 9u) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(42u), static_cast<T>(30u)), static_cast<T>( 6u) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(3u), static_cast<T>(7u)), static_cast<T>( 1u) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(8u), static_cast<T>(9u)), static_cast<T>( 1u) ); + BOOST_TEST_EQ( boost::integer::gcd(static_cast<T>(7u), static_cast<T>(49u)), static_cast<T>( 7u) ); +} + +// GCD at compile-time +void gcd_static_test() +{ +#ifndef BOOST_MSVC + using boost::integer::static_gcd; +#else + using namespace boost::integer; +#endif + + // Can't use "BOOST_TEST_EQ", otherwise the "value" member will be + // disqualified as compile-time-only constant, needing explicit definition + BOOST_TEST( (static_gcd< 1, 1>::value) == 1 ); + BOOST_TEST( (static_gcd< 0, 0>::value) == 0 ); + BOOST_TEST( (static_gcd< 7, 0>::value) == 7 ); + BOOST_TEST( (static_gcd< 0, 9>::value) == 9 ); + BOOST_TEST( (static_gcd<42, 30>::value) == 6 ); + BOOST_TEST( (static_gcd< 3, 7>::value) == 1 ); + BOOST_TEST( (static_gcd< 8, 9>::value) == 1 ); + BOOST_TEST( (static_gcd< 7, 49>::value) == 7 ); +} + +void gcd_method_test() +{ + // Verify that the 3 different methods all yield the same result: + boost::random::mt19937 gen; + boost::random::uniform_int_distribution<int> d(0, ((std::numeric_limits<int>::max)() / 2)); + + for (unsigned int i = 0; i < 10000; ++i) + { + int v1 = d(gen); + int v2 = d(gen); + int g = boost::integer::gcd_detail::Euclid_gcd(v1, v2); + BOOST_TEST(v1 % g == 0); + BOOST_TEST(v2 % g == 0); + BOOST_TEST_EQ(g, boost::integer::gcd_detail::mixed_binary_gcd(v1, v2)); + BOOST_TEST_EQ(g, boost::integer::gcd_detail::Stein_gcd(v1, v2)); + } +} + +// LCM tests + +// LCM on signed integer types +template< class T > void lcm_int_test() // signed_test_types +{ +#ifndef BOOST_MSVC + using boost::integer::lcm; + using boost::integer::lcm_evaluator; +#else + using namespace boost::integer; +#endif + + // Originally from Boost.Rational tests + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(1), static_cast<T>(-1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(-1), static_cast<T>(1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(1), static_cast<T>(1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(-1), static_cast<T>(-1)), static_cast<T>( 1) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(0), static_cast<T>(0)), static_cast<T>( 0) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(6), static_cast<T>(0)), static_cast<T>( 0) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(0), static_cast<T>(7)), static_cast<T>( 0) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(-5), static_cast<T>(0)), static_cast<T>( 0) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(0), static_cast<T>(-4)), static_cast<T>( 0) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(18), static_cast<T>(30)), static_cast<T>(90) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(-6), static_cast<T>(9)), static_cast<T>(18) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(-10), static_cast<T>(-10)), static_cast<T>(10) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(25), static_cast<T>(-10)), static_cast<T>(50) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(3), static_cast<T>(7)), static_cast<T>(21) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(8), static_cast<T>(9)), static_cast<T>(72) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(7), static_cast<T>(49)), static_cast<T>(49) ); + // Again with function object: + BOOST_TEST_EQ(lcm_evaluator<T>()(1, -1), static_cast<T>(1)); + BOOST_TEST_EQ(lcm_evaluator<T>()(-1, 1), static_cast<T>(1)); + BOOST_TEST_EQ(lcm_evaluator<T>()(1, 1), static_cast<T>(1)); + BOOST_TEST_EQ(lcm_evaluator<T>()(-1, -1), static_cast<T>(1)); + BOOST_TEST_EQ(lcm_evaluator<T>()(0, 0), static_cast<T>(0)); + BOOST_TEST_EQ(lcm_evaluator<T>()(6, 0), static_cast<T>(0)); + BOOST_TEST_EQ(lcm_evaluator<T>()(0, 7), static_cast<T>(0)); + BOOST_TEST_EQ(lcm_evaluator<T>()(-5, 0), static_cast<T>(0)); + BOOST_TEST_EQ(lcm_evaluator<T>()(0, -4), static_cast<T>(0)); + BOOST_TEST_EQ(lcm_evaluator<T>()(18, 30), static_cast<T>(90)); + BOOST_TEST_EQ(lcm_evaluator<T>()(-6, 9), static_cast<T>(18)); + BOOST_TEST_EQ(lcm_evaluator<T>()(-10, -10), static_cast<T>(10)); + BOOST_TEST_EQ(lcm_evaluator<T>()(25, -10), static_cast<T>(50)); + BOOST_TEST_EQ(lcm_evaluator<T>()(3, 7), static_cast<T>(21)); + BOOST_TEST_EQ(lcm_evaluator<T>()(8, 9), static_cast<T>(72)); + BOOST_TEST_EQ(lcm_evaluator<T>()(7, 49), static_cast<T>(49)); +} + +// LCM on unmarked signed integer type +void lcm_unmarked_int_test() +{ +#ifndef BOOST_MSVC + using boost::integer::lcm; +#else + using namespace boost::integer; +#endif + + // The regular signed-integer LCM function performs the unsigned version, + // then does an absolute-value on the result. Signed types that are not + // marked as such (due to no std::numeric_limits specialization) may be off + // by a sign. + BOOST_TEST_EQ( abs(boost::integer::lcm( static_cast<MyInt2>(1), static_cast<MyInt2>(-1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(-1), static_cast<MyInt2>(1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(1), static_cast<MyInt2>(1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(-1), static_cast<MyInt2>(-1) )), MyInt2( 1) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(0), static_cast<MyInt2>(0) )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(6), static_cast<MyInt2>(0) )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(0), static_cast<MyInt2>(7) )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(-5), static_cast<MyInt2>(0) )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(0), static_cast<MyInt2>(-4) )), MyInt2( 0) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(18), static_cast<MyInt2>(30) )), MyInt2(90) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(-6), static_cast<MyInt2>(9) )), MyInt2(18) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(-10), static_cast<MyInt2>(-10) )), MyInt2(10) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(25), static_cast<MyInt2>(-10) )), MyInt2(50) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(3), static_cast<MyInt2>(7) )), MyInt2(21) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(8), static_cast<MyInt2>(9) )), MyInt2(72) ); + BOOST_TEST_EQ( abs(boost::integer::lcm(static_cast<MyInt2>(7), static_cast<MyInt2>(49) )), MyInt2(49) ); +} + +// LCM on unsigned integer types +template< class T > void lcm_unsigned_test() // unsigned_test_types +{ +#ifndef BOOST_MSVC + using boost::integer::lcm; +#else + using namespace boost::integer; +#endif + + // Note that unmarked types (i.e. have no std::numeric_limits + // specialization) are treated like non/unsigned types + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(1u), static_cast<T>(1u)), static_cast<T>( 1u) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(0u), static_cast<T>(0u)), static_cast<T>( 0u) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(6u), static_cast<T>(0u)), static_cast<T>( 0u) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(0u), static_cast<T>(7u)), static_cast<T>( 0u) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(18u), static_cast<T>(30u)), static_cast<T>(90u) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(3u), static_cast<T>(7u)), static_cast<T>(21u) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(8u), static_cast<T>(9u)), static_cast<T>(72u) ); + BOOST_TEST_EQ( boost::integer::lcm(static_cast<T>(7u), static_cast<T>(49u)), static_cast<T>(49u) ); +} + +// LCM at compile-time +void lcm_static_test() +{ +#ifndef BOOST_MSVC + using boost::integer::static_lcm; +#else + using namespace boost::integer; +#endif + + // Can't use "BOOST_TEST_EQ", otherwise the "value" member will be + // disqualified as compile-time-only constant, needing explicit definition + BOOST_TEST( (static_lcm< 1, 1>::value) == 1 ); + BOOST_TEST( (static_lcm< 0, 0>::value) == 0 ); + BOOST_TEST( (static_lcm< 6, 0>::value) == 0 ); + BOOST_TEST( (static_lcm< 0, 7>::value) == 0 ); + BOOST_TEST( (static_lcm<18, 30>::value) == 90 ); + BOOST_TEST( (static_lcm< 3, 7>::value) == 21 ); + BOOST_TEST( (static_lcm< 8, 9>::value) == 72 ); + BOOST_TEST( (static_lcm< 7, 49>::value) == 49 ); +} + +void variadics() +{ + unsigned i[] = { 44, 56, 76, 88 }; + BOOST_TEST_EQ(boost::integer::gcd_range(i, i + 4).first, 4); + BOOST_TEST_EQ(boost::integer::gcd_range(i, i + 4).second, i + 4); + BOOST_TEST_EQ(boost::integer::lcm_range(i, i + 4).first, 11704); + BOOST_TEST_EQ(boost::integer::lcm_range(i, i + 4).second, i + 4); + + unsigned i_gcd_unity[] = { 44, 56, 1, 88 }; + BOOST_TEST_EQ(boost::integer::gcd_range(i_gcd_unity, i_gcd_unity + 4).first, 1); + BOOST_TEST_EQ(boost::integer::gcd_range(i_gcd_unity, i_gcd_unity + 4).second, i_gcd_unity + 3); + + unsigned i_lcm_unity[] = { 44, 56, 0, 88 }; + BOOST_TEST_EQ(boost::integer::lcm_range(i_lcm_unity, i_lcm_unity + 4).first, 0); + BOOST_TEST_EQ(boost::integer::lcm_range(i_lcm_unity, i_lcm_unity + 4).second, i_lcm_unity + 3); + +#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES + BOOST_TEST_EQ(boost::integer::gcd(i[0], i[1], i[2], i[3]), 4); + BOOST_TEST_EQ(boost::integer::lcm(i[0], i[1], i[2], i[3]), 11704); +#endif +} + +// Test case from Boost.Rational, need to make sure we don't break the rational lib: +template <class T> void gcd_and_lcm_on_rationals() +{ + typedef boost::rational<T> rational; + BOOST_TEST_EQ(boost::integer::gcd(rational(1, 4), rational(1, 3)), + rational(1, 12)); + BOOST_TEST_EQ(boost::integer::lcm(rational(1, 4), rational(1, 3)), + rational(1)); +} + +#ifndef DISABLE_MP_TESTS +#define TEST_SIGNED_( test ) \ + test<signed char>(); \ + test<short>(); \ + test<int>(); \ + test<long>(); \ + test<MyInt1>(); \ + test<boost::multiprecision::cpp_int>(); \ + test<boost::multiprecision::int512_t>(); +#else +#define TEST_SIGNED_( test ) \ + test<signed char>(); \ + test<short>(); \ + test<int>(); \ + test<long>(); \ + test<MyInt1>(); +#endif + +#ifdef BOOST_HAS_LONG_LONG +# define TEST_SIGNED__( test ) \ + TEST_SIGNED_( test ) \ + test<boost::long_long_type>(); +#elif defined(BOOST_HAS_MS_INT64) +# define TEST_SIGNED__( test ) \ + TEST_SIGNED_( test ) \ + test<__int64>(); +#endif +#ifndef DISABLE_MP_TESTS +#define TEST_UNSIGNED_( test ) \ + test<unsigned char>(); \ + test<unsigned short>(); \ + test<unsigned>(); \ + test<unsigned long>(); \ + test<MyUnsigned1>(); \ + test<MyUnsigned2>(); \ + test<boost::multiprecision::uint512_t>(); +#else +#define TEST_UNSIGNED_( test ) \ + test<unsigned char>(); \ + test<unsigned short>(); \ + test<unsigned>(); \ + test<unsigned long>(); \ + test<MyUnsigned1>(); \ + test<MyUnsigned2>(); +#endif + +#ifdef BOOST_HAS_LONG_LONG +# define TEST_UNSIGNED( test ) \ + TEST_UNSIGNED_( test ) \ + test<boost::ulong_long_type>(); +#elif defined(BOOST_HAS_MS_INT64) +# define TEST_UNSIGNED( test ) \ + TEST_UNSIGNED_( test ) \ + test<unsigned __int64>(); +#endif + +#ifdef BOOST_INTEGER_HAS_GMPXX_H +# define TEST_SIGNED(test)\ + TEST_SIGNED__(test)\ + test<mpz_class>(); +# define TEST_SIGNED_NO_GMP(test) TEST_SIGNED__(test) +#else +# define TEST_SIGNED(test) TEST_SIGNED__(test) +# define TEST_SIGNED_NO_GMP(test) TEST_SIGNED__(test) +#endif + +int main() +{ + TEST_SIGNED(gcd_int_test) + gcd_unmarked_int_test(); + TEST_UNSIGNED(gcd_unsigned_test) + gcd_static_test(); + gcd_method_test(); + + TEST_SIGNED(lcm_int_test) + lcm_unmarked_int_test(); + TEST_UNSIGNED(lcm_unsigned_test) + lcm_static_test(); + variadics(); + TEST_SIGNED_NO_GMP(gcd_and_lcm_on_rationals) + + return boost::report_errors(); +} diff --git a/src/boost/libs/integer/test/extended_euclidean_test.cpp b/src/boost/libs/integer/test/extended_euclidean_test.cpp new file mode 100644 index 00000000..8299a259 --- /dev/null +++ b/src/boost/libs/integer/test/extended_euclidean_test.cpp @@ -0,0 +1,58 @@ +/* + * (C) Copyright Nick Thompson 2018. + * Use, modification and distribution are subject to 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 "multiprecision_config.hpp" + +#ifndef DISABLE_MP_TESTS +#include <boost/integer/extended_euclidean.hpp> +#include <boost/cstdint.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/multiprecision/cpp_int.hpp> +#include <boost/integer/common_factor.hpp> + +using boost::multiprecision::int128_t; +using boost::multiprecision::int256_t; +using boost::integer::extended_euclidean; +using boost::integer::gcd; + +template<class Z> +void test_extended_euclidean() +{ + // Stress test: + //Z max_arg = std::numeric_limits<Z>::max(); + Z max_arg = 500; + for (Z m = max_arg; m > 0; --m) + { + for (Z n = max_arg; n > 0; --n) + { + boost::integer::euclidean_result_t<Z> u = extended_euclidean(m, n); + int256_t gcdmn = gcd(m, n); + int256_t x = u.x; + int256_t y = u.y; + BOOST_TEST_EQ(u.gcd, gcdmn); + BOOST_TEST_EQ(m*x + n*y, gcdmn); + } + } +} + + + +int main() +{ + test_extended_euclidean<boost::int16_t>(); + test_extended_euclidean<boost::int32_t>(); + test_extended_euclidean<boost::int64_t>(); + test_extended_euclidean<int128_t>(); + + return boost::report_errors();; +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/integer/test/fail_int_exact.cpp b/src/boost/libs/integer/test/fail_int_exact.cpp new file mode 100644 index 00000000..1b6e66a6 --- /dev/null +++ b/src/boost/libs/integer/test/fail_int_exact.cpp @@ -0,0 +1,8 @@ +// Copyright John Maddock 2012. +// 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/integer.hpp> + +typedef boost::int_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::exact fail_int_exact; diff --git a/src/boost/libs/integer/test/fail_int_fast.cpp b/src/boost/libs/integer/test/fail_int_fast.cpp new file mode 100644 index 00000000..8e65b7c2 --- /dev/null +++ b/src/boost/libs/integer/test/fail_int_fast.cpp @@ -0,0 +1,8 @@ +// Copyright John Maddock 2012. +// 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/integer.hpp> + +typedef boost::int_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::fast fail_int_fast; diff --git a/src/boost/libs/integer/test/fail_int_least.cpp b/src/boost/libs/integer/test/fail_int_least.cpp new file mode 100644 index 00000000..d06ce6d4 --- /dev/null +++ b/src/boost/libs/integer/test/fail_int_least.cpp @@ -0,0 +1,8 @@ +// Copyright John Maddock 2012. +// 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/integer.hpp> + +typedef boost::int_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::least fail_int_least; diff --git a/src/boost/libs/integer/test/fail_uint_65.cpp b/src/boost/libs/integer/test/fail_uint_65.cpp new file mode 100644 index 00000000..76b485e8 --- /dev/null +++ b/src/boost/libs/integer/test/fail_uint_65.cpp @@ -0,0 +1,13 @@ +// Copyright John Maddock 2012. +// 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/integer.hpp> +#include <iostream> + +int main() +{ + std::cout << std::numeric_limits<boost::uint_t<65>::least>::digits; + return 0; +} diff --git a/src/boost/libs/integer/test/fail_uint_exact.cpp b/src/boost/libs/integer/test/fail_uint_exact.cpp new file mode 100644 index 00000000..36f86280 --- /dev/null +++ b/src/boost/libs/integer/test/fail_uint_exact.cpp @@ -0,0 +1,8 @@ +// Copyright John Maddock 2012. +// 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/integer.hpp> + +typedef boost::uint_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::exact fail_uint_exact; diff --git a/src/boost/libs/integer/test/fail_uint_fast.cpp b/src/boost/libs/integer/test/fail_uint_fast.cpp new file mode 100644 index 00000000..99f92b2f --- /dev/null +++ b/src/boost/libs/integer/test/fail_uint_fast.cpp @@ -0,0 +1,8 @@ +// Copyright John Maddock 2012. +// 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/integer.hpp> + +typedef boost::uint_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::fast fail_uint_fast; diff --git a/src/boost/libs/integer/test/fail_uint_least.cpp b/src/boost/libs/integer/test/fail_uint_least.cpp new file mode 100644 index 00000000..8cdfbaf8 --- /dev/null +++ b/src/boost/libs/integer/test/fail_uint_least.cpp @@ -0,0 +1,8 @@ +// Copyright John Maddock 2012. +// 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/integer.hpp> + +typedef boost::uint_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::least fail_uint_least; diff --git a/src/boost/libs/integer/test/gcd_constexpr14_test.cpp b/src/boost/libs/integer/test/gcd_constexpr14_test.cpp new file mode 100644 index 00000000..05bef348 --- /dev/null +++ b/src/boost/libs/integer/test/gcd_constexpr14_test.cpp @@ -0,0 +1,66 @@ + +// (C) Copyright John Maddock 2017. +// 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/integer/common_factor.hpp> + +#ifndef BOOST_NO_CXX14_CONSTEXPR + +void test_constexpr1() +{ + constexpr const boost::int64_t i = 347 * 463 * 727; + constexpr const boost::int64_t j = 191 * 347 * 281; + + constexpr const boost::int64_t k = boost::integer::gcd(i, j); + constexpr const boost::int64_t l = boost::integer::lcm(i, j); + + static_assert(k == 347, "Expected result not integer in constexpr gcd."); + static_assert(l == 6268802158037, "Expected result not integer in constexpr lcm."); +} + +void test_constexpr2() +{ + constexpr const boost::uint64_t i = 347 * 463 * 727; + constexpr const boost::uint64_t j = 191 * 347 * 281; + + constexpr const boost::uint64_t k = boost::integer::gcd(i, j); + constexpr const boost::uint64_t l = boost::integer::lcm(i, j); + + static_assert(k == 347, "Expected result not integer in constexpr gcd."); + static_assert(l == 6268802158037, "Expected result not integer in constexpr lcm."); +} + +void test_constexpr3() +{ + constexpr const boost::uint64_t i = 347 * 463 * 727; + constexpr const boost::uint64_t j = 191 * 347 * 281; + + constexpr const boost::uint64_t k = boost::integer::gcd_detail::Euclid_gcd(i, j); + + static_assert(k == 347, "Expected result not integer in constexpr gcd."); +} + +void test_constexpr4() +{ + constexpr const boost::uint64_t i = 347 * 463 * 727; + constexpr const boost::uint64_t j = 191 * 347 * 281; + + constexpr const boost::uint64_t k = boost::integer::gcd_detail::mixed_binary_gcd(i, j); + + static_assert(k == 347, "Expected result not integer in constexpr gcd."); +} + +void test_constexpr5() +{ + constexpr const boost::uint64_t i = 347 * 463 * 727; + constexpr const boost::uint64_t j = 191 * 347 * 281; + + constexpr const boost::uint64_t k = boost::integer::gcd_detail::Stein_gcd(i, j); + + static_assert(k == 347, "Expected result not integer in constexpr gcd."); +} +#endif + + diff --git a/src/boost/libs/integer/test/gcd_noexcept_test.cpp b/src/boost/libs/integer/test/gcd_noexcept_test.cpp new file mode 100644 index 00000000..9100744d --- /dev/null +++ b/src/boost/libs/integer/test/gcd_noexcept_test.cpp @@ -0,0 +1,35 @@ + +// (C) Copyright John Maddock 2017. +// 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/integer/common_factor.hpp> + +#if !defined(BOOST_NO_CXX11_NOEXCEPT) && !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +// +// These tests don't pass with GCC-4.x: +// +#if !defined(BOOST_GCC) || (BOOST_GCC >= 50000) + +void test_noexcept(unsigned char a, unsigned char b) +{ + static_assert(noexcept(boost::integer::gcd(static_cast<unsigned char>(a), static_cast<unsigned char>(b))), "Expected a noexcept function."); +#ifndef _MSC_VER + // This generates an internal compiler error if enabled as well as the following test: + static_assert(noexcept(boost::integer::gcd(static_cast<char>(a), static_cast<char>(b))), "Expected a noexcept function."); +#endif + static_assert(noexcept(boost::integer::gcd(static_cast<signed char>(a), static_cast<signed char>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<short>(a), static_cast<short>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<unsigned short>(a), static_cast<unsigned short>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<int>(a), static_cast<int>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<unsigned int>(a), static_cast<unsigned int>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<long>(a), static_cast<long>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<unsigned long>(a), static_cast<unsigned long>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<long long>(a), static_cast<long long>(b))), "Expected a noexcept function."); + static_assert(noexcept(boost::integer::gcd(static_cast<unsigned long long>(a), static_cast<unsigned long long>(b))), "Expected a noexcept function."); +} + +#endif +#endif + diff --git a/src/boost/libs/integer/test/has_gmpxx.cpp b/src/boost/libs/integer/test/has_gmpxx.cpp new file mode 100644 index 00000000..4d4a41c9 --- /dev/null +++ b/src/boost/libs/integer/test/has_gmpxx.cpp @@ -0,0 +1,15 @@ +// Copyright John Maddock 2008. +// Use, modification and distribution are subject to 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 <gmpxx.h> + +// On Linux, libgmpxx is built with gcc and libstdc++. When the user application, such as tests, are built against libc++, +// linking fails because of the C++ standard library symbol names mismatch. So fail the test if we're not using libstdc++. +#if defined(__linux__) || defined(__linux) || defined(linux) +#include <utility> +#if !defined(__GLIBCPP__) && !defined(__GLIBCXX__) +#error "libgmpxx is not supported on this platform with this C++ standard library" +#endif +#endif diff --git a/src/boost/libs/integer/test/integer_fwd_include_test.cpp b/src/boost/libs/integer/test/integer_fwd_include_test.cpp new file mode 100644 index 00000000..4346b69e --- /dev/null +++ b/src/boost/libs/integer/test/integer_fwd_include_test.cpp @@ -0,0 +1,22 @@ +// Copyright John Maddock 2009. +// 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/integer_fwd.hpp> // must be the only #include! + +// just declare some functions that use the incomplete types in the header: + +void f1(const boost::integer_traits<char>*); +void f2(const boost::int_fast_t<char>*); +void f3(const boost::int_t<12>*); +void f4(const boost::uint_t<31>*); +void f5(const boost::int_max_value_t<100>*); +void f6(const boost::int_min_value_t<-100>*); +void f7(const boost::uint_value_t<100>*); +void f8(const boost::high_bit_mask_t<10>*); +void f9(const boost::low_bits_mask_t<10>*); +void f10(boost::static_log2_argument_type, boost::static_log2_result_type, boost::static_log2<10>*); +void f11(boost::static_min_max_signed_type, boost::static_min_max_unsigned_type); +void f12(boost::static_signed_min<1, 2>*, boost::static_signed_max<1,2>*); +void f13(boost::static_unsigned_min<1,2>*, boost::static_unsigned_min<1,2>*); diff --git a/src/boost/libs/integer/test/integer_include_test.cpp b/src/boost/libs/integer/test/integer_include_test.cpp new file mode 100644 index 00000000..653a197b --- /dev/null +++ b/src/boost/libs/integer/test/integer_include_test.cpp @@ -0,0 +1,36 @@ +// Copyright John Maddock 2009. +// 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/integer.hpp> // must be the only #include! + +int main() +{ + boost::int_fast_t<char>::fast f = 0; + (void)f; + boost::int_t<16>::fast f2 = 0; + (void)f2; + boost::int_t<32>::exact e = 0; + (void)e; + boost::int_t<12>::least l = 0; + (void)l; + boost::uint_t<16>::fast uf2 = 0; + (void)uf2; + boost::uint_t<32>::exact ue = 0; + (void)ue; + boost::uint_t<12>::least ul = 0; + (void)ul; + boost::int_max_value_t<200>::fast v1 = 0; + (void)v1; + boost::int_max_value_t<2000>::least v2 = 0; + (void)v2; + boost::int_min_value_t<-200>::fast v3 = 0; + (void)v3; + boost::int_min_value_t<-2000>::least v4 = 0; + (void)v4; + boost::uint_value_t<200>::fast v5 = 0; + (void)v5; + boost::uint_value_t<2000>::least v6 = 0; + (void)v6; +} diff --git a/src/boost/libs/integer/test/integer_mask_include_test.cpp b/src/boost/libs/integer/test/integer_mask_include_test.cpp new file mode 100644 index 00000000..09af1897 --- /dev/null +++ b/src/boost/libs/integer/test/integer_mask_include_test.cpp @@ -0,0 +1,18 @@ +// Copyright John Maddock 2009. +// 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/integer/integer_mask.hpp> // must be the only #include! + +int main() +{ + boost::high_bit_mask_t<20>::least l = boost::high_bit_mask_t<20>::high_bit; + boost::high_bit_mask_t<12>::fast f = boost::high_bit_mask_t<12>::high_bit_fast; + l += f + boost::high_bit_mask_t<12>::bit_position; + (void)l; + boost::low_bits_mask_t<20>::least l2 = boost::low_bits_mask_t<20>::sig_bits; + boost::low_bits_mask_t<12>::fast f2 = boost::low_bits_mask_t<12>::sig_bits_fast; + l2 += f2 + boost::low_bits_mask_t<12>::bit_count; + (void)l2; +} diff --git a/src/boost/libs/integer/test/integer_mask_test.cpp b/src/boost/libs/integer/test/integer_mask_test.cpp new file mode 100644 index 00000000..a66ab8d3 --- /dev/null +++ b/src/boost/libs/integer/test/integer_mask_test.cpp @@ -0,0 +1,203 @@ +// boost integer_mask.hpp test program -------------------------------------// + +// (C) Copyright Daryle Walker 2001. +// 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) + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 23 Sep 2001 Initial version (Daryle Walker) + +#include <boost/detail/lightweight_test.hpp> + +#include <boost/cstdlib.hpp> // for boost::exit_success +#include <boost/integer/integer_mask.hpp> // for boost::high_bit_mask_t, etc. + +#include <iostream> // for std::cout (std::endl indirectly) + +#ifdef BOOST_MSVC +#pragma warning(disable:4127) // conditional expression is constant +#endif + +#if defined(BOOST_HAS_LONG_LONG) +#define MASK_TYPE ::boost::ulong_long_type +#elif defined(BOOST_HAS_MS_INT64) +#define MASK_TYPE unsigned __int64 +#else +#define MASK_TYPE unsigned long +#endif + +#define ONE (static_cast<MASK_TYPE>(1)) + +#define PRIVATE_HIGH_BIT_SLOW_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ + (v) >::high_bit == (ONE << (v)) ); +#define PRIVATE_HIGH_BIT_FAST_TEST(v) BOOST_TEST( ::boost::high_bit_mask_t< \ + (v) >::high_bit_fast == (ONE << (v)) ); +#define PRIVATE_HIGH_BIT_TEST(v) do { PRIVATE_HIGH_BIT_SLOW_TEST(v); \ + PRIVATE_HIGH_BIT_FAST_TEST(v); } while (false) + +#define PRIVATE_LOW_BITS_SLOW_TEST(v) \ + do{ \ + MASK_TYPE mask = 0;\ + if(v > 0)\ + { mask = ((ONE << (v-1)) - 1); mask <<= 1; mask |= 1; }\ + BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits == mask); \ + }while(false); +#define PRIVATE_LOW_BITS_FAST_TEST(v) \ + do{ \ + MASK_TYPE mask = 0;\ + if(v > 0)\ + { mask = ((ONE << (v-1)) - 1); mask <<= 1; mask |= 1; }\ + BOOST_TEST( ::boost::low_bits_mask_t< (v) >::sig_bits_fast == mask);\ + }while(false); +#define PRIVATE_LOW_BITS_TEST(v) do { PRIVATE_LOW_BITS_SLOW_TEST(v); \ + PRIVATE_LOW_BITS_FAST_TEST(v); } while (false) + + +int main( int, char*[] ) +{ + using std::cout; + using std::endl; + + cout << "Doing high_bit_mask_t tests." << endl; + +#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64) + PRIVATE_HIGH_BIT_TEST( 63 ); + PRIVATE_HIGH_BIT_TEST( 62 ); + PRIVATE_HIGH_BIT_TEST( 61 ); + PRIVATE_HIGH_BIT_TEST( 60 ); + PRIVATE_HIGH_BIT_TEST( 59 ); + PRIVATE_HIGH_BIT_TEST( 58 ); + PRIVATE_HIGH_BIT_TEST( 57 ); + PRIVATE_HIGH_BIT_TEST( 56 ); + PRIVATE_HIGH_BIT_TEST( 55 ); + PRIVATE_HIGH_BIT_TEST( 54 ); + PRIVATE_HIGH_BIT_TEST( 53 ); + PRIVATE_HIGH_BIT_TEST( 52 ); + PRIVATE_HIGH_BIT_TEST( 51 ); + PRIVATE_HIGH_BIT_TEST( 50 ); + PRIVATE_HIGH_BIT_TEST( 49 ); + PRIVATE_HIGH_BIT_TEST( 48 ); + PRIVATE_HIGH_BIT_TEST( 47 ); + PRIVATE_HIGH_BIT_TEST( 46 ); + PRIVATE_HIGH_BIT_TEST( 45 ); + PRIVATE_HIGH_BIT_TEST( 44 ); + PRIVATE_HIGH_BIT_TEST( 43 ); + PRIVATE_HIGH_BIT_TEST( 42 ); + PRIVATE_HIGH_BIT_TEST( 41 ); + PRIVATE_HIGH_BIT_TEST( 40 ); + PRIVATE_HIGH_BIT_TEST( 39 ); + PRIVATE_HIGH_BIT_TEST( 38 ); + PRIVATE_HIGH_BIT_TEST( 37 ); + PRIVATE_HIGH_BIT_TEST( 36 ); + PRIVATE_HIGH_BIT_TEST( 35 ); + PRIVATE_HIGH_BIT_TEST( 34 ); + PRIVATE_HIGH_BIT_TEST( 33 ); + PRIVATE_HIGH_BIT_TEST( 32 ); +#endif + PRIVATE_HIGH_BIT_TEST( 31 ); + PRIVATE_HIGH_BIT_TEST( 30 ); + PRIVATE_HIGH_BIT_TEST( 29 ); + PRIVATE_HIGH_BIT_TEST( 28 ); + PRIVATE_HIGH_BIT_TEST( 27 ); + PRIVATE_HIGH_BIT_TEST( 26 ); + PRIVATE_HIGH_BIT_TEST( 25 ); + PRIVATE_HIGH_BIT_TEST( 24 ); + PRIVATE_HIGH_BIT_TEST( 23 ); + PRIVATE_HIGH_BIT_TEST( 22 ); + PRIVATE_HIGH_BIT_TEST( 21 ); + PRIVATE_HIGH_BIT_TEST( 20 ); + PRIVATE_HIGH_BIT_TEST( 19 ); + PRIVATE_HIGH_BIT_TEST( 18 ); + PRIVATE_HIGH_BIT_TEST( 17 ); + PRIVATE_HIGH_BIT_TEST( 16 ); + PRIVATE_HIGH_BIT_TEST( 15 ); + PRIVATE_HIGH_BIT_TEST( 14 ); + PRIVATE_HIGH_BIT_TEST( 13 ); + PRIVATE_HIGH_BIT_TEST( 12 ); + PRIVATE_HIGH_BIT_TEST( 11 ); + PRIVATE_HIGH_BIT_TEST( 10 ); + PRIVATE_HIGH_BIT_TEST( 9 ); + PRIVATE_HIGH_BIT_TEST( 8 ); + PRIVATE_HIGH_BIT_TEST( 7 ); + PRIVATE_HIGH_BIT_TEST( 6 ); + PRIVATE_HIGH_BIT_TEST( 5 ); + PRIVATE_HIGH_BIT_TEST( 4 ); + PRIVATE_HIGH_BIT_TEST( 3 ); + PRIVATE_HIGH_BIT_TEST( 2 ); + PRIVATE_HIGH_BIT_TEST( 1 ); + PRIVATE_HIGH_BIT_TEST( 0 ); + + cout << "Doing low_bits_mask_t tests." << endl; + +#if defined(BOOST_HAS_LONG_LONG) || defined(BOOST_HAS_MS_INT64) + PRIVATE_LOW_BITS_TEST( 64 ); + PRIVATE_LOW_BITS_TEST( 63 ); + PRIVATE_LOW_BITS_TEST( 62 ); + PRIVATE_LOW_BITS_TEST( 61 ); + PRIVATE_LOW_BITS_TEST( 60 ); + PRIVATE_LOW_BITS_TEST( 59 ); + PRIVATE_LOW_BITS_TEST( 58 ); + PRIVATE_LOW_BITS_TEST( 57 ); + PRIVATE_LOW_BITS_TEST( 56 ); + PRIVATE_LOW_BITS_TEST( 55 ); + PRIVATE_LOW_BITS_TEST( 54 ); + PRIVATE_LOW_BITS_TEST( 53 ); + PRIVATE_LOW_BITS_TEST( 52 ); + PRIVATE_LOW_BITS_TEST( 51 ); + PRIVATE_LOW_BITS_TEST( 50 ); + PRIVATE_LOW_BITS_TEST( 49 ); + PRIVATE_LOW_BITS_TEST( 48 ); + PRIVATE_LOW_BITS_TEST( 47 ); + PRIVATE_LOW_BITS_TEST( 46 ); + PRIVATE_LOW_BITS_TEST( 45 ); + PRIVATE_LOW_BITS_TEST( 44 ); + PRIVATE_LOW_BITS_TEST( 43 ); + PRIVATE_LOW_BITS_TEST( 42 ); + PRIVATE_LOW_BITS_TEST( 41 ); + PRIVATE_LOW_BITS_TEST( 40 ); + PRIVATE_LOW_BITS_TEST( 39 ); + PRIVATE_LOW_BITS_TEST( 38 ); + PRIVATE_LOW_BITS_TEST( 37 ); + PRIVATE_LOW_BITS_TEST( 36 ); + PRIVATE_LOW_BITS_TEST( 35 ); + PRIVATE_LOW_BITS_TEST( 34 ); + PRIVATE_LOW_BITS_TEST( 33 ); +#endif + PRIVATE_LOW_BITS_TEST( 32 ); + PRIVATE_LOW_BITS_TEST( 31 ); + PRIVATE_LOW_BITS_TEST( 30 ); + PRIVATE_LOW_BITS_TEST( 29 ); + PRIVATE_LOW_BITS_TEST( 28 ); + PRIVATE_LOW_BITS_TEST( 27 ); + PRIVATE_LOW_BITS_TEST( 26 ); + PRIVATE_LOW_BITS_TEST( 25 ); + PRIVATE_LOW_BITS_TEST( 24 ); + PRIVATE_LOW_BITS_TEST( 23 ); + PRIVATE_LOW_BITS_TEST( 22 ); + PRIVATE_LOW_BITS_TEST( 21 ); + PRIVATE_LOW_BITS_TEST( 20 ); + PRIVATE_LOW_BITS_TEST( 19 ); + PRIVATE_LOW_BITS_TEST( 18 ); + PRIVATE_LOW_BITS_TEST( 17 ); + PRIVATE_LOW_BITS_TEST( 16 ); + PRIVATE_LOW_BITS_TEST( 15 ); + PRIVATE_LOW_BITS_TEST( 14 ); + PRIVATE_LOW_BITS_TEST( 13 ); + PRIVATE_LOW_BITS_TEST( 12 ); + PRIVATE_LOW_BITS_TEST( 11 ); + PRIVATE_LOW_BITS_TEST( 10 ); + PRIVATE_LOW_BITS_TEST( 9 ); + PRIVATE_LOW_BITS_TEST( 8 ); + PRIVATE_LOW_BITS_TEST( 7 ); + PRIVATE_LOW_BITS_TEST( 6 ); + PRIVATE_LOW_BITS_TEST( 5 ); + PRIVATE_LOW_BITS_TEST( 4 ); + PRIVATE_LOW_BITS_TEST( 3 ); + PRIVATE_LOW_BITS_TEST( 2 ); + PRIVATE_LOW_BITS_TEST( 1 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/integer/test/integer_test.cpp b/src/boost/libs/integer/test/integer_test.cpp new file mode 100644 index 00000000..a79db2d5 --- /dev/null +++ b/src/boost/libs/integer/test/integer_test.cpp @@ -0,0 +1,264 @@ +// boost integer.hpp test program ------------------------------------------// + +// Copyright Beman Dawes 1999. +// Copyright Daryle Walker 2001. +// Copyright John Maddock 2009. +// 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) + + +// See http://www.boost.org/libs/integer for documentation. + +// Revision History +// 04 Oct 01 Added tests for new templates; rewrote code (Daryle Walker) +// 10 Mar 01 Boost Test Library now used for tests (Beman Dawes) +// 31 Aug 99 Initial version + +#include <boost/detail/lightweight_test.hpp> // for main, BOOST_TEST +#include <boost/integer.hpp> // for boost::int_t, boost::uint_t +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/bool.hpp> // for mpl::true_ and false_ + +#include <climits> // for ULONG_MAX, LONG_MAX, LONG_MIN +#include <iostream> // for std::cout (std::endl indirectly) +#include <typeinfo> // for std::type_info + +#ifdef BOOST_MSVC +#pragma warning(disable:4127) // conditional expression is constant +#endif +#if defined( __BORLANDC__ ) +# pragma option -w-8008 -w-8066 // condition is always true +#endif + +// +// Keep track of error count, so we can print out detailed +// info only if we need it: +// +int last_error_count = 0; +// +// Helpers to print out the name of a type, +// we use these as typeid(X).name() doesn't always +// return a human readable string: +// +template <class T> const char* get_name_of_type(T){ return typeid(T).name(); } +const char* get_name_of_type(signed char){ return "signed char"; } +const char* get_name_of_type(unsigned char){ return "unsigned char"; } +const char* get_name_of_type(short){ return "short"; } +const char* get_name_of_type(unsigned short){ return "unsigned short"; } +const char* get_name_of_type(int){ return "int"; } +const char* get_name_of_type(unsigned int){ return "unsigned int"; } +const char* get_name_of_type(long){ return "long"; } +const char* get_name_of_type(unsigned long){ return "unsigned long"; } +#ifdef BOOST_HAS_LONG_LONG +const char* get_name_of_type(boost::long_long_type){ return "boost::long_long_type"; } +const char* get_name_of_type(boost::ulong_long_type){ return "boost::ulong_long_type"; } +#endif + +template <int Bits> +void do_test_exact(boost::mpl::true_ const&) +{ + // Test the ::exact member: + typedef typename boost::int_t<Bits>::exact int_exact; + typedef typename boost::uint_t<Bits>::exact uint_exact; + typedef typename boost::int_t<Bits>::least least_int; + typedef typename boost::uint_t<Bits>::least least_uint; + + BOOST_TEST((boost::is_same<int_exact, least_int>::value)); + BOOST_TEST((boost::is_same<uint_exact, least_uint>::value)); +} +template <int Bits> +void do_test_exact(boost::mpl::false_ const&) +{ + // Nothing to do, type does not have an ::extact member. +} + +template <int Bits> +void do_test_bits() +{ + // + // Recurse to next smallest number of bits: + // + do_test_bits<Bits - 1>(); + // + // Test exact types if we have them: + // + do_test_exact<Bits>( + boost::mpl::bool_< + (sizeof(unsigned char) * CHAR_BIT == Bits) + || (sizeof(unsigned short) * CHAR_BIT == Bits) + || (sizeof(unsigned int) * CHAR_BIT == Bits) + || (sizeof(unsigned long) * CHAR_BIT == Bits) +#ifdef BOOST_HAS_LONG_LONG + || (sizeof(boost::ulong_long_type) * CHAR_BIT == Bits) +#endif + >()); + // + // We need to check all aspects of the members of int_t<Bits> and uint_t<Bits>: + // + typedef typename boost::int_t<Bits>::least least_int; + typedef typename boost::int_t<Bits>::least fast_int; + typedef typename boost::uint_t<Bits>::least least_uint; + typedef typename boost::uint_t<Bits>::fast fast_uint; + + if(std::numeric_limits<least_int>::is_specialized) + { + BOOST_TEST(std::numeric_limits<least_int>::digits + 1 >= Bits); + } + if(std::numeric_limits<least_uint>::is_specialized) + { + BOOST_TEST(std::numeric_limits<least_uint>::digits >= Bits); + } + BOOST_TEST(sizeof(least_int) * CHAR_BIT >= Bits); + BOOST_TEST(sizeof(least_uint) * CHAR_BIT >= Bits); + BOOST_TEST(sizeof(fast_int) >= sizeof(least_int)); + BOOST_TEST(sizeof(fast_uint) >= sizeof(least_uint)); + // + // There should be no type smaller than least_* that also has enough bits: + // + if(!boost::is_same<signed char, least_int>::value) + { + BOOST_TEST(std::numeric_limits<signed char>::digits < Bits); + if(!boost::is_same<short, least_int>::value) + { + BOOST_TEST(std::numeric_limits<short>::digits < Bits); + if(!boost::is_same<int, least_int>::value) + { + BOOST_TEST(std::numeric_limits<int>::digits < Bits); + if(!boost::is_same<long, least_int>::value) + { + BOOST_TEST(std::numeric_limits<long>::digits < Bits); + } + } + } + } + // And again, but unsigned: + if(!boost::is_same<unsigned char, least_uint>::value) + { + BOOST_TEST(std::numeric_limits<unsigned char>::digits < Bits); + if(!boost::is_same<unsigned short, least_uint>::value) + { + BOOST_TEST(std::numeric_limits<unsigned short>::digits < Bits); + if(!boost::is_same<unsigned int, least_uint>::value) + { + BOOST_TEST(std::numeric_limits<unsigned int>::digits < Bits); + if(!boost::is_same<unsigned long, least_uint>::value) + { + BOOST_TEST(std::numeric_limits<unsigned long>::digits < Bits); + } + } + } + } + + if(boost::detail::test_errors() != last_error_count) + { + last_error_count = boost::detail::test_errors(); + std::cout << "Errors occurred while testing with bit count = " << Bits << std::endl; + std::cout << "Type int_t<" << Bits << ">::least was " << get_name_of_type(least_int(0)) << std::endl; + std::cout << "Type int_t<" << Bits << ">::fast was " << get_name_of_type(fast_int(0)) << std::endl; + std::cout << "Type uint_t<" << Bits << ">::least was " << get_name_of_type(least_uint(0)) << std::endl; + std::cout << "Type uint_t<" << Bits << ">::fast was " << get_name_of_type(fast_uint(0)) << std::endl; + } +} +template <> +void do_test_bits<-1>() +{ + // Nothing to do here!! +} + +template <class Traits, class Expected> +void test_min_max_type(Expected val) +{ + typedef typename Traits::least least_type; + typedef typename Traits::fast fast_type; + BOOST_TEST((boost::is_same<least_type, Expected>::value)); + BOOST_TEST(sizeof(fast_type) >= sizeof(least_type)); + BOOST_TEST((std::numeric_limits<least_type>::min)() <= val); + BOOST_TEST((std::numeric_limits<least_type>::max)() >= val); + + if(boost::detail::test_errors() != last_error_count) + { + last_error_count = boost::detail::test_errors(); + std::cout << "Traits type is: " << typeid(Traits).name() << std::endl; + std::cout << "Least type is: " << get_name_of_type(least_type(0)) << std::endl; + std::cout << "Fast type is: " << get_name_of_type(fast_type(0)) << std::endl; + std::cout << "Expected type is: " << get_name_of_type(Expected(0)) << std::endl; + std::cout << "Required value is: " << val << std::endl; + } +} + +// Test program +int main(int, char*[]) +{ + // Test int_t and unint_t first: + if(std::numeric_limits<boost::intmax_t>::is_specialized) + do_test_bits<std::numeric_limits<boost::uintmax_t>::digits>(); + else + do_test_bits<std::numeric_limits<long>::digits>(); + + // + // Test min and max value types: + // + test_min_max_type<boost::int_max_value_t<SCHAR_MAX>, signed char>(SCHAR_MAX); + test_min_max_type<boost::int_min_value_t<SCHAR_MIN>, signed char>(SCHAR_MIN); + test_min_max_type<boost::uint_value_t<UCHAR_MAX>, unsigned char>(UCHAR_MAX); +#if(USHRT_MAX != UCHAR_MAX) + test_min_max_type<boost::int_max_value_t<SCHAR_MAX+1>, short>(SCHAR_MAX+1); + test_min_max_type<boost::int_min_value_t<SCHAR_MIN-1>, short>(SCHAR_MIN-1); + test_min_max_type<boost::uint_value_t<UCHAR_MAX+1>, unsigned short>(UCHAR_MAX+1); + test_min_max_type<boost::int_max_value_t<SHRT_MAX>, short>(SHRT_MAX); + test_min_max_type<boost::int_min_value_t<SHRT_MIN>, short>(SHRT_MIN); + test_min_max_type<boost::uint_value_t<USHRT_MAX>, unsigned short>(USHRT_MAX); +#endif +#if(UINT_MAX != USHRT_MAX) + test_min_max_type<boost::int_max_value_t<SHRT_MAX+1>, int>(SHRT_MAX+1); + test_min_max_type<boost::int_min_value_t<SHRT_MIN-1>, int>(SHRT_MIN-1); + test_min_max_type<boost::uint_value_t<USHRT_MAX+1>, unsigned int>(USHRT_MAX+1); + test_min_max_type<boost::int_max_value_t<INT_MAX>, int>(INT_MAX); + test_min_max_type<boost::int_min_value_t<INT_MIN>, int>(INT_MIN); + test_min_max_type<boost::uint_value_t<UINT_MAX>, unsigned int>(UINT_MAX); +#endif +#if(ULONG_MAX != UINT_MAX) + test_min_max_type<boost::int_max_value_t<INT_MAX+1L>, long>(INT_MAX+1L); + test_min_max_type<boost::int_min_value_t<INT_MIN-1L>, long>(INT_MIN-1L); + test_min_max_type<boost::uint_value_t<UINT_MAX+1uL>, unsigned long>(UINT_MAX+1uL); + test_min_max_type<boost::int_max_value_t<LONG_MAX>, long>(LONG_MAX); + test_min_max_type<boost::int_min_value_t<LONG_MIN>, long>(LONG_MIN); + test_min_max_type<boost::uint_value_t<ULONG_MAX>, unsigned long>(ULONG_MAX); +#endif +#ifndef BOOST_NO_INTEGRAL_INT64_T +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULLONG_MAX) && (ULLONG_MAX != ULONG_MAX)) + test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type<boost::int_max_value_t<LLONG_MAX>, boost::long_long_type>(LLONG_MAX); + test_min_max_type<boost::int_min_value_t<LLONG_MIN>, boost::long_long_type>(LLONG_MIN); + test_min_max_type<boost::uint_value_t<ULLONG_MAX>, boost::ulong_long_type>(ULLONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONG_LONG_MAX) && (ULONG_LONG_MAX != ULONG_MAX)) + test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type<boost::int_max_value_t<LONG_LONG_MAX>, boost::long_long_type>(LONG_LONG_MAX); + test_min_max_type<boost::int_min_value_t<LONG_LONG_MIN>, boost::long_long_type>(LONG_LONG_MIN); + test_min_max_type<boost::uint_value_t<ULONG_LONG_MAX>, boost::ulong_long_type>(ULONG_LONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(ULONGLONG_MAX) && (ULONGLONG_MAX != ULONG_MAX)) + test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type<boost::int_max_value_t<LONGLONG_MAX>, boost::long_long_type>(LONGLONG_MAX); + test_min_max_type<boost::int_min_value_t<LONGLONG_MIN>, boost::long_long_type>(LONGLONG_MAX); + test_min_max_type<boost::uint_value_t<ULONGLONG_MAX>, boost::ulong_long_type>(ULONGLONG_MAX); +#endif +#if defined(BOOST_HAS_LONG_LONG) && (defined(_ULLONG_MAX) && defined(_LLONG_MIN) && (_ULLONG_MAX != ULONG_MAX)) + test_min_max_type<boost::int_max_value_t<LONG_MAX+1LL>, boost::long_long_type>(LONG_MAX+1LL); + test_min_max_type<boost::int_min_value_t<LONG_MIN-1LL>, boost::long_long_type>(LONG_MIN-1LL); + test_min_max_type<boost::uint_value_t<ULONG_MAX+1uLL>, boost::ulong_long_type>(ULONG_MAX+1uLL); + test_min_max_type<boost::int_max_value_t<_LLONG_MAX>, boost::long_long_type>(_LLONG_MAX); + test_min_max_type<boost::int_min_value_t<_LLONG_MIN>, boost::long_long_type>(_LLONG_MIN); + test_min_max_type<boost::uint_value_t<_ULLONG_MAX>, boost::ulong_long_type>(_ULLONG_MAX); +#endif // BOOST_HAS_LONG_LONG +#endif // BOOST_NO_INTEGRAL_INT64_T + return boost::report_errors(); +} diff --git a/src/boost/libs/integer/test/integer_traits_include_test.cpp b/src/boost/libs/integer/test/integer_traits_include_test.cpp new file mode 100644 index 00000000..a71fb33a --- /dev/null +++ b/src/boost/libs/integer/test/integer_traits_include_test.cpp @@ -0,0 +1,37 @@ +// Copyright John Maddock 2009. +// 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/integer_traits.hpp> // must be the only #include! + +template <class T> +void check_numeric_limits_derived(const std::numeric_limits<T>&){} + +template <class T> +void check() +{ + typedef boost::integer_traits<T> traits; + check_numeric_limits_derived(traits()); + bool b = traits::is_integral; + (void)b; + T v = traits::const_min + traits::const_max; + (void)v; +} + +int main() +{ + check<signed char>(); + check<unsigned char>(); + check<char>(); + check<short>(); + check<unsigned short>(); + check<int>(); + check<unsigned int>(); + check<signed long>(); + check<unsigned long>(); +#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG) + check<boost::long_long_type>(); + check<boost::ulong_long_type>(); +#endif +} diff --git a/src/boost/libs/integer/test/integer_traits_test.cpp b/src/boost/libs/integer/test/integer_traits_test.cpp new file mode 100644 index 00000000..b6e0d491 --- /dev/null +++ b/src/boost/libs/integer/test/integer_traits_test.cpp @@ -0,0 +1,101 @@ +/* boost integer_traits.hpp tests + * + * Copyright Jens Maurer 2000 + * 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$ + * + * Revision history + * 2000-02-22 Small improvements by Beman Dawes + * 2000-06-27 Rework for better MSVC and BCC co-operation + */ + +#include <iostream> +#include <boost/integer_traits.hpp> +// use int64_t instead of long long for better portability +#include <boost/cstdint.hpp> + +#include <boost/detail/lightweight_test.hpp> + +/* + * General portability note: + * MSVC mis-compiles explicit function template instantiations. + * For example, f<A>() and f<B>() are both compiled to call f<A>(). + * BCC is unable to implicitly convert a "const char *" to a std::string + * when using explicit function template instantiations. + * + * Therefore, avoid explicit function template instantiations. + */ + +#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300) +template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; } +namespace fix{ +inline int make_char_numeric_for_streaming(char c) { return c; } +inline int make_char_numeric_for_streaming(signed char c) { return c; } +inline int make_char_numeric_for_streaming(unsigned char c) { return c; } +} +using namespace fix; +#else +template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; } +inline int make_char_numeric_for_streaming(char c) { return c; } +inline int make_char_numeric_for_streaming(signed char c) { return c; } +inline int make_char_numeric_for_streaming(unsigned char c) { return c; } +#endif + +template<class T> +void runtest(const char * type, T) +{ + typedef boost::integer_traits<T> traits; + std::cout << "Checking " << type + << "; min is " << make_char_numeric_for_streaming((traits::min)()) + << ", max is " << make_char_numeric_for_streaming((traits::max)()) + << std::endl; + BOOST_TEST(traits::is_specialized); +#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200) + // MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler + // generates different symbol names with a very long common prefix: + // the dummy "&& true" disambiguates between the symbols generated by this + // BOOST_TEST instantiation and the preceding one. + BOOST_TEST(traits::is_integer && true); +#else + BOOST_TEST(traits::is_integer); +#endif + BOOST_TEST(traits::is_integral == true); + BOOST_TEST(traits::const_min == (traits::min)()); + BOOST_TEST(traits::const_max == (traits::max)()); +} + +int main(int, char*[]) +{ + runtest("bool", bool()); + runtest("char", char()); + typedef signed char signed_char; + runtest("signed char", signed_char()); + typedef unsigned char unsigned_char; + runtest("unsigned char", unsigned_char()); + runtest("wchar_t", wchar_t()); + runtest("short", short()); + typedef unsigned short unsigned_short; + runtest("unsigned short", unsigned_short()); + runtest("int", int()); + typedef unsigned int unsigned_int; + runtest("unsigned int", unsigned_int()); + runtest("long", long()); + typedef unsigned long unsigned_long; + runtest("unsigned long", unsigned_long()); +#ifndef BOOST_NO_INTEGRAL_INT64_T + // + // MS/Borland compilers can't support 64-bit member constants + // BeOS doesn't have specialisations for long long in SGI's <limits> header. + runtest("int64_t (possibly long long)", boost::int64_t()); + runtest("uint64_t (possibly unsigned long long)", boost::uint64_t()); +#else + std::cout << "Skipped int64_t and uint64_t" << std::endl; +#endif + // Some compilers don't pay attention to std:3.6.1/5 and issue a + // warning here if "return 0;" is omitted. + return boost::report_errors(); +} + diff --git a/src/boost/libs/integer/test/mod_inverse_test.cpp b/src/boost/libs/integer/test/mod_inverse_test.cpp new file mode 100644 index 00000000..729bbb35 --- /dev/null +++ b/src/boost/libs/integer/test/mod_inverse_test.cpp @@ -0,0 +1,71 @@ +/* + * (C) Copyright Nick Thompson 2018. + * Use, modification and distribution are subject to 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 "multiprecision_config.hpp" + +#ifndef DISABLE_MP_TESTS +#include <boost/integer/mod_inverse.hpp> +#include <boost/cstdint.hpp> +#include <boost/optional/optional.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/multiprecision/cpp_int.hpp> +#include <boost/integer/common_factor.hpp> + +using boost::multiprecision::int128_t; +using boost::multiprecision::int256_t; +using boost::integer::mod_inverse; +using boost::integer::gcd; + +template<class Z> +void test_mod_inverse() +{ + //Z max_arg = std::numeric_limits<Z>::max(); + Z max_arg = 500; + for (Z modulus = 2; modulus < max_arg; ++modulus) + { + if (modulus % 1000 == 0) + { + std::cout << "Testing all inverses modulo " << modulus << std::endl; + } + for (Z a = 1; a < modulus; ++a) + { + Z gcdam = gcd(a, modulus); + Z inv_a = mod_inverse(a, modulus); + // Should fail if gcd(a, mod) != 1: + if (gcdam > 1) + { + BOOST_TEST(inv_a == 0); + } + else + { + BOOST_TEST(inv_a > 0); + // Cast to a bigger type so the multiplication won't overflow. + int256_t a_inv = inv_a; + int256_t big_a = a; + int256_t m = modulus; + int256_t outta_be_one = (a_inv*big_a) % m; + BOOST_TEST_EQ(outta_be_one, 1); + } + } + } +} + +int main() +{ + test_mod_inverse<boost::int16_t>(); + test_mod_inverse<boost::int32_t>(); + test_mod_inverse<boost::int64_t>(); + test_mod_inverse<int128_t>(); + + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/integer/test/multiprecision_config.hpp b/src/boost/libs/integer/test/multiprecision_config.hpp new file mode 100644 index 00000000..e4231116 --- /dev/null +++ b/src/boost/libs/integer/test/multiprecision_config.hpp @@ -0,0 +1,18 @@ +// Copyright (c) 2018 Andrey Semashev +// +// Use, modification, and distribution is subject to 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_INTEGER_TEST_MULTIPRECISION_CONFIG_HPP_INCLUDED_ +#define BOOST_INTEGER_TEST_MULTIPRECISION_CONFIG_HPP_INCLUDED_ + +#include <boost/config.hpp> + +#if (defined(BOOST_MSVC) && (BOOST_MSVC < 1500)) || \ + (defined(__clang_major__) && (__clang_major__ == 3) && (__clang_minor__ < 2)) || \ + (defined(BOOST_GCC) && defined(BOOST_GCC_CXX11) && BOOST_GCC < 40800) +#define DISABLE_MP_TESTS +#endif + +#endif // BOOST_INTEGER_TEST_MULTIPRECISION_CONFIG_HPP_INCLUDED_ diff --git a/src/boost/libs/integer/test/static_log2_include_test.cpp b/src/boost/libs/integer/test/static_log2_include_test.cpp new file mode 100644 index 00000000..d39b871c --- /dev/null +++ b/src/boost/libs/integer/test/static_log2_include_test.cpp @@ -0,0 +1,14 @@ +// Copyright John Maddock 2009. +// 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/integer/static_log2.hpp> // must be the only #include! + +int main() +{ + boost::static_log2_argument_type arg = 0; + (void)arg; + boost::static_log2_result_type result = boost::static_log2<30>::value; + (void)result; +} diff --git a/src/boost/libs/integer/test/static_log2_test.cpp b/src/boost/libs/integer/test/static_log2_test.cpp new file mode 100644 index 00000000..f92d8017 --- /dev/null +++ b/src/boost/libs/integer/test/static_log2_test.cpp @@ -0,0 +1,149 @@ +// Boost static_log2.hpp test program --------------------------------------// + +// (C) Copyright Daryle Walker 2001. +// 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) + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 01 Oct 2001 Initial version (Daryle Walker) + +#include <boost/detail/lightweight_test.hpp> // for main + +#include <boost/cstdlib.hpp> // for boost::exit_success +#include <boost/integer/static_log2.hpp> // for boost::static_log2 + +#include <iostream> // for std::cout (std::endl indirectly) + + +// Macros to compact code +#define PRIVATE_LB_TEST( v, e ) BOOST_TEST( ::boost::static_log2<v>::value == e ) + +#define PRIVATE_PRINT_LB( v ) ::std::cout << "boost::static_log2<" << (v) \ + << "> = " << ::boost::static_log2< (v) >::value << '.' << ::std::endl + +// Control to check for a compile-time error +#ifndef CONTROL_LB_0_TEST +#define PRIVATE_LB_0_TEST +#else +#define PRIVATE_LB_0_TEST PRIVATE_PRINT_LB( 0 ) +#endif + + +// Main testing function +int +main +( + int , // "argc" is unused + char * [] // "argv" is unused +) +{ + std::cout << "Doing tests on static_log2." << std::endl; + + PRIVATE_LB_0_TEST; + + PRIVATE_LB_TEST( 1, 0 ); + + PRIVATE_LB_TEST( 2, 1 ); + PRIVATE_LB_TEST( 3, 1 ); + + PRIVATE_LB_TEST( 4, 2 ); + PRIVATE_LB_TEST( 5, 2 ); + PRIVATE_LB_TEST( 6, 2 ); + PRIVATE_LB_TEST( 7, 2 ); + + PRIVATE_LB_TEST( 8, 3 ); + PRIVATE_LB_TEST( 9, 3 ); + PRIVATE_LB_TEST( 10, 3 ); + PRIVATE_LB_TEST( 11, 3 ); + PRIVATE_LB_TEST( 12, 3 ); + PRIVATE_LB_TEST( 13, 3 ); + PRIVATE_LB_TEST( 14, 3 ); + PRIVATE_LB_TEST( 15, 3 ); + + PRIVATE_LB_TEST( 16, 4 ); + PRIVATE_LB_TEST( 17, 4 ); + PRIVATE_LB_TEST( 18, 4 ); + PRIVATE_LB_TEST( 19, 4 ); + PRIVATE_LB_TEST( 20, 4 ); + PRIVATE_LB_TEST( 21, 4 ); + PRIVATE_LB_TEST( 22, 4 ); + PRIVATE_LB_TEST( 23, 4 ); + PRIVATE_LB_TEST( 24, 4 ); + PRIVATE_LB_TEST( 25, 4 ); + PRIVATE_LB_TEST( 26, 4 ); + PRIVATE_LB_TEST( 27, 4 ); + PRIVATE_LB_TEST( 28, 4 ); + PRIVATE_LB_TEST( 29, 4 ); + PRIVATE_LB_TEST( 30, 4 ); + PRIVATE_LB_TEST( 31, 4 ); + + PRIVATE_LB_TEST( 32, 5 ); + PRIVATE_LB_TEST( 33, 5 ); + PRIVATE_LB_TEST( 34, 5 ); + PRIVATE_LB_TEST( 35, 5 ); + PRIVATE_LB_TEST( 36, 5 ); + PRIVATE_LB_TEST( 37, 5 ); + PRIVATE_LB_TEST( 38, 5 ); + PRIVATE_LB_TEST( 39, 5 ); + PRIVATE_LB_TEST( 40, 5 ); + + PRIVATE_LB_TEST( 63, 5 ); + + PRIVATE_LB_TEST( 64, 6 ); + PRIVATE_LB_TEST( 65, 6 ); + + PRIVATE_LB_TEST( 127, 6 ); + + PRIVATE_LB_TEST( 128, 7 ); + PRIVATE_LB_TEST( 129, 7 ); + + PRIVATE_LB_TEST( 255, 7 ); + + PRIVATE_LB_TEST( 256, 8 ); + PRIVATE_LB_TEST( 257, 8 ); + + PRIVATE_LB_TEST( 511, 8 ); + + PRIVATE_LB_TEST( 512, 9 ); + PRIVATE_LB_TEST( 513, 9 ); + + PRIVATE_LB_TEST( 1023, 9 ); + + PRIVATE_LB_TEST( 1024, 10 ); + PRIVATE_LB_TEST( 1025, 10 ); + + PRIVATE_LB_TEST( 2047, 10 ); + + PRIVATE_LB_TEST( 2048, 11 ); + PRIVATE_LB_TEST( 2049, 11 ); + + PRIVATE_LB_TEST( 4095, 11 ); + + PRIVATE_LB_TEST( 4096, 12 ); + PRIVATE_LB_TEST( 4097, 12 ); + + PRIVATE_LB_TEST( 8191, 12 ); + + PRIVATE_LB_TEST( 8192, 13 ); + PRIVATE_LB_TEST( 8193, 13 ); + + PRIVATE_LB_TEST( 16383, 13 ); + + PRIVATE_LB_TEST( 16384, 14 ); + PRIVATE_LB_TEST( 16385, 14 ); + + PRIVATE_LB_TEST( 32767, 14 ); + + PRIVATE_LB_TEST( 32768, 15 ); + PRIVATE_LB_TEST( 32769, 15 ); + + PRIVATE_LB_TEST( 65535, 15 ); + + PRIVATE_LB_TEST( 65536, 16 ); + PRIVATE_LB_TEST( 65537, 16 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/integer/test/static_min_max_include_test.cpp b/src/boost/libs/integer/test/static_min_max_include_test.cpp new file mode 100644 index 00000000..80550622 --- /dev/null +++ b/src/boost/libs/integer/test/static_min_max_include_test.cpp @@ -0,0 +1,14 @@ +// Copyright John Maddock 2009. +// 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/integer/static_min_max.hpp> // must be the only #include! + +int main() +{ + boost::static_min_max_signed_type m = boost::static_signed_min<2, 3>::value + boost::static_signed_max<2, 3>::value; + (void)m; + boost::static_min_max_unsigned_type u = boost::static_unsigned_min<2, 3>::value + boost::static_unsigned_max<2, 3>::value; + (void)u; +} diff --git a/src/boost/libs/integer/test/static_min_max_test.cpp b/src/boost/libs/integer/test/static_min_max_test.cpp new file mode 100644 index 00000000..124e137b --- /dev/null +++ b/src/boost/libs/integer/test/static_min_max_test.cpp @@ -0,0 +1,92 @@ +// Boost static_min_max.hpp test program -----------------------------------// + +// (C) Copyright Daryle Walker 2001. +// 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) + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 23 Sep 2001 Initial version (Daryle Walker) + +#include <boost/detail/lightweight_test.hpp> // for main, BOOST_TEST + +#include <boost/cstdlib.hpp> // for boost::exit_success +#include <boost/integer/static_min_max.hpp> // for boost::static_signed_min, etc. + +#include <iostream> // for std::cout (std::endl indirectly) + + +// Main testing function +int +main +( + int , // "argc" is unused + char * [] // "argv" is unused +) +{ + using std::cout; + using std::endl; + using boost::static_signed_min; + using boost::static_signed_max; + using boost::static_unsigned_min; + using boost::static_unsigned_max; + + // Two positives + cout << "Doing tests with two positive values." << endl; + + BOOST_TEST( (static_signed_min< 9, 14>::value) == 9 ); + BOOST_TEST( (static_signed_max< 9, 14>::value) == 14 ); + BOOST_TEST( (static_signed_min<14, 9>::value) == 9 ); + BOOST_TEST( (static_signed_max<14, 9>::value) == 14 ); + + BOOST_TEST( (static_unsigned_min< 9, 14>::value) == 9 ); + BOOST_TEST( (static_unsigned_max< 9, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_min<14, 9>::value) == 9 ); + BOOST_TEST( (static_unsigned_max<14, 9>::value) == 14 ); + + // Two negatives + cout << "Doing tests with two negative values." << endl; + + BOOST_TEST( (static_signed_min< -8, -101>::value) == -101 ); + BOOST_TEST( (static_signed_max< -8, -101>::value) == -8 ); + BOOST_TEST( (static_signed_min<-101, -8>::value) == -101 ); + BOOST_TEST( (static_signed_max<-101, -8>::value) == -8 ); + + // With zero + cout << "Doing tests with zero and a positive or negative value." << endl; + + BOOST_TEST( (static_signed_min< 0, 14>::value) == 0 ); + BOOST_TEST( (static_signed_max< 0, 14>::value) == 14 ); + BOOST_TEST( (static_signed_min<14, 0>::value) == 0 ); + BOOST_TEST( (static_signed_max<14, 0>::value) == 14 ); + + BOOST_TEST( (static_unsigned_min< 0, 14>::value) == 0 ); + BOOST_TEST( (static_unsigned_max< 0, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_min<14, 0>::value) == 0 ); + BOOST_TEST( (static_unsigned_max<14, 0>::value) == 14 ); + + BOOST_TEST( (static_signed_min< 0, -101>::value) == -101 ); + BOOST_TEST( (static_signed_max< 0, -101>::value) == 0 ); + BOOST_TEST( (static_signed_min<-101, 0>::value) == -101 ); + BOOST_TEST( (static_signed_max<-101, 0>::value) == 0 ); + + // With identical + cout << "Doing tests with two identical values." << endl; + + BOOST_TEST( (static_signed_min<0, 0>::value) == 0 ); + BOOST_TEST( (static_signed_max<0, 0>::value) == 0 ); + BOOST_TEST( (static_unsigned_min<0, 0>::value) == 0 ); + BOOST_TEST( (static_unsigned_max<0, 0>::value) == 0 ); + + BOOST_TEST( (static_signed_min<14, 14>::value) == 14 ); + BOOST_TEST( (static_signed_max<14, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_min<14, 14>::value) == 14 ); + BOOST_TEST( (static_unsigned_max<14, 14>::value) == 14 ); + + BOOST_TEST( (static_signed_min< -101, -101>::value) == -101 ); + BOOST_TEST( (static_signed_max< -101, -101>::value) == -101 ); + + return boost::report_errors(); +} |