mirror of
https://github.com/boostorg/integer.git
synced 2026-01-19 16:22:19 +00:00
Compare commits
3 Commits
boost-1.66
...
doc_revisi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c86f9a11a | ||
|
|
b82f5a792b | ||
|
|
2de3837ca6 |
348
.travis.yml
348
.travis.yml
@@ -1,348 +0,0 @@
|
||||
# Copyright 2016, 2017 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
language: cpp
|
||||
|
||||
sudo: false
|
||||
|
||||
python: "2.7"
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
|
||||
env:
|
||||
matrix:
|
||||
- BOGUS_JOB=true
|
||||
|
||||
matrix:
|
||||
|
||||
exclude:
|
||||
- env: BOGUS_JOB=true
|
||||
|
||||
include:
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++ CXXSTD=c++03
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- g++-6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.5
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.5
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.6
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.6
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.6
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.7
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.8
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.8
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++03
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++11
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++14
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: linux
|
||||
env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=c++1z
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.9
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.9
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++14
|
||||
|
||||
- os: osx
|
||||
env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++1z
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b $TRAVIS_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init libs/core
|
||||
- git submodule update --init libs/detail
|
||||
- git submodule update --init libs/assert
|
||||
- git submodule update --init libs/static_assert
|
||||
- git submodule update --init libs/type_traits
|
||||
- git submodule update --init libs/mpl
|
||||
- git submodule update --init libs/preprocessor
|
||||
- git submodule update --init libs/multiprecision
|
||||
- git submodule update --init libs/math
|
||||
- git submodule update --init libs/rational
|
||||
- git submodule update --init libs/throw_exception
|
||||
- git submodule update --init libs/predef
|
||||
- git submodule update --init libs/lexical_cast
|
||||
- git submodule update --init libs/range
|
||||
- git submodule update --init libs/iterator
|
||||
- git submodule update --init libs/concept_check
|
||||
- git submodule update --init libs/numeric
|
||||
- git submodule update --init libs/array
|
||||
- git submodule update --init libs/container
|
||||
- git submodule update --init libs/move
|
||||
- git submodule update --init libs/functional
|
||||
- git submodule update --init libs/random
|
||||
- git submodule update --init libs/utility
|
||||
- cp -r $TRAVIS_BUILD_DIR/* libs/integer
|
||||
- ./bootstrap.sh
|
||||
- ./b2 headers
|
||||
|
||||
script:
|
||||
- |-
|
||||
echo "using $TOOLSET : : $COMPILER : <cxxflags>-std=$CXXSTD ;" > ~/user-config.jam
|
||||
- ./b2 libs/integer/test toolset=$TOOLSET
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: always
|
||||
83
appveyor.yml
83
appveyor.yml
@@ -1,83 +0,0 @@
|
||||
# Copyright 2016 Peter Dimov
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
|
||||
|
||||
version: 1.0.{build}-{branch}
|
||||
|
||||
shallow_clone: true
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- develop
|
||||
|
||||
platform:
|
||||
- x64
|
||||
|
||||
environment:
|
||||
matrix:
|
||||
- ARGS: --toolset=msvc-9.0 address-model=32
|
||||
- ARGS: --toolset=msvc-10.0 address-model=32
|
||||
- ARGS: --toolset=msvc-11.0 address-model=32
|
||||
- ARGS: --toolset=msvc-12.0 address-model=32
|
||||
- ARGS: --toolset=msvc-14.0 address-model=32
|
||||
- ARGS: --toolset=msvc-12.0 address-model=64
|
||||
- ARGS: --toolset=msvc-14.0 address-model=64
|
||||
- ARGS: --toolset=msvc-14.0 address-model=64 cxxflags=-std:c++latest
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARGS: --toolset=msvc-14.1 address-model=64
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARGS: --toolset=msvc-14.1 address-model=32
|
||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||
ARGS: --toolset=msvc-14.1 address-model=64 cxxflags=-std:c++latest
|
||||
- ARGS: --toolset=gcc address-model=64
|
||||
PATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%
|
||||
- ARGS: --toolset=gcc address-model=64 cxxflags=-std=gnu++1z
|
||||
PATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;%PATH%
|
||||
- ARGS: --toolset=gcc address-model=32
|
||||
PATH: C:\mingw-w64\i686-5.3.0-posix-dwarf-rt_v4-rev0\mingw32\bin;%PATH%
|
||||
- ARGS: --toolset=gcc address-model=32 linkflags=-Wl,-allow-multiple-definition
|
||||
PATH: C:\MinGW\bin;%PATH%
|
||||
|
||||
|
||||
install:
|
||||
- cd ..
|
||||
- git clone -b %APPVEYOR_REPO_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
|
||||
- cd boost-root
|
||||
- git submodule update --init tools/build
|
||||
- git submodule update --init libs/config
|
||||
- git submodule update --init libs/core
|
||||
- git submodule update --init libs/detail
|
||||
- git submodule update --init libs/assert
|
||||
- git submodule update --init libs/static_assert
|
||||
- git submodule update --init libs/type_traits
|
||||
- git submodule update --init libs/mpl
|
||||
- git submodule update --init libs/preprocessor
|
||||
- git submodule update --init libs/multiprecision
|
||||
- git submodule update --init libs/math
|
||||
- git submodule update --init libs/rational
|
||||
- git submodule update --init libs/throw_exception
|
||||
- git submodule update --init libs/predef
|
||||
- git submodule update --init libs/lexical_cast
|
||||
- git submodule update --init libs/range
|
||||
- git submodule update --init libs/iterator
|
||||
- git submodule update --init libs/concept_check
|
||||
- git submodule update --init libs/numeric
|
||||
- git submodule update --init libs/array
|
||||
- git submodule update --init libs/container
|
||||
- git submodule update --init libs/move
|
||||
- git submodule update --init libs/functional
|
||||
- git submodule update --init libs/random
|
||||
- git submodule update --init libs/utility
|
||||
- xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\integer
|
||||
- bootstrap
|
||||
- b2 headers
|
||||
|
||||
build: off
|
||||
|
||||
test_script:
|
||||
- cd libs\config\test
|
||||
- ..\..\..\b2 config_info_travis_install %ARGS%
|
||||
- config_info_travis
|
||||
- cd ..\..\integer\test
|
||||
- ..\..\..\b2 -j3 %ARGS% define=CI_SUPPRESS_KNOWN_ISSUES
|
||||
105
doc/Jamfile.v2
105
doc/Jamfile.v2
@@ -1,12 +1,88 @@
|
||||
|
||||
# jamfile to build Boost.Integer Documentation.
|
||||
|
||||
# Copyright John Maddock 2005. 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)
|
||||
|
||||
using quickbook ;
|
||||
# Revised to include Doxygen and Autoindex, and code snippets from examples.
|
||||
# Copyright Paul A. Bristow 2015
|
||||
|
||||
using boostbook ;
|
||||
using doxygen ; # Required if you want to use Doxygen.
|
||||
using quickbook ;
|
||||
using auto-index ;
|
||||
|
||||
path-constant here : . ; # convenient to refer to files in the same directory as this jamfile.v2
|
||||
path-constant parent : .. ; # Parent directory, /libs/integer/
|
||||
|
||||
if --enable-index in [ modules.peek : ARGV ]
|
||||
{
|
||||
ECHO "Building the Integer docs with automatic index generation enabled." ;
|
||||
using auto-index ;
|
||||
project integer_doc : requirements
|
||||
<auto-index>on
|
||||
<auto-index-script>integer.idx
|
||||
<auto-index-prefix>.
|
||||
<auto-index-verbose>on
|
||||
<format>html:<auto-index-internal>on
|
||||
<format>html:<xsl:param>generate.index=0
|
||||
<format>pdf:<auto-index-internal>on
|
||||
<format>pdf:<xsl:param>index.on.type=1
|
||||
<quickbook-define>enable_index ;
|
||||
}
|
||||
else
|
||||
{
|
||||
project integer_doc ;
|
||||
ECHO "Building the Integer docs with automatic index generation disabled. Try building with --enable-index." ;
|
||||
}
|
||||
|
||||
|
||||
xml integer
|
||||
:
|
||||
integer.qbk # This is 'root' Quickbook file (that may include other .qbk files).
|
||||
;
|
||||
|
||||
doxygen autodoc
|
||||
:
|
||||
[ glob $(here)/../include/boost/*.hpp ]
|
||||
[ glob $(here)/../include/boost/integer/*.hpp ]
|
||||
# but could also include this and switch Boost.Integer C++ reference info to include implementation details (or not) using Doxygen macro DETAIL.
|
||||
# See http://www.stack.nl/~dimitri/doxygen/manual/commands.html#cmdcond
|
||||
# and http://www.stack.nl/~dimitri/doxygen/manual/config.html#cfg_enabled_sections
|
||||
# by adding this line below with other Doxygen parameters
|
||||
# <doxygen:param>ENABLED_SECTIONS="DETAIL"
|
||||
# Or setting this macro value ENABLED_SECTIONS="DETAIL" in /doxygen/integer_doxyfile.txt for Standalone Doxygen documentaation.
|
||||
# This might be useful for maintainers.
|
||||
|
||||
:
|
||||
<doxygen:param>PROJECT_NAME="Integer"
|
||||
<doxygen:param>RECURSIVE=NO # Specify all folders and files above explicitly.
|
||||
<doxygen:param>ENABLE_PREPROCESSING=YES
|
||||
<doxygen:param>EXPAND_ONLY_PREDEF=YES
|
||||
<doxygen:param>EXTRACT_ALL=NO
|
||||
<doxygen:param>EXTRACT_PRIVATE=NO
|
||||
<doxygen:param>HIDE_UNDOC_MEMBERS=YES
|
||||
<doxygen:param>MACRO_EXPANSION=YES
|
||||
<doxygen:param>SORT_MEMBER_DOCS=NO
|
||||
<doxygen:param>SHOW_INCLUDE_FILES=NO
|
||||
<doxygen:param>MAX_INITIALIZER_LINES=0
|
||||
<doxygen:param>VERBATIM_HEADERS=NO
|
||||
<doxygen:param>WARNINGS=NO # If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings for undocumented members.
|
||||
# If EXTRACT_ALL is set to YES then this flag will automatically be disabled.
|
||||
<doxygen:param>WARN_IF_UNDOCUMENTED=YES # If WARN_IF_UNDOCUMENTED is set to YES,
|
||||
# then doxygen will generate warnings for all undocumented members.
|
||||
<doxygen:param>WARN_IF_DOC_ERROR=YES # If WARN_IF_DOC_ERROR is set to YES, Doxygen will generate warnings for
|
||||
# potential errors in the documentation.
|
||||
<doxygen:param>WARN_LOGFILE=AutoDoxywarnings.log # This may not be empty (usually not a good sign!), depending on options chosen.
|
||||
# Much better to send message to a logfile than the default stderr.
|
||||
# and make sure that there are no Doxygen errors or significant warnings in the log file.
|
||||
|
||||
#<reftitle>"Reference" # Default is "Reference" but helpful to specify library.
|
||||
<xsl:param>"boost.doxygen.reftitle=Boost.Integer C++ Reference"
|
||||
# See Doxygen configuration for detailed explanation of these options.
|
||||
# Usually these match those in /doc/doxygen/integer_doxyfile.txt.
|
||||
;
|
||||
|
||||
xml integer : integer.qbk ;
|
||||
boostbook standalone
|
||||
:
|
||||
integer
|
||||
@@ -14,6 +90,7 @@ boostbook standalone
|
||||
# HTML options first:
|
||||
# Use graphics not text for navigation:
|
||||
<xsl:param>navig.graphics=1
|
||||
<xsl:param>chapter.autolabel=0 # No Chapter numbering.
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=1
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
@@ -26,7 +103,7 @@ boostbook standalone
|
||||
<xsl:param>generate.section.toc.level=4
|
||||
# Path for links to Boost:
|
||||
<xsl:param>boost.root=../../../..
|
||||
|
||||
|
||||
# PDF Options:
|
||||
# TOC Generation: this is needed for FOP-0.9 and later:
|
||||
<xsl:param>fop1.extensions=0
|
||||
@@ -47,14 +124,20 @@ boostbook standalone
|
||||
# better use SVG's instead:
|
||||
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
|
||||
<format>pdf:<xsl:param>admon.graphics.path=$(boost-images)/
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/regex/doc/html
|
||||
# Use Arial for PDF.
|
||||
<format>pdf:<xsl:param>title.font.family="sans-serif"
|
||||
<format>pdf:<xsl:param>body.font.family="sans-serif"
|
||||
<format>pdf:<xsl:param>monospace.font.family="sans-serif"
|
||||
|
||||
<dependency>autodoc # Add Doxygen info.
|
||||
|
||||
;
|
||||
|
||||
install pdfinstall : standalone/<format>pdf : <location>. <install-type>PDF ;
|
||||
# install pdfinstall : standalone/<format>pdf : <location>. <install-type>PDF <name>boost.pdf ;
|
||||
|
||||
|
||||
install pdf-install : standalone : <install-type>PDF <location>. <name>integer.pdf ;
|
||||
|
||||
explicit pdfinstall ;
|
||||
|
||||
###############################################################################
|
||||
alias boostdoc ;
|
||||
explicit boostdoc ;
|
||||
alias boostrelease : standalone ;
|
||||
explicit boostrelease ;
|
||||
|
||||
|
||||
0
doc/doxygen/boost-no-inspect
Normal file
0
doc/doxygen/boost-no-inspect
Normal file
2433
doc/doxygen/integer_doxyfile.txt
Normal file
2433
doc/doxygen/integer_doxyfile.txt
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
|
||||
[section:gcd_lcm Greatest Common Divisor and Least Common Multiple]
|
||||
[mathpart gcd_lcm Integer Utilities (Greatest Common Divisor and Least Common Multiple)]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
@@ -24,20 +24,9 @@ programming problems.
|
||||
class lcm_evaluator;
|
||||
|
||||
template < typename IntegerType >
|
||||
constexpr IntegerType gcd( IntegerType const &a, IntegerType const &b );
|
||||
IntegerType gcd( IntegerType const &a, IntegerType const &b );
|
||||
template < typename IntegerType >
|
||||
constexpr IntegerType lcm( IntegerType const &a, IntegerType const &b );
|
||||
template < typename IntegerType, typename... Args >
|
||||
constexpr IntegerType gcd( IntegerType const &a, IntegerType const &b, Args const&... );
|
||||
template < typename IntegerType, typename... Args >
|
||||
constexpr IntegerType lcm( IntegerType const &a, IntegerType const &b, Args const&... );
|
||||
|
||||
template <typename I>
|
||||
std::pair<typename std::iterator_traits<I>::value_type, I>
|
||||
gcd_range(I first, I last);
|
||||
template <typename I>
|
||||
std::pair<typename std::iterator_traits<I>::value_type, I>
|
||||
lcm_range(I first, I last);
|
||||
IntegerType lcm( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
typedef ``['see-below]`` static_gcd_type;
|
||||
|
||||
@@ -65,9 +54,8 @@ programming problems.
|
||||
typedef IntegerType second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
constexpr result_type operator ()(
|
||||
first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
result_type operator ()( first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
};
|
||||
|
||||
The boost::math::gcd_evaluator class template defines a function object
|
||||
@@ -82,9 +70,6 @@ the GCD function template. If a numeric type wants to customize evaluations
|
||||
of its greatest common divisors, then the type should specialize on the
|
||||
gcd_evaluator class template.
|
||||
|
||||
Note that these function objects are `constexpr` in C++14 and later only.
|
||||
They are also declared `noexcept` when appropriate.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section LCM Function Object]
|
||||
@@ -101,9 +86,8 @@ They are also declared `noexcept` when appropriate.
|
||||
typedef IntegerType second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
constexpr result_type operator ()(
|
||||
first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
result_type operator ()( first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
};
|
||||
|
||||
The boost::math::lcm_evaluator class template defines a function object
|
||||
@@ -119,9 +103,6 @@ of the LCM function template. If a numeric type wants to customize
|
||||
evaluations of its least common multiples, then the type should
|
||||
specialize on the lcm_evaluator class template.
|
||||
|
||||
Note that these function objects are constexpr in C++14 and later only.
|
||||
They are also declared `noexcept` when appropriate.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:run_time Run-time GCD & LCM Determination]
|
||||
@@ -129,48 +110,24 @@ They are also declared `noexcept` when appropriate.
|
||||
[*Header: ] [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>]
|
||||
|
||||
template < typename IntegerType >
|
||||
constexpr IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b );
|
||||
IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
template < typename IntegerType >
|
||||
constexpr IntegerType boost::math::lcm( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
template < typename IntegerType, typename... Args >
|
||||
constexpr IntegerType gcd( IntegerType const &a, IntegerType const &b, Args const&... );
|
||||
|
||||
template < typename IntegerType, typename... Args >
|
||||
constexpr IntegerType lcm( IntegerType const &a, IntegerType const &b, Args const&... );
|
||||
|
||||
template <typename I>
|
||||
std::pair<typename std::iterator_traits<I>::value_type, I>
|
||||
gcd_range(I first, I last);
|
||||
|
||||
template <typename I>
|
||||
std::pair<typename std::iterator_traits<I>::value_type, I>
|
||||
lcm_range(I first, I last);
|
||||
IntegerType boost::math::lcm( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
The boost::math::gcd function template returns the greatest common
|
||||
(nonnegative) divisor of the two integers passed to it.
|
||||
`boost::math::gcd_range` is the iteration of the above gcd algorithm over a
|
||||
range, returning the greatest common divisor of all the elements. The algorithm
|
||||
terminates when the gcd reaches unity or the end of the range. Thus it also
|
||||
returns the iterator after the last element inspected because this may not be
|
||||
equal to the end of the range. The variadic version of `gcd` behaves similarly
|
||||
but does not indicate which input value caused the gcd to reach unity.
|
||||
|
||||
The boost::math::lcm function template returns the least common
|
||||
(nonnegative) multiple of the two integers passed to it.
|
||||
As with gcd, there are range and variadic versions of the function for
|
||||
more than 2 arguments.
|
||||
|
||||
Note that these functions are constexpr in C++14 and later only.
|
||||
They are also declared `noexcept` when appropriate.
|
||||
The function templates are parameterized on the function arguments'
|
||||
IntegerType, which is also the return type. Internally, these function
|
||||
templates use an object of the corresponding version of the
|
||||
gcd_evaluator and lcm_evaluator class templates, respectively.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:compile_time Compile time GCD and LCM determination]
|
||||
|
||||
[note These functions are deprecated in favor of constexpr `gcd` and `lcm` on C++14 capable compilers.]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_ct.hpp <boost/math/common_factor_ct.hpp>]
|
||||
|
||||
typedef ``['unspecified]`` static_gcd_type;
|
||||
@@ -262,8 +219,6 @@ code factoring and eases maintainence.
|
||||
|
||||
[section:gcd_history History]
|
||||
|
||||
* 24th April 2017 Moved to Jeremy Murphy's improved algorithms, added constexpr and noexcept support,
|
||||
added compiler intrinsic support, added variadic and range based versions of the algorithms.
|
||||
* 13 May 2013 Moved into main Boost.Math Quickbook documentation.
|
||||
* 17 Dec 2005: Converted documentation to Quickbook Format.
|
||||
* 2 Jul 2002: Compile-time and run-time items separated to new headers.
|
||||
@@ -280,7 +235,7 @@ pool library. The code had updates by Helmut Zeisel.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endsect]
|
||||
[endmathpart]
|
||||
|
||||
[/
|
||||
Copyright 2005, 2013 Daryle Walker.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Removed from library: Standard Integer Types</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="history.html" title="History">
|
||||
|
||||
@@ -1,400 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Greatest Common Divisor and Least Common Multiple</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="integer.html" title="Integer Type Selection">
|
||||
<link rel="next" href="mask.html" title="Integer Masks">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
|
||||
<td align="center"><a href="../../../../../index.html">Home</a></td>
|
||||
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||||
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.gcd_lcm"></a><a class="link" href="gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">Greatest Common Divisor and Least
|
||||
Common Multiple</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.introduction">Introduction</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_function_object">GCD Function
|
||||
Object</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.lcm_function_object">LCM Function
|
||||
Object</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.run_time">Run-time GCD & LCM
|
||||
Determination</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.compile_time">Compile time GCD
|
||||
and LCM determination</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_header">Header <boost/math/common_factor.hpp></a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.demo">Demonstration Program</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.rationale">Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_history">History</a></span></dt>
|
||||
<dt><span class="section"><a href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_credits">Credits</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.introduction"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.introduction" title="Introduction">Introduction</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The class and function templates in <boost/math/common_factor.hpp>
|
||||
provide run-time and compile-time evaluation of the greatest common divisor
|
||||
(GCD) or least common multiple (LCM) of two integers. These facilities are
|
||||
useful for many numeric-oriented generic programming problems.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.synopsis"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">namespace</span> <span class="identifier">math</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">gcd_evaluator</span><span class="special">;</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">lcm_evaluator</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">gcd_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">lcm_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>see-below</em></span> <span class="identifier">static_gcd_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_gcd</span><span class="special">;</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_lcm</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_function_object"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_function_object" title="GCD Function Object">GCD Function
|
||||
Object</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd_evaluator</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="comment">// Types</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">result_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">first_argument_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">second_argument_type</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Function object interface</span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">result_type</span> <span class="keyword">operator</span> <span class="special">()(</span>
|
||||
<span class="identifier">first_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span>
|
||||
<span class="identifier">second_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
The boost::math::gcd_evaluator class template defines a function object class
|
||||
to return the greatest common divisor of two integers. The template is parameterized
|
||||
by a single type, called IntegerType here. This type should be a numeric
|
||||
type that represents integers. The result of the function object is always
|
||||
nonnegative, even if either of the operator arguments is negative.
|
||||
</p>
|
||||
<p>
|
||||
This function object class template is used in the corresponding version
|
||||
of the GCD function template. If a numeric type wants to customize evaluations
|
||||
of its greatest common divisors, then the type should specialize on the gcd_evaluator
|
||||
class template.
|
||||
</p>
|
||||
<p>
|
||||
Note that these function objects are <code class="computeroutput"><span class="keyword">constexpr</span></code>
|
||||
in C++14 and later only. They are also declared <code class="computeroutput"><span class="keyword">noexcept</span></code>
|
||||
when appropriate.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.lcm_function_object"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.lcm_function_object" title="LCM Function Object">LCM Function
|
||||
Object</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">lcm_evaluator</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="comment">// Types</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">result_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">first_argument_type</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">IntegerType</span> <span class="identifier">second_argument_type</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Function object interface</span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">result_type</span> <span class="keyword">operator</span> <span class="special">()(</span>
|
||||
<span class="identifier">first_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span>
|
||||
<span class="identifier">second_argument_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
The boost::math::lcm_evaluator class template defines a function object class
|
||||
to return the least common multiple of two integers. The template is parameterized
|
||||
by a single type, called IntegerType here. This type should be a numeric
|
||||
type that represents integers. The result of the function object is always
|
||||
nonnegative, even if either of the operator arguments is negative. If the
|
||||
least common multiple is beyond the range of the integer type, the results
|
||||
are undefined.
|
||||
</p>
|
||||
<p>
|
||||
This function object class template is used in the corresponding version
|
||||
of the LCM function template. If a numeric type wants to customize evaluations
|
||||
of its least common multiples, then the type should specialize on the lcm_evaluator
|
||||
class template.
|
||||
</p>
|
||||
<p>
|
||||
Note that these function objects are constexpr in C++14 and later only. They
|
||||
are also declared <code class="computeroutput"><span class="keyword">noexcept</span></code> when
|
||||
appropriate.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.run_time"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.run_time" title="Run-time GCD & LCM Determination">Run-time GCD & LCM
|
||||
Determination</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">gcd</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">IntegerType</span><span class="special">,</span> <span class="keyword">typename</span><span class="special">...</span> <span class="identifier">Args</span> <span class="special">></span>
|
||||
<span class="keyword">constexpr</span> <span class="identifier">IntegerType</span> <span class="identifier">lcm</span><span class="special">(</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">IntegerType</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">b</span><span class="special">,</span> <span class="identifier">Args</span> <span class="keyword">const</span><span class="special">&...</span> <span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">gcd_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">typename</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pair</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">iterator_traits</span><span class="special"><</span><span class="identifier">I</span><span class="special">>::</span><span class="identifier">value_type</span><span class="special">,</span> <span class="identifier">I</span><span class="special">></span>
|
||||
<span class="identifier">lcm_range</span><span class="special">(</span><span class="identifier">I</span> <span class="identifier">first</span><span class="special">,</span> <span class="identifier">I</span> <span class="identifier">last</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
The boost::math::gcd function template returns the greatest common (nonnegative)
|
||||
divisor of the two integers passed to it. <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd_range</span></code>
|
||||
is the iteration of the above gcd algorithm over a range, returning the greatest
|
||||
common divisor of all the elements. The algorithm terminates when the gcd
|
||||
reaches unity or the end of the range. Thus it also returns the iterator
|
||||
after the last element inspected because this may not be equal to the end
|
||||
of the range. The variadic version of <code class="computeroutput"><span class="identifier">gcd</span></code>
|
||||
behaves similarly but does not indicate which input value caused the gcd
|
||||
to reach unity.
|
||||
</p>
|
||||
<p>
|
||||
The boost::math::lcm function template returns the least common (nonnegative)
|
||||
multiple of the two integers passed to it. As with gcd, there are range and
|
||||
variadic versions of the function for more than 2 arguments.
|
||||
</p>
|
||||
<p>
|
||||
Note that these functions are constexpr in C++14 and later only. They are
|
||||
also declared <code class="computeroutput"><span class="keyword">noexcept</span></code> when
|
||||
appropriate.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.compile_time"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.compile_time" title="Compile time GCD and LCM determination">Compile time GCD
|
||||
and LCM determination</a>
|
||||
</h3></div></div></div>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
These functions are deprecated in favor of constexpr <code class="computeroutput"><span class="identifier">gcd</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">lcm</span></code> on C++14 capable
|
||||
compilers.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<p>
|
||||
<span class="bold"><strong>Header: </strong></span> <a href="../../../../../boost/math/common_factor_ct.hpp" target="_top"><boost/math/common_factor_ct.hpp></a>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">typedef</span> <span class="emphasis"><em>unspecified</em></span> <span class="identifier">static_gcd_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_gcd</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special"><</span><span class="identifier">static_gcd_type</span><span class="special">,</span> <span class="identifier">implementation_defined</span><span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value1</span><span class="special">,</span> <span class="identifier">static_gcd_type</span> <span class="identifier">Value2</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_lcm</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span><span class="special"><</span><span class="identifier">static_gcd_type</span><span class="special">,</span> <span class="identifier">implementation_defined</span><span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
The type <code class="computeroutput"><span class="identifier">static_gcd_type</span></code>
|
||||
is the widest unsigned-integer-type that is supported for use in integral-constant-expressions
|
||||
by the compiler. Usually this the same type as <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uintmax_t</span></code>,
|
||||
but may fall back to being <code class="computeroutput"><span class="keyword">unsigned</span>
|
||||
<span class="keyword">long</span></code> for some older compilers.
|
||||
</p>
|
||||
<p>
|
||||
The boost::math::static_gcd and boost::math::static_lcm class templates take
|
||||
two value-based template parameters of the <span class="emphasis"><em>static_gcd_type</em></span>
|
||||
type and inherit from the type <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">integral_c</span></code>. Inherited from the base class,
|
||||
they have a member <span class="emphasis"><em>value</em></span> that is the greatest common
|
||||
factor or least common multiple, respectively, of the template arguments.
|
||||
A compile-time error will occur if the least common multiple is beyond the
|
||||
range of <code class="computeroutput"><span class="identifier">static_gcd_type</span></code>.
|
||||
</p>
|
||||
<h4>
|
||||
<a name="boost_integer.gcd_lcm.compile_time.h0"></a>
|
||||
<span class="phrase"><a name="boost_integer.gcd_lcm.compile_time.example"></a></span><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.compile_time.example">Example</a>
|
||||
</h4>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">common_factor</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">algorithm</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iterator</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"The GCD and LCM of 6 and 15 are "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd</span><span class="special">(</span><span class="number">6</span><span class="special">,</span> <span class="number">15</span><span class="special">)</span> <span class="special"><<</span> <span class="string">" and "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">lcm</span><span class="special">(</span><span class="number">6</span><span class="special">,</span> <span class="number">15</span><span class="special">)</span> <span class="special"><<</span> <span class="string">", respectively."</span>
|
||||
<span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"The GCD and LCM of 8 and 9 are "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_gcd</span><span class="special"><</span><span class="number">8</span><span class="special">,</span> <span class="number">9</span><span class="special">>::</span><span class="identifier">value</span>
|
||||
<span class="special"><<</span> <span class="string">" and "</span>
|
||||
<span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">static_lcm</span><span class="special"><</span><span class="number">8</span><span class="special">,</span> <span class="number">9</span><span class="special">>::</span><span class="identifier">value</span>
|
||||
<span class="special"><<</span> <span class="string">", respectively."</span> <span class="special"><<</span> <span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">a</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">4</span><span class="special">,</span> <span class="number">5</span><span class="special">,</span> <span class="number">6</span> <span class="special">},</span> <span class="identifier">b</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">7</span><span class="special">,</span> <span class="number">8</span><span class="special">,</span> <span class="number">9</span> <span class="special">},</span> <span class="identifier">c</span><span class="special">[</span><span class="number">3</span><span class="special">];</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">transform</span><span class="special">(</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">a</span> <span class="special">+</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gcd_evaluator</span><span class="special"><</span><span class="keyword">int</span><span class="special">>()</span> <span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">copy</span><span class="special">(</span> <span class="identifier">c</span><span class="special">,</span> <span class="identifier">c</span> <span class="special">+</span> <span class="number">3</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream_iterator</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">cout</span><span class="special">,</span> <span class="string">" "</span><span class="special">)</span> <span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_header"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_header" title="Header <boost/math/common_factor.hpp>">Header <boost/math/common_factor.hpp></a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
This header simply includes the headers <a href="../../../../../boost/math/common_factor_ct.hpp" target="_top"><boost/math/common_factor_ct.hpp></a>
|
||||
and <a href="../../../../../boost/math/common_factor_rt.hpp" target="_top"><boost/math/common_factor_rt.hpp></a>.
|
||||
</p>
|
||||
<p>
|
||||
Note this is a legacy header: it used to contain the actual implementation,
|
||||
but the compile-time and run-time facilities were moved to separate headers
|
||||
(since they were independent of each other).
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.demo"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.demo" title="Demonstration Program">Demonstration Program</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The program <a href="../../../../../libs/math/test/common_factor_test.cpp" target="_top">common_factor_test.cpp</a>
|
||||
is a demonstration of the results from instantiating various examples of
|
||||
the run-time GCD and LCM function templates and the compile-time GCD and
|
||||
LCM class templates. (The run-time GCD and LCM class templates are tested
|
||||
indirectly through the run-time function templates.)
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.rationale"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.rationale" title="Rationale">Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The greatest common divisor and least common multiple functions are greatly
|
||||
used in some numeric contexts, including some of the other Boost libraries.
|
||||
Centralizing these functions to one header improves code factoring and eases
|
||||
maintainence.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_history"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_history" title="History">History</a>
|
||||
</h3></div></div></div>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
24th April 2017 Moved to Jeremy Murphy's improved algorithms, added constexpr
|
||||
and noexcept support, added compiler intrinsic support, added variadic
|
||||
and range based versions of the algorithms.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
13 May 2013 Moved into main Boost.Math Quickbook documentation.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
17 Dec 2005: Converted documentation to Quickbook Format.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
2 Jul 2002: Compile-time and run-time items separated to new headers.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
7 Nov 2001: Initial version
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.gcd_lcm.gcd_credits"></a><a class="link" href="gcd_lcm.html#boost_integer.gcd_lcm.gcd_credits" title="Credits">Credits</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The author of the Boost compilation of GCD and LCM computations is Daryle
|
||||
Walker. The code was prompted by existing code hiding in the implementations
|
||||
of Paul Moore's rational library and Steve Cleary's pool library. The code
|
||||
had updates by Helmut Zeisel.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>History</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="minmax.html" title="Compile time min/max calculation">
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Type Selection</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="traits.html" title="Integer Traits">
|
||||
<link rel="next" href="gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">
|
||||
<link rel="next" href="mask.html" title="Integer Masks">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@@ -20,13 +20,13 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="gcd_lcm.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.integer"></a><a class="link" href="integer.html" title="Integer Type Selection">Integer Type Selection</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.easiest">Easiest-to-Manipulate
|
||||
Types</a></span></dt>
|
||||
@@ -426,7 +426,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="gcd_lcm.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="traits.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="mask.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Compile Time log2 Calculation</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="mask.html" title="Integer Masks">
|
||||
@@ -26,7 +26,7 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.log2"></a><a class="link" href="log2.html" title="Compile Time log2 Calculation">Compile Time log2 Calculation</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.usage">Usage</a></span></dt>
|
||||
<dt><span class="section"><a href="log2.html#boost_integer.log2.demonstration_program">Demonstration
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Masks</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">
|
||||
<link rel="prev" href="integer.html" title="Integer Type Selection">
|
||||
<link rel="next" href="log2.html" title="Compile Time log2 Calculation">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
@@ -20,13 +20,13 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gcd_lcm.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.mask"></a><a class="link" href="mask.html" title="Integer Masks">Integer Masks</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.overview">Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="mask.html#boost_integer.mask.single_bit_mask_class_template">Single
|
||||
@@ -374,7 +374,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gcd_lcm.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="integer.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Compile time min/max calculation</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="log2.html" title="Compile Time log2 Calculation">
|
||||
@@ -26,7 +26,7 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.minmax"></a><a class="link" href="minmax.html" title="Compile time min/max calculation">Compile time min/max calculation</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.usage">Usage</a></span></dt>
|
||||
<dt><span class="section"><a href="minmax.html#boost_integer.minmax.example">Example</a></span></dt>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Traits</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="../index.html" title="Boost.Integer">
|
||||
<link rel="up" href="../index.html" title="Boost.Integer">
|
||||
<link rel="prev" href="../index.html" title="Boost.Integer">
|
||||
@@ -26,7 +26,7 @@
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.traits"></a><a class="link" href="traits.html" title="Integer Traits">Integer Traits</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<div class="toc"><dl class="toc">
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.motivation">Motivation</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.synopsis">Synopsis</a></span></dt>
|
||||
<dt><span class="section"><a href="traits.html#boost_integer.traits.description">Description</a></span></dt>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Boost.Integer</title>
|
||||
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
||||
<link rel="home" href="index.html" title="Boost.Integer">
|
||||
<link rel="next" href="boost_integer/traits.html" title="Integer Traits">
|
||||
</head>
|
||||
@@ -50,12 +50,10 @@
|
||||
</div>
|
||||
<div class="toc">
|
||||
<p><b>Table of Contents</b></p>
|
||||
<dl>
|
||||
<dl class="toc">
|
||||
<dt><span class="section"><a href="index.html#boost_integer.overview">Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/traits.html">Integer Traits</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/integer.html">Integer Type Selection</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/gcd_lcm.html">Greatest Common Divisor and Least
|
||||
Common Multiple</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/mask.html">Integer Masks</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/log2.html">Compile Time log2 Calculation</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/minmax.html">Compile time min/max calculation</a></span></dt>
|
||||
@@ -160,27 +158,6 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/gcd_lcm.html" title="Greatest Common Divisor and Least Common Multiple">Greatest Common Divisor and
|
||||
Least Common Multiple</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/integer/common_factor_rt.hpp" target="_top"><boost/integer/common_factor_rt.hpp></a></code>
|
||||
and <code class="literal"><a href="../../../../boost/integer/common_factor_ct.hpp" target="_top"><boost/integer/common_factor_ct.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Functions <code class="computeroutput"><span class="identifier">gcd</span></code> and
|
||||
<code class="computeroutput"><span class="identifier">lcm</span></code> plus function
|
||||
objects and compile time versions.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/mask.html" title="Integer Masks">Integer Masks</a>.
|
||||
@@ -242,7 +219,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"><p><small>Last revised: April 24, 2017 at 17:49:59 GMT</small></p></td>
|
||||
<td align="left"><p><small>Last revised: June 01, 2014 at 19:57:36 GMT</small></p></td>
|
||||
<td align="right"><div class="copyright-footer"></div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
|
||||
28
doc/integer.idx
Normal file
28
doc/integer.idx
Normal file
@@ -0,0 +1,28 @@
|
||||
# integer.idx for Boost.integer/Spreadinteger Quickbook, Doxygen and Auto-index.
|
||||
|
||||
# Note needs more customization to be useful in practice! TODO?
|
||||
|
||||
#!debug "\<\w*\>"
|
||||
|
||||
# integer Header files.
|
||||
!scan-path "../include/boost/" ".*\.hpp" false
|
||||
!scan-path "../include/boost/integer" ".*\.hpp" false
|
||||
|
||||
# All example source files, assuming no sub-folders.
|
||||
# integer example files.
|
||||
#!scan-path "../example" ".*\.cpp" true
|
||||
|
||||
# Allow alternative spellings colour | color, and plurals etc.
|
||||
color \<\w*(colour|color)\w*\>
|
||||
example \<example\w*\>
|
||||
font \<font\w*\>
|
||||
greek
|
||||
ioflags
|
||||
origin
|
||||
outlier
|
||||
maximum \<max\w*\>
|
||||
minimum \<min\w*\>
|
||||
precision
|
||||
range \<\w*\range\w*\>
|
||||
title
|
||||
Unicode \<unicode\w*\>
|
||||
946
doc/integer.qbk
946
doc/integer.qbk
File diff suppressed because it is too large
Load Diff
62
example/integer_common_factor_example.cpp
Normal file
62
example/integer_common_factor_example.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
// boost integer_common_factor_example.cpp
|
||||
|
||||
// Copyright Paul A. Bristow 2015
|
||||
// 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)
|
||||
|
||||
// Caution: this file contains Quickbook markup as well as code
|
||||
// and comments, don't change any of the special comment markups!
|
||||
|
||||
// #include <boost/integer/common_factor.hpp> // Includes both ct and rt but now deprecated.
|
||||
|
||||
//[integer_common_factor_example_0]
|
||||
#include <boost/integer/common_factor_ct.hpp> // For compile-time GCD & LCM Determination.
|
||||
#include <boost/integer/common_factor_rt.hpp> // For run-time GCD & LCM Determination.
|
||||
//] [/integer_common_factor_example_0]
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
#include <limits> // for numeric_limits min and max.
|
||||
|
||||
int main()
|
||||
{
|
||||
//[integer_common_factor_example_1
|
||||
std::cout << "The run-time GCD and LCM of 6 and 15 are "
|
||||
<< boost::integer::gcd(6, 15) << " and "
|
||||
<< boost::integer::lcm(6, 15) << ", respectively."
|
||||
<< std::endl;
|
||||
// The GCD and LCM of 6 and 15 are 3 and 30, respectively.
|
||||
//] [/integer_common_factor_example_1]
|
||||
|
||||
//[integer_common_factor_example_2
|
||||
|
||||
std::cout << "The compile-time GCD and LCM of 8 and 9 are "
|
||||
<< boost::integer::static_gcd<8, 9>::value
|
||||
<< " and "
|
||||
<< boost::integer::static_lcm<8, 9>::value
|
||||
<< ", respectively." << std::endl;
|
||||
// The GCD and LCM of 8 and 9 are 1 and 72, respectively.
|
||||
//] [/integer_common_factor_example_2]
|
||||
|
||||
//[integer_common_factor_example_3
|
||||
int a[] = { 4, 5, 6 }, b[] = { 7, 8, 9 }, c[3];
|
||||
std::transform(a, a + 3, b, c, boost::integer::gcd_evaluator<int>());
|
||||
std::copy(c, c + 3, std::ostream_iterator<int>(std::cout, " "));
|
||||
//] [/integer_common_factor_example_3]
|
||||
|
||||
} // int main
|
||||
|
||||
/*
|
||||
//[integer_common_factor_example_output_1
|
||||
The run-time GCD and LCM of 6 and 15 are 3 and 30, respectively.
|
||||
|
||||
The compile-time GCD and LCM of 8 and 9 are 1 and 72, respectively.
|
||||
//] [/integer_common_factor_example_output_1]
|
||||
|
||||
//[integer_common_factor_example_output_2
|
||||
1 1 3
|
||||
//] [/integer_common_factor_example_output_2]
|
||||
*/
|
||||
41
example/integer_log2_example.cpp
Normal file
41
example/integer_log2_example.cpp
Normal file
@@ -0,0 +1,41 @@
|
||||
// boost integer_log2_example.cpp
|
||||
|
||||
// Copyright Paul A. Bristow 2015
|
||||
// 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)
|
||||
|
||||
// Caution: this file contains Quickbook markup as well as code
|
||||
// and comments, don't change any of the special comment markups!
|
||||
|
||||
//[integer_log2_example_0
|
||||
#include <boost/integer/static_log2.hpp> // For boost::static_log2
|
||||
//] [/integer_log2s_example_0]
|
||||
#include <iostream>
|
||||
#include <limits> // for numeric_limits min and max.
|
||||
|
||||
//[integer_log2_example_
|
||||
//] [/integer_log2s_example_]
|
||||
|
||||
int main()
|
||||
{
|
||||
//[integer_log2_example_1
|
||||
int n = boost::static_log2<256>::value;
|
||||
//] [/integer_log2_example_1]
|
||||
|
||||
std::cout << n << std::endl; // 8
|
||||
|
||||
//[integer_log2_example_2
|
||||
int n2 = boost::static_log2<65536>::value;
|
||||
//] [/integer_log2_example_2]
|
||||
|
||||
std::cout << n2 << std::endl; // 16
|
||||
|
||||
} // int main
|
||||
|
||||
/*
|
||||
//[integer_log2_example_output
|
||||
8
|
||||
//] [/integer_log2_example_output]
|
||||
*/
|
||||
69
example/integer_mask_example.cpp
Normal file
69
example/integer_mask_example.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
// boost integer_mask_example.cpp
|
||||
|
||||
// Copyright Paul A. Bristow 2015
|
||||
// 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)
|
||||
|
||||
// Caution: this file contains Quickbook markup as well as code
|
||||
// and comments, don't change any of the special comment markups!
|
||||
|
||||
//[integer_mask_example_0
|
||||
#include <boost/integer/integer_mask.hpp> // For boost::high_bit_mask_t etc
|
||||
//] [/integer_masks_example_0]
|
||||
#include <iostream>
|
||||
#include <limits> // for numeric_limits min and max.
|
||||
|
||||
//[integer_mask_example_
|
||||
//] [/integer_masks_example_]
|
||||
|
||||
int main()
|
||||
{
|
||||
//[integer_mask_example_1
|
||||
typedef boost::high_bit_mask_t<29> mask1_type;
|
||||
typedef boost::low_bits_mask_t<15> mask2_type;
|
||||
//] [/integer_masks_example_1]
|
||||
|
||||
//[integer_mask_example_2
|
||||
// high_bit_mask_t
|
||||
std::cout << std::hex << mask1_type::bit_position << std::endl; // 1d
|
||||
std::cout << std::hex << mask1_type::high_bit << std::endl; // 20000000
|
||||
std::cout << std::hex << mask1_type::high_bit_fast << std::endl; // 20000000
|
||||
|
||||
// low_bits_mask_t
|
||||
std::cout << std::hex << mask2_type::bit_count << std::endl; // F
|
||||
std::cout << std::hex << mask2_type::sig_bits << std::endl; // 7fff
|
||||
std::cout << std::hex << mask2_type::sig_bits_fast << std::endl; // 7fff
|
||||
//] [/integer_masks_example_2]
|
||||
|
||||
//[integer_mask_example_3
|
||||
mask1_type::least my_var1;
|
||||
mask2_type::fast my_var2;
|
||||
//] [/integer_masks_example_3]
|
||||
|
||||
//[integer_mask_example_4
|
||||
my_var1 |= mask1_type::high_bit;
|
||||
std::cout << std::hex << my_var1 << std::endl; // eccccccc
|
||||
//] [/integer_masks_example_4]
|
||||
|
||||
//[integer_mask_example_5
|
||||
my_var2 &= mask2_type::sig_bits;
|
||||
std::cout << std::hex << my_var2 << std::endl; // 4ccc
|
||||
//] [/integer_masks_example_5]
|
||||
|
||||
} // int main
|
||||
|
||||
/*
|
||||
//[integer_mask_example_output
|
||||
1d
|
||||
20000000
|
||||
20000000
|
||||
f
|
||||
7fff
|
||||
7fff
|
||||
eccccccc
|
||||
4ccc
|
||||
//] [/integer_mask_example_output]
|
||||
|
||||
*/
|
||||
73
example/integer_static_minmax_example.cpp
Normal file
73
example/integer_static_minmax_example.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// boost integer_static_minmax_example.cpp
|
||||
|
||||
// Copyright Paul A. Bristow 2015
|
||||
// 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)
|
||||
|
||||
// Caution: this file contains Quickbook markup as well as code
|
||||
// and comments, don't change any of the special comment markups!
|
||||
|
||||
#include <boost/integer/static_min_max.hpp> // For boost::static_signed_min
|
||||
#include <iostream>
|
||||
#include <limits> // for numeric_limits min and max.
|
||||
|
||||
//[integer_min_max_example_0
|
||||
|
||||
template < unsigned long AddendSize1, unsigned long AddendSize2 >
|
||||
class adder
|
||||
{
|
||||
public:
|
||||
static unsigned long const addend1_size = AddendSize1;
|
||||
static unsigned long const addend2_size = AddendSize2;
|
||||
static unsigned long const sum_size = boost::static_unsigned_max<AddendSize1, AddendSize2>::value + 1;
|
||||
|
||||
typedef int addend1_type[addend1_size];
|
||||
typedef int addend2_type[addend2_size];
|
||||
typedef int sum_type[sum_size];
|
||||
|
||||
void operator ()(addend1_type const &a1, addend2_type const &a2, sum_type &s) const;
|
||||
}; // class adder
|
||||
|
||||
//] [/integer_min_max_example_0]
|
||||
|
||||
int main()
|
||||
{
|
||||
//[integer_min_max_example_1
|
||||
|
||||
std::cout << "boost::static_signed_min< 9, 14>::value = "<< boost::static_signed_min< 9, 14>::value << std::endl;
|
||||
std::cout << "boost::static_signed_max< 9, 14>::value = "<< boost::static_signed_max< 9, 14>::value << std::endl;
|
||||
|
||||
//] [/integer_min_max_example_1]
|
||||
|
||||
//[integer_min_max_example_2
|
||||
int const a1[] = { 0, 4, 3 }; // 340
|
||||
int const a2[] = { 9, 8 }; // 89
|
||||
int s[4];
|
||||
|
||||
adder<3, 2> obj;
|
||||
// adder<sizeof(a1), sizeof(a2)> obj;
|
||||
|
||||
std::cout << "obj.addend1_size = " << obj.addend1_size << std::endl; // 3
|
||||
std::cout << "obj.addend2_size = " << obj.addend2_size << std::endl; // 2
|
||||
std::cout << "obj.sum_size = " << obj.sum_size << std::endl; // 4
|
||||
//] [/integer_min_max_example_2]
|
||||
|
||||
// obj(a1, a2, s); // 's' should be 429 or { 9, 2, 4, 0 }
|
||||
//void adder<3,2>::operator()(int const (&)[3],int const (&)[2],int (&)[4])const
|
||||
|
||||
std::cout << s[0] << s[1] << s[2] << s[3]<< std::endl; // 's' should be 429 or { 9, 2, 4, 0 }
|
||||
|
||||
} // int main
|
||||
|
||||
/*
|
||||
//[integer_min_max_example_output
|
||||
|
||||
boost::static_signed_min< 9, 14>::value = 9
|
||||
boost::static_signed_max< 9, 14>::value = 14
|
||||
obj.addend1_size = 3
|
||||
obj.addend2_size = 2
|
||||
obj.sum_size = 4
|
||||
//] [/integer_min_max_example_output]
|
||||
*/
|
||||
55
example/integer_traits_example.cpp
Normal file
55
example/integer_traits_example.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// boost integer_traits_example.cpp
|
||||
|
||||
// Copyright Paul A. Bristow 2015
|
||||
// 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)
|
||||
|
||||
// Caution: this file contains Quickbook markup as well as code
|
||||
// and comments, don't change any of the special comment markups!
|
||||
|
||||
#include <boost/integer_traits.hpp>
|
||||
#include <iostream>
|
||||
#include <limits> // for numeric_limits min and max.
|
||||
|
||||
//[integer_traits_example_1
|
||||
template<int N>
|
||||
void f()
|
||||
{ // Entirely contrived templated function.
|
||||
std::cout << N << std::endl; // Do something pointless.
|
||||
}
|
||||
//] [/integer_traits_example_1]
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Type int, min = "
|
||||
<< (std::numeric_limits<int>::min)()
|
||||
<< ", const_min = " << boost::integer_traits<int>::const_min
|
||||
<< std::endl; // Type int, min = -2147483648, const_min = -2147483648
|
||||
|
||||
//[integer_traits_example_2
|
||||
f<2>();
|
||||
//] [/integer_traits_example_2]
|
||||
|
||||
//[integer_traits_example_3
|
||||
int i = 2;
|
||||
// f<i>(); // A local variable cannot be used as a non-type argument.
|
||||
//] [/integer_traits_example_3]
|
||||
|
||||
//[integer_traits_example_4
|
||||
const int ci = 2;
|
||||
f<ci>(); // But a const variable can.
|
||||
//] [/integer_traits_example_4]
|
||||
//[integer_traits_example_5
|
||||
|
||||
// f<std::numeric_limits<int>::min()>(); // Function call must have a constant value in a constant expression.
|
||||
//] [/integer_traits_example_5]
|
||||
//[integer_traits_example_6
|
||||
|
||||
f<boost::integer_traits<int>::const_min>();
|
||||
//] [/integer_traits_example_6]
|
||||
|
||||
} // int main
|
||||
|
||||
251
example/integer_type_selection_example.cpp
Normal file
251
example/integer_type_selection_example.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
// boost integer_type_selection.cpp
|
||||
|
||||
// Copyright Paul A. Bristow 2015
|
||||
// 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)
|
||||
|
||||
// Caution: this file contains Quickbook markup as well as code
|
||||
// and comments, don't change any of the special comment markups!
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
#include <iostream>
|
||||
#include <limits> // for numeric_limits min and max.
|
||||
// Note use of extra brackets to avoid potential clash for any min and max macros:
|
||||
// (std::numeric_limits<T>::max)() (std::numeric_limits<T>::min)()
|
||||
|
||||
//! Show info about type
|
||||
template <const int Bits, typename T>
|
||||
void show_type()
|
||||
{
|
||||
std::cout << typeid(T).name()
|
||||
<< " is a signed int using at least " << Bits << " bits uses "
|
||||
<< std::numeric_limits<boost::int_t<Bits>::least>::digits
|
||||
<< " bits, needing at most "
|
||||
<< std::numeric_limits<boost::int_t<Bits>::least>::digits10
|
||||
<< " decimal digits, " " and representing a maximum decimal value of "
|
||||
<< static_cast<int>((std::numeric_limits<boost::int_t<Bits>::least>::max)())
|
||||
<< std::endl;
|
||||
} // template <const int Bits, typename T> void show_type()
|
||||
|
||||
template <typename T>
|
||||
void show_consts()
|
||||
{ //
|
||||
std::cout << "Type " << typeid(T).name();
|
||||
if (std::numeric_limits<T>::is_specialized)
|
||||
{
|
||||
std::cout << " is specialized for std::numeric_limits,";
|
||||
if (std::numeric_limits<T>::is_integer)
|
||||
{
|
||||
std::cout << " and is integer type." << std::endl;
|
||||
// If a constant expression for `min` and `max` are required, see
|
||||
// Boost integer_traits.
|
||||
std::cout << "const_max = " << boost::integer_traits<T>::const_max << std::endl;
|
||||
std::cout << "const_min = " << boost::integer_traits<T>::const_min << std::endl;
|
||||
}
|
||||
}
|
||||
} // void show_consts()
|
||||
|
||||
template <typename T>
|
||||
void show_type()
|
||||
{
|
||||
std::cout << "Type " << typeid(T).name(); // name of resultant type.
|
||||
if (std::numeric_limits<T>::is_specialized)
|
||||
{
|
||||
if (std::numeric_limits<T>::is_integer)
|
||||
{
|
||||
std::cout << " is an unsigned int with at least 13 bits using "
|
||||
<< std::numeric_limits<T>::digits + (std::numeric_limits<T>::is_signed ? 1 : 0) << " bits,\n"
|
||||
// See http://en.cppreference.com/w/cpp/types/numeric_limits/digits for details on the meaning of digits10.
|
||||
// The value of std::numeric_limits<T>::digits is the number of digits in base-radix that can be represented
|
||||
// by the type T without change.
|
||||
// For integer types, this is the number of bits *not counting the sign bit*, so add one for the total.
|
||||
// (For floating-point types, this is the number of digits in the mantissa).
|
||||
"guaranteeing at most " << std::numeric_limits<T>::digits10 << " decimal digits precision,\n"
|
||||
"and using at most " << std::numeric_limits<T>::digits10 + 1
|
||||
<< " decimal digits,\n"
|
||||
// See http://en.cppreference.com/w/cpp/types/numeric_limits/digits10 for details on the meaning of digits10.
|
||||
// The value of std::numeric_limits<T>::digits is the number of digits in base-radix that can be represented
|
||||
// by the type T without change.
|
||||
// For integer types, the maximum number of digits that may be required is one more than digits10.
|
||||
"a maximum decimal value of " << static_cast<long>((std::numeric_limits<T>::max)())
|
||||
<< " and a minimum decimal value of " << static_cast<long>((std::numeric_limits<T>::min)()) << "."
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "is floating-point." << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // is NOT specialized.
|
||||
std::cout << " is NOT specialized for std::numeric_limits!" << std::endl;
|
||||
}
|
||||
} // template <typename T> void show_type()
|
||||
|
||||
|
||||
template <typename T>
|
||||
void show_type_limits()
|
||||
{ //
|
||||
|
||||
std::cout <<"Type " << typeid(T).name();
|
||||
if (std::numeric_limits<T>::is_specialized)
|
||||
{
|
||||
std::cout << " is specialized for std::numeric_limits." << std::endl;
|
||||
if (std::numeric_limits<T>::is_integer)
|
||||
{
|
||||
std::cout << "is integer." << std::endl;
|
||||
|
||||
std::cout << (std::numeric_limits<T>::is_bounded ? "is bounded." : "") << std::endl;
|
||||
std::cout << (std::numeric_limits<T>::is_exact ? "is exact." : "") << std::endl;
|
||||
std::cout << (std::numeric_limits<T>::is_modulo ? "is modulo." : "") << std::endl;
|
||||
std::cout << "radix = " << std::numeric_limits<T>::radix << std::endl;
|
||||
std::cout << (std::numeric_limits<T>::is_signed ? "is signed." : "is unsigned.") << std::endl;
|
||||
|
||||
std::cout << "max = " << static_cast<long>((std::numeric_limits<T>::max)()) << std::endl;
|
||||
std::cout << "min = " << static_cast<long>((std::numeric_limits<T>::min)()) << std::endl;
|
||||
// Can't list const_max or const_min here because compiler will protest that
|
||||
// const_max' : is not a member of 'boost::integer_traits<T>' when T is double.
|
||||
//std::cout << "const_max = " << boost::integer_traits<T>::const_max << std::endl;
|
||||
//std::cout << "const_min = " << boost::integer_traits<T>::const_min << std::endl;
|
||||
|
||||
std::cout << "digits = " << std::numeric_limits<T>::digits << std::endl;
|
||||
std::cout << "bits = " << std::numeric_limits<T>::digits +1 << std::endl;
|
||||
// digits is the number of bits not counting the sign bit for integer types.
|
||||
|
||||
std::cout << "digits10 = " << std::numeric_limits<T>::digits10 << std::endl;
|
||||
// max_digits10 is not defined for integer types.
|
||||
//std::cout << "max_digits10 = " << std::numeric_limits<T>::max_digits10 << std::endl;
|
||||
}
|
||||
else
|
||||
{ // Not integral, so might be floating-point, or ?
|
||||
std::cout << "is NOT integral type." << std::endl;
|
||||
if ((std::numeric_limits<T>::max_exponent != 0) && (std::numeric_limits<T>::max_exponent10 != 0))
|
||||
{ // floating-point type including fundamental float, double and multiprecision like cpp_dec_float_50 and cpp_bin_float_50.
|
||||
std::cout << "is floating-point type." << std::endl;
|
||||
std::cout << "digits = " << std::numeric_limits<T>::digits << std::endl;
|
||||
// digits is the number of bits in the significand (not counting the sign bit) for floating-point types.
|
||||
std::cout << "digits10 = " << std::numeric_limits<T>::digits10 << std::endl;
|
||||
// http://en.cppreference.com/w/cpp/types/numeric_limits/digits10
|
||||
std::cout << "max_digits10 = " << std::numeric_limits<T>::max_digits10 << std::endl;
|
||||
std::cout << "is_modulo = " << std::numeric_limits<T>::is_modulo << std::endl;
|
||||
std::cout << "is_iec559 = " << std::numeric_limits<T>::is_iec559 << std::endl;
|
||||
std::cout << (std::numeric_limits<T>::is_exact ? "is exact." : "") << std::endl;
|
||||
std::cout << (std::numeric_limits<T>::is_signed ? "is signed." : "is unsigned.") << std::endl;
|
||||
std::cout << "has_quiet_NaN = " << std::numeric_limits<T>::has_quiet_NaN << std::endl;
|
||||
std::cout << "has_infinity = " << std::numeric_limits<T>::has_infinity << std::endl;
|
||||
std::cout << "has_denorm_loss = " << std::numeric_limits<T>::has_denorm_loss << std::endl;
|
||||
std::cout << "max_exponent = " << std::numeric_limits<T>::max_exponent << std::endl;
|
||||
std::cout << "min_exponent = " << std::numeric_limits<T>::min_exponent << std::endl;
|
||||
std::cout << "max_exponent10 = " << std::numeric_limits<T>::max_exponent10 << std::endl;
|
||||
std::cout << "min_exponent10 = " << std::numeric_limits<T>::min_exponent10 << std::endl;
|
||||
}
|
||||
else
|
||||
{ // Unknown type
|
||||
std::cout << "Unknown type." << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Not specialized!
|
||||
std::cout << " is NOT specialized for std::numeric_limits!" << std::endl;
|
||||
}
|
||||
} // show_type_limits
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// Select, construct and assign an unsigned integer of at least 13 bits.
|
||||
//[integer_type_selection_1
|
||||
boost::uint_t<13>::least my_var13 = 42;
|
||||
//] [/integer_type_selection_1]
|
||||
|
||||
//[integer_type_selection_2
|
||||
show_type<boost::uint_t<13>::least>();
|
||||
//] [/integer_type_selection_2]
|
||||
|
||||
// Select fastest signed integer of at least 7 bits.
|
||||
//[integer_type_selection_3
|
||||
typedef boost::int_t<7>::fast int_7;
|
||||
//] [/integer_type_selection_3]
|
||||
|
||||
//[integer_type_selection_4
|
||||
show_type<int_7>();
|
||||
//] [/integer_type_selection_4]
|
||||
|
||||
|
||||
// Choose an integer size that can hold at least a value of 1000
|
||||
// Assignment of this value is guaranteed not to be truncated:
|
||||
//[integer_value_type_selection_5
|
||||
|
||||
boost::int_max_value_t<1000>::least thousand = 1000;
|
||||
//] [/integer_value_type_selection_5]
|
||||
|
||||
std::cout << thousand << std::endl;
|
||||
|
||||
//[integer_value_type_selection_6
|
||||
|
||||
std::cout << (std::numeric_limits<boost::int_max_value_t<1000>::least>::max)() << std::endl;
|
||||
|
||||
//] [/integer_value_type_selection_6]
|
||||
|
||||
//[integer_value_type_selection_7
|
||||
|
||||
thousand = 100000; // Probably too big!
|
||||
|
||||
// warning C4305 : warning C4305: '=' : truncation from 'int' to 'short'
|
||||
// warning C4309: '=' : truncation of constant value
|
||||
|
||||
//] [/integer_value_type_selection_7]
|
||||
|
||||
//[integer_value_type_selection_8
|
||||
|
||||
boost::int_t<32>::exact my_exact32 = 1000000;
|
||||
|
||||
std::cout << "boost::int_t<32>::exact has "
|
||||
<< std::numeric_limits<boost::int_t<32>::exact>::digits
|
||||
<< " bits and 1 sign bit." << std::endl;
|
||||
// boost::int_t<32>::exact has 31 bits and 1 sign bit.
|
||||
|
||||
//] [/integer_value_type_selection_8]
|
||||
|
||||
// If we ask for an unachievable number of bits or value
|
||||
|
||||
//boost::int_t<128>::exact exact128;
|
||||
//error C2338 : No suitable signed integer type with the requested number of bits is available.
|
||||
// see reference to class template instantiation 'boost::int_t<128>' being compiled
|
||||
|
||||
show_consts<boost::int_t<32>::exact>();
|
||||
// const_max = 2147483647 const_min = -2147483648
|
||||
|
||||
show_type<16, boost::int_max_value_t<1000>::least>();
|
||||
|
||||
}
|
||||
catch (std::exception ex)
|
||||
{
|
||||
std::cout << ex.what() << std::endl;
|
||||
}
|
||||
return 0;
|
||||
} // int main
|
||||
|
||||
|
||||
/*
|
||||
|
||||
//[integer_type_selection_output_1
|
||||
Type short is an unsigned int with at least 13 bits using 16 bits,
|
||||
guaranteeing at most 4 decimal digits precision,
|
||||
and using at most 5 decimal digits,
|
||||
//] [/integer_type_selection_output_1]
|
||||
|
||||
//[integer_type_selection_output_2
|
||||
Type signed char is an unsigned int with at least 13 bits using 8 bits,
|
||||
guaranteeing at most 2 decimal digits precision,
|
||||
and using at most 3 decimal digits,
|
||||
a maximum decimal value of 127 and a minimum decimal value of -128.
|
||||
//] [/integer_type_selection_output_2]
|
||||
|
||||
*/
|
||||
33
example/jamfile.v2
Normal file
33
example/jamfile.v2
Normal file
@@ -0,0 +1,33 @@
|
||||
# libs/integer/example Jamfile
|
||||
# Copyright (c) Vladimir Batov 2009-2014
|
||||
# Copyright Paul A. Bristow 2015
|
||||
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# See copy at http://www.boost.org/LICENSE_1_0.txt.
|
||||
|
||||
# bring in the rules for testing
|
||||
import testing ;
|
||||
|
||||
project convert_examples
|
||||
: requirements
|
||||
<warnings>on
|
||||
<toolset>gcc:<warnings>all
|
||||
<toolset>msvc:<warnings>all
|
||||
<toolset>gcc:<cxxflags>"-Wno-unused-local-typedefs -Wno-unused-variable -Wno-long-long"
|
||||
<toolset>msvc:<cxxflags>"/wd4996 /wd4512 /wd4610 /wd4510 /wd4127 /wd4701 /wd4127 /wd4305 /wd4100 /wd4512 /wd4714"
|
||||
<toolset>msvc:<asynch-exceptions>on
|
||||
<toolset>msvc:<define>_CRT_SECURE_NO_DEPRECATE
|
||||
<toolset>msvc:<define>_SCL_SECURE_NO_DEPRECATE
|
||||
<toolset>msvc:<define>_SCL_SECURE_NO_WARNINGS
|
||||
<toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS
|
||||
<include>../include
|
||||
;
|
||||
|
||||
run integer_mask_example.cpp ;
|
||||
run integer_traits_example.cpp ;
|
||||
run integer_type_selection_example.cpp ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
//! \file
|
||||
//! \brief Compile-time evaluation of specified (least and fast) integer types.
|
||||
|
||||
// Revision History
|
||||
// 22 Sep 01 Added value-based integer templates. (Daryle Walker)
|
||||
// 01 Apr 01 Modified to use new <boost/limits.hpp> header. (John Maddock)
|
||||
@@ -48,6 +51,7 @@ namespace boost
|
||||
typedef fast type;
|
||||
}; // imps may specialize
|
||||
|
||||
//! \cond DETAIL
|
||||
namespace detail{
|
||||
|
||||
// convert category to type
|
||||
@@ -91,8 +95,7 @@ namespace boost
|
||||
template <> struct exact_signed_base_helper<sizeof(int)* CHAR_BIT> { typedef int exact; };
|
||||
template <> struct exact_unsigned_base_helper<sizeof(unsigned int)* CHAR_BIT> { typedef unsigned int exact; };
|
||||
#endif
|
||||
#if ULONG_MAX != UINT_MAX && ( !defined __TI_COMPILER_VERSION__ || \
|
||||
( __TI_COMPILER_VERSION__ >= 7000000 && !defined __TI_40BIT_LONG__ ) )
|
||||
#if ULONG_MAX != UINT_MAX
|
||||
template <> struct exact_signed_base_helper<sizeof(long)* CHAR_BIT> { typedef long exact; };
|
||||
template <> struct exact_unsigned_base_helper<sizeof(unsigned long)* CHAR_BIT> { typedef unsigned long exact; };
|
||||
#endif
|
||||
@@ -105,8 +108,8 @@ namespace boost
|
||||
template <> struct exact_unsigned_base_helper<sizeof(boost::ulong_long_type)* CHAR_BIT> { typedef boost::ulong_long_type exact; };
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace detail
|
||||
//! \endcond // DETAIL
|
||||
|
||||
// integer templates specifying number of bits ---------------------------//
|
||||
|
||||
@@ -167,7 +170,7 @@ namespace boost
|
||||
// integer templates specifying extreme value ----------------------------//
|
||||
|
||||
// signed
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
template< boost::long_long_type MaxValue > // maximum value to require support
|
||||
#else
|
||||
template< long MaxValue > // maximum value to require support
|
||||
@@ -176,7 +179,7 @@ namespace boost
|
||||
{
|
||||
typedef typename boost::detail::int_least_helper
|
||||
<
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
(MaxValue <= ::boost::integer_traits<boost::long_long_type>::const_max) +
|
||||
#else
|
||||
1 +
|
||||
@@ -189,7 +192,7 @@ namespace boost
|
||||
typedef typename int_fast_t<least>::type fast;
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
template< boost::long_long_type MinValue > // minimum value to require support
|
||||
#else
|
||||
template< long MinValue > // minimum value to require support
|
||||
@@ -198,7 +201,7 @@ namespace boost
|
||||
{
|
||||
typedef typename boost::detail::int_least_helper
|
||||
<
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && !defined(BOOST_NO_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
(MinValue >= ::boost::integer_traits<boost::long_long_type>::const_min) +
|
||||
#else
|
||||
1 +
|
||||
@@ -256,7 +259,6 @@ namespace boost
|
||||
typedef typename int_fast_t<least>::type fast;
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_INTEGER_HPP
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//! \file
|
||||
//! \brief Include both GCD and LCM.
|
||||
|
||||
#ifndef BOOST_INTEGER_COMMON_FACTOR_HPP
|
||||
#define BOOST_INTEGER_COMMON_FACTOR_HPP
|
||||
|
||||
@@ -5,21 +5,25 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//! \file
|
||||
//! \brief Evaluate Greatest Common Divisor and Least Common Multiple at compile-time.
|
||||
|
||||
#ifndef BOOST_INTEGER_COMMON_FACTOR_CT_HPP
|
||||
#define BOOST_INTEGER_COMMON_FACTOR_CT_HPP
|
||||
|
||||
#include <boost/integer_fwd.hpp> // self include
|
||||
#include <boost/integer_fwd.hpp> // Include for declaration of static_gcd_type and static_gcd.
|
||||
#include <boost/config.hpp> // for BOOST_STATIC_CONSTANT, etc.
|
||||
#include <boost/cstdint.hpp> // for boost::uintmax_t
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace integer
|
||||
{
|
||||
// Warning: From 1.58 this is in namespace boost::integer and no longer in namespace boost::math.
|
||||
|
||||
// Implementation details --------------------------------------------------//
|
||||
|
||||
//! \cond DETAIL
|
||||
namespace detail
|
||||
{
|
||||
// Build GCD with Euclid's recursive algorithm
|
||||
@@ -71,7 +75,7 @@ namespace detail
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
//! \endcond // DETAIL
|
||||
|
||||
// Compile-time greatest common divisor evaluator class declaration --------//
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,18 @@
|
||||
// -----------------------------------------------------------
|
||||
// integer_log2.hpp
|
||||
//
|
||||
// Gives the integer part of the logarithm, in base 2, of a
|
||||
// given number. Behavior is undefined if the argument is <= 0.
|
||||
//
|
||||
// Copyright (c) 2003-2004, 2008 Gennaro Prota
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
//! \file
|
||||
//! \brief Function integer_log2 gives the integer part of the logarithm, in base 2, of a
|
||||
//! given number (at run-time). Behavior is undefined if the argument is <= 0.
|
||||
//
|
||||
//! \note For analogous compile-time computation of log2 see static_log2.
|
||||
//! \sa http::www.boost.org/doc/integer
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_INTEGER_INTEGER_LOG2_HPP
|
||||
@@ -24,6 +27,8 @@
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
//! \cond DETAIL
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
@@ -46,7 +51,6 @@ namespace boost {
|
||||
}
|
||||
|
||||
|
||||
|
||||
// helper to find the maximum power of two
|
||||
// less than p (more involved than necessary,
|
||||
// to avoid PTS)
|
||||
@@ -82,9 +86,8 @@ namespace boost {
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
//! \endcond // DETAIL
|
||||
|
||||
// ---------
|
||||
// integer_log2
|
||||
@@ -104,9 +107,6 @@ namespace boost {
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // include guard
|
||||
#endif // BOOST_INTEGER_INTEGER_LOG2_HPP include guard
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
|
||||
//! \file
|
||||
//! \brief Compile-time integer mask evaluation.
|
||||
|
||||
#ifndef BOOST_INTEGER_INTEGER_MASK_HPP
|
||||
#define BOOST_INTEGER_INTEGER_MASK_HPP
|
||||
@@ -35,7 +38,6 @@
|
||||
namespace boost
|
||||
{
|
||||
|
||||
|
||||
// Specified single-bit mask class declaration -----------------------------//
|
||||
// (Lowest bit starts counting at 0.)
|
||||
|
||||
@@ -57,27 +59,19 @@ struct high_bit_mask_t
|
||||
// Makes masks for the lowest N bits
|
||||
// (Specializations are needed when N fills up a type.)
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4310) // cast truncates constant value
|
||||
#endif
|
||||
|
||||
template < std::size_t Bits >
|
||||
struct low_bits_mask_t
|
||||
{
|
||||
typedef typename uint_t<Bits>::least least;
|
||||
typedef typename uint_t<Bits>::fast fast;
|
||||
|
||||
BOOST_STATIC_CONSTANT( least, sig_bits = least(~(least(~(least( 0u ))) << Bits )) );
|
||||
BOOST_STATIC_CONSTANT( least, sig_bits = (~( ~(least( 0u )) << Bits )) );
|
||||
BOOST_STATIC_CONSTANT( fast, sig_bits_fast = fast(sig_bits) );
|
||||
|
||||
BOOST_STATIC_CONSTANT( std::size_t, bit_count = Bits );
|
||||
|
||||
}; // boost::low_bits_mask_t
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#define BOOST_LOW_BITS_MASK_SPECIALIZE( Type ) \
|
||||
template < > struct low_bits_mask_t< std::numeric_limits<Type>::digits > { \
|
||||
|
||||
@@ -10,6 +10,11 @@
|
||||
//
|
||||
// ---------------------------------------------------
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
//! \file
|
||||
//! \brief Compile-time calculation of integer part of the logarithm, in base 2, of a given number.
|
||||
//! \note For a run-time calculation of log2, see function integer_log2 at integer_log2.hpp.
|
||||
|
||||
// ------------------------------------------------------------------------- //
|
||||
|
||||
|
||||
@@ -20,6 +25,8 @@
|
||||
|
||||
namespace boost {
|
||||
|
||||
//! \cond DETAIL
|
||||
|
||||
namespace detail {
|
||||
|
||||
namespace static_log2_impl {
|
||||
@@ -99,8 +106,7 @@ namespace boost {
|
||||
|
||||
}
|
||||
} // detail
|
||||
|
||||
|
||||
//! \endcond // DETAIL
|
||||
|
||||
// --------------------------------------
|
||||
// static_log2<x>
|
||||
@@ -120,7 +126,7 @@ namespace boost {
|
||||
template <>
|
||||
struct static_log2<0> { };
|
||||
|
||||
}
|
||||
} // namespace boost
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//! \file
|
||||
//! \brief Compile-time evaluation of extrema: minimum or maximum of two values, signed or unsigned.
|
||||
|
||||
#ifndef BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
||||
#define BOOST_INTEGER_STATIC_MIN_MAX_HPP
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
//! \file
|
||||
//! \brief Include all Boost.Integer files.
|
||||
|
||||
#ifndef BOOST_INTEGER_FWD_HPP
|
||||
#define BOOST_INTEGER_FWD_HPP
|
||||
@@ -16,7 +18,6 @@
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
#include <boost/cstdint.hpp> // For intmax_t
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
@@ -158,9 +159,9 @@ template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Valu
|
||||
template <static_min_max_unsigned_type Value1, static_min_max_unsigned_type Value2>
|
||||
struct static_unsigned_max;
|
||||
|
||||
|
||||
namespace integer
|
||||
{
|
||||
|
||||
// From <boost/integer/common_factor_ct.hpp>
|
||||
|
||||
#ifdef BOOST_NO_INTEGRAL_INT64_T
|
||||
@@ -182,7 +183,7 @@ template < typename IntegerType >
|
||||
template < typename IntegerType >
|
||||
class lcm_evaluator;
|
||||
|
||||
} // namespace integer
|
||||
] // namespace integer
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
@@ -8,10 +8,15 @@
|
||||
* $Id$
|
||||
*
|
||||
* Idea by Beman Dawes, Ed Brey, Steve Cleary, and Nathan Myers
|
||||
|
||||
*/
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
//! \file
|
||||
//! \brief integer traits
|
||||
//! \sa http://www.boost.org/libs/integer
|
||||
|
||||
|
||||
#ifndef BOOST_INTEGER_TRAITS_HPP
|
||||
#define BOOST_INTEGER_TRAITS_HPP
|
||||
@@ -47,6 +52,7 @@ public:
|
||||
BOOST_STATIC_CONSTANT(bool, is_integral = false);
|
||||
};
|
||||
|
||||
//! \cond DETAIL
|
||||
namespace detail {
|
||||
template<class T, T min_val, T max_val>
|
||||
class integer_traits_base
|
||||
@@ -70,6 +76,7 @@ const T integer_traits_base<T, min_val, max_val>::const_max;
|
||||
#endif
|
||||
|
||||
} // namespace detail
|
||||
//! \endcond // DETAIL
|
||||
|
||||
template<>
|
||||
class integer_traits<bool>
|
||||
|
||||
@@ -6,9 +6,6 @@ import testing ;
|
||||
|
||||
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 ]
|
||||
@@ -22,14 +19,11 @@ test-suite integer
|
||||
[ 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 ] ]
|
||||
[ run common_factor_test.cpp ]
|
||||
;
|
||||
|
||||
@@ -15,32 +15,19 @@
|
||||
// 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"
|
||||
#define BOOST_TEST_MAIN "Boost.Math GCD & LCM unit tests"
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_MSVC, etc.
|
||||
#include <boost/integer/common_factor.hpp>
|
||||
|
||||
#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
|
||||
|
||||
#if (defined(BOOST_MSVC) && (BOOST_MSVC < 1500)) || (defined(__clang_major__) && (__clang_major__ == 3) && (__clang_minor__ < 2))
|
||||
#define DISABLE_MP_TESTS
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_MP_TESTS
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -122,29 +109,6 @@ 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 /**/
|
||||
@@ -282,321 +246,199 @@ inline ostream& operator<<(ostream& os, unsigned __int64 i)
|
||||
// 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));
|
||||
BOOST_TEST_EQ( gcd<T>( 1, -1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( gcd<T>( -1, 1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( gcd<T>( 1, 1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( gcd<T>( -1, -1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( gcd<T>( 0, 0), static_cast<T>( 0) );
|
||||
BOOST_TEST_EQ( gcd<T>( 7, 0), static_cast<T>( 7) );
|
||||
BOOST_TEST_EQ( gcd<T>( 0, 9), static_cast<T>( 9) );
|
||||
BOOST_TEST_EQ( gcd<T>( -7, 0), static_cast<T>( 7) );
|
||||
BOOST_TEST_EQ( gcd<T>( 0, -9), static_cast<T>( 9) );
|
||||
BOOST_TEST_EQ( gcd<T>( 42, 30), static_cast<T>( 6) );
|
||||
BOOST_TEST_EQ( gcd<T>( 6, -9), static_cast<T>( 3) );
|
||||
BOOST_TEST_EQ( gcd<T>(-10, -10), static_cast<T>(10) );
|
||||
BOOST_TEST_EQ( gcd<T>(-25, -10), static_cast<T>( 5) );
|
||||
BOOST_TEST_EQ( gcd<T>( 3, 7), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( gcd<T>( 8, 9), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( gcd<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) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 1, -1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( -1, 1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 1, 1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( -1, -1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 0, 0 )), MyInt2( 0) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 7, 0 )), MyInt2( 7) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 0, 9 )), MyInt2( 9) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( -7, 0 )), MyInt2( 7) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 0, -9 )), MyInt2( 9) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 42, 30 )), MyInt2( 6) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 6, -9 )), MyInt2( 3) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( -10, -10 )), MyInt2(10) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( -25, -10 )), MyInt2( 5) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 3, 7 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 8, 9 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(gcd<MyInt2>( 7, 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) );
|
||||
BOOST_TEST_EQ( gcd<T>( 1u, 1u), static_cast<T>( 1u) );
|
||||
BOOST_TEST_EQ( gcd<T>( 0u, 0u), static_cast<T>( 0u) );
|
||||
BOOST_TEST_EQ( gcd<T>( 7u, 0u), static_cast<T>( 7u) );
|
||||
BOOST_TEST_EQ( gcd<T>( 0u, 9u), static_cast<T>( 9u) );
|
||||
BOOST_TEST_EQ( gcd<T>(42u, 30u), static_cast<T>( 6u) );
|
||||
BOOST_TEST_EQ( gcd<T>( 3u, 7u), static_cast<T>( 1u) );
|
||||
BOOST_TEST_EQ( gcd<T>( 8u, 9u), static_cast<T>( 1u) );
|
||||
BOOST_TEST_EQ( gcd<T>( 7u, 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 );
|
||||
BOOST_TEST_EQ( (static_gcd< 1, 1>::value), 1 );
|
||||
BOOST_TEST_EQ( (static_gcd< 0, 0>::value), 0 );
|
||||
BOOST_TEST_EQ( (static_gcd< 7, 0>::value), 7 );
|
||||
BOOST_TEST_EQ( (static_gcd< 0, 9>::value), 9 );
|
||||
BOOST_TEST_EQ( (static_gcd<42, 30>::value), 6 );
|
||||
BOOST_TEST_EQ( (static_gcd< 3, 7>::value), 1 );
|
||||
BOOST_TEST_EQ( (static_gcd< 8, 9>::value), 1 );
|
||||
BOOST_TEST_EQ( (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));
|
||||
// TODO: non-built-in signed and unsigned integer tests, with and without
|
||||
// numeric_limits specialization; polynominal tests; note any changes if
|
||||
// built-ins switch to binary-GCD algorithm
|
||||
|
||||
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));
|
||||
BOOST_TEST_EQ( lcm<T>( 1, -1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( lcm<T>( -1, 1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( lcm<T>( 1, 1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( lcm<T>( -1, -1), static_cast<T>( 1) );
|
||||
BOOST_TEST_EQ( lcm<T>( 0, 0), static_cast<T>( 0) );
|
||||
BOOST_TEST_EQ( lcm<T>( 6, 0), static_cast<T>( 0) );
|
||||
BOOST_TEST_EQ( lcm<T>( 0, 7), static_cast<T>( 0) );
|
||||
BOOST_TEST_EQ( lcm<T>( -5, 0), static_cast<T>( 0) );
|
||||
BOOST_TEST_EQ( lcm<T>( 0, -4), static_cast<T>( 0) );
|
||||
BOOST_TEST_EQ( lcm<T>( 18, 30), static_cast<T>(90) );
|
||||
BOOST_TEST_EQ( lcm<T>( -6, 9), static_cast<T>(18) );
|
||||
BOOST_TEST_EQ( lcm<T>(-10, -10), static_cast<T>(10) );
|
||||
BOOST_TEST_EQ( lcm<T>( 25, -10), static_cast<T>(50) );
|
||||
BOOST_TEST_EQ( lcm<T>( 3, 7), static_cast<T>(21) );
|
||||
BOOST_TEST_EQ( lcm<T>( 8, 9), static_cast<T>(72) );
|
||||
BOOST_TEST_EQ( lcm<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) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 1, -1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( -1, 1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 1, 1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( -1, -1 )), MyInt2( 1) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 0, 0 )), MyInt2( 0) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 6, 0 )), MyInt2( 0) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 0, 7 )), MyInt2( 0) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( -5, 0 )), MyInt2( 0) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 0, -4 )), MyInt2( 0) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 18, 30 )), MyInt2(90) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( -6, 9 )), MyInt2(18) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( -10, -10 )), MyInt2(10) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 25, -10 )), MyInt2(50) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 3, 7 )), MyInt2(21) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 8, 9 )), MyInt2(72) );
|
||||
BOOST_TEST_EQ( abs(lcm<MyInt2>( 7, 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) );
|
||||
BOOST_TEST_EQ( lcm<T>( 1u, 1u), static_cast<T>( 1u) );
|
||||
BOOST_TEST_EQ( lcm<T>( 0u, 0u), static_cast<T>( 0u) );
|
||||
BOOST_TEST_EQ( lcm<T>( 6u, 0u), static_cast<T>( 0u) );
|
||||
BOOST_TEST_EQ( lcm<T>( 0u, 7u), static_cast<T>( 0u) );
|
||||
BOOST_TEST_EQ( lcm<T>(18u, 30u), static_cast<T>(90u) );
|
||||
BOOST_TEST_EQ( lcm<T>( 3u, 7u), static_cast<T>(21u) );
|
||||
BOOST_TEST_EQ( lcm<T>( 8u, 9u), static_cast<T>(72u) );
|
||||
BOOST_TEST_EQ( lcm<T>( 7u, 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 );
|
||||
BOOST_TEST_EQ( (static_lcm< 1, 1>::value), 1 );
|
||||
BOOST_TEST_EQ( (static_lcm< 0, 0>::value), 0 );
|
||||
BOOST_TEST_EQ( (static_lcm< 6, 0>::value), 0 );
|
||||
BOOST_TEST_EQ( (static_lcm< 0, 7>::value), 0 );
|
||||
BOOST_TEST_EQ( (static_lcm<18, 30>::value), 90 );
|
||||
BOOST_TEST_EQ( (static_lcm< 3, 7>::value), 21 );
|
||||
BOOST_TEST_EQ( (static_lcm< 8, 9>::value), 72 );
|
||||
BOOST_TEST_EQ( (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);
|
||||
#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
|
||||
}
|
||||
// TODO: see GCD to-do
|
||||
|
||||
// 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));
|
||||
}
|
||||
// main
|
||||
|
||||
// Various types to test with each GCD/LCM
|
||||
|
||||
#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 ) \
|
||||
# define TEST_SIGNED( test ) \
|
||||
TEST_SIGNED_( test ) \
|
||||
test<boost::long_long_type>();
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
# define TEST_SIGNED__( test ) \
|
||||
# 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>(); \
|
||||
@@ -604,7 +446,6 @@ template <class T> void gcd_and_lcm_on_rationals()
|
||||
test<unsigned long>(); \
|
||||
test<MyUnsigned1>(); \
|
||||
test<MyUnsigned2>();
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
# define TEST_UNSIGNED( test ) \
|
||||
@@ -616,30 +457,17 @@ template <class T> void gcd_and_lcm_on_rationals()
|
||||
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( gcd_int_test )
|
||||
gcd_unmarked_int_test();
|
||||
TEST_UNSIGNED( gcd_unsigned_test )
|
||||
gcd_static_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)
|
||||
TEST_SIGNED( lcm_int_test )
|
||||
lcm_unmarked_int_test();
|
||||
TEST_UNSIGNED( lcm_unsigned_test )
|
||||
lcm_static_test();
|
||||
|
||||
return boost::report_errors();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// 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;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
|
||||
// (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
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
|
||||
// (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
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// 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>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#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)
|
||||
@@ -70,7 +69,7 @@ void do_test_exact(boost::mpl::true_ const&)
|
||||
template <int Bits>
|
||||
void do_test_exact(boost::mpl::false_ const&)
|
||||
{
|
||||
// Nothing to do, type does not have an ::extact member.
|
||||
// Nothing to do, type does not have an ::exact member.
|
||||
}
|
||||
|
||||
template <int Bits>
|
||||
|
||||
Reference in New Issue
Block a user