forked from boostorg/integer
Compare commits
117 Commits
svn-branch
...
doc_revisi
Author | SHA1 | Date | |
---|---|---|---|
0c86f9a11a | |||
b82f5a792b | |||
2de3837ca6 | |||
c5370a9705 | |||
8dae82faeb | |||
1a72919419 | |||
acf272ee7d | |||
7ada3ee926 | |||
4622a12f01 | |||
88b3ac5619 | |||
ae8ee599ac | |||
9677dbd035 | |||
e394f8fd86 | |||
95a4f1e235 | |||
f194e652ab | |||
e64047b7c7 | |||
dcf16f30bc | |||
b70c89a3ff | |||
9f43b6a7d6 | |||
fecb6b5509 | |||
eea434b0f1 | |||
72b569f84f | |||
ce4bd6cc98 | |||
d38557f5f3 | |||
5174291e08 | |||
7c528c325e | |||
bdafb07012 | |||
fe60fee95b | |||
e20431e713 | |||
217fa37de2 | |||
307fee457a | |||
a9d91361fa | |||
f1076ff42c | |||
18a37cbab2 | |||
80b59192ae | |||
1f5f827a5e | |||
56b287a590 | |||
c8faa83d47 | |||
c041451a54 | |||
6e6179b932 | |||
791b547d25 | |||
cd696b2f6a | |||
fadad77a39 | |||
9880cf69dc | |||
56bd3fd0b3 | |||
bb16ad8ea0 | |||
82ad7a9edb | |||
6a8080014a | |||
f6738d210c | |||
5f810b2754 | |||
7c2b4a799d | |||
dcfac1423f | |||
494f52d48e | |||
40b52301df | |||
e0ae3b54d8 | |||
740a20e4bb | |||
afa395b517 | |||
78b9452696 | |||
775d25573b | |||
5328370ab6 | |||
a76279f48c | |||
f71f747400 | |||
70c7ae271c | |||
ff18de3b35 | |||
357349a423 | |||
304cce63f5 | |||
7ad2ddb3bc | |||
ee352dee03 | |||
914b459763 | |||
0f7eb589da | |||
10e19f0e3e | |||
1fd7a3080a | |||
5c91a3c17c | |||
0f228bcf5b | |||
6ac4f9bdac | |||
081eb01f88 | |||
f43bd9288d | |||
9b71d9e83f | |||
bb54ac650f | |||
05330d178e | |||
75134014bf | |||
3f26103101 | |||
06c28356cc | |||
365d61fc4e | |||
72438055a9 | |||
590f9819f9 | |||
d131434ef1 | |||
d12ea4e301 | |||
90f779a9a3 | |||
1898e66238 | |||
2f6544e54d | |||
cc73477d13 | |||
24785bf997 | |||
8457bd01b1 | |||
614515a77b | |||
245c28d187 | |||
f390a64825 | |||
e3da9260e1 | |||
730be18188 | |||
60db1676fc | |||
be17e798df | |||
a1bf7131b3 | |||
dcdfca5f38 | |||
12e2311aa4 | |||
e6bbb33660 | |||
1b9549693a | |||
382eabdff5 | |||
3531eb1ac5 | |||
85e4d3e23d | |||
550fe9d89f | |||
19ed0e48e0 | |||
559b44c259 | |||
b162db6b72 | |||
4935afbcd4 | |||
167961aba1 | |||
7ce7ba6bfd | |||
c8cb2b24a1 |
100
doc/Jamfile.v2
100
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,9 +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 pdf-install : standalone : <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 ;
|
||||
|
||||
|
||||
|
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
247
doc/gcd/math-gcd.qbk
Normal file
247
doc/gcd/math-gcd.qbk
Normal file
@ -0,0 +1,247 @@
|
||||
|
||||
[mathpart gcd_lcm Integer Utilities (Greatest Common Divisor and Least Common Multiple)]
|
||||
|
||||
[section Introduction]
|
||||
|
||||
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.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Synopsis]
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace math
|
||||
{
|
||||
|
||||
template < typename IntegerType >
|
||||
class gcd_evaluator;
|
||||
template < typename IntegerType >
|
||||
class lcm_evaluator;
|
||||
|
||||
template < typename IntegerType >
|
||||
IntegerType gcd( IntegerType const &a, IntegerType const &b );
|
||||
template < typename IntegerType >
|
||||
IntegerType lcm( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
typedef ``['see-below]`` static_gcd_type;
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct static_gcd;
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct static_lcm;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section GCD Function Object]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>]
|
||||
|
||||
template < typename IntegerType >
|
||||
class boost::math::gcd_evaluator
|
||||
{
|
||||
public:
|
||||
// Types
|
||||
typedef IntegerType result_type;
|
||||
typedef IntegerType first_argument_type;
|
||||
typedef IntegerType second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
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
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section LCM Function Object]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>]
|
||||
|
||||
template < typename IntegerType >
|
||||
class boost::math::lcm_evaluator
|
||||
{
|
||||
public:
|
||||
// Types
|
||||
typedef IntegerType result_type;
|
||||
typedef IntegerType first_argument_type;
|
||||
typedef IntegerType second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
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
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:run_time Run-time GCD & LCM Determination]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>]
|
||||
|
||||
template < typename IntegerType >
|
||||
IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
template < typename IntegerType >
|
||||
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.
|
||||
The boost::math::lcm function template returns the least common
|
||||
(nonnegative) multiple of the two integers passed to it.
|
||||
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]
|
||||
|
||||
[*Header: ] [@../../../../boost/math/common_factor_ct.hpp <boost/math/common_factor_ct.hpp>]
|
||||
|
||||
typedef ``['unspecified]`` static_gcd_type;
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct boost::math::static_gcd : public mpl::integral_c<static_gcd_type, implementation_defined>
|
||||
{
|
||||
};
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct boost::math::static_lcm : public mpl::integral_c<static_gcd_type, implementation_defined>
|
||||
{
|
||||
};
|
||||
|
||||
The type `static_gcd_type` is the widest unsigned-integer-type that is supported
|
||||
for use in integral-constant-expressions by the compiler. Usually this
|
||||
the same type as `boost::uintmax_t`, but may fall back to being `unsigned long`
|
||||
for some older compilers.
|
||||
|
||||
The boost::math::static_gcd and boost::math::static_lcm class templates
|
||||
take two value-based template parameters of the ['static_gcd_type] type
|
||||
and inherit from the type `boost::mpl::integral_c`.
|
||||
Inherited from the base class, they have a member /value/
|
||||
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 `static_gcd_type`.
|
||||
|
||||
[h3 Example]
|
||||
|
||||
#include <boost/math/common_factor.hpp>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
cout << "The GCD and LCM of 6 and 15 are "
|
||||
<< boost::math::gcd(6, 15) << " and "
|
||||
<< boost::math::lcm(6, 15) << ", respectively."
|
||||
<< endl;
|
||||
|
||||
cout << "The GCD and LCM of 8 and 9 are "
|
||||
<< boost::math::static_gcd<8, 9>::value
|
||||
<< " and "
|
||||
<< boost::math::static_lcm<8, 9>::value
|
||||
<< ", respectively." << endl;
|
||||
|
||||
int a[] = { 4, 5, 6 }, b[] = { 7, 8, 9 }, c[3];
|
||||
std::transform( a, a + 3, b, c, boost::math::gcd_evaluator<int>() );
|
||||
std::copy( c, c + 3, std::ostream_iterator<int>(cout, " ") );
|
||||
}
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:gcd_header Header <boost/math/common_factor.hpp>]
|
||||
|
||||
This header simply includes the headers
|
||||
[@../../../../boost/math/common_factor_ct.hpp <boost/math/common_factor_ct.hpp>]
|
||||
and [@../../../../boost/math/common_factor_rt.hpp <boost/math/common_factor_rt.hpp>].
|
||||
|
||||
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).
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:demo Demonstration Program]
|
||||
|
||||
The program [@../../../../libs/math/test/common_factor_test.cpp common_factor_test.cpp] 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.)
|
||||
|
||||
[endsect]
|
||||
|
||||
[section Rationale]
|
||||
|
||||
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.
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:gcd_history History]
|
||||
|
||||
* 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.
|
||||
* 7 Nov 2001: Initial version
|
||||
|
||||
[endsect]
|
||||
|
||||
[section:gcd_credits Credits]
|
||||
|
||||
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.
|
||||
|
||||
[endsect]
|
||||
|
||||
[endmathpart]
|
||||
|
||||
[/
|
||||
Copyright 2005, 2013 Daryle Walker.
|
||||
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).
|
||||
]
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Standard Integer Types</title>
|
||||
<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.75.2">
|
||||
<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">
|
||||
<link rel="next" href="traits.html" title="Integer Traits">
|
||||
<link rel="prev" href="history.html" title="History">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@ -20,262 +19,23 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.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="traits.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="history.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>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.cstdint"></a><a class="link" href="cstdint.html" title="Standard Integer Types"> Standard Integer Types</a>
|
||||
<a name="boost_integer.cstdint"></a><a class="link" href="cstdint.html" title="Removed from library: Standard Integer Types">Removed from library: Standard Integer
|
||||
Types</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.overview">Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.rationale"> Rationale</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.ce"> <span class="emphasis"><em>Caveat emptor</em></span></a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.exact_width_integer_types">Exact-width
|
||||
integer types</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.minimum_width_integer_types">Minimum-width
|
||||
integer types</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.fastest_minimum_width_integer_types">Fastest
|
||||
minimum-width integer types</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.greatest_width_integer_types">Greatest-width
|
||||
integer types</a></span></dt>
|
||||
<dt><span class="section"><a href="cstdint.html#boost_integer.cstdint.integer_constant_macros">Integer
|
||||
Constant Macros</a></span></dt>
|
||||
</dl></div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.overview"></a><a class="link" href="cstdint.html#boost_integer.cstdint.overview" title="Overview">Overview</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The header <code class="literal"><a href="../../../../../boost/cstdint.hpp" target="_top"><boost/cstdint.hpp></a></code>
|
||||
provides the typedef's useful for writing portable code that requires certain
|
||||
integer widths. All typedef's are in namespace boost.
|
||||
</p>
|
||||
<p>
|
||||
The specifications for these types are based on the ISO/IEC 9899:1999 C Language
|
||||
standard header <stdint.h>. The 64-bit types required by the C standard
|
||||
are <span class="emphasis"><em>not required</em></span> in the boost header, and may not be
|
||||
supplied for all platforms/compilers, because <code class="literal">long long</code>
|
||||
is not [yet] included in the C++ standard.
|
||||
</p>
|
||||
<p>
|
||||
See <a href="../../../test/cstdint_test.cpp" target="_top">cstdint_test.cpp</a> for
|
||||
a test program.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.rationale"></a><a class="link" href="cstdint.html#boost_integer.cstdint.rationale" title="Rationale"> Rationale</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The organization of the Boost.Integer headers and classes is designed to
|
||||
take advantage of <stdint.h> types from the 1999 C standard without
|
||||
causing undefined behavior in terms of the 1998 C++ standard. The header
|
||||
<boost/cstdint.hpp> makes the standard integer types safely available
|
||||
in namespace <code class="literal">boost</code> without placing any names in namespace
|
||||
<code class="literal">std</code>. The intension is to complement rather than compete
|
||||
with the C++ Standard Library. Should some future C++ standard include <stdint.h>
|
||||
and <cstdint>, then <boost/cstdint.hpp> will continue to function,
|
||||
but will become redundant and may be safely deprecated.
|
||||
</p>
|
||||
<p>
|
||||
Because these are boost headers, their names conform to boost header naming
|
||||
conventions rather than C++ Standard Library header naming conventions.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.ce"></a><a class="link" href="cstdint.html#boost_integer.cstdint.ce" title="Caveat emptor"> <span class="emphasis"><em>Caveat emptor</em></span></a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
As an implementation artifact, certain C <limits.h> macro names may
|
||||
possibly be visible to users of <boost/cstdint.hpp>. Don't use these
|
||||
macros; they are not part of any Boost-specified interface. Use <code class="literal">boost::integer_traits<></code>
|
||||
or <code class="literal">std::numeric_limits<></code> instead.
|
||||
</p>
|
||||
<p>
|
||||
As another implementation artifact, certain C <stdint.h> typedef names
|
||||
may possibly be visible in the global namespace to users of <boost/cstdint.hpp>.
|
||||
Don't use these names, they are not part of any Boost-specified interface.
|
||||
Use the respective names in namespace <code class="literal">boost</code> instead.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.exact_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.exact_width_integer_types" title="Exact-width integer types">Exact-width
|
||||
integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">int#_t</code>, with # replaced by the width, designates
|
||||
a signed integer type of exactly # bits; for example <code class="literal">int8_t</code>
|
||||
denotes an 8-bit signed integer type. Similarly, the typedef <code class="literal">uint#_t</code>
|
||||
designates an unsigned integer type of exactly # bits.
|
||||
</p>
|
||||
<p>
|
||||
These types are optional. However, if a platform supports integer types with
|
||||
widths of 8, 16, 32, 64, or any combination thereof, then <boost/cstdint.hpp>
|
||||
does provide the corresponding typedefs.
|
||||
</p>
|
||||
<p>
|
||||
The absence of int64_t and uint64_t is indicated by the macro <code class="computeroutput"><span class="identifier">BOOST_NO_INT64_T</span></code>.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.minimum_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.minimum_width_integer_types" title="Minimum-width integer types">Minimum-width
|
||||
integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">int_least#_t</code>, with # replaced by the width,
|
||||
designates a signed integer type with a width of at least # bits, such that
|
||||
no signed integer type with lesser size has at least the specified width.
|
||||
Thus, <code class="literal">int_least32_t</code> denotes the smallest signed integer
|
||||
type with a width of at least 32 bits. Similarly, the typedef name <code class="literal">uint_least#_t</code>
|
||||
designates an unsigned integer type with a width of at least # bits, such
|
||||
that no unsigned integer type with lesser size has at least the specified
|
||||
width.
|
||||
</p>
|
||||
<p>
|
||||
The following minimum-width integer types are provided for all platforms:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<li class="listitem">
|
||||
<code class="literal">int_least8_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">int_least16_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">int_least32_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_least8_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_least16_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_least32_t</code>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
The following types are available only if, after including <boost/cstdint.hpp>,
|
||||
the macro BOOST_NO_INT64_T is not defined:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<li class="listitem">
|
||||
<code class="literal">int_least64_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_least64_t</code>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
All other minimum-width integer types are optional.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.fastest_minimum_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.fastest_minimum_width_integer_types" title="Fastest minimum-width integer types">Fastest
|
||||
minimum-width integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">int_fast#_t</code>, with # replaced by the width,
|
||||
designates the fastest signed integer type with a width of at least # bits.
|
||||
Similarly, the typedef name <code class="literal">uint_fast#_t</code> designates the
|
||||
fastest unsigned integer type with a width of at least # bits.
|
||||
</p>
|
||||
<p>
|
||||
There is no guarantee that these types are fastest for all purposes. In any
|
||||
case, however, they satisfy the signedness and width requirements.
|
||||
</p>
|
||||
<p>
|
||||
The following fastest minimum-width integer types are provided for all platforms:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<li class="listitem">
|
||||
<code class="literal">int_fast8_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">int_fast16_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">int_fast32_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_fast8_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_fast16_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_fast32_t</code>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
The following types are available only if, after including <boost/cstdint.hpp>,
|
||||
the macro BOOST_NO_INT64_T is not defined:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<li class="listitem">
|
||||
<code class="literal">int_fast64_t</code>
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="literal">uint_fast64_t</code>
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
All other fastest minimum-width integer types are optional.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.greatest_width_integer_types"></a><a class="link" href="cstdint.html#boost_integer.cstdint.greatest_width_integer_types" title="Greatest-width integer types">Greatest-width
|
||||
integer types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The typedef <code class="literal">intmax_t </code>designates a signed integer type
|
||||
capable of representing any value of any signed integer type.
|
||||
</p>
|
||||
<p>
|
||||
The typedef <code class="literal">uintmax_t</code> designates an unsigned integer type
|
||||
capable of representing any value of any unsigned integer type.
|
||||
</p>
|
||||
<p>
|
||||
These types are provided for all platforms.
|
||||
</p>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.cstdint.integer_constant_macros"></a><a class="link" href="cstdint.html#boost_integer.cstdint.integer_constant_macros" title="Integer Constant Macros">Integer
|
||||
Constant Macros</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The following macros are always defined after inclusion of this header, these
|
||||
allow integer constants of at least the specified width to be declared: INT8_C,
|
||||
UINT8_C, INT16_C, UINT16_C, INT32_C, UINT32_C, INTMAX_C, UINTMAX_C.
|
||||
</p>
|
||||
<p>
|
||||
The macros INT64_C and UINT64_C are also defined if the the macro BOOST_NO_INT64_T
|
||||
is not defined.
|
||||
</p>
|
||||
<p>
|
||||
The C99 macro __STDC_CONSTANT_MACROS is also defined as an artifact of the
|
||||
implementation.
|
||||
</p>
|
||||
<p>
|
||||
For example:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="comment">// Here the constant 0x1FFFFFFFF has the correct suffix applied:
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint64_t</span> <span class="identifier">c</span> <span class="special">=</span> <span class="identifier">INT64_C</span><span class="special">(</span><span class="number">0</span><span class="identifier">x1FFFFFFFF</span><span class="special">);</span>
|
||||
</pre>
|
||||
</div>
|
||||
The <a href="../../../../../libs/config/doc/html/boost_config/cstdint.html" target="_top">Boost.Config</a>
|
||||
module provides the typedefs useful for writing portable code that requires
|
||||
certain integer widths.
|
||||
</p>
|
||||
</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>
|
||||
<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>
|
||||
@ -283,7 +43,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.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="traits.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="history.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>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -3,10 +3,11 @@
|
||||
<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.75.2">
|
||||
<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">
|
||||
<link rel="next" href="cstdint.html" title="Removed from library: Standard Integer Types">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@ -19,17 +20,24 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="minmax.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="p" href="minmax.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="cstdint.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.history"></a><a class="link" href="history.html" title="History"> History</a>
|
||||
<a name="boost_integer.history"></a><a class="link" href="history.html" title="History">History</a>
|
||||
</h2></div></div></div>
|
||||
<a name="boost_integer.history.1_42_0"></a><h5>
|
||||
<a name="id766183"></a>
|
||||
<a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
|
||||
<h5>
|
||||
<a name="boost_integer.history.h0"></a>
|
||||
<span class="phrase"><a name="boost_integer.history.1_56_0"></a></span><a class="link" href="history.html#boost_integer.history.1_56_0">1.56.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Moved <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">cstdint</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code> into <a href="../../../../../libs/config/index.html" target="_top">Boost.Config</a>.
|
||||
</li></ul></div>
|
||||
<h5>
|
||||
<a name="boost_integer.history.h1"></a>
|
||||
<span class="phrase"><a name="boost_integer.history.1_42_0"></a></span><a class="link" href="history.html#boost_integer.history.1_42_0">1.42.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Reverted Trunk to release branch state (i.e. a "known good state").
|
||||
</li>
|
||||
@ -54,11 +62,11 @@
|
||||
provided typedefs in new code (and update old code as soon as possible).
|
||||
</li>
|
||||
</ul></div>
|
||||
<a name="boost_integer.history.1_32_0"></a><h5>
|
||||
<a name="id766314"></a>
|
||||
<a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
|
||||
<h5>
|
||||
<a name="boost_integer.history.h2"></a>
|
||||
<span class="phrase"><a name="boost_integer.history.1_32_0"></a></span><a class="link" href="history.html#boost_integer.history.1_32_0">1.32.0</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc"><li class="listitem">
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
The argument type and the result type of <code class="literal">boost::static_log2</code>
|
||||
are now typedef'd. Formerly, they were hardcoded as <code class="literal">unsigned long</code>
|
||||
and <code class="literal">int</code> respectively. Please, use the provided typedefs
|
||||
@ -67,8 +75,8 @@
|
||||
</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>
|
||||
<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>
|
||||
@ -76,7 +84,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="minmax.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="p" href="minmax.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="cstdint.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>Integer Type Selection</title>
|
||||
<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
|
||||
<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">
|
||||
@ -24,13 +24,13 @@
|
||||
</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>
|
||||
<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>
|
||||
<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
|
||||
<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>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.sized"> Sized Types</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.sized">Sized Types</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.example">Example</a></span></dt>
|
||||
<dt><span class="section"><a href="integer.html#boost_integer.integer.demonstration_program">Demonstration
|
||||
Program</a></span></dt>
|
||||
@ -46,20 +46,20 @@
|
||||
</p>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.synopsis"></a><a class="link" href="integer.html#boost_integer.integer.synopsis" title="Synopsis"> Synopsis</a>
|
||||
<a name="boost_integer.integer.synopsis"></a><a class="link" href="integer.html#boost_integer.integer.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="comment">// fast integers from least integers
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">LeastInt</span><span class="special">></span>
|
||||
<span class="comment">// fast integers from least integers</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">LeastInt</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_fast_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">type</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// signed
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_t</span>
|
||||
<span class="comment">// signed</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</span><span class="special">;</span>
|
||||
@ -67,9 +67,9 @@
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// unsigned
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_t</span>
|
||||
<span class="comment">// unsigned</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">int</span> <span class="identifier">Bits</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">/* Member exact may or may not be defined depending upon Bits */</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">exact</span><span class="special">;</span>
|
||||
@ -77,34 +77,34 @@
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// signed
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MaxValue</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_max_value_t</span>
|
||||
<span class="comment">// signed</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MaxValue</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_max_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">MinValue</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_min_value_t</span>
|
||||
<span class="keyword">struct</span> <span class="identifier">int_min_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// unsigned
|
||||
</span> <span class="keyword">template</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">Value</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_value_t</span>
|
||||
<span class="comment">// unsigned</span>
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">Value</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">uint_value_t</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span> <span class="identifier">least</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">int_fast_t</span><span class="special"><</span><span class="identifier">least</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">fast</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
<span class="special">}</span> <span class="comment">// namespace boost
|
||||
</span></pre>
|
||||
<span class="special">}</span> <span class="comment">// namespace boost</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.easiest"></a><a class="link" href="integer.html#boost_integer.integer.easiest" title="Easiest-to-Manipulate Types"> Easiest-to-Manipulate
|
||||
<a name="boost_integer.integer.easiest"></a><a class="link" href="integer.html#boost_integer.integer.easiest" title="Easiest-to-Manipulate Types">Easiest-to-Manipulate
|
||||
Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
@ -128,7 +128,7 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.integer.sized"></a><a class="link" href="integer.html#boost_integer.integer.sized" title="Sized Types"> Sized Types</a>
|
||||
<a name="boost_integer.integer.sized"></a><a class="link" href="integer.html#boost_integer.integer.sized" title="Sized Types">Sized Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The <code class="literal">int_t</code>, <code class="literal">uint_t</code>, <code class="literal">int_max_value_t</code>,
|
||||
@ -347,19 +347,19 @@
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_t</span><span class="special"><</span><span class="number">24</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my_var</span><span class="special">;</span> <span class="comment">// my_var has at least 24-bits
|
||||
</span> <span class="comment">//...
|
||||
</span> <span class="comment">// This one is guarenteed not to be truncated:
|
||||
</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="comment">//...
|
||||
</span> <span class="comment">// This one is guarenteed not to be truncated, and as fast
|
||||
</span> <span class="comment">// to manipulate as possible, its size may be greater than
|
||||
</span> <span class="comment">// that of my1000:
|
||||
</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">my_fast1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_t</span><span class="special"><</span><span class="number">24</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my_var</span><span class="special">;</span> <span class="comment">// my_var has at least 24-bits</span>
|
||||
<span class="comment">//...</span>
|
||||
<span class="comment">// This one is guarenteed not to be truncated:</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">least</span> <span class="identifier">my1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="comment">//...</span>
|
||||
<span class="comment">// This one is guarenteed not to be truncated, and as fast</span>
|
||||
<span class="comment">// to manipulate as possible, its size may be greater than</span>
|
||||
<span class="comment">// that of my1000:</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">int_max_value_t</span><span class="special"><</span><span class="number">1000</span><span class="special">>::</span><span class="identifier">fast</span> <span class="identifier">my_fast1000</span> <span class="special">=</span> <span class="number">1000</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
@ -381,7 +381,7 @@
|
||||
<p>
|
||||
The rationale for the design of the templates in this header includes:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Avoid recursion because of concern about C++'s limited guaranteed recursion
|
||||
depth (17).
|
||||
@ -417,8 +417,8 @@
|
||||
</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>
|
||||
<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>
|
||||
|
@ -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.75.2">
|
||||
<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">
|
||||
@ -24,9 +24,9 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<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>
|
||||
<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
|
||||
@ -59,12 +59,12 @@
|
||||
<span class="keyword">template</span> <span class="special"><</span> <span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">static_log2</span><span class="special"><</span> <span class="number">0</span> <span class="special">></span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// The logarithm of zero is undefined.
|
||||
</span> <span class="special">};</span>
|
||||
<span class="comment">// The logarithm of zero is undefined.</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
|
||||
<span class="special">}</span> <span class="comment">// namespace boost
|
||||
</span></pre>
|
||||
<span class="special">}</span> <span class="comment">// namespace boost</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
@ -85,7 +85,7 @@
|
||||
<p>
|
||||
Note:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
<code class="literal">static_log2_argument_type</code> is an <span class="emphasis"><em>unsigned
|
||||
integer type</em></span> (C++ standard, 3.9.1p3).
|
||||
@ -136,8 +136,8 @@
|
||||
</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>
|
||||
<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>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<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.75.2">
|
||||
<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="integer.html" title="Integer Type Selection">
|
||||
@ -24,9 +24,9 @@
|
||||
</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>
|
||||
<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
|
||||
@ -56,8 +56,8 @@
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_integer.mask.synopsis"></a><a class="link" href="mask.html#boost_integer.mask.synopsis" title="Synopsis">Synopsis</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cstddef</span><span class="special">></span> <span class="comment">// for std::size_t
|
||||
</span>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cstddef</span><span class="special">></span> <span class="comment">// for std::size_t</span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">boost</span>
|
||||
<span class="special">{</span>
|
||||
|
||||
@ -85,10 +85,10 @@
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bit_count</span> <span class="special">=</span> <span class="identifier">Bits</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">// Specializations for low_bits_mask_t exist for certain bit counts.
|
||||
</span>
|
||||
<span class="special">}</span> <span class="comment">// namespace boost
|
||||
</span></pre>
|
||||
<span class="comment">// Specializations for low_bits_mask_t exist for certain bit counts.</span>
|
||||
|
||||
<span class="special">}</span> <span class="comment">// namespace boost</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
@ -105,8 +105,10 @@
|
||||
of <code class="literal">high_bit_mask_t</code>.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_integer.mask.single_bit_mask_class_template.members_of_the__boost__high_bit_mask_t__class_template"></a><p class="title"><b>Table 2. Members of the `boost::high_bit_mask_t` Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the `boost::high_bit_mask_t` Class Template">
|
||||
<a name="boost_integer.mask.single_bit_mask_class_template.members_of_the__boost__high_bit_mask_t__class_template"></a><p class="title"><b>Table 2. Members of the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">high_bit_mask_t</span></code>
|
||||
Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the boost::high_bit_mask_t
|
||||
Class Template">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
@ -205,8 +207,8 @@
|
||||
type. The following table describes the members of <code class="literal">low_bits_mask_t</code>.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_integer.mask.group_bit_mask_class_template.members_of_the___boost__low_bits_mask_t__class_template"></a><p class="title"><b>Table 3. Members of the [^boost::low_bits_mask_t] Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the [^boost::low_bits_mask_t] Class Template">
|
||||
<a name="boost_integer.mask.group_bit_mask_class_template.members_of_the___boost__low_bits_mask_t__class_template"></a><p class="title"><b>Table 3. Members of the <code class="literal">boost::low_bits_mask_t</code> Class Template</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Members of the boost::low_bits_mask_t Class Template">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
@ -310,8 +312,8 @@
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">integer</span><span class="special">/</span><span class="identifier">integer_mask</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">high_bit_mask_t</span><span class="special"><</span><span class="number">29</span><span class="special">></span> <span class="identifier">mask1_type</span><span class="special">;</span>
|
||||
@ -319,13 +321,13 @@
|
||||
|
||||
<span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">least</span> <span class="identifier">my_var1</span><span class="special">;</span>
|
||||
<span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">fast</span> <span class="identifier">my_var2</span><span class="special">;</span>
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="identifier">my_var1</span> <span class="special">|=</span> <span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">high_bit</span><span class="special">;</span>
|
||||
<span class="identifier">my_var2</span> <span class="special">&=</span> <span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">sig_bits_fast</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span><span class="special">}</span>
|
||||
<span class="comment">//...</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
@ -363,8 +365,8 @@
|
||||
</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>
|
||||
<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>
|
||||
|
@ -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.75.2">
|
||||
<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">
|
||||
@ -24,9 +24,9 @@
|
||||
</div>
|
||||
<div class="section">
|
||||
<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>
|
||||
<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>
|
||||
@ -98,18 +98,18 @@
|
||||
<span class="keyword">void</span> <span class="keyword">operator</span> <span class="special">()(</span> <span class="identifier">addend1_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a1</span><span class="special">,</span> <span class="identifier">addend2_type</span> <span class="keyword">const</span> <span class="special">&</span><span class="identifier">a2</span><span class="special">,</span> <span class="identifier">sum_type</span> <span class="special">&</span><span class="identifier">s</span> <span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="comment">//...
|
||||
</span>
|
||||
<span class="comment">//...</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a1</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">0</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">3</span> <span class="special">};</span> <span class="comment">// 340
|
||||
</span> <span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a2</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">9</span><span class="special">,</span> <span class="number">8</span> <span class="special">};</span> <span class="comment">// 89
|
||||
</span> <span class="keyword">int</span> <span class="identifier">s</span><span class="special">[</span> <span class="number">4</span> <span class="special">];</span>
|
||||
<span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a1</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">0</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">3</span> <span class="special">};</span> <span class="comment">// 340</span>
|
||||
<span class="keyword">int</span> <span class="keyword">const</span> <span class="identifier">a2</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="number">9</span><span class="special">,</span> <span class="number">8</span> <span class="special">};</span> <span class="comment">// 89</span>
|
||||
<span class="keyword">int</span> <span class="identifier">s</span><span class="special">[</span> <span class="number">4</span> <span class="special">];</span>
|
||||
<span class="identifier">adder</span><span class="special"><</span><span class="number">3</span><span class="special">,</span><span class="number">2</span><span class="special">></span> <span class="identifier">obj</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">obj</span><span class="special">(</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span> <span class="identifier">s</span> <span class="special">);</span> <span class="comment">// 's' should be 429 or { 9, 2, 4, 0 }
|
||||
</span> <span class="comment">//...
|
||||
</span><span class="special">}</span>
|
||||
<span class="identifier">obj</span><span class="special">(</span> <span class="identifier">a1</span><span class="special">,</span> <span class="identifier">a2</span><span class="special">,</span> <span class="identifier">s</span> <span class="special">);</span> <span class="comment">// 's' should be 429 or { 9, 2, 4, 0 }</span>
|
||||
<span class="comment">//...</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</div>
|
||||
<div class="section">
|
||||
@ -145,8 +145,8 @@
|
||||
</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>
|
||||
<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>
|
||||
|
@ -3,10 +3,10 @@
|
||||
<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.75.2">
|
||||
<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="cstdint.html" title="Standard Integer Types">
|
||||
<link rel="prev" href="../index.html" title="Boost.Integer">
|
||||
<link rel="next" href="integer.html" title="Integer Type Selection">
|
||||
</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="cstdint.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="integer.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="../index.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="integer.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.traits"></a><a class="link" href="traits.html" title="Integer Traits"> Integer Traits</a>
|
||||
<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>
|
||||
@ -45,14 +45,14 @@
|
||||
<p>
|
||||
For integer types, the interesting members of <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><></span></code> are:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_specialized</span><span class="special">;</span> <span class="comment">// Will be true for integer types.
|
||||
</span><span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">min</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Smallest representable value.
|
||||
</span><span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">max</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Largest representable value.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits</span><span class="special">;</span> <span class="comment">// For integers, the number of value bits.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits10</span><span class="special">;</span> <span class="comment">// The number of base 10 digits that can be represented.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_signed</span><span class="special">;</span> <span class="comment">// True if the type is signed.
|
||||
</span><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_integer</span><span class="special">;</span> <span class="comment">// Will be true for all integer types.
|
||||
</span></pre>
|
||||
<pre class="programlisting"><span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_specialized</span><span class="special">;</span> <span class="comment">// Will be true for integer types.</span>
|
||||
<span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">min</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Smallest representable value.</span>
|
||||
<span class="keyword">static</span> <span class="identifier">T</span> <span class="identifier">max</span><span class="special">()</span> <span class="keyword">throw</span><span class="special">();</span> <span class="comment">// Largest representable value.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits</span><span class="special">;</span> <span class="comment">// For integers, the number of value bits.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">digits10</span><span class="special">;</span> <span class="comment">// The number of base 10 digits that can be represented.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_signed</span><span class="special">;</span> <span class="comment">// True if the type is signed.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_integer</span><span class="special">;</span> <span class="comment">// Will be true for all integer types.</span>
|
||||
</pre>
|
||||
<p>
|
||||
For many uses, these are sufficient. But min() and max() are problematical
|
||||
because they are not constant expressions (std::5.19), yet some usages require
|
||||
@ -72,11 +72,11 @@
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_integral</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>
|
||||
<span class="comment">//
|
||||
</span> <span class="comment">// These members are defined only if T is a built-in
|
||||
</span> <span class="comment">// integal type:
|
||||
</span> <span class="comment">//
|
||||
</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">const_min</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// These members are defined only if T is a built-in</span>
|
||||
<span class="comment">// integal type:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">const_min</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">T</span> <span class="identifier">const_max</span> <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
<span class="special">}</span>
|
||||
@ -200,8 +200,8 @@
|
||||
</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>
|
||||
<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>
|
||||
@ -209,7 +209,7 @@
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cstdint.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="integer.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
<a accesskey="p" href="../index.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="integer.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -3,9 +3,9 @@
|
||||
<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.75.2">
|
||||
<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/cstdint.html" title="Standard Integer Types">
|
||||
<link rel="next" href="boost_integer/traits.html" title="Integer Traits">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<table cellpadding="2" width="100%"><tr>
|
||||
@ -17,7 +17,7 @@
|
||||
<td align="center"><a href="../../../../more/index.htm">More</a></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/cstdint.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/traits.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
|
||||
<div class="article">
|
||||
<div class="titlepage">
|
||||
<div>
|
||||
@ -37,10 +37,10 @@
|
||||
<span class="firstname">John</span> <span class="surname">Maddock</span>
|
||||
</h3></div>
|
||||
</div></div>
|
||||
<div><p class="copyright">Copyright © 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
|
||||
John Maddock</p></div>
|
||||
<div><p class="copyright">Copyright © 2001-2009 Beman
|
||||
Dawes, Daryle Walker, Gennaro Prota, John Maddock</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="id759732"></a><p>
|
||||
<a name="boost_integer.legal"></a><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>
|
||||
@ -50,31 +50,31 @@
|
||||
</div>
|
||||
<div class="toc">
|
||||
<p><b>Table of Contents</b></p>
|
||||
<dl>
|
||||
<dt><span class="section"><a href="index.html#boost_integer.overview"> Overview</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/cstdint.html"> Standard Integer Types</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/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>
|
||||
<dt><span class="section"><a href="boost_integer/history.html"> History</a></span></dt>
|
||||
<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/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>
|
||||
<dt><span class="section"><a href="boost_integer/history.html">History</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_integer/cstdint.html">Removed from library: Standard Integer
|
||||
Types</a></span></dt>
|
||||
</dl>
|
||||
</div>
|
||||
<div class="section">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_integer.overview"></a><a class="link" href="index.html#boost_integer.overview" title="Overview"> Overview</a>
|
||||
<a name="boost_integer.overview"></a><a class="link" href="index.html#boost_integer.overview" title="Overview">Overview</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
Boost.Integer provides integer type support, particularly helpful in generic
|
||||
programming. It provides standard C99 integer types, such as might be found
|
||||
in <stdint.h>, without requiring that header. It provides the means to
|
||||
select an integer type based upon its properties, like the number of bits or
|
||||
the maximum supported value, as well as compile-time bit mask selection. There
|
||||
is a derivative of std::numeric_limits that provides integral constant expressions
|
||||
for <code class="computeroutput"><span class="identifier">min</span></code> and <code class="computeroutput"><span class="identifier">max</span></code>.
|
||||
Finally, it provides two compile-time algorithms: determining the highest power
|
||||
of two in a compile-time value; and computing min and max of constant expressions.
|
||||
programming. It provides the means to select an integer type based upon its
|
||||
properties, like the number of bits or the maximum supported value, as well
|
||||
as compile-time bit mask selection. There is a derivative of std::numeric_limits
|
||||
that provides integral constant expressions for <code class="computeroutput"><span class="identifier">min</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">max</span></code>. Finally, it provides
|
||||
two compile-time algorithms: determining the highest power of two in a compile-time
|
||||
value; and computing min and max of constant expressions.
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
@ -119,24 +119,6 @@
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/cstdint.html" title="Standard Integer Types">Standard Integer Types</a>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="literal"><a href="../../../../boost/cstdint.hpp" target="_top"><boost/cstdint.hpp></a></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Provides typedef's based on the 1999 C Standard header <code class="computeroutput"><span class="special"><</span><span class="identifier">stdint</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span></code>, wrapped in namespace boost.
|
||||
This implementation may #include the compiler supplied <code class="computeroutput"><span class="special"><</span><span class="identifier">stdint</span><span class="special">.</span><span class="identifier">h</span><span class="special">></span></code>, if present.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="boost_integer/traits.html" title="Integer Traits">Integer Traits</a>.
|
||||
@ -237,10 +219,10 @@
|
||||
</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: July 08, 2010 at 20:45:20 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>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/cstdint.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_integer/traits.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
|
||||
</body>
|
||||
</html>
|
||||
|
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*\>
|
1088
doc/integer.qbk
1088
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 ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,508 +0,0 @@
|
||||
// boost cstdint.hpp header file ------------------------------------------//
|
||||
|
||||
// (C) Copyright Beman Dawes 1999.
|
||||
// (C) Copyright Jens Mauer 2001
|
||||
// (C) Copyright John Maddock 2001
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 31 Oct 01 use BOOST_HAS_LONG_LONG to check for "long long" (Jens M.)
|
||||
// 16 Apr 01 check LONGLONG_MAX when looking for "long long" (Jens Maurer)
|
||||
// 23 Jan 01 prefer "long" over "int" for int32_t and intmax_t (Jens Maurer)
|
||||
// 12 Nov 00 Merged <boost/stdint.h> (Jens Maurer)
|
||||
// 23 Sep 00 Added INTXX_C macro support (John Maddock).
|
||||
// 22 Sep 00 Better 64-bit support (John Maddock)
|
||||
// 29 Jun 00 Reimplement to avoid including stdint.h within namespace boost
|
||||
// 8 Aug 99 Initial version (Beman Dawes)
|
||||
|
||||
|
||||
#ifndef BOOST_CSTDINT_HPP
|
||||
#define BOOST_CSTDINT_HPP
|
||||
|
||||
//
|
||||
// Since we always define the INT#_C macros as per C++0x,
|
||||
// define __STDC_CONSTANT_MACROS so that <stdint.h> does the right
|
||||
// thing if possible, and so that the user knows that the macros
|
||||
// are actually defined as per C99.
|
||||
//
|
||||
#ifndef __STDC_CONSTANT_MACROS
|
||||
# define __STDC_CONSTANT_MACROS
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
//
|
||||
// Note that GLIBC is a bit inconsistent about whether int64_t is defined or not
|
||||
// depending upon what headers happen to have been included first...
|
||||
// so we disable use of stdint.h when GLIBC does not define __GLIBC_HAVE_LONG_LONG.
|
||||
// See https://svn.boost.org/trac/boost/ticket/3548 and http://sources.redhat.com/bugzilla/show_bug.cgi?id=10990
|
||||
//
|
||||
#if defined(BOOST_HAS_STDINT_H) && (!defined(__GLIBC__) || defined(__GLIBC_HAVE_LONG_LONG))
|
||||
|
||||
// The following #include is an implementation artifact; not part of interface.
|
||||
# ifdef __hpux
|
||||
// HP-UX has a vaguely nice <stdint.h> in a non-standard location
|
||||
# include <inttypes.h>
|
||||
# ifdef __STDC_32_MODE__
|
||||
// this is triggered with GCC, because it defines __cplusplus < 199707L
|
||||
# define BOOST_NO_INT64_T
|
||||
# endif
|
||||
# elif defined(__FreeBSD__) || defined(__IBMCPP__) || defined(_AIX)
|
||||
# include <inttypes.h>
|
||||
# else
|
||||
# include <stdint.h>
|
||||
|
||||
// There is a bug in Cygwin two _C macros
|
||||
# if defined(__STDC_CONSTANT_MACROS) && defined(__CYGWIN__)
|
||||
# undef INTMAX_C
|
||||
# undef UINTMAX_C
|
||||
# define INTMAX_C(c) c##LL
|
||||
# define UINTMAX_C(c) c##ULL
|
||||
# endif
|
||||
|
||||
# endif
|
||||
|
||||
#ifdef __QNX__
|
||||
|
||||
// QNX (Dinkumware stdlib) defines these as non-standard names.
|
||||
// Reflect to the standard names.
|
||||
|
||||
typedef ::intleast8_t int_least8_t;
|
||||
typedef ::intfast8_t int_fast8_t;
|
||||
typedef ::uintleast8_t uint_least8_t;
|
||||
typedef ::uintfast8_t uint_fast8_t;
|
||||
|
||||
typedef ::intleast16_t int_least16_t;
|
||||
typedef ::intfast16_t int_fast16_t;
|
||||
typedef ::uintleast16_t uint_least16_t;
|
||||
typedef ::uintfast16_t uint_fast16_t;
|
||||
|
||||
typedef ::intleast32_t int_least32_t;
|
||||
typedef ::intfast32_t int_fast32_t;
|
||||
typedef ::uintleast32_t uint_least32_t;
|
||||
typedef ::uintfast32_t uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
typedef ::intleast64_t int_least64_t;
|
||||
typedef ::intfast64_t int_fast64_t;
|
||||
typedef ::uintleast64_t uint_least64_t;
|
||||
typedef ::uintfast64_t uint_fast64_t;
|
||||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
using ::int8_t;
|
||||
using ::int_least8_t;
|
||||
using ::int_fast8_t;
|
||||
using ::uint8_t;
|
||||
using ::uint_least8_t;
|
||||
using ::uint_fast8_t;
|
||||
|
||||
using ::int16_t;
|
||||
using ::int_least16_t;
|
||||
using ::int_fast16_t;
|
||||
using ::uint16_t;
|
||||
using ::uint_least16_t;
|
||||
using ::uint_fast16_t;
|
||||
|
||||
using ::int32_t;
|
||||
using ::int_least32_t;
|
||||
using ::int_fast32_t;
|
||||
using ::uint32_t;
|
||||
using ::uint_least32_t;
|
||||
using ::uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
using ::int64_t;
|
||||
using ::int_least64_t;
|
||||
using ::int_fast64_t;
|
||||
using ::uint64_t;
|
||||
using ::uint_least64_t;
|
||||
using ::uint_fast64_t;
|
||||
|
||||
# endif
|
||||
|
||||
using ::intmax_t;
|
||||
using ::uintmax_t;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#elif defined(__FreeBSD__) && (__FreeBSD__ <= 4) || defined(__osf__) || defined(__VMS)
|
||||
// FreeBSD and Tru64 have an <inttypes.h> that contains much of what we need.
|
||||
# include <inttypes.h>
|
||||
|
||||
namespace boost {
|
||||
|
||||
using ::int8_t;
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int8_t int_fast8_t;
|
||||
using ::uint8_t;
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint8_t uint_fast8_t;
|
||||
|
||||
using ::int16_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int16_t int_fast16_t;
|
||||
using ::uint16_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint16_t uint_fast16_t;
|
||||
|
||||
using ::int32_t;
|
||||
typedef int32_t int_least32_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
using ::uint32_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
|
||||
# ifndef BOOST_NO_INT64_T
|
||||
|
||||
using ::int64_t;
|
||||
typedef int64_t int_least64_t;
|
||||
typedef int64_t int_fast64_t;
|
||||
using ::uint64_t;
|
||||
typedef uint64_t uint_least64_t;
|
||||
typedef uint64_t uint_fast64_t;
|
||||
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
|
||||
# else
|
||||
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
|
||||
# endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#else // BOOST_HAS_STDINT_H
|
||||
|
||||
# include <boost/limits.hpp> // implementation artifact; not part of interface
|
||||
# include <limits.h> // needed for limits macros
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
|
||||
// These are fairly safe guesses for some 16-bit, and most 32-bit and 64-bit
|
||||
// platforms. For other systems, they will have to be hand tailored.
|
||||
//
|
||||
// Because the fast types are assumed to be the same as the undecorated types,
|
||||
// it may be possible to hand tailor a more efficient implementation. Such
|
||||
// an optimization may be illusionary; on the Intel x86-family 386 on, for
|
||||
// example, byte arithmetic and load/stores are as fast as "int" sized ones.
|
||||
|
||||
// 8-bit types ------------------------------------------------------------//
|
||||
|
||||
# if UCHAR_MAX == 0xff
|
||||
typedef signed char int8_t;
|
||||
typedef signed char int_least8_t;
|
||||
typedef signed char int_fast8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned char uint_least8_t;
|
||||
typedef unsigned char uint_fast8_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if USHRT_MAX == 0xffff
|
||||
# if defined(__crayx1)
|
||||
// The Cray X1 has a 16-bit short, however it is not recommend
|
||||
// for use in performance critical code.
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef int int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned int uint_fast16_t;
|
||||
# else
|
||||
typedef short int16_t;
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# endif
|
||||
# elif (USHRT_MAX == 0xffffffff) && defined(__MTA__)
|
||||
// On MTA / XMT short is 32 bits unless the -short16 compiler flag is specified
|
||||
// MTA / XMT does support the following non-standard integer types
|
||||
typedef __short16 int16_t;
|
||||
typedef __short16 int_least16_t;
|
||||
typedef __short16 int_fast16_t;
|
||||
typedef unsigned __short16 uint16_t;
|
||||
typedef unsigned __short16 uint_least16_t;
|
||||
typedef unsigned __short16 uint_fast16_t;
|
||||
# elif (USHRT_MAX == 0xffffffff) && defined(CRAY)
|
||||
// no 16-bit types on Cray:
|
||||
typedef short int_least16_t;
|
||||
typedef short int_fast16_t;
|
||||
typedef unsigned short uint_least16_t;
|
||||
typedef unsigned short uint_fast16_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 32-bit types -----------------------------------------------------------//
|
||||
|
||||
# if UINT_MAX == 0xffffffff
|
||||
typedef int int32_t;
|
||||
typedef int int_least32_t;
|
||||
typedef int int_fast32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned int uint_least32_t;
|
||||
typedef unsigned int uint_fast32_t;
|
||||
# elif (USHRT_MAX == 0xffffffff)
|
||||
typedef short int32_t;
|
||||
typedef short int_least32_t;
|
||||
typedef short int_fast32_t;
|
||||
typedef unsigned short uint32_t;
|
||||
typedef unsigned short uint_least32_t;
|
||||
typedef unsigned short uint_fast32_t;
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
typedef long int32_t;
|
||||
typedef long int_least32_t;
|
||||
typedef long int_fast32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
typedef unsigned long uint_least32_t;
|
||||
typedef unsigned long uint_fast32_t;
|
||||
# elif (UINT_MAX == 0xffffffffffffffff) && defined(__MTA__)
|
||||
// Integers are 64 bits on the MTA / XMT
|
||||
typedef __int32 int32_t;
|
||||
typedef __int32 int_least32_t;
|
||||
typedef __int32 int_fast32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef unsigned __int32 uint_least32_t;
|
||||
typedef unsigned __int32 uint_fast32_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
|
||||
# if defined(BOOST_HAS_LONG_LONG) && \
|
||||
!defined(BOOST_MSVC) && !defined(__BORLANDC__) && \
|
||||
(!defined(__GLIBCPP__) || defined(_GLIBCPP_USE_LONG_LONG)) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX))
|
||||
# if defined(__hpux)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || (defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || (defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL)
|
||||
// 2**64 - 1
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
typedef ::boost::long_long_type intmax_t;
|
||||
typedef ::boost::ulong_long_type uintmax_t;
|
||||
typedef ::boost::long_long_type int64_t;
|
||||
typedef ::boost::long_long_type int_least64_t;
|
||||
typedef ::boost::long_long_type int_fast64_t;
|
||||
typedef ::boost::ulong_long_type uint64_t;
|
||||
typedef ::boost::ulong_long_type uint_least64_t;
|
||||
typedef ::boost::ulong_long_type uint_fast64_t;
|
||||
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615 // 2**64 - 1
|
||||
typedef long intmax_t;
|
||||
typedef unsigned long uintmax_t;
|
||||
typedef long int64_t;
|
||||
typedef long int_least64_t;
|
||||
typedef long int_fast64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
typedef unsigned long uint_least64_t;
|
||||
typedef unsigned long uint_fast64_t;
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif defined(__GNUC__) && defined(BOOST_HAS_LONG_LONG)
|
||||
__extension__ typedef long long intmax_t;
|
||||
__extension__ typedef unsigned long long uintmax_t;
|
||||
__extension__ typedef long long int64_t;
|
||||
__extension__ typedef long long int_least64_t;
|
||||
__extension__ typedef long long int_fast64_t;
|
||||
__extension__ typedef unsigned long long uint64_t;
|
||||
__extension__ typedef unsigned long long uint_least64_t;
|
||||
__extension__ typedef unsigned long long uint_fast64_t;
|
||||
# elif defined(BOOST_HAS_MS_INT64)
|
||||
//
|
||||
// we have Borland/Intel/Microsoft __int64:
|
||||
//
|
||||
typedef __int64 intmax_t;
|
||||
typedef unsigned __int64 uintmax_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef __int64 int_least64_t;
|
||||
typedef __int64 int_fast64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
typedef unsigned __int64 uint_least64_t;
|
||||
typedef unsigned __int64 uint_fast64_t;
|
||||
# else // assume no 64-bit integers
|
||||
# define BOOST_NO_INT64_T
|
||||
typedef int32_t intmax_t;
|
||||
typedef uint32_t uintmax_t;
|
||||
# endif
|
||||
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_HAS_STDINT_H
|
||||
|
||||
#endif // BOOST_CSTDINT_HPP
|
||||
|
||||
|
||||
/****************************************************
|
||||
|
||||
Macro definition section:
|
||||
|
||||
Added 23rd September 2000 (John Maddock).
|
||||
Modified 11th September 2001 to be excluded when
|
||||
BOOST_HAS_STDINT_H is defined (John Maddock).
|
||||
Modified 11th Dec 2009 to always define the
|
||||
INT#_C macros if they're not already defined (John Maddock).
|
||||
|
||||
******************************************************/
|
||||
|
||||
#if !defined(BOOST__STDC_CONSTANT_MACROS_DEFINED) && \
|
||||
(!defined(INT8_C) || !defined(INT16_C) || !defined(INT32_C) || !defined(INT64_C))
|
||||
//
|
||||
// For the following code we get several warnings along the lines of:
|
||||
//
|
||||
// boost/cstdint.hpp:428:35: error: use of C99 long long integer constant
|
||||
//
|
||||
// So we declare this a system header to suppress these warnings.
|
||||
//
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
# define BOOST__STDC_CONSTANT_MACROS_DEFINED
|
||||
# if defined(BOOST_HAS_MS_INT64)
|
||||
//
|
||||
// Borland/Intel/Microsoft compilers have width specific suffixes:
|
||||
//
|
||||
#ifndef INT8_C
|
||||
# define INT8_C(value) value##i8
|
||||
#endif
|
||||
#ifndef INT16_C
|
||||
# define INT16_C(value) value##i16
|
||||
#endif
|
||||
#ifndef INT32_C
|
||||
# define INT32_C(value) value##i32
|
||||
#endif
|
||||
#ifndef INT64_C
|
||||
# define INT64_C(value) value##i64
|
||||
#endif
|
||||
# ifdef __BORLANDC__
|
||||
// Borland bug: appending ui8 makes the type a signed char
|
||||
# define UINT8_C(value) static_cast<unsigned char>(value##u)
|
||||
# else
|
||||
# define UINT8_C(value) value##ui8
|
||||
# endif
|
||||
#ifndef UINT16_C
|
||||
# define UINT16_C(value) value##ui16
|
||||
#endif
|
||||
#ifndef UINT32_C
|
||||
# define UINT32_C(value) value##ui32
|
||||
#endif
|
||||
#ifndef UINT64_C
|
||||
# define UINT64_C(value) value##ui64
|
||||
#endif
|
||||
#ifndef INTMAX_C
|
||||
# define INTMAX_C(value) value##i64
|
||||
# define UINTMAX_C(value) value##ui64
|
||||
#endif
|
||||
|
||||
# else
|
||||
// do it the old fashioned way:
|
||||
|
||||
// 8-bit types ------------------------------------------------------------//
|
||||
|
||||
# if (UCHAR_MAX == 0xff) && !defined(INT8_C)
|
||||
# define INT8_C(value) static_cast<boost::int8_t>(value)
|
||||
# define UINT8_C(value) static_cast<boost::uint8_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 16-bit types -----------------------------------------------------------//
|
||||
|
||||
# if (USHRT_MAX == 0xffff) && !defined(INT16_C)
|
||||
# define INT16_C(value) static_cast<boost::int16_t>(value)
|
||||
# define UINT16_C(value) static_cast<boost::uint16_t>(value##u)
|
||||
# endif
|
||||
|
||||
// 32-bit types -----------------------------------------------------------//
|
||||
#ifndef INT32_C
|
||||
# if (UINT_MAX == 0xffffffff)
|
||||
# define INT32_C(value) value
|
||||
# define UINT32_C(value) value##u
|
||||
# elif ULONG_MAX == 0xffffffff
|
||||
# define INT32_C(value) value##L
|
||||
# define UINT32_C(value) value##uL
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// 64-bit types + intmax_t and uintmax_t ----------------------------------//
|
||||
#ifndef INT64_C
|
||||
# if defined(BOOST_HAS_LONG_LONG) && \
|
||||
(defined(ULLONG_MAX) || defined(ULONG_LONG_MAX) || defined(ULONGLONG_MAX) || defined(_LLONG_MAX))
|
||||
|
||||
# if defined(__hpux)
|
||||
// HP-UX's value of ULONG_LONG_MAX is unusable in preprocessor expressions
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# elif (defined(ULLONG_MAX) && ULLONG_MAX == 18446744073709551615ULL) || \
|
||||
(defined(ULONG_LONG_MAX) && ULONG_LONG_MAX == 18446744073709551615ULL) || \
|
||||
(defined(ULONGLONG_MAX) && ULONGLONG_MAX == 18446744073709551615ULL) || \
|
||||
(defined(_LLONG_MAX) && _LLONG_MAX == 18446744073709551615ULL)
|
||||
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif ULONG_MAX != 0xffffffff
|
||||
|
||||
# if ULONG_MAX == 18446744073709551615U // 2**64 - 1
|
||||
# define INT64_C(value) value##L
|
||||
# define UINT64_C(value) value##uL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# elif defined(BOOST_HAS_LONG_LONG)
|
||||
// Usual macros not defined, work things out for ourselves:
|
||||
# if(~0uLL == 18446744073709551615ULL)
|
||||
# define INT64_C(value) value##LL
|
||||
# define UINT64_C(value) value##uLL
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
# else
|
||||
# error defaults not correct; you must hand modify boost/cstdint.hpp
|
||||
# endif
|
||||
|
||||
# ifdef BOOST_NO_INT64_T
|
||||
# define INTMAX_C(value) INT32_C(value)
|
||||
# define UINTMAX_C(value) UINT32_C(value)
|
||||
# else
|
||||
# define INTMAX_C(value) INT64_C(value)
|
||||
# define UINTMAX_C(value) UINT64_C(value)
|
||||
# endif
|
||||
#endif
|
||||
# endif // Borland/Microsoft specific width suffixes
|
||||
|
||||
#endif // INT#_C macros.
|
||||
|
||||
|
||||
|
||||
|
@ -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)
|
||||
@ -20,6 +23,7 @@
|
||||
#include <boost/integer_traits.hpp> // for boost::::boost::integer_traits
|
||||
#include <boost/limits.hpp> // for ::std::numeric_limits
|
||||
#include <boost/cstdint.hpp> // for boost::int64_t and BOOST_NO_INTEGRAL_INT64_T
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
//
|
||||
// We simply cannot include this header on gcc without getting copious warnings of the kind:
|
||||
@ -41,16 +45,18 @@ namespace boost
|
||||
// fast integers from least integers
|
||||
// int_fast_t<> works correctly for unsigned too, in spite of the name.
|
||||
template< typename LeastInt >
|
||||
struct int_fast_t
|
||||
{
|
||||
typedef LeastInt fast;
|
||||
struct int_fast_t
|
||||
{
|
||||
typedef LeastInt fast;
|
||||
typedef fast type;
|
||||
}; // imps may specialize
|
||||
|
||||
//! \cond DETAIL
|
||||
namespace detail{
|
||||
|
||||
// convert category to type
|
||||
// convert category to type
|
||||
template< int Category > struct int_least_helper {}; // default is empty
|
||||
template< int Category > struct uint_least_helper {}; // default is empty
|
||||
|
||||
// specializatons: 1=long, 2=int, 3=short, 4=signed char,
|
||||
// 6=unsigned long, 7=unsigned int, 8=unsigned short, 9=unsigned char
|
||||
@ -65,14 +71,14 @@ namespace boost
|
||||
template<> struct int_least_helper<4> { typedef short least; };
|
||||
template<> struct int_least_helper<5> { typedef signed char least; };
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
template<> struct int_least_helper<6> { typedef boost::ulong_long_type least; };
|
||||
template<> struct uint_least_helper<1> { typedef boost::ulong_long_type least; };
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
template<> struct int_least_helper<6> { typedef unsigned __int64 least; };
|
||||
template<> struct uint_least_helper<1> { typedef unsigned __int64 least; };
|
||||
#endif
|
||||
template<> struct int_least_helper<7> { typedef unsigned long least; };
|
||||
template<> struct int_least_helper<8> { typedef unsigned int least; };
|
||||
template<> struct int_least_helper<9> { typedef unsigned short least; };
|
||||
template<> struct int_least_helper<10> { typedef unsigned char least; };
|
||||
template<> struct uint_least_helper<2> { typedef unsigned long least; };
|
||||
template<> struct uint_least_helper<3> { typedef unsigned int least; };
|
||||
template<> struct uint_least_helper<4> { typedef unsigned short least; };
|
||||
template<> struct uint_least_helper<5> { typedef unsigned char least; };
|
||||
|
||||
template <int Bits>
|
||||
struct exact_signed_base_helper{};
|
||||
@ -102,19 +108,21 @@ 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 ---------------------------//
|
||||
|
||||
// signed
|
||||
template< int Bits > // bits (including sign) required
|
||||
struct int_t : public detail::exact_signed_base_helper<Bits>
|
||||
struct int_t : public boost::detail::exact_signed_base_helper<Bits>
|
||||
{
|
||||
typedef typename detail::int_least_helper
|
||||
BOOST_STATIC_ASSERT_MSG(Bits <= (int)(sizeof(boost::intmax_t) * CHAR_BIT),
|
||||
"No suitable signed integer type with the requested number of bits is available.");
|
||||
typedef typename boost::detail::int_least_helper
|
||||
<
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
(Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
|
||||
(Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
|
||||
#else
|
||||
1 +
|
||||
#endif
|
||||
@ -128,11 +136,13 @@ namespace boost
|
||||
|
||||
// unsigned
|
||||
template< int Bits > // bits required
|
||||
struct uint_t : public detail::exact_unsigned_base_helper<Bits>
|
||||
struct uint_t : public boost::detail::exact_unsigned_base_helper<Bits>
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(Bits <= (int)(sizeof(boost::uintmax_t) * CHAR_BIT),
|
||||
"No suitable unsigned integer type with the requested number of bits is available.");
|
||||
#if (defined(__BORLANDC__) || defined(__CODEGEAR__)) && defined(BOOST_NO_INTEGRAL_INT64_T)
|
||||
// It's really not clear why this workaround should be needed... shrug I guess! JM
|
||||
BOOST_STATIC_CONSTANT(int, s =
|
||||
BOOST_STATIC_CONSTANT(int, s =
|
||||
6 +
|
||||
(Bits <= ::std::numeric_limits<unsigned long>::digits) +
|
||||
(Bits <= ::std::numeric_limits<unsigned int>::digits) +
|
||||
@ -140,11 +150,10 @@ namespace boost
|
||||
(Bits <= ::std::numeric_limits<unsigned char>::digits));
|
||||
typedef typename detail::int_least_helper< ::boost::uint_t<Bits>::s>::least least;
|
||||
#else
|
||||
typedef typename detail::int_least_helper
|
||||
<
|
||||
5 +
|
||||
typedef typename boost::detail::uint_least_helper
|
||||
<
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
(Bits-1 <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
|
||||
(Bits <= (int)(sizeof(boost::long_long_type) * CHAR_BIT)) +
|
||||
#else
|
||||
1 +
|
||||
#endif
|
||||
@ -166,9 +175,9 @@ namespace boost
|
||||
#else
|
||||
template< long MaxValue > // maximum value to require support
|
||||
#endif
|
||||
struct int_max_value_t
|
||||
struct int_max_value_t
|
||||
{
|
||||
typedef typename detail::int_least_helper
|
||||
typedef typename boost::detail::int_least_helper
|
||||
<
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
(MaxValue <= ::boost::integer_traits<boost::long_long_type>::const_max) +
|
||||
@ -188,9 +197,9 @@ namespace boost
|
||||
#else
|
||||
template< long MinValue > // minimum value to require support
|
||||
#endif
|
||||
struct int_min_value_t
|
||||
struct int_min_value_t
|
||||
{
|
||||
typedef typename detail::int_least_helper
|
||||
typedef typename boost::detail::int_least_helper
|
||||
<
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
(MinValue >= ::boost::integer_traits<boost::long_long_type>::const_min) +
|
||||
@ -211,32 +220,31 @@ namespace boost
|
||||
#else
|
||||
template< unsigned long MaxValue > // minimum value to require support
|
||||
#endif
|
||||
struct uint_value_t
|
||||
struct uint_value_t
|
||||
{
|
||||
#if (defined(__BORLANDC__) || defined(__CODEGEAR__))
|
||||
// It's really not clear why this workaround should be needed... shrug I guess! JM
|
||||
#if defined(BOOST_NO_INTEGRAL_INT64_T)
|
||||
BOOST_STATIC_CONSTANT(unsigned, which =
|
||||
6 +
|
||||
BOOST_STATIC_CONSTANT(unsigned, which =
|
||||
1 +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned char>::const_max));
|
||||
typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
|
||||
#else // BOOST_NO_INTEGRAL_INT64_T
|
||||
BOOST_STATIC_CONSTANT(unsigned, which =
|
||||
5 +
|
||||
BOOST_STATIC_CONSTANT(unsigned, which =
|
||||
1 +
|
||||
(MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned long>::const_max) +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned int>::const_max) +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned short>::const_max) +
|
||||
(MaxValue <= ::boost::integer_traits<unsigned char>::const_max));
|
||||
typedef typename detail::int_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
|
||||
typedef typename detail::uint_least_helper< ::boost::uint_value_t<MaxValue>::which>::least least;
|
||||
#endif // BOOST_NO_INTEGRAL_INT64_T
|
||||
#else
|
||||
typedef typename detail::int_least_helper
|
||||
<
|
||||
5 +
|
||||
typedef typename boost::detail::uint_least_helper
|
||||
<
|
||||
#if !defined(BOOST_NO_INTEGRAL_INT64_T) && defined(BOOST_HAS_LONG_LONG)
|
||||
(MaxValue <= ::boost::integer_traits<boost::ulong_long_type>::const_max) +
|
||||
#else
|
||||
@ -251,7 +259,6 @@ namespace boost
|
||||
typedef typename int_fast_t<least>::type fast;
|
||||
};
|
||||
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_INTEGER_HPP
|
||||
|
18
include/boost/integer/common_factor.hpp
Normal file
18
include/boost/integer/common_factor.hpp
Normal file
@ -0,0 +1,18 @@
|
||||
// Boost common_factor.hpp header file -------------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001-2002.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//! \file
|
||||
//! \brief Include both GCD and LCM.
|
||||
|
||||
#ifndef BOOST_INTEGER_COMMON_FACTOR_HPP
|
||||
#define BOOST_INTEGER_COMMON_FACTOR_HPP
|
||||
|
||||
#include <boost/integer/common_factor_ct.hpp>
|
||||
#include <boost/integer/common_factor_rt.hpp>
|
||||
|
||||
#endif // BOOST_INTEGER_COMMON_FACTOR_HPP
|
106
include/boost/integer/common_factor_ct.hpp
Normal file
106
include/boost/integer/common_factor_ct.hpp
Normal file
@ -0,0 +1,106 @@
|
||||
// Boost common_factor_ct.hpp header file ----------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker and Stephen Cleary 2001-2002.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for 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> // 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
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct static_gcd_helper_t
|
||||
{
|
||||
private:
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, new_value1 = Value2 );
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, new_value2 = Value1 % Value2 );
|
||||
|
||||
#ifndef __BORLANDC__
|
||||
#define BOOST_DETAIL_GCD_HELPER_VAL(Value) static_cast<static_gcd_type>(Value)
|
||||
#else
|
||||
typedef static_gcd_helper_t self_type;
|
||||
#define BOOST_DETAIL_GCD_HELPER_VAL(Value) (self_type:: Value )
|
||||
#endif
|
||||
|
||||
typedef static_gcd_helper_t< BOOST_DETAIL_GCD_HELPER_VAL(new_value1),
|
||||
BOOST_DETAIL_GCD_HELPER_VAL(new_value2) > next_step_type;
|
||||
|
||||
#undef BOOST_DETAIL_GCD_HELPER_VAL
|
||||
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, value = next_step_type::value );
|
||||
};
|
||||
|
||||
// Non-recursive case
|
||||
template < static_gcd_type Value1 >
|
||||
struct static_gcd_helper_t< Value1, 0UL >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 );
|
||||
};
|
||||
|
||||
// Build the LCM from the GCD
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct static_lcm_helper_t
|
||||
{
|
||||
typedef static_gcd_helper_t<Value1, Value2> gcd_type;
|
||||
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, value = Value1 / gcd_type::value
|
||||
* Value2 );
|
||||
};
|
||||
|
||||
// Special case for zero-GCD values
|
||||
template < >
|
||||
struct static_lcm_helper_t< 0UL, 0UL >
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, value = 0UL );
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
//! \endcond // DETAIL
|
||||
|
||||
// Compile-time greatest common divisor evaluator class declaration --------//
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 > struct static_gcd
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_gcd_helper_t<Value1, Value2>::value) );
|
||||
}; // boost::integer::static_gcd
|
||||
|
||||
#if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)
|
||||
template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_gcd< Value1, Value2 >::value;
|
||||
#endif
|
||||
|
||||
// Compile-time least common multiple evaluator class declaration ----------//
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 > struct static_lcm
|
||||
{
|
||||
BOOST_STATIC_CONSTANT( static_gcd_type, value = (detail::static_lcm_helper_t<Value1, Value2>::value) );
|
||||
}; // boost::integer::static_lcm
|
||||
|
||||
#if !defined(BOOST_NO_INCLASS_MEMBER_INITIALIZATION)
|
||||
template< static_gcd_type Value1, static_gcd_type Value2 > static_gcd_type const static_lcm< Value1, Value2 >::value;
|
||||
#endif
|
||||
|
||||
} // namespace integer
|
||||
} // namespace boost
|
||||
|
||||
|
||||
#endif // BOOST_INTEGER_COMMON_FACTOR_CT_HPP
|
488
include/boost/integer/common_factor_rt.hpp
Normal file
488
include/boost/integer/common_factor_rt.hpp
Normal file
@ -0,0 +1,488 @@
|
||||
// Boost common_factor_rt.hpp header file ----------------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker and Paul Moore 2001-2002. Permission to copy,
|
||||
// use, modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided "as is"
|
||||
// without express or implied warranty, and with no claim as to its suitability
|
||||
// for any purpose.
|
||||
|
||||
// boostinspect:nolicense (don't complain about the lack of a Boost license)
|
||||
// (Paul Moore hasn't been in contact for years, so there's no way to change the
|
||||
// license.)
|
||||
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//! \file
|
||||
//! \brief Evaluate Least Common Multiple at compile-time.
|
||||
|
||||
#ifndef BOOST_INTEGER_COMMON_FACTOR_RT_HPP
|
||||
#define BOOST_INTEGER_COMMON_FACTOR_RT_HPP
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_NESTED_TEMPLATE, etc.
|
||||
#include <boost/limits.hpp> // for std::numeric_limits
|
||||
#include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <boost/integer_fwd.hpp> // Include for declarations of gcd_evaluator and lcm_evaluator.
|
||||
|
||||
#include <climits> // for CHAR_MIN
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127 4244) // Conditional expression is constant
|
||||
#endif
|
||||
|
||||
// Warning: this is from 1.58 in namespace boost::integer and no longer in namespace boost::math.
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace integer
|
||||
{
|
||||
// Forward declarations copied from <boost/math/common_factor_rt.hpp> at 1.58 -----//
|
||||
|
||||
// Forward declarations for function templates -----------------------------//
|
||||
|
||||
template < typename IntegerType >
|
||||
IntegerType gcd( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
template < typename IntegerType >
|
||||
IntegerType lcm( IntegerType const &a, IntegerType const &b );
|
||||
|
||||
// Greatest common divisor evaluator class declaration ---------------------//
|
||||
|
||||
template < typename IntegerType >
|
||||
class gcd_evaluator;
|
||||
|
||||
template < typename IntegerType >
|
||||
class lcm_evaluator;
|
||||
|
||||
template < typename IntegerType >
|
||||
class gcd_evaluator
|
||||
{
|
||||
public:
|
||||
// Types
|
||||
typedef IntegerType result_type, first_argument_type, second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
result_type operator ()( first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
|
||||
}; // boost::integer::gcd_evaluator
|
||||
|
||||
|
||||
// Least common multiple evaluator class declaration -----------------------//
|
||||
|
||||
template < typename IntegerType >
|
||||
class lcm_evaluator
|
||||
{
|
||||
public:
|
||||
// Types
|
||||
typedef IntegerType result_type, first_argument_type, second_argument_type;
|
||||
|
||||
// Function object interface
|
||||
result_type operator ()( first_argument_type const &a,
|
||||
second_argument_type const &b ) const;
|
||||
|
||||
}; // boost::integer::lcm_evaluator
|
||||
|
||||
|
||||
// Implementation details --------------------------------------------------//
|
||||
//! \cond DETAIL
|
||||
|
||||
namespace detail
|
||||
{
|
||||
// Greatest common divisor for rings (including unsigned integers)
|
||||
template < typename RingType >
|
||||
RingType
|
||||
gcd_euclidean
|
||||
(
|
||||
RingType a,
|
||||
RingType b
|
||||
)
|
||||
{
|
||||
// Avoid repeated construction
|
||||
#ifndef __BORLANDC__
|
||||
RingType const zero = static_cast<RingType>( 0 );
|
||||
#else
|
||||
RingType zero = static_cast<RingType>( 0 );
|
||||
#endif
|
||||
|
||||
// Reduce by GCD-remainder property [GCD(a,b) == GCD(b,a MOD b)]
|
||||
while ( true )
|
||||
{
|
||||
if ( a == zero )
|
||||
return b;
|
||||
b %= a;
|
||||
|
||||
if ( b == zero )
|
||||
return a;
|
||||
a %= b;
|
||||
}
|
||||
}
|
||||
|
||||
// Greatest common divisor for (signed) integers
|
||||
template < typename IntegerType >
|
||||
inline
|
||||
IntegerType
|
||||
gcd_integer
|
||||
(
|
||||
IntegerType const & a,
|
||||
IntegerType const & b
|
||||
)
|
||||
{
|
||||
// Avoid repeated construction
|
||||
IntegerType const zero = static_cast<IntegerType>( 0 );
|
||||
IntegerType const result = gcd_euclidean( a, b );
|
||||
|
||||
return ( result < zero ) ? static_cast<IntegerType>(-result) : result;
|
||||
}
|
||||
|
||||
// Greatest common divisor for unsigned binary integers
|
||||
template < typename BuiltInUnsigned >
|
||||
BuiltInUnsigned
|
||||
gcd_binary
|
||||
(
|
||||
BuiltInUnsigned u,
|
||||
BuiltInUnsigned v
|
||||
)
|
||||
{
|
||||
if ( u && v )
|
||||
{
|
||||
// Shift out common factors of 2
|
||||
unsigned shifts = 0;
|
||||
|
||||
while ( !(u & 1u) && !(v & 1u) )
|
||||
{
|
||||
++shifts;
|
||||
u >>= 1;
|
||||
v >>= 1;
|
||||
}
|
||||
|
||||
// Start with the still-even one, if any
|
||||
BuiltInUnsigned r[] = { u, v };
|
||||
unsigned which = static_cast<bool>( u & 1u );
|
||||
|
||||
// Whittle down the values via their differences
|
||||
do
|
||||
{
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x582))
|
||||
while ( !(r[ which ] & 1u) )
|
||||
{
|
||||
r[ which ] = (r[which] >> 1);
|
||||
}
|
||||
#else
|
||||
// Remove factors of two from the even one
|
||||
while ( !(r[ which ] & 1u) )
|
||||
{
|
||||
r[ which ] >>= 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Replace the larger of the two with their difference
|
||||
if ( r[!which] > r[which] )
|
||||
{
|
||||
which ^= 1u;
|
||||
}
|
||||
|
||||
r[ which ] -= r[ !which ];
|
||||
}
|
||||
while ( r[which] );
|
||||
|
||||
// Shift-in the common factor of 2 to the residues' GCD
|
||||
return r[ !which ] << shifts;
|
||||
}
|
||||
else
|
||||
{
|
||||
// At least one input is zero, return the other
|
||||
// (adding since zero is the additive identity)
|
||||
// or zero if both are zero.
|
||||
return u + v;
|
||||
}
|
||||
}
|
||||
|
||||
// Least common multiple for rings (including unsigned integers)
|
||||
template < typename RingType >
|
||||
inline
|
||||
RingType
|
||||
lcm_euclidean
|
||||
(
|
||||
RingType const & a,
|
||||
RingType const & b
|
||||
)
|
||||
{
|
||||
RingType const zero = static_cast<RingType>( 0 );
|
||||
RingType const temp = gcd_euclidean( a, b );
|
||||
|
||||
return ( temp != zero ) ? ( a / temp * b ) : zero;
|
||||
}
|
||||
|
||||
// Least common multiple for (signed) integers
|
||||
template < typename IntegerType >
|
||||
inline
|
||||
IntegerType
|
||||
lcm_integer
|
||||
(
|
||||
IntegerType const & a,
|
||||
IntegerType const & b
|
||||
)
|
||||
{
|
||||
// Avoid repeated construction
|
||||
IntegerType const zero = static_cast<IntegerType>( 0 );
|
||||
IntegerType const result = lcm_euclidean( a, b );
|
||||
|
||||
return ( result < zero ) ? static_cast<IntegerType>(-result) : result;
|
||||
}
|
||||
|
||||
// Function objects to find the best way of computing GCD or LCM
|
||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
template < typename T, bool IsSpecialized, bool IsSigned >
|
||||
struct gcd_optimal_evaluator_helper_t
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
return gcd_euclidean( a, b );
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct gcd_optimal_evaluator_helper_t< T, true, true >
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
return gcd_integer( a, b );
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct gcd_optimal_evaluator
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
typedef ::std::numeric_limits<T> limits_type;
|
||||
|
||||
typedef gcd_optimal_evaluator_helper_t<T,
|
||||
limits_type::is_specialized, limits_type::is_signed> helper_type;
|
||||
|
||||
helper_type solver;
|
||||
|
||||
return solver( a, b );
|
||||
}
|
||||
};
|
||||
#else // BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
template < typename T >
|
||||
struct gcd_optimal_evaluator
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
return gcd_integer( a, b );
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// Specialize for the built-in integers
|
||||
#define BOOST_PRIVATE_GCD_UF( Ut ) \
|
||||
template < > struct gcd_optimal_evaluator<Ut> \
|
||||
{ Ut operator ()( Ut a, Ut b ) const { return gcd_binary( a, b ); } }
|
||||
|
||||
BOOST_PRIVATE_GCD_UF( unsigned char );
|
||||
BOOST_PRIVATE_GCD_UF( unsigned short );
|
||||
BOOST_PRIVATE_GCD_UF( unsigned );
|
||||
BOOST_PRIVATE_GCD_UF( unsigned long );
|
||||
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
BOOST_PRIVATE_GCD_UF( boost::ulong_long_type );
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
BOOST_PRIVATE_GCD_UF( unsigned __int64 );
|
||||
#endif
|
||||
|
||||
#if CHAR_MIN == 0
|
||||
BOOST_PRIVATE_GCD_UF( char ); // char is unsigned
|
||||
#endif
|
||||
|
||||
#undef BOOST_PRIVATE_GCD_UF
|
||||
|
||||
#define BOOST_PRIVATE_GCD_SF( St, Ut ) \
|
||||
template < > struct gcd_optimal_evaluator<St> \
|
||||
{ St operator ()( St a, St b ) const { Ut const a_abs = \
|
||||
static_cast<Ut>( a < 0 ? -a : +a ), b_abs = static_cast<Ut>( \
|
||||
b < 0 ? -b : +b ); return static_cast<St>( \
|
||||
gcd_optimal_evaluator<Ut>()(a_abs, b_abs) ); } }
|
||||
|
||||
BOOST_PRIVATE_GCD_SF( signed char, unsigned char );
|
||||
BOOST_PRIVATE_GCD_SF( short, unsigned short );
|
||||
BOOST_PRIVATE_GCD_SF( int, unsigned );
|
||||
BOOST_PRIVATE_GCD_SF( long, unsigned long );
|
||||
|
||||
#if CHAR_MIN < 0
|
||||
BOOST_PRIVATE_GCD_SF( char, unsigned char ); // char is signed
|
||||
#endif
|
||||
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
BOOST_PRIVATE_GCD_SF( boost::long_long_type, boost::ulong_long_type );
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
BOOST_PRIVATE_GCD_SF( __int64, unsigned __int64 );
|
||||
#endif
|
||||
|
||||
#undef BOOST_PRIVATE_GCD_SF
|
||||
|
||||
#ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
template < typename T, bool IsSpecialized, bool IsSigned >
|
||||
struct lcm_optimal_evaluator_helper_t
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
return lcm_euclidean( a, b );
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct lcm_optimal_evaluator_helper_t< T, true, true >
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
return lcm_integer( a, b );
|
||||
}
|
||||
};
|
||||
|
||||
template < typename T >
|
||||
struct lcm_optimal_evaluator
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
typedef ::std::numeric_limits<T> limits_type;
|
||||
|
||||
typedef lcm_optimal_evaluator_helper_t<T,
|
||||
limits_type::is_specialized, limits_type::is_signed> helper_type;
|
||||
|
||||
helper_type solver;
|
||||
|
||||
return solver( a, b );
|
||||
}
|
||||
};
|
||||
#else // BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS
|
||||
template < typename T >
|
||||
struct lcm_optimal_evaluator
|
||||
{
|
||||
T operator ()( T const &a, T const &b )
|
||||
{
|
||||
return lcm_integer( a, b );
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// Functions to find the GCD or LCM in the best way
|
||||
template < typename T >
|
||||
inline
|
||||
T
|
||||
gcd_optimal
|
||||
(
|
||||
T const & a,
|
||||
T const & b
|
||||
)
|
||||
{
|
||||
gcd_optimal_evaluator<T> solver;
|
||||
|
||||
return solver( a, b );
|
||||
}
|
||||
|
||||
template < typename T >
|
||||
inline
|
||||
T
|
||||
lcm_optimal
|
||||
(
|
||||
T const & a,
|
||||
T const & b
|
||||
)
|
||||
{
|
||||
lcm_optimal_evaluator<T> solver;
|
||||
|
||||
return solver( a, b );
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
//! \endcond // DETAIL
|
||||
|
||||
// Greatest common divisor operator() evaluator member function definition ------------//
|
||||
//! Evaluation operator() for Greatest Common Divisor (GCD) of two arguments.
|
||||
//! \tparam IntegerType must be an integral constant http://en.cppreference.com/w/cpp/types/integral_constant
|
||||
//! \param a first_argument_type
|
||||
//! \param b second_argument_type
|
||||
|
||||
template < typename IntegerType >
|
||||
inline
|
||||
typename gcd_evaluator<IntegerType>::result_type
|
||||
gcd_evaluator<IntegerType>::operator ()
|
||||
(
|
||||
first_argument_type const & a,
|
||||
second_argument_type const & b
|
||||
) const
|
||||
{
|
||||
return detail::gcd_optimal( a, b );
|
||||
}
|
||||
|
||||
|
||||
// Least common multiple evaluator member function definition --------------//
|
||||
//! Evaluates Least Common Multiplier of two arguments.
|
||||
//! \tparam IntegerType must be an integral constant http://en.cppreference.com/w/cpp/types/integral_constant
|
||||
//! \tparam IntegerType must be an integral constant http://en.cppreference.com/w/cpp/types/integral_constant
|
||||
//! \param a first_argument_type
|
||||
//! \param b second_argument_type
|
||||
template < typename IntegerType >
|
||||
inline
|
||||
typename lcm_evaluator<IntegerType>::result_type
|
||||
lcm_evaluator<IntegerType>::operator ()
|
||||
(
|
||||
first_argument_type const & a,
|
||||
second_argument_type const & b
|
||||
) const
|
||||
{
|
||||
return detail::lcm_optimal( a, b );
|
||||
}
|
||||
|
||||
|
||||
// Greatest common divisor and least common multiple function definitions --//
|
||||
//! Function for Greatest Common Divisor (GCD) of two arguments.
|
||||
//! \tparam IntegerType must be an integral constant http://en.cppreference.com/w/cpp/types/integral_constant
|
||||
//! \param a first_argument_type
|
||||
//! \param b second_argument_type
|
||||
|
||||
template < typename IntegerType >
|
||||
inline
|
||||
IntegerType
|
||||
gcd
|
||||
(
|
||||
IntegerType const & a,
|
||||
IntegerType const & b
|
||||
)
|
||||
{
|
||||
gcd_evaluator<IntegerType> solver;
|
||||
|
||||
return solver( a, b );
|
||||
}
|
||||
|
||||
//! Function for Least Common Multiplier (LCM) of two arguments.
|
||||
//! \tparam IntegerType must be an integral constant http://en.cppreference.com/w/cpp/types/integral_constant
|
||||
//! \param a first_argument_type
|
||||
//! \param b second_argument_type
|
||||
|
||||
template < typename IntegerType >
|
||||
inline
|
||||
IntegerType
|
||||
lcm
|
||||
(
|
||||
IntegerType const & a,
|
||||
IntegerType const & b
|
||||
)
|
||||
{
|
||||
lcm_evaluator<IntegerType> solver;
|
||||
|
||||
return solver( a, b );
|
||||
}
|
||||
|
||||
|
||||
} // namespace integer
|
||||
} // namespace boost
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // BOOST_INTEGER_COMMON_FACTOR_RT_HPP
|
112
include/boost/integer/integer_log2.hpp
Normal file
112
include/boost/integer/integer_log2.hpp
Normal file
@ -0,0 +1,112 @@
|
||||
// -----------------------------------------------------------
|
||||
// integer_log2.hpp
|
||||
//
|
||||
// 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
|
||||
#define BOOST_INTEGER_INTEGER_LOG2_HPP
|
||||
|
||||
#include <assert.h>
|
||||
#ifdef __BORLANDC__
|
||||
#include <climits>
|
||||
#endif
|
||||
#include <boost/limits.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
//! \cond DETAIL
|
||||
namespace detail {
|
||||
|
||||
template <typename T>
|
||||
int integer_log2_impl(T x, int n) {
|
||||
|
||||
int result = 0;
|
||||
|
||||
while (x != 1) {
|
||||
|
||||
const T t = static_cast<T>(x >> n);
|
||||
if (t) {
|
||||
result += n;
|
||||
x = t;
|
||||
}
|
||||
n /= 2;
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// helper to find the maximum power of two
|
||||
// less than p (more involved than necessary,
|
||||
// to avoid PTS)
|
||||
//
|
||||
template <int p, int n>
|
||||
struct max_pow2_less {
|
||||
|
||||
enum { c = 2*n < p };
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, value =
|
||||
c ? (max_pow2_less< c*p, 2*c*n>::value) : n);
|
||||
|
||||
};
|
||||
|
||||
template <>
|
||||
struct max_pow2_less<0, 0> {
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, value = 0);
|
||||
};
|
||||
|
||||
// this template is here just for Borland :(
|
||||
// we could simply rely on numeric_limits but sometimes
|
||||
// Borland tries to use numeric_limits<const T>, because
|
||||
// of its usual const-related problems in argument deduction
|
||||
// - gps
|
||||
template <typename T>
|
||||
struct width {
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
BOOST_STATIC_CONSTANT(int, value = sizeof(T) * CHAR_BIT);
|
||||
#else
|
||||
BOOST_STATIC_CONSTANT(int, value = (std::numeric_limits<T>::digits));
|
||||
#endif
|
||||
|
||||
};
|
||||
} // detail
|
||||
//! \endcond // DETAIL
|
||||
|
||||
// ---------
|
||||
// integer_log2
|
||||
// ---------------
|
||||
//
|
||||
template <typename T>
|
||||
int integer_log2(T x) {
|
||||
|
||||
assert(x > 0);
|
||||
|
||||
const int n = detail::max_pow2_less<
|
||||
detail::width<T> :: value, 4
|
||||
> :: value;
|
||||
|
||||
return detail::integer_log2_impl(x, n);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#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.)
|
||||
|
||||
|
@ -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,6 +159,32 @@ 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
|
||||
typedef unsigned long static_gcd_type;
|
||||
#else
|
||||
typedef boost::uintmax_t static_gcd_type;
|
||||
#endif
|
||||
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct static_gcd;
|
||||
template < static_gcd_type Value1, static_gcd_type Value2 >
|
||||
struct static_lcm;
|
||||
|
||||
|
||||
// From <boost/integer/common_factor_rt.hpp>
|
||||
|
||||
template < typename IntegerType >
|
||||
class gcd_evaluator;
|
||||
template < typename IntegerType >
|
||||
class lcm_evaluator;
|
||||
|
||||
] // 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>
|
||||
@ -119,11 +126,6 @@ class integer_traits<wchar_t>
|
||||
// - Mac OS X with native library
|
||||
// - gcc on FreeBSD, OpenBSD and NetBSD
|
||||
public detail::integer_traits_base<wchar_t, INT_MIN, INT_MAX>
|
||||
#elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
|
||||
// No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
|
||||
// - gcc 2.95.x on HP-UX
|
||||
// (also, std::numeric_limits<wchar_t> appears to return the wrong values).
|
||||
public detail::integer_traits_base<wchar_t, 0, UINT_MAX>
|
||||
#else
|
||||
#error No WCHAR_MIN and WCHAR_MAX present, please adjust integer_traits<> for your compiler.
|
||||
#endif
|
||||
@ -227,7 +229,7 @@ class integer_traits< ::boost::ulong_long_type>
|
||||
template<>
|
||||
class integer_traits< ::boost::long_long_type>
|
||||
: public std::numeric_limits< ::boost::long_long_type>,
|
||||
public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) - 1)), ~(1LL << (sizeof(::boost::long_long_type) - 1))>
|
||||
public detail::integer_traits_base< ::boost::long_long_type, (1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1)), ~(1LL << (sizeof(::boost::long_long_type) * CHAR_BIT - 1))>
|
||||
{ };
|
||||
|
||||
template<>
|
||||
|
9
include/boost/pending/integer_log2.hpp
Normal file
9
include/boost/pending/integer_log2.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef BOOST_PENDING_INTEGER_LOG2_HPP
|
||||
#define BOOST_PENDING_INTEGER_LOG2_HPP
|
||||
|
||||
// The header file at this path is deprecated;
|
||||
// use boost/integer/integer_log2.hpp instead.
|
||||
|
||||
#include <boost/integer/integer_log2.hpp>
|
||||
|
||||
#endif
|
12
meta/libraries.json
Normal file
12
meta/libraries.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"key": "integer",
|
||||
"name": "Integer",
|
||||
"description": "The organization of boost integer headers and classes is designed to take advantage of <stdint.h> types from the 1999 C standard without resorting to undefined behavior in terms of the 1998 C++ standard. The header <boost/cstdint.hpp> makes the standard integer types safely available in namespace boost without placing any names in namespace std.",
|
||||
"category": [
|
||||
"Math"
|
||||
],
|
||||
"authors": "",
|
||||
"maintainers": [
|
||||
"Daryle Walker <darylew -at- hotmail.com>"
|
||||
]
|
||||
}
|
@ -8,18 +8,22 @@ project : requirements <warnings>all <toolset>gcc:<cxxflags>-Wextra ;
|
||||
|
||||
test-suite integer
|
||||
:
|
||||
[ run cstdint_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long ]
|
||||
[ run cstdint_test2.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long ]
|
||||
[ run integer_traits_test.cpp ]
|
||||
[ run integer_test.cpp : : : <toolset>gcc:<cxxflags>-Wno-long-long <toolset>darwin:<cxxflags>-Wno-long-long <toolset>sun:<cxxflags>"-Qoption ccfe -tmpldepth=128" ]
|
||||
[ run integer_mask_test.cpp ]
|
||||
[ run static_log2_test.cpp ]
|
||||
[ run static_min_max_test.cpp ]
|
||||
[ compile cstdint_include_test.cpp ]
|
||||
[ compile integer_traits_include_test.cpp ]
|
||||
[ compile integer_include_test.cpp ]
|
||||
[ compile integer_mask_include_test.cpp ]
|
||||
[ compile static_log2_include_test.cpp ]
|
||||
[ compile static_min_max_include_test.cpp ]
|
||||
[ compile integer_fwd_include_test.cpp ]
|
||||
[ compile-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 ]
|
||||
[ run common_factor_test.cpp ]
|
||||
;
|
||||
|
473
test/common_factor_test.cpp
Normal file
473
test/common_factor_test.cpp
Normal file
@ -0,0 +1,473 @@
|
||||
// Boost GCD & LCM common_factor.hpp test program --------------------------//
|
||||
|
||||
// (C) Copyright Daryle Walker 2001, 2006.
|
||||
// Distributed under the Boost Software License, Version 1.0. (See
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
// Revision History
|
||||
// 01 Dec 2006 Various fixes for old compilers (Joaquin M Lopez Munoz)
|
||||
// 10 Nov 2006 Make long long and __int64 mutually exclusive (Daryle Walker)
|
||||
// 04 Nov 2006 Use more built-in numeric types, binary-GCD (Daryle Walker)
|
||||
// 03 Nov 2006 Use custom numeric types (Daryle Walker)
|
||||
// 02 Nov 2006 Change to Boost.Test's unit test system (Daryle Walker)
|
||||
// 07 Nov 2001 Initial version (Daryle Walker)
|
||||
|
||||
#define BOOST_TEST_MAIN "Boost.Math GCD & LCM unit tests"
|
||||
|
||||
#include <boost/integer/common_factor.hpp>
|
||||
|
||||
#include <boost/config.hpp> // for BOOST_MSVC, etc.
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
#include <istream> // for std::basic_istream
|
||||
#include <limits> // for std::numeric_limits
|
||||
#include <ostream> // for std::basic_ostream
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
// TODO: add polynominal/non-real type; especially after any switch to the
|
||||
// binary-GCD algorithm for built-in types
|
||||
|
||||
// Custom integer class (template)
|
||||
template < typename IntType, int ID = 0 >
|
||||
class my_wrapped_integer
|
||||
: private ::boost::shiftable1<my_wrapped_integer<IntType, ID>,
|
||||
::boost::operators<my_wrapped_integer<IntType, ID> > >
|
||||
{
|
||||
// Helper type-aliases
|
||||
typedef my_wrapped_integer self_type;
|
||||
typedef IntType self_type::* bool_type;
|
||||
|
||||
// Member data
|
||||
IntType v_;
|
||||
|
||||
public:
|
||||
// Template parameters
|
||||
typedef IntType int_type;
|
||||
|
||||
BOOST_STATIC_CONSTANT(int,id = ID);
|
||||
|
||||
// Lifetime management (use automatic destructor and copy constructor)
|
||||
my_wrapped_integer( int_type const &v = int_type() ) : v_( v ) {}
|
||||
|
||||
// Accessors
|
||||
int_type value() const { return this->v_; }
|
||||
|
||||
// Operators (use automatic copy assignment)
|
||||
operator bool_type() const { return this->v_ ? &self_type::v_ : 0; }
|
||||
|
||||
self_type & operator ++() { ++this->v_; return *this; }
|
||||
self_type & operator --() { --this->v_; return *this; }
|
||||
|
||||
self_type operator ~() const { return self_type( ~this->v_ ); }
|
||||
self_type operator !() const { return self_type( !this->v_ ); }
|
||||
self_type operator +() const { return self_type( +this->v_ ); }
|
||||
self_type operator -() const { return self_type( -this->v_ ); }
|
||||
|
||||
bool operator <( self_type const &r ) const { return this->v_ < r.v_; }
|
||||
bool operator ==( self_type const &r ) const { return this->v_ == r.v_; }
|
||||
|
||||
self_type &operator *=(self_type const &r) {this->v_ *= r.v_; return *this;}
|
||||
self_type &operator /=(self_type const &r) {this->v_ /= r.v_; return *this;}
|
||||
self_type &operator %=(self_type const &r) {this->v_ %= r.v_; return *this;}
|
||||
self_type &operator +=(self_type const &r) {this->v_ += r.v_; return *this;}
|
||||
self_type &operator -=(self_type const &r) {this->v_ -= r.v_; return *this;}
|
||||
self_type &operator<<=(self_type const &r){this->v_ <<= r.v_; return *this;}
|
||||
self_type &operator>>=(self_type const &r){this->v_ >>= r.v_; return *this;}
|
||||
self_type &operator &=(self_type const &r) {this->v_ &= r.v_; return *this;}
|
||||
self_type &operator |=(self_type const &r) {this->v_ |= r.v_; return *this;}
|
||||
self_type &operator ^=(self_type const &r) {this->v_ ^= r.v_; return *this;}
|
||||
|
||||
// Input & output
|
||||
friend std::istream & operator >>( std::istream &i, self_type &x )
|
||||
{ return i >> x.v_; }
|
||||
|
||||
friend std::ostream & operator <<( std::ostream &o, self_type const &x )
|
||||
{ return o << x.v_; }
|
||||
|
||||
}; // my_wrapped_integer
|
||||
|
||||
template < typename IntType, int ID >
|
||||
my_wrapped_integer<IntType, ID> abs( my_wrapped_integer<IntType, ID> const &x )
|
||||
{ return ( x < my_wrapped_integer<IntType, ID>(0) ) ? -x : +x; }
|
||||
|
||||
typedef my_wrapped_integer<int> MyInt1;
|
||||
typedef my_wrapped_integer<unsigned> MyUnsigned1;
|
||||
typedef my_wrapped_integer<int, 1> MyInt2;
|
||||
typedef my_wrapped_integer<unsigned, 1> MyUnsigned2;
|
||||
|
||||
// Without these explicit instantiations, MSVC++ 6.5/7.0 does not find
|
||||
// some friend operators in certain contexts.
|
||||
MyInt1 dummy1;
|
||||
MyUnsigned1 dummy2;
|
||||
MyInt2 dummy3;
|
||||
MyUnsigned2 dummy4;
|
||||
|
||||
} // namespace
|
||||
|
||||
#define BOOST_NO_MACRO_EXPAND /**/
|
||||
|
||||
// Specialize numeric_limits for _some_ of our types
|
||||
namespace std
|
||||
{
|
||||
|
||||
template < >
|
||||
class numeric_limits< MyInt1 >
|
||||
{
|
||||
typedef MyInt1::int_type int_type;
|
||||
typedef numeric_limits<int_type> limits_type;
|
||||
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = limits_type::is_specialized);
|
||||
|
||||
static MyInt1 min BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::min)(); }
|
||||
static MyInt1 max BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::max)(); }
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, digits = limits_type::digits);
|
||||
BOOST_STATIC_CONSTANT(int, digits10 = limits_type::digits10);
|
||||
#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
BOOST_STATIC_CONSTANT(int, max_digits10 = limits_type::max_digits10);
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_signed = limits_type::is_signed);
|
||||
BOOST_STATIC_CONSTANT(bool, is_integer = limits_type::is_integer);
|
||||
BOOST_STATIC_CONSTANT(bool, is_exact = limits_type::is_exact);
|
||||
BOOST_STATIC_CONSTANT(int, radix = limits_type::radix);
|
||||
static MyInt1 epsilon() throw() { return limits_type::epsilon(); }
|
||||
static MyInt1 round_error() throw() { return limits_type::round_error(); }
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, min_exponent = limits_type::min_exponent);
|
||||
BOOST_STATIC_CONSTANT(int, min_exponent10 = limits_type::min_exponent10);
|
||||
BOOST_STATIC_CONSTANT(int, max_exponent = limits_type::max_exponent);
|
||||
BOOST_STATIC_CONSTANT(int, max_exponent10 = limits_type::max_exponent10);
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, has_infinity = limits_type::has_infinity);
|
||||
BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = limits_type::has_quiet_NaN);
|
||||
BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = limits_type::has_signaling_NaN);
|
||||
BOOST_STATIC_CONSTANT(float_denorm_style, has_denorm = limits_type::has_denorm);
|
||||
BOOST_STATIC_CONSTANT(bool, has_denorm_loss = limits_type::has_denorm_loss);
|
||||
|
||||
static MyInt1 infinity() throw() { return limits_type::infinity(); }
|
||||
static MyInt1 quiet_NaN() throw() { return limits_type::quiet_NaN(); }
|
||||
static MyInt1 signaling_NaN() throw() {return limits_type::signaling_NaN();}
|
||||
static MyInt1 denorm_min() throw() { return limits_type::denorm_min(); }
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, is_iec559 = limits_type::is_iec559);
|
||||
BOOST_STATIC_CONSTANT(bool, is_bounded = limits_type::is_bounded);
|
||||
BOOST_STATIC_CONSTANT(bool, is_modulo = limits_type::is_modulo);
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, traps = limits_type::traps);
|
||||
BOOST_STATIC_CONSTANT(bool, tinyness_before = limits_type::tinyness_before);
|
||||
BOOST_STATIC_CONSTANT(float_round_style, round_style = limits_type::round_style);
|
||||
|
||||
}; // std::numeric_limits<MyInt1>
|
||||
|
||||
template < >
|
||||
class numeric_limits< MyUnsigned1 >
|
||||
{
|
||||
typedef MyUnsigned1::int_type int_type;
|
||||
typedef numeric_limits<int_type> limits_type;
|
||||
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, is_specialized = limits_type::is_specialized);
|
||||
|
||||
static MyUnsigned1 min BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::min)(); }
|
||||
static MyUnsigned1 max BOOST_NO_MACRO_EXPAND() throw() { return (limits_type::max)(); }
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, digits = limits_type::digits);
|
||||
BOOST_STATIC_CONSTANT(int, digits10 = limits_type::digits10);
|
||||
#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
|
||||
BOOST_STATIC_CONSTANT(int, max_digits10 = limits_type::max_digits10);
|
||||
#endif
|
||||
BOOST_STATIC_CONSTANT(bool, is_signed = limits_type::is_signed);
|
||||
BOOST_STATIC_CONSTANT(bool, is_integer = limits_type::is_integer);
|
||||
BOOST_STATIC_CONSTANT(bool, is_exact = limits_type::is_exact);
|
||||
BOOST_STATIC_CONSTANT(int, radix = limits_type::radix);
|
||||
static MyUnsigned1 epsilon() throw() { return limits_type::epsilon(); }
|
||||
static MyUnsigned1 round_error() throw(){return limits_type::round_error();}
|
||||
|
||||
BOOST_STATIC_CONSTANT(int, min_exponent = limits_type::min_exponent);
|
||||
BOOST_STATIC_CONSTANT(int, min_exponent10 = limits_type::min_exponent10);
|
||||
BOOST_STATIC_CONSTANT(int, max_exponent = limits_type::max_exponent);
|
||||
BOOST_STATIC_CONSTANT(int, max_exponent10 = limits_type::max_exponent10);
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, has_infinity = limits_type::has_infinity);
|
||||
BOOST_STATIC_CONSTANT(bool, has_quiet_NaN = limits_type::has_quiet_NaN);
|
||||
BOOST_STATIC_CONSTANT(bool, has_signaling_NaN = limits_type::has_signaling_NaN);
|
||||
BOOST_STATIC_CONSTANT(float_denorm_style, has_denorm = limits_type::has_denorm);
|
||||
BOOST_STATIC_CONSTANT(bool, has_denorm_loss = limits_type::has_denorm_loss);
|
||||
|
||||
static MyUnsigned1 infinity() throw() { return limits_type::infinity(); }
|
||||
static MyUnsigned1 quiet_NaN() throw() { return limits_type::quiet_NaN(); }
|
||||
static MyUnsigned1 signaling_NaN() throw()
|
||||
{ return limits_type::signaling_NaN(); }
|
||||
static MyUnsigned1 denorm_min() throw(){ return limits_type::denorm_min(); }
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, is_iec559 = limits_type::is_iec559);
|
||||
BOOST_STATIC_CONSTANT(bool, is_bounded = limits_type::is_bounded);
|
||||
BOOST_STATIC_CONSTANT(bool, is_modulo = limits_type::is_modulo);
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, traps = limits_type::traps);
|
||||
BOOST_STATIC_CONSTANT(bool, tinyness_before = limits_type::tinyness_before);
|
||||
BOOST_STATIC_CONSTANT(float_round_style, round_style = limits_type::round_style);
|
||||
|
||||
}; // std::numeric_limits<MyUnsigned1>
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC,<1300)
|
||||
// MSVC 6.0 lacks operator<< for __int64, see
|
||||
// http://support.microsoft.com/default.aspx?scid=kb;en-us;168440
|
||||
|
||||
inline ostream& operator<<(ostream& os, __int64 i)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf,"%I64d", i);
|
||||
os << buf;
|
||||
return os;
|
||||
}
|
||||
|
||||
inline ostream& operator<<(ostream& os, unsigned __int64 i)
|
||||
{
|
||||
char buf[20];
|
||||
sprintf(buf,"%I64u", i);
|
||||
os << buf;
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace std
|
||||
|
||||
// GCD tests
|
||||
|
||||
// GCD on signed integer types
|
||||
template< class T > void gcd_int_test() // signed_test_types
|
||||
{
|
||||
using boost::integer::gcd;
|
||||
|
||||
// Originally from Boost.Rational tests
|
||||
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()
|
||||
{
|
||||
using boost::integer::gcd;
|
||||
|
||||
// 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(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
|
||||
{
|
||||
using boost::integer::gcd;
|
||||
|
||||
// Note that unmarked types (i.e. have no std::numeric_limits
|
||||
// specialization) are treated like non/unsigned types
|
||||
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()
|
||||
{
|
||||
using boost::integer::static_gcd;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
|
||||
// LCM tests
|
||||
|
||||
// LCM on signed integer types
|
||||
template< class T > void lcm_int_test() // signed_test_types
|
||||
{
|
||||
using boost::integer::lcm;
|
||||
|
||||
// Originally from Boost.Rational tests
|
||||
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()
|
||||
{
|
||||
using boost::integer::lcm;
|
||||
|
||||
// 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(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
|
||||
{
|
||||
using boost::integer::lcm;
|
||||
|
||||
// Note that unmarked types (i.e. have no std::numeric_limits
|
||||
// specialization) are treated like non/unsigned types
|
||||
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()
|
||||
{
|
||||
using boost::integer::static_lcm;
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
// TODO: see GCD to-do
|
||||
|
||||
// main
|
||||
|
||||
// Various types to test with each GCD/LCM
|
||||
|
||||
#define TEST_SIGNED_( test ) \
|
||||
test<signed char>(); \
|
||||
test<short>(); \
|
||||
test<int>(); \
|
||||
test<long>(); \
|
||||
test<MyInt1>();
|
||||
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
# define TEST_SIGNED( test ) \
|
||||
TEST_SIGNED_( test ) \
|
||||
test<boost::long_long_type>();
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
# define TEST_SIGNED( test ) \
|
||||
TEST_SIGNED_( test ) \
|
||||
test<__int64>();
|
||||
#endif
|
||||
|
||||
#define TEST_UNSIGNED_( test ) \
|
||||
test<unsigned char>(); \
|
||||
test<unsigned short>(); \
|
||||
test<unsigned>(); \
|
||||
test<unsigned long>(); \
|
||||
test<MyUnsigned1>(); \
|
||||
test<MyUnsigned2>();
|
||||
|
||||
#ifdef BOOST_HAS_LONG_LONG
|
||||
# define TEST_UNSIGNED( test ) \
|
||||
TEST_UNSIGNED_( test ) \
|
||||
test<boost::ulong_long_type>();
|
||||
#elif defined(BOOST_HAS_MS_INT64)
|
||||
# define TEST_UNSIGNED( test ) \
|
||||
TEST_UNSIGNED_( test ) \
|
||||
test<unsigned __int64>();
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
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();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
// Copyright John Maddock 2009.
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#define __STDC_CONSTANT_MACROS
|
||||
#include <boost/cstdint.hpp> // must be the only #include!
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::int8_t i8 = INT8_C(0);
|
||||
(void)i8;
|
||||
boost::uint8_t ui8 = UINT8_C(0);
|
||||
(void)ui8;
|
||||
boost::int16_t i16 = INT16_C(0);
|
||||
(void)i16;
|
||||
boost::uint16_t ui16 = UINT16_C(0);
|
||||
(void)ui16;
|
||||
boost::int32_t i32 = INT32_C(0);
|
||||
(void)i32;
|
||||
boost::uint32_t ui32 = UINT32_C(0);
|
||||
(void)ui32;
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int64_t i64 = 0;
|
||||
(void)i64;
|
||||
boost::uint64_t ui64 = 0;
|
||||
(void)ui64;
|
||||
#endif
|
||||
boost::int_least8_t i8least = INT8_C(0);
|
||||
(void)i8least;
|
||||
boost::uint_least8_t ui8least = UINT8_C(0);
|
||||
(void)ui8least;
|
||||
boost::int_least16_t i16least = INT16_C(0);
|
||||
(void)i16least;
|
||||
boost::uint_least16_t ui16least = UINT16_C(0);
|
||||
(void)ui16least;
|
||||
boost::int_least32_t i32least = INT32_C(0);
|
||||
(void)i32least;
|
||||
boost::uint_least32_t ui32least = UINT32_C(0);
|
||||
(void)ui32least;
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int_least64_t i64least = 0;
|
||||
(void)i64least;
|
||||
boost::uint_least64_t ui64least = 0;
|
||||
(void)ui64least;
|
||||
#endif
|
||||
boost::int_fast8_t i8fast = INT8_C(0);
|
||||
(void)i8fast;
|
||||
boost::uint_fast8_t ui8fast = UINT8_C(0);
|
||||
(void)ui8fast;
|
||||
boost::int_fast16_t i16fast = INT16_C(0);
|
||||
(void)i16fast;
|
||||
boost::uint_fast16_t ui16fast = UINT16_C(0);
|
||||
(void)ui16fast;
|
||||
boost::int_fast32_t i32fast = INT32_C(0);
|
||||
(void)i32fast;
|
||||
boost::uint_fast32_t ui32fast = UINT32_C(0);
|
||||
(void)ui32fast;
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int_fast64_t i64fast = 0;
|
||||
(void)i64fast;
|
||||
boost::uint_fast64_t ui64fast = 0;
|
||||
(void)ui64fast;
|
||||
#endif
|
||||
boost::intmax_t im = 0;
|
||||
(void)im;
|
||||
boost::uintmax_t uim = 0;
|
||||
(void)uim;
|
||||
}
|
@ -1,238 +0,0 @@
|
||||
// boost cstdint.hpp test program ------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2000. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
|
||||
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
||||
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
||||
// 28 Jun 00 Initial version
|
||||
|
||||
//
|
||||
// There are two ways to test this: in version 1, we include cstdint.hpp as the first
|
||||
// include, which means we get decide whether __STDC_CONSTANT_MACROS is defined.
|
||||
// In version two we include stdint.h with __STDC_CONSTANT_MACROS *NOT* defined first,
|
||||
// and check that we still end up with compatible definitions for the INT#_C macros.
|
||||
//
|
||||
// This is version 1.
|
||||
//
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
|
||||
// We can't suppress this warning on the command line as not all GCC versions support -Wno-type-limits :
|
||||
#pragma GCC diagnostic ignored "-Wtype-limits"
|
||||
#endif
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
//
|
||||
// the following class is designed to verify
|
||||
// that the various INTXX_C macros can be used
|
||||
// in integral constant expressions:
|
||||
//
|
||||
struct integral_constant_checker
|
||||
{
|
||||
static const boost::int8_t int8 = INT8_C(-127);
|
||||
static const boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
static const boost::uint8_t uint8 = UINT8_C(255);
|
||||
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
static const boost::int16_t int16 = INT16_C(-32767);
|
||||
static const boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
static const boost::uint16_t uint16 = UINT16_C(65535);
|
||||
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
static const boost::int32_t int32 = INT32_C(-2147483647);
|
||||
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
static const boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
static void check();
|
||||
};
|
||||
|
||||
void integral_constant_checker::check()
|
||||
{
|
||||
BOOST_TEST( int8 == -127 );
|
||||
BOOST_TEST( int_least8 == -127 );
|
||||
BOOST_TEST( int_fast8 == -127 );
|
||||
BOOST_TEST( uint8 == 255u );
|
||||
BOOST_TEST( uint_least8 == 255u );
|
||||
BOOST_TEST( uint_fast8 == 255u );
|
||||
BOOST_TEST( int16 == -32767 );
|
||||
BOOST_TEST( int_least16 == -32767 );
|
||||
BOOST_TEST( int_fast16 == -32767 );
|
||||
BOOST_TEST( uint16 == 65535u );
|
||||
BOOST_TEST( uint_least16 == 65535u );
|
||||
BOOST_TEST( uint_fast16 == 65535u );
|
||||
BOOST_TEST( int32 == -2147483647 );
|
||||
BOOST_TEST( int_least32 == -2147483647 );
|
||||
BOOST_TEST( int_fast32 == -2147483647 );
|
||||
BOOST_TEST( uint32 == 4294967295u );
|
||||
BOOST_TEST( uint_least32 == 4294967295u );
|
||||
BOOST_TEST( uint_fast32 == 4294967295u );
|
||||
}
|
||||
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
|
||||
//
|
||||
// the following function simply verifies that the type
|
||||
// of an integral constant is correctly defined:
|
||||
//
|
||||
#ifdef __BORLANDC__
|
||||
#pragma option -w-8008
|
||||
#pragma option -w-8066
|
||||
#endif
|
||||
template <class T1, class T2>
|
||||
void integral_constant_type_check(T1, T2)
|
||||
{
|
||||
//
|
||||
// the types T1 and T2 may not be exactly
|
||||
// the same type, but they should be the
|
||||
// same size and signedness. We could use
|
||||
// numeric_limits to verify this, but
|
||||
// numeric_limits implementations currently
|
||||
// vary too much, or are incomplete or missing.
|
||||
//
|
||||
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
|
||||
T2 t2 = static_cast<T2>(-1); // ditto
|
||||
#if defined(BOOST_HAS_STDINT_H)
|
||||
// if we have a native stdint.h
|
||||
// then the INTXX_C macros may define
|
||||
// a type that's wider than required:
|
||||
BOOST_TEST(sizeof(T1) <= sizeof(T2));
|
||||
#else
|
||||
BOOST_TEST(sizeof(T1) == sizeof(T2));
|
||||
BOOST_TEST(t1 == t2);
|
||||
#endif
|
||||
#if defined(BOOST_HAS_STDINT_H)
|
||||
// native headers are permitted to promote small
|
||||
// unsigned types to type int:
|
||||
if(sizeof(T1) >= sizeof(int))
|
||||
{
|
||||
if(t1 > 0)
|
||||
BOOST_TEST(t2 > 0);
|
||||
else
|
||||
BOOST_TEST(!(t2 > 0));
|
||||
}
|
||||
else if(t1 < 0)
|
||||
BOOST_TEST(!(t2 > 0));
|
||||
#else
|
||||
if(t1 > 0)
|
||||
BOOST_TEST(t2 > 0);
|
||||
else
|
||||
BOOST_TEST(!(t2 > 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
integral_constant_checker::check();
|
||||
#endif
|
||||
//
|
||||
// verify the types of the integral constants:
|
||||
//
|
||||
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
|
||||
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
|
||||
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
|
||||
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
|
||||
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
|
||||
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
|
||||
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
|
||||
#endif
|
||||
//
|
||||
boost::int8_t int8 = INT8_C(-127);
|
||||
boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
boost::uint8_t uint8 = UINT8_C(255);
|
||||
boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
boost::int16_t int16 = INT16_C(-32767);
|
||||
boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
boost::uint16_t uint16 = UINT16_C(65535);
|
||||
boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
boost::int32_t int32 = INT32_C(-2147483647);
|
||||
boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int64_t int64 = INT64_C(-9223372036854775807);
|
||||
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
|
||||
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
|
||||
|
||||
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
|
||||
|
||||
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
|
||||
#else
|
||||
boost::intmax_t intmax = INTMAX_C(-2147483647);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
|
||||
#endif
|
||||
|
||||
BOOST_TEST( int8 == -127 );
|
||||
BOOST_TEST( int_least8 == -127 );
|
||||
BOOST_TEST( int_fast8 == -127 );
|
||||
BOOST_TEST( uint8 == 255u );
|
||||
BOOST_TEST( uint_least8 == 255u );
|
||||
BOOST_TEST( uint_fast8 == 255u );
|
||||
BOOST_TEST( int16 == -32767 );
|
||||
BOOST_TEST( int_least16 == -32767 );
|
||||
BOOST_TEST( int_fast16 == -32767 );
|
||||
BOOST_TEST( uint16 == 65535u );
|
||||
BOOST_TEST( uint_least16 == 65535u );
|
||||
BOOST_TEST( uint_fast16 == 65535u );
|
||||
BOOST_TEST( int32 == -2147483647 );
|
||||
BOOST_TEST( int_least32 == -2147483647 );
|
||||
BOOST_TEST( int_fast32 == -2147483647 );
|
||||
BOOST_TEST( uint32 == 4294967295u );
|
||||
BOOST_TEST( uint_least32 == 4294967295u );
|
||||
BOOST_TEST( uint_fast32 == 4294967295u );
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
BOOST_TEST( int64 == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( int_least64 == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( int_fast64 == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( uint64 == UINT64_C(18446744073709551615) );
|
||||
BOOST_TEST( uint_least64 == UINT64_C(18446744073709551615) );
|
||||
BOOST_TEST( uint_fast64 == UINT64_C(18446744073709551615) );
|
||||
BOOST_TEST( intmax == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( uintmax == UINT64_C(18446744073709551615) );
|
||||
#else
|
||||
BOOST_TEST( intmax == -2147483647 );
|
||||
BOOST_TEST( uintmax == 4294967295u );
|
||||
#endif
|
||||
|
||||
|
||||
std::cout << "OK\n";
|
||||
return boost::report_errors();
|
||||
}
|
@ -1,248 +0,0 @@
|
||||
// boost cstdint.hpp test program ------------------------------------------//
|
||||
|
||||
// Copyright Beman Dawes 2000. Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
// See http://www.boost.org/libs/integer for documentation.
|
||||
|
||||
// Revision History
|
||||
// 11 Sep 01 Adapted to work with macros defined in native stdint.h (John Maddock)
|
||||
// 12 Nov 00 Adapted to merged <boost/cstdint.hpp>
|
||||
// 23 Sep 00 Added INTXX_C constant macro support + int64_t support (John Maddock).
|
||||
// 28 Jun 00 Initial version
|
||||
|
||||
//
|
||||
// There are two ways to test this: in version 1, we include cstdint.hpp as the first
|
||||
// include, which means we get decide whether __STDC_CONSTANT_MACROS is defined.
|
||||
// In version two we include stdint.h with __STDC_CONSTANT_MACROS *NOT* defined first,
|
||||
// and check that we still end up with compatible definitions for the INT#_C macros.
|
||||
//
|
||||
// This is version 2.
|
||||
//
|
||||
|
||||
#if defined(__GNUC__) && (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4))
|
||||
// We can't suppress this warning on the command line as not all GCC versions support -Wno-type-limits :
|
||||
#pragma GCC diagnostic ignored "-Wtype-limits"
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
|
||||
#ifdef BOOST_HAS_STDINT_H
|
||||
#ifdef __hpux
|
||||
# include <inttypes.h>
|
||||
#else
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/detail/lightweight_test.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
//
|
||||
// the following class is designed to verify
|
||||
// that the various INTXX_C macros can be used
|
||||
// in integral constant expressions:
|
||||
//
|
||||
struct integral_constant_checker
|
||||
{
|
||||
static const boost::int8_t int8 = INT8_C(-127);
|
||||
static const boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
static const boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
static const boost::uint8_t uint8 = UINT8_C(255);
|
||||
static const boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
static const boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
static const boost::int16_t int16 = INT16_C(-32767);
|
||||
static const boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
static const boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
static const boost::uint16_t uint16 = UINT16_C(65535);
|
||||
static const boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
static const boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
static const boost::int32_t int32 = INT32_C(-2147483647);
|
||||
static const boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
static const boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
static const boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
static const boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
static const boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
static void check();
|
||||
};
|
||||
|
||||
void integral_constant_checker::check()
|
||||
{
|
||||
BOOST_TEST( int8 == -127 );
|
||||
BOOST_TEST( int_least8 == -127 );
|
||||
BOOST_TEST( int_fast8 == -127 );
|
||||
BOOST_TEST( uint8 == 255u );
|
||||
BOOST_TEST( uint_least8 == 255u );
|
||||
BOOST_TEST( uint_fast8 == 255u );
|
||||
BOOST_TEST( int16 == -32767 );
|
||||
BOOST_TEST( int_least16 == -32767 );
|
||||
BOOST_TEST( int_fast16 == -32767 );
|
||||
BOOST_TEST( uint16 == 65535u );
|
||||
BOOST_TEST( uint_least16 == 65535u );
|
||||
BOOST_TEST( uint_fast16 == 65535u );
|
||||
BOOST_TEST( int32 == -2147483647 );
|
||||
BOOST_TEST( int_least32 == -2147483647 );
|
||||
BOOST_TEST( int_fast32 == -2147483647 );
|
||||
BOOST_TEST( uint32 == 4294967295u );
|
||||
BOOST_TEST( uint_least32 == 4294967295u );
|
||||
BOOST_TEST( uint_fast32 == 4294967295u );
|
||||
}
|
||||
#endif // BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
|
||||
//
|
||||
// the following function simply verifies that the type
|
||||
// of an integral constant is correctly defined:
|
||||
//
|
||||
#ifdef __BORLANDC__
|
||||
#pragma option -w-8008
|
||||
#pragma option -w-8066
|
||||
#endif
|
||||
template <class T1, class T2>
|
||||
void integral_constant_type_check(T1, T2)
|
||||
{
|
||||
//
|
||||
// the types T1 and T2 may not be exactly
|
||||
// the same type, but they should be the
|
||||
// same size and signedness. We could use
|
||||
// numeric_limits to verify this, but
|
||||
// numeric_limits implementations currently
|
||||
// vary too much, or are incomplete or missing.
|
||||
//
|
||||
T1 t1 = static_cast<T1>(-1); // cast suppresses warnings
|
||||
T2 t2 = static_cast<T2>(-1); // ditto
|
||||
#if defined(BOOST_HAS_STDINT_H)
|
||||
// if we have a native stdint.h
|
||||
// then the INTXX_C macros may define
|
||||
// a type that's wider than required:
|
||||
BOOST_TEST(sizeof(T1) <= sizeof(T2));
|
||||
#else
|
||||
BOOST_TEST(sizeof(T1) == sizeof(T2));
|
||||
BOOST_TEST(t1 == t2);
|
||||
#endif
|
||||
#if defined(BOOST_HAS_STDINT_H)
|
||||
// native headers are permitted to promote small
|
||||
// unsigned types to type int:
|
||||
if(sizeof(T1) >= sizeof(int))
|
||||
{
|
||||
if(t1 > 0)
|
||||
BOOST_TEST(t2 > 0);
|
||||
else
|
||||
BOOST_TEST(!(t2 > 0));
|
||||
}
|
||||
else if(t1 < 0)
|
||||
BOOST_TEST(!(t2 > 0));
|
||||
#else
|
||||
if(t1 > 0)
|
||||
BOOST_TEST(t2 > 0);
|
||||
else
|
||||
BOOST_TEST(!(t2 > 0));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(int, char*[])
|
||||
{
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
integral_constant_checker::check();
|
||||
#endif
|
||||
//
|
||||
// verify the types of the integral constants:
|
||||
//
|
||||
integral_constant_type_check(boost::int8_t(0), INT8_C(0));
|
||||
integral_constant_type_check(boost::uint8_t(0), UINT8_C(0));
|
||||
integral_constant_type_check(boost::int16_t(0), INT16_C(0));
|
||||
integral_constant_type_check(boost::uint16_t(0), UINT16_C(0));
|
||||
integral_constant_type_check(boost::int32_t(0), INT32_C(0));
|
||||
integral_constant_type_check(boost::uint32_t(0), UINT32_C(0));
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
integral_constant_type_check(boost::int64_t(0), INT64_C(0));
|
||||
integral_constant_type_check(boost::uint64_t(0), UINT64_C(0));
|
||||
#endif
|
||||
//
|
||||
boost::int8_t int8 = INT8_C(-127);
|
||||
boost::int_least8_t int_least8 = INT8_C(-127);
|
||||
boost::int_fast8_t int_fast8 = INT8_C(-127);
|
||||
|
||||
boost::uint8_t uint8 = UINT8_C(255);
|
||||
boost::uint_least8_t uint_least8 = UINT8_C(255);
|
||||
boost::uint_fast8_t uint_fast8 = UINT8_C(255);
|
||||
|
||||
boost::int16_t int16 = INT16_C(-32767);
|
||||
boost::int_least16_t int_least16 = INT16_C(-32767);
|
||||
boost::int_fast16_t int_fast16 = INT16_C(-32767);
|
||||
|
||||
boost::uint16_t uint16 = UINT16_C(65535);
|
||||
boost::uint_least16_t uint_least16 = UINT16_C(65535);
|
||||
boost::uint_fast16_t uint_fast16 = UINT16_C(65535);
|
||||
|
||||
boost::int32_t int32 = INT32_C(-2147483647);
|
||||
boost::int_least32_t int_least32 = INT32_C(-2147483647);
|
||||
boost::int_fast32_t int_fast32 = INT32_C(-2147483647);
|
||||
|
||||
boost::uint32_t uint32 = UINT32_C(4294967295);
|
||||
boost::uint_least32_t uint_least32 = UINT32_C(4294967295);
|
||||
boost::uint_fast32_t uint_fast32 = UINT32_C(4294967295);
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
boost::int64_t int64 = INT64_C(-9223372036854775807);
|
||||
boost::int_least64_t int_least64 = INT64_C(-9223372036854775807);
|
||||
boost::int_fast64_t int_fast64 = INT64_C(-9223372036854775807);
|
||||
|
||||
boost::uint64_t uint64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_least64_t uint_least64 = UINT64_C(18446744073709551615);
|
||||
boost::uint_fast64_t uint_fast64 = UINT64_C(18446744073709551615);
|
||||
|
||||
boost::intmax_t intmax = INTMAX_C(-9223372036854775807);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(18446744073709551615);
|
||||
#else
|
||||
boost::intmax_t intmax = INTMAX_C(-2147483647);
|
||||
boost::uintmax_t uintmax = UINTMAX_C(4294967295);
|
||||
#endif
|
||||
|
||||
BOOST_TEST( int8 == -127 );
|
||||
BOOST_TEST( int_least8 == -127 );
|
||||
BOOST_TEST( int_fast8 == -127 );
|
||||
BOOST_TEST( uint8 == 255u );
|
||||
BOOST_TEST( uint_least8 == 255u );
|
||||
BOOST_TEST( uint_fast8 == 255u );
|
||||
BOOST_TEST( int16 == -32767 );
|
||||
BOOST_TEST( int_least16 == -32767 );
|
||||
BOOST_TEST( int_fast16 == -32767 );
|
||||
BOOST_TEST( uint16 == 65535u );
|
||||
BOOST_TEST( uint_least16 == 65535u );
|
||||
BOOST_TEST( uint_fast16 == 65535u );
|
||||
BOOST_TEST( int32 == -2147483647 );
|
||||
BOOST_TEST( int_least32 == -2147483647 );
|
||||
BOOST_TEST( int_fast32 == -2147483647 );
|
||||
BOOST_TEST( uint32 == 4294967295u );
|
||||
BOOST_TEST( uint_least32 == 4294967295u );
|
||||
BOOST_TEST( uint_fast32 == 4294967295u );
|
||||
|
||||
#ifndef BOOST_NO_INT64_T
|
||||
BOOST_TEST( int64 == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( int_least64 == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( int_fast64 == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( uint64 == UINT64_C(18446744073709551615) );
|
||||
BOOST_TEST( uint_least64 == UINT64_C(18446744073709551615) );
|
||||
BOOST_TEST( uint_fast64 == UINT64_C(18446744073709551615) );
|
||||
BOOST_TEST( intmax == INT64_C(-9223372036854775807) );
|
||||
BOOST_TEST( uintmax == UINT64_C(18446744073709551615) );
|
||||
#else
|
||||
BOOST_TEST( intmax == -2147483647 );
|
||||
BOOST_TEST( uintmax == 4294967295u );
|
||||
#endif
|
||||
|
||||
|
||||
std::cout << "OK\n";
|
||||
return boost::report_errors();
|
||||
}
|
8
test/fail_int_exact.cpp
Normal file
8
test/fail_int_exact.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright John Maddock 2012.
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
typedef boost::int_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::exact fail_int_exact;
|
8
test/fail_int_fast.cpp
Normal file
8
test/fail_int_fast.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright John Maddock 2012.
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
typedef boost::int_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::fast fail_int_fast;
|
8
test/fail_int_least.cpp
Normal file
8
test/fail_int_least.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright John Maddock 2012.
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
typedef boost::int_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::least fail_int_least;
|
8
test/fail_uint_exact.cpp
Normal file
8
test/fail_uint_exact.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright John Maddock 2012.
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
typedef boost::uint_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::exact fail_uint_exact;
|
8
test/fail_uint_fast.cpp
Normal file
8
test/fail_uint_fast.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright John Maddock 2012.
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
typedef boost::uint_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::fast fail_uint_fast;
|
8
test/fail_uint_least.cpp
Normal file
8
test/fail_uint_least.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
// Copyright John Maddock 2012.
|
||||
// Distributed under the Boost
|
||||
// Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
typedef boost::uint_t<sizeof(boost::intmax_t)*CHAR_BIT + 1>::least fail_uint_least;
|
@ -69,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>
|
||||
@ -152,7 +152,7 @@ void do_test_bits()
|
||||
if(boost::detail::test_errors() != last_error_count)
|
||||
{
|
||||
last_error_count = boost::detail::test_errors();
|
||||
std::cout << "Errors occured while testing with bit count = " << Bits << std::endl;
|
||||
std::cout << "Errors occurred while testing with bit count = " << Bits << std::endl;
|
||||
std::cout << "Type int_t<" << Bits << ">::least was " << get_name_of_type(least_int(0)) << std::endl;
|
||||
std::cout << "Type int_t<" << Bits << ">::fast was " << get_name_of_type(fast_int(0)) << std::endl;
|
||||
std::cout << "Type uint_t<" << Bits << ">::least was " << get_name_of_type(least_uint(0)) << std::endl;
|
||||
|
Reference in New Issue
Block a user