mirror of
https://github.com/boostorg/multiprecision.git
synced 2026-07-21 13:23:49 +00:00
Merge multiprecision from sandbox.
[SVN r81417]
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
# copyright John Maddock 2008
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt.
|
||||
|
||||
import modules ;
|
||||
import path ;
|
||||
|
||||
local gmp_path = [ modules.peek : GMP_PATH ] ;
|
||||
local mpfr_path = [ modules.peek : MPFR_PATH ] ;
|
||||
local tommath_path = [ modules.peek : TOMMATH_PATH ] ;
|
||||
|
||||
obj has_gmp : has_gmp.cpp :
|
||||
<include>$(gmp_path) <include>$(gmp_path)/mpfr <include>$(gmp_path)/gmpfrxx ;
|
||||
obj has_mpfr : has_mpfr.cpp :
|
||||
<include>$(mpfr_path) <include>$(gmp_path)/mpfr <include>$(gmp_path)/gmpfrxx <include>$(gmp_path) ;
|
||||
obj has_tommath : has_tommath.cpp :
|
||||
<include>$(tommath_path) ;
|
||||
|
||||
explicit has_gmp ;
|
||||
explicit has_mpfr ;
|
||||
explicit has_tommath ;
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright John Maddock 2008.
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <gmp.h>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright John Maddock 2008.
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <mpfr.h>
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright John Maddock 2011.
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0. (See accompanying file
|
||||
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include <tommath.h>
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
|
||||
# Copyright John Maddock 2011. 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 ;
|
||||
using auto-index ;
|
||||
|
||||
path-constant images_location : html ;
|
||||
path-constant here : . ;
|
||||
|
||||
xml big_number : multiprecision.qbk ;
|
||||
boostbook standalone
|
||||
:
|
||||
big_number
|
||||
:
|
||||
# Path for links to Boost:
|
||||
#<xsl:param>boost.root=http://www.boost.org/doc/libs/release
|
||||
|
||||
# Some general style settings:
|
||||
<xsl:param>table.footnote.number.format=1
|
||||
<xsl:param>footnote.number.format=1
|
||||
<xsl:param>html.stylesheet=http://www.boost.org/doc/libs/release/doc/src/boostbook.css
|
||||
|
||||
# HTML options first:
|
||||
# Use graphics not text for navigation:
|
||||
<xsl:param>navig.graphics=1
|
||||
# How far down we chunk nested sections, basically all of them:
|
||||
<xsl:param>chunk.section.depth=10
|
||||
# Don't put the first section on the same page as the TOC:
|
||||
<xsl:param>chunk.first.sections=10
|
||||
# How far down sections get TOC's
|
||||
<xsl:param>toc.section.depth=10
|
||||
# Max depth in each TOC:
|
||||
<xsl:param>toc.max.depth=4
|
||||
# How far down we go with TOC's
|
||||
#<xsl:param>generate.section.toc.level=10
|
||||
# Index on type:
|
||||
<xsl:param>index.on.type=1
|
||||
|
||||
# PDF Options:
|
||||
# TOC Generation: this is needed for FOP-0.9 and later:
|
||||
<xsl:param>fop1.extensions=0
|
||||
<format>pdf:<xsl:param>xep.extensions=1
|
||||
# TOC generation: this is needed for FOP 0.2, but must not be set to zero for FOP-0.9!
|
||||
<format>pdf:<xsl:param>fop.extensions=0
|
||||
<format>pdf:<xsl:param>fop1.extensions=0
|
||||
# No indent on body text:
|
||||
<format>pdf:<xsl:param>body.start.indent=0pt
|
||||
# Margin size:
|
||||
<format>pdf:<xsl:param>page.margin.inner=0.5in
|
||||
# Margin size:
|
||||
<format>pdf:<xsl:param>page.margin.outer=0.5in
|
||||
# Paper type = A4
|
||||
<format>pdf:<xsl:param>paper.type=A4
|
||||
# Yes, we want graphics for admonishments:
|
||||
<xsl:param>admon.graphics=1
|
||||
# Set this one for PDF generation *only*:
|
||||
# default pnd graphics are awful in PDF form,
|
||||
# better use SVG's instead:
|
||||
<format>pdf:<xsl:param>admon.graphics.extension=".svg"
|
||||
<format>pdf:<xsl:param>use.role.for.mediaobject=1
|
||||
<format>pdf:<xsl:param>preferred.mediaobject.role=print
|
||||
<format>pdf:<xsl:param>img.src.path=$(images_location)/
|
||||
<format>pdf:<xsl:param>draft.mode="no"
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/libs/math/doc/sf_and_dist/html
|
||||
# Index generation:
|
||||
<auto-index>on
|
||||
<auto-index-script>$(here)/index.idx
|
||||
<auto-index-prefix>$(here)/../../..
|
||||
<auto-index-verbose>on
|
||||
<format>html:<auto-index-internal>on
|
||||
<quickbook-define>enable_index
|
||||
<format>pdf:<xsl:param>index.on.type=1
|
||||
;
|
||||
|
||||
install pdf-install : standalone : <location>. <install-type>PDF ;
|
||||
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
<?xml version='1.0'?>
|
||||
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN'
|
||||
'http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd'
|
||||
[<!ENTITY mathml 'http://www.w3.org/1998/Math/MathML'>]>
|
||||
<html xmlns='http://www.w3.org/1999/xhtml'>
|
||||
<head><title>floating_point_eg1</title>
|
||||
<!-- MathML created with MathCast Equation Editor version 0.89 -->
|
||||
</head>
|
||||
<body>
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
|
||||
<mrow>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mn>1</mn>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
<mspace width="1em"/>
|
||||
<mspace width="1em"/>
|
||||
<mtable>
|
||||
<mtr>
|
||||
<mtd>
|
||||
<mi>f</mi>
|
||||
<mo>′</mo>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mo>≈</mo>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>1</mn>
|
||||
</msub>
|
||||
<mo>+</mo>
|
||||
<mi>O</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>d</mi>
|
||||
<msup>
|
||||
<mi>x</mi>
|
||||
<mn>2</mn>
|
||||
</msup>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mtd>
|
||||
</mtr>
|
||||
<mtr>
|
||||
<mtd>
|
||||
<mi>f</mi>
|
||||
<mo>′</mo>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mo>≈</mo>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mfrac>
|
||||
<mn>4</mn>
|
||||
<mn>3</mn>
|
||||
</mfrac>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>1</mn>
|
||||
</msub>
|
||||
<mo>−</mo>
|
||||
<mfrac>
|
||||
<mn>1</mn>
|
||||
<mn>3</mn>
|
||||
</mfrac>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>2</mn>
|
||||
</msub>
|
||||
<mo>+</mo>
|
||||
<mi>O</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>d</mi>
|
||||
<msup>
|
||||
<mi>x</mi>
|
||||
<mn>4</mn>
|
||||
</msup>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mtd>
|
||||
</mtr>
|
||||
<mtr>
|
||||
<mtd>
|
||||
<mi>f</mi>
|
||||
<mo>′</mo>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mo>≈</mo>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mfrac>
|
||||
<mn>3</mn>
|
||||
<mn>2</mn>
|
||||
</mfrac>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>1</mn>
|
||||
</msub>
|
||||
<mo>−</mo>
|
||||
<mfrac>
|
||||
<mn>3</mn>
|
||||
<mn>5</mn>
|
||||
</mfrac>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>2</mn>
|
||||
</msub>
|
||||
<mo>+</mo>
|
||||
<mfrac>
|
||||
<mn>1</mn>
|
||||
<mn>10</mn>
|
||||
</mfrac>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>3</mn>
|
||||
</msub>
|
||||
<mo>+</mo>
|
||||
<mi>O</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>d</mi>
|
||||
<msup>
|
||||
<mi>x</mi>
|
||||
<mn>6</mn>
|
||||
</msup>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mtd>
|
||||
</mtr>
|
||||
</mtable>
|
||||
</mrow>
|
||||
</math>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 15 KiB |
@@ -0,0 +1,152 @@
|
||||
<?xml version='1.0'?>
|
||||
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN'
|
||||
'http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd'
|
||||
[<!ENTITY mathml 'http://www.w3.org/1998/Math/MathML'>]>
|
||||
<html xmlns='http://www.w3.org/1999/xhtml'>
|
||||
<head><title>floating_point_eg2</title>
|
||||
<!-- MathML created with MathCast Equation Editor version 0.89 -->
|
||||
</head>
|
||||
<body>
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
|
||||
<mrow>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mn>2</mn>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
<mspace width="1em"/>
|
||||
<mspace width="1em"/>
|
||||
<mtable>
|
||||
<mtr>
|
||||
<mtd>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>1</mn>
|
||||
</msub>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mo>=</mo>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mfrac>
|
||||
<mrow>
|
||||
<mi>f</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
<mo>−</mo>
|
||||
<mi>f</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>−</mo>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mrow>
|
||||
<mrow>
|
||||
<mn>2</mn>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfrac>
|
||||
</mtd>
|
||||
</mtr>
|
||||
<mtr>
|
||||
<mtd>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>2</mn>
|
||||
</msub>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mo>=</mo>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mfrac>
|
||||
<mrow>
|
||||
<mi>f</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mn>2</mn>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
<mo>−</mo>
|
||||
<mi>f</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>−</mo>
|
||||
<mn>2</mn>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mrow>
|
||||
<mrow>
|
||||
<mn>4</mn>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfrac>
|
||||
</mtd>
|
||||
</mtr>
|
||||
<mtr>
|
||||
<mtd>
|
||||
<msub>
|
||||
<mi>m</mi>
|
||||
<mn>3</mn>
|
||||
</msub>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mo>=</mo>
|
||||
</mtd>
|
||||
<mtd>
|
||||
<mfrac>
|
||||
<mrow>
|
||||
<mi>f</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>+</mo>
|
||||
<mn>3</mn>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
<mo>−</mo>
|
||||
<mi>f</mi>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>−</mo>
|
||||
<mn>3</mn>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
</mrow>
|
||||
<mrow>
|
||||
<mn>6</mn>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfrac>
|
||||
</mtd>
|
||||
</mtr>
|
||||
</mtable>
|
||||
</mrow>
|
||||
</math>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.8 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,53 @@
|
||||
<?xml version='1.0'?>
|
||||
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN'
|
||||
'http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd'
|
||||
[<!ENTITY mathml 'http://www.w3.org/1998/Math/MathML'>]>
|
||||
<html xmlns='http://www.w3.org/1999/xhtml'>
|
||||
<head><title>floating_point_eg3</title>
|
||||
<!-- MathML created with MathCast Equation Editor version 0.89 -->
|
||||
</head>
|
||||
<body>
|
||||
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
|
||||
<mrow>
|
||||
<mfenced>
|
||||
<mrow>
|
||||
<mn>3</mn>
|
||||
</mrow>
|
||||
</mfenced>
|
||||
<mspace width="1em"/>
|
||||
<mspace width="1em"/>
|
||||
<mfrac>
|
||||
<mi>d</mi>
|
||||
<mrow>
|
||||
<mi>d</mi>
|
||||
<mi>x</mi>
|
||||
</mrow>
|
||||
</mfrac>
|
||||
<mi>sin</mi>
|
||||
<mi>x</mi>
|
||||
<msub>
|
||||
<mo>|</mo>
|
||||
<mrow>
|
||||
<mi>x</mi>
|
||||
<mo>=</mo>
|
||||
<mfrac>
|
||||
<mi>π</mi>
|
||||
<mn>3</mn>
|
||||
</mfrac>
|
||||
</mrow>
|
||||
</msub>
|
||||
<mo>=</mo>
|
||||
<mi>cos</mi>
|
||||
<mfrac>
|
||||
<mi>π</mi>
|
||||
<mn>3</mn>
|
||||
</mfrac>
|
||||
<mo>=</mo>
|
||||
<mfrac>
|
||||
<mn>1</mn>
|
||||
<mn>2</mn>
|
||||
</mfrac>
|
||||
</mrow>
|
||||
</math>
|
||||
</body>
|
||||
</html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.5 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.3 KiB |
Executable
+33
@@ -0,0 +1,33 @@
|
||||
# Copyright John Maddock 2008.
|
||||
# Use, modification and distribution are subject to the
|
||||
# Boost Software License, Version 1.0. (See accompanying file
|
||||
# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
# Generates SVG and PNG files from the MML masters.
|
||||
#
|
||||
# Paths to tools come first, change these to match your system:
|
||||
#
|
||||
math2svg='m:\download\open\SVGMath-0.3.1\math2svg.py'
|
||||
python=/cygdrive/c/Python26/python.exe
|
||||
inkscape=/cygdrive/c/progra~1/Inkscape/inkscape
|
||||
# Image DPI:
|
||||
dpi=120
|
||||
|
||||
for mmlfile in $*; do
|
||||
svgfile=$(basename $mmlfile .mml).svg
|
||||
pngfile=$(basename $svgfile .svg).png
|
||||
tempfile=temp.mml
|
||||
# strip html wrappers put in by MathCast:
|
||||
cat $mmlfile | tr -d "\r\n" | sed -e 's/.*\(<math[^>]*>.*<\/math>\).*/\1/' > $tempfile
|
||||
|
||||
echo Generating $svgfile
|
||||
$python $math2svg $tempfile > $svgfile
|
||||
echo Generating $pngfile
|
||||
$inkscape -d $dpi -e $(cygpath -a -w $pngfile) $(cygpath -a -w $svgfile)
|
||||
rm $tempfile
|
||||
done
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Indexes</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="prev" href="map/ack.html" title="Acknowledgements">
|
||||
<link rel="next" href="indexes/s01.html" title="Function Index">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="map/ack.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="indexes/s01.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_indexes">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_multiprecision.indexes"></a><a class="link" href="indexes.html" title="Indexes">Indexes</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="indexes/s01.html">Function Index</a></span></dt>
|
||||
<dt><span class="section"><a href="indexes/s02.html">Class Index</a></span></dt>
|
||||
<dt><span class="section"><a href="indexes/s03.html">Typedef Index</a></span></dt>
|
||||
<dt><span class="section"><a href="indexes/s04.html">Index</a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="map/ack.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="indexes/s01.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,515 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Function Index</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../indexes.html" title="Indexes">
|
||||
<link rel="prev" href="../indexes.html" title="Indexes">
|
||||
<link rel="next" href="s02.html" title="Class Index">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../indexes.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../indexes.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="s02.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section id965816">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="id965816"></a>Function Index</h3></div></div></div>
|
||||
<p><a class="link" href="s01.html#idx_id_0">A</a> <a class="link" href="s01.html#idx_id_1">B</a> <a class="link" href="s01.html#idx_id_2">C</a> <a class="link" href="s01.html#idx_id_3">D</a> <a class="link" href="s01.html#idx_id_4">E</a> <a class="link" href="s01.html#idx_id_5">F</a> <a class="link" href="s01.html#idx_id_7">I</a> <a class="link" href="s01.html#idx_id_8">L</a> <a class="link" href="s01.html#idx_id_9">M</a> <a class="link" href="s01.html#idx_id_12">P</a> <a class="link" href="s01.html#idx_id_13">R</a> <a class="link" href="s01.html#idx_id_14">S</a> <a class="link" href="s01.html#idx_id_15">T</a> <a class="link" href="s01.html#idx_id_17">Z</a></p>
|
||||
<div class="variablelist"><dl class="variablelist">
|
||||
<dt>
|
||||
<a name="idx_id_0"></a><span class="term">A</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">abs</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">add</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/mixed.html" title="Mixed Precision Arithmetic"><span class="index-entry-level-1">Mixed Precision Arithmetic</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../map/todo.html" title="TODO"><span class="index-entry-level-1">TODO</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">assign</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">assign_components</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_1"></a><span class="term">B</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">bit_flip</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">bit_set</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">bit_test</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">bit_unset</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_2"></a><span class="term">C</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">compare</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">cpp_dec_float</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../map/todo.html" title="TODO"><span class="index-entry-level-1">TODO</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_3"></a><span class="term">D</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">data</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-1">gmp_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/gmp_int.html" title="gmp_int"><span class="index-entry-level-1">gmp_int</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/gmp_rational.html" title="gmp_rational"><span class="index-entry-level-1">gmp_rational</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">default_precision</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">divide_qr</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_4"></a><span class="term">E</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_acos</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_add</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_asin</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_atan</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_atan2</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_bitwise_and</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_bitwise_or</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_bitwise_xor</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_bit_flip</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_bit_set</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_bit_test</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_bit_unset</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_ceil</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_complement</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_convert_to</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_cos</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_cosh</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_decrement</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_divide</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_eq</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_exp</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_fabs</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_floor</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_fmod</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_frexp</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_gcd</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_get_sign</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_gt</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_increment</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_is_zero</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_lcm</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_ldexp</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_left_shift</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_log</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_log10</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_lt</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_modulus</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_multiply</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_multiply_add</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_multiply_subtract</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_pow</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_powm</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_qr</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_right_shift</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_round</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_sin</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_sinh</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_sqrt</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_subtract</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.compulsory_requirements_on_the_backend_type_" title="Table 1.4. Compulsory Requirements on the Backend type."><span class="index-entry-level-1">Compulsory Requirements on the Backend type.</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_tan</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_tanh</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">eval_trunc</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type" title="Table 1.5. Optional Requirements on the Backend Type"><span class="index-entry-level-1">Optional Requirements on the Backend Type</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_5"></a><span class="term">F</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">fpclassify</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li></ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_7"></a><span class="term">I</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">if</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/primetest.html" title="Primality Testing"><span class="index-entry-level-1">Primality Testing</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">integer_modulus</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">iround</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">isfinite</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">isinf</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">isnan</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">isnormal</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">itrunc</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_8"></a><span class="term">L</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">llround</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">lltrunc</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">lround</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">lsb</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">ltrunc</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_9"></a><span class="term">M</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">miller_rabin_test</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/primetest.html" title="Primality Testing"><span class="index-entry-level-1">Primality Testing</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">multiply</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/mixed.html" title="Mixed Precision Arithmetic"><span class="index-entry-level-1">Mixed Precision Arithmetic</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_12"></a><span class="term">P</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">powm</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">precision</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../map/faq.html" title="FAQ"><span class="index-entry-level-1">FAQ</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../intro.html" title="Introduction"><span class="index-entry-level-1">Introduction</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_13"></a><span class="term">R</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">r</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/egs/bitops.html" title="Bit Operations"><span class="index-entry-level-1">Bit Operations</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">round</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_14"></a><span class="term">S</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">str</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">subtract</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/mixed.html" title="Mixed Precision Arithmetic"><span class="index-entry-level-1">Mixed Precision Arithmetic</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">swap</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_15"></a><span class="term">T</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">trunc</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li></ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_17"></a><span class="term">Z</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">zero</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-1">gmp_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/gmp_int.html" title="gmp_int"><span class="index-entry-level-1">gmp_int</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/gmp_rational.html" title="gmp_rational"><span class="index-entry-level-1">gmp_rational</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/tommath_rational.html" title="tommath_rational"><span class="index-entry-level-1">tommath_rational</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/tom_int.html" title="tom_int"><span class="index-entry-level-1">tom_int</span></a></p></li>
|
||||
</ul></div>
|
||||
</li></ul></div></dd>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../indexes.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../indexes.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="s02.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,125 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Class Index</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../indexes.html" title="Indexes">
|
||||
<link rel="prev" href="s01.html" title="Function Index">
|
||||
<link rel="next" href="s03.html" title="Typedef Index">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="s01.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../indexes.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="s03.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section id969283">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="id969283"></a>Class Index</h3></div></div></div>
|
||||
<p><a class="link" href="s02.html#idx_id_20">C</a> <a class="link" href="s02.html#idx_id_22">E</a> <a class="link" href="s02.html#idx_id_24">G</a> <a class="link" href="s02.html#idx_id_25">I</a> <a class="link" href="s02.html#idx_id_27">M</a> <a class="link" href="s02.html#idx_id_28">N</a> <a class="link" href="s02.html#idx_id_33">T</a></p>
|
||||
<div class="variablelist"><dl class="variablelist">
|
||||
<dt>
|
||||
<a name="idx_id_20"></a><span class="term">C</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">component_type</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/cpp_dec_float.html" title="cpp_dec_float"><span class="index-entry-level-0">cpp_dec_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">cpp_int_backend</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_22"></a><span class="term">E</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">expression_template_default</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li></ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_24"></a><span class="term">G</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-0">gmp_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/gmp_int.html" title="gmp_int"><span class="index-entry-level-0">gmp_int</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/gmp_rational.html" title="gmp_rational"><span class="index-entry-level-0">gmp_rational</span></a></p></li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_25"></a><span class="term">I</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">is_explicitly_convertible</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/internals.html" title="Internal Support Code"><span class="index-entry-level-1">Internal Support Code</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">is_lossy_conversion</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/internals.html" title="Internal Support Code"><span class="index-entry-level-1">Internal Support Code</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">is_number</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">is_number_expression</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">is_restricted_conversion</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/internals.html" title="Internal Support Code"><span class="index-entry-level-1">Internal Support Code</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">is_signed_number</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/internals.html" title="Internal Support Code"><span class="index-entry-level-1">Internal Support Code</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">is_unsigned_number</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/internals.html" title="Internal Support Code"><span class="index-entry-level-1">Internal Support Code</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_27"></a><span class="term">M</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpfr_float_backend</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><span class="bold"><strong><a class="link" href="../ref/mpfr_ref.html" title="mpfr_float_backend"><span class="index-entry-level-1">mpfr_float_backend</span></a></strong></span></p></li>
|
||||
</ul></div>
|
||||
</li></ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_28"></a><span class="term">N</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-0">number</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">number_category</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/number.html" title="number"><span class="index-entry-level-1">number</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_33"></a><span class="term">T</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">tommath_int</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/tom_int.html" title="tom_int"><span class="index-entry-level-1">tom_int</span></a></p></li></ul></div>
|
||||
</li></ul></div></dd>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="s01.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../indexes.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="s03.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,260 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Typedef Index</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../indexes.html" title="Indexes">
|
||||
<link rel="prev" href="s02.html" title="Class Index">
|
||||
<link rel="next" href="s04.html" title="Index">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="s02.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../indexes.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="s04.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section id969700">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="id969700"></a>Typedef Index</h3></div></div></div>
|
||||
<p><a class="link" href="s03.html#idx_id_38">C</a> <a class="link" href="s03.html#idx_id_43">I</a> <a class="link" href="s03.html#idx_id_44">L</a> <a class="link" href="s03.html#idx_id_45">M</a> <a class="link" href="s03.html#idx_id_50">S</a> <a class="link" href="s03.html#idx_id_51">T</a> <a class="link" href="s03.html#idx_id_52">U</a></p>
|
||||
<div class="variablelist"><dl class="variablelist">
|
||||
<dt>
|
||||
<a name="idx_id_38"></a><span class="term">C</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_cpp_int</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_cpp_rational</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_cpp_rational_backend</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_int1024_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_int128_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_int256_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_int512_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_uint1024_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_uint128_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_uint256_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">checked_uint512_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">cpp_dec_float_100</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/cpp_dec_float.html" title="cpp_dec_float"><span class="index-entry-level-1">cpp_dec_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">cpp_dec_float_50</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/cpp_dec_float.html" title="cpp_dec_float"><span class="index-entry-level-1">cpp_dec_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-0">cpp_int</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">cpp_rational</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><span class="bold"><strong><a class="link" href="../tut/rational/cpp_rational.html" title="cpp_rational"><span class="index-entry-level-1">cpp_rational</span></a></strong></span></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">cpp_rational_backend</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/cpp_rational.html" title="cpp_rational"><span class="index-entry-level-1">cpp_rational</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_43"></a><span class="term">I</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">int1024_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">int128_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">int256_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">int512_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">int_type</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/primetest.html" title="Primality Testing"><span class="index-entry-level-1">Primality Testing</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_44"></a><span class="term">L</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">limb_type</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li></ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_45"></a><span class="term">M</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpfr_float</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><span class="bold"><strong><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></strong></span></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/mpfr_ref.html" title="mpfr_float_backend"><span class="index-entry-level-1">mpfr_float_backend</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpfr_float_100</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/mpfr_ref.html" title="mpfr_float_backend"><span class="index-entry-level-1">mpfr_float_backend</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpfr_float_1000</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/mpfr_ref.html" title="mpfr_float_backend"><span class="index-entry-level-1">mpfr_float_backend</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpfr_float_50</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/mpfr_ref.html" title="mpfr_float_backend"><span class="index-entry-level-1">mpfr_float_backend</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpfr_float_500</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../ref/mpfr_ref.html" title="mpfr_float_backend"><span class="index-entry-level-1">mpfr_float_backend</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpf_float</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-1">gmp_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpf_float_100</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-1">gmp_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpf_float_1000</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-1">gmp_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpf_float_50</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-1">gmp_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpf_float_500</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/gmp_float.html" title="gmp_float"><span class="index-entry-level-1">gmp_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpq_rational</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/gmp_rational.html" title="gmp_rational"><span class="index-entry-level-1">gmp_rational</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mpz_int</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/gmp_int.html" title="gmp_int"><span class="index-entry-level-1">gmp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">mp_type</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/gi.html" title="Calculating an Integral"><span class="index-entry-level-1">Calculating an Integral</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/fp_eg/poly_eg.html" title="Polynomial Evaluation"><span class="index-entry-level-1">Polynomial Evaluation</span></a></p></li>
|
||||
</ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_50"></a><span class="term">S</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">static_mpfr_float_100</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">static_mpfr_float_50</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float"><span class="index-entry-level-1">mpfr_float</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_51"></a><span class="term">T</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/tommath_rational.html" title="tommath_rational"><span class="index-entry-level-0">tommath_rational</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/tom_int.html" title="tom_int"><span class="index-entry-level-0">tom_int</span></a></p></li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">tom_rational</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/rational/tommath_rational.html" title="tommath_rational"><span class="index-entry-level-1">tommath_rational</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
<dt>
|
||||
<a name="idx_id_52"></a><span class="term">U</span>
|
||||
</dt>
|
||||
<dd><div class="index"><ul class="index" style="list-style-type: none; ">
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">uint1024_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">uint128_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">uint256_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
<li class="listitem" style="list-style-type: none">
|
||||
<p><span class="index-entry-level-0">uint512_t</span></p>
|
||||
<div class="index"><ul class="index" style="list-style-type: none; "><li class="listitem" style="list-style-type: none"><p><a class="link" href="../tut/ints/cpp_int.html" title="cpp_int"><span class="index-entry-level-1">cpp_int</span></a></p></li></ul></div>
|
||||
</li>
|
||||
</ul></div></dd>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="s02.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../indexes.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="s04.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,681 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Introduction</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="prev" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="next" href="tut.html" title="Tutorial">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="tut.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_intro">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_multiprecision.intro"></a><a class="link" href="intro.html" title="Introduction">Introduction</a>
|
||||
</h2></div></div></div>
|
||||
<p>
|
||||
The Multiprecision Library provides <span class="emphasis"><em>User-defined</em></span> integer,
|
||||
rational and floating-point C++ types which try to emulate as closely as practicable
|
||||
the C++ built-in types, but provide for more range and precision. Depending
|
||||
upon the number type, precision may be arbitrarily large (limited only by available
|
||||
memory), fixed at compile time values, for example 50 decimal digits, or a
|
||||
variable controlled at run-time by member functions. The types are expression-template-enabled
|
||||
for better performance than naive user-defined types.
|
||||
</p>
|
||||
<p>
|
||||
The Multiprecision library comes in two distinct parts:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
An expression-template-enabled front-end <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
that handles all the operator overloading, expression evaluation optimization,
|
||||
and code reduction.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
A selection of back-ends that implement the actual arithmetic operations,
|
||||
and need conform only to the reduced interface requirements of the front-end.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
Separation of front-end and back-end allows use of highly refined, but restricted
|
||||
license libraries where possible, but provides Boost license alternatives for
|
||||
users who must have a portable unconstrained license. Which is to say some
|
||||
back-ends rely on 3rd party libraries, but a header-only Boost license version
|
||||
is always available (if somewhat slower).
|
||||
</p>
|
||||
<p>
|
||||
Should you just wish to cut to the chase and use a fully Boost-licensed number
|
||||
type, then skip to <a class="link" href="tut/ints/cpp_int.html" title="cpp_int">cpp_int</a>
|
||||
for multiprecision integers, <a class="link" href="tut/floats/cpp_dec_float.html" title="cpp_dec_float">cpp_dec_float</a>
|
||||
for multiprecision floating point types and <a class="link" href="tut/rational/cpp_rational.html" title="cpp_rational">cpp_rational</a>
|
||||
for rational types.
|
||||
</p>
|
||||
<p>
|
||||
The library is often used via one of the predefined typedefs: for example if
|
||||
you wanted an <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_top">arbitrary
|
||||
precision</a> integer type using <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
as the underlying implementation then you could use:
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="comment">// Defines the wrappers around the GMP library's types</span>
|
||||
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">mpz_int</span> <span class="identifier">myint</span><span class="special">;</span> <span class="comment">// Arbitrary precision integer type.</span>
|
||||
</pre>
|
||||
<p>
|
||||
Alternatively, you can compose your own multiprecision type, by combining
|
||||
<code class="computeroutput"><span class="identifier">number</span></code> with one of the predefined
|
||||
back-end types. For example, suppose you wanted a 300 decimal digit floating-point
|
||||
type based on the <a href="http://www.mpfr.org" target="_top">MPFR</a> library. In
|
||||
this case, there's no predefined typedef with that level of precision, so instead
|
||||
we compose our own:
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">mpfr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="comment">// Defines the Backend type that wraps MPFR</span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">mp</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span> <span class="comment">// Reduce the typing a bit later...</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">mp</span><span class="special">::</span><span class="identifier">number</span><span class="special"><</span><span class="identifier">mp</span><span class="special">::</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">300</span><span class="special">></span> <span class="special">></span> <span class="identifier">my_float</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">my_float</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">c</span><span class="special">;</span> <span class="comment">// These variables have 300 decimal digits precision</span>
|
||||
</pre>
|
||||
<p>
|
||||
We can repeat the above example, but with the expression templates disabled
|
||||
(for faster compile times, but slower runtimes) by passing a second template
|
||||
argument to <code class="computeroutput"><span class="identifier">number</span></code>:
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">mpfr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> <span class="comment">// Defines the Backend type that wraps MPFR</span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">mp</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span> <span class="comment">// Reduce the typing a bit later...</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">mp</span><span class="special">::</span><span class="identifier">number</span><span class="special"><</span><span class="identifier">mp</span><span class="special">::</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">300</span><span class="special">>,</span> <span class="identifier">et_off</span><span class="special">></span> <span class="identifier">my_float</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">my_float</span> <span class="identifier">a</span><span class="special">,</span> <span class="identifier">b</span><span class="special">,</span> <span class="identifier">c</span><span class="special">;</span> <span class="comment">// These variables have 300 decimal digits precision</span>
|
||||
</pre>
|
||||
<p>
|
||||
We can also mix arithmetic operations between different types, provided there
|
||||
is an unambiguous implicit conversion from one type to the other:
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">namespace</span> <span class="identifier">mp</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span> <span class="comment">// Reduce the typing a bit later...</span>
|
||||
|
||||
<span class="identifier">mp</span><span class="special">::</span><span class="identifier">int128_t</span> <span class="identifier">a</span><span class="special">(</span><span class="number">3</span><span class="special">),</span> <span class="identifier">b</span><span class="special">(</span><span class="number">4</span><span class="special">);</span>
|
||||
<span class="identifier">mp</span><span class="special">::</span><span class="identifier">int512_t</span> <span class="identifier">c</span><span class="special">(</span><span class="number">50</span><span class="special">),</span> <span class="identifier">d</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">d</span> <span class="special">=</span> <span class="identifier">c</span> <span class="special">*</span> <span class="identifier">a</span><span class="special">;</span> <span class="comment">// OK, result of mixed arithmetic is an int512_t</span>
|
||||
</pre>
|
||||
<p>
|
||||
Conversions are also allowed:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">d</span> <span class="special">=</span> <span class="identifier">a</span><span class="special">;</span> <span class="comment">// OK, widening conversion.</span>
|
||||
<span class="identifier">d</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">b</span><span class="special">;</span> <span class="comment">// OK, can convert from an expression template too.</span>
|
||||
</pre>
|
||||
<p>
|
||||
However conversions that are inherently lossy are either declared explicit
|
||||
or else forbidden altogether:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">d</span> <span class="special">=</span> <span class="number">3.14</span><span class="special">;</span> <span class="comment">// Error implicit conversion from float not allowed.</span>
|
||||
<span class="identifier">d</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">mp</span><span class="special">::</span><span class="identifier">int512_t</span><span class="special">>(</span><span class="number">3.14</span><span class="special">);</span> <span class="comment">// OK explicit construction is allowed</span>
|
||||
</pre>
|
||||
<p>
|
||||
Mixed arithmetic will fail if the conversion is either ambiguous or explicit:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><>,</span> <span class="identifier">et_off</span><span class="special">></span> <span class="identifier">a</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>
|
||||
<span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><>,</span> <span class="identifier">et_on</span><span class="special">></span> <span class="identifier">b</span><span class="special">(</span><span class="number">3</span><span class="special">);</span>
|
||||
|
||||
<span class="identifier">b</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">b</span><span class="special">;</span> <span class="comment">// Error, implicit conversion could go either way.</span>
|
||||
<span class="identifier">b</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">*</span> <span class="number">3.14</span><span class="special">;</span> <span class="comment">// Error, no operator overload if the conversion would be explicit.</span>
|
||||
</pre>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.intro.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.intro.move_semantics"></a></span><a class="link" href="intro.html#boost_multiprecision.intro.move_semantics">Move
|
||||
Semantics</a>
|
||||
</h5>
|
||||
<p>
|
||||
On compilers that support rvalue-references, class <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
is move-enabled if the underlying backend is.
|
||||
</p>
|
||||
<p>
|
||||
In addition the non-expression template operator overloads (see below) are
|
||||
move aware and have overloads that look something like:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">B</span><span class="special">></span>
|
||||
<span class="identifier">number</span><span class="special"><</span><span class="identifier">B</span><span class="special">,</span> <span class="identifier">et_off</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">number</span><span class="special">&&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">number</span><span class="special">&</span> <span class="identifier">b</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">a</span> <span class="special">+=</span> <span class="identifier">b</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
These operator overloads ensure that many expressions can be evaluated without
|
||||
actually generating any temporaries. However, there are still many simple expressions
|
||||
such as:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">a</span> <span class="special">=</span> <span class="identifier">b</span> <span class="special">*</span> <span class="identifier">c</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
Which don't noticeably benefit from move support. Therefore, optimal performance
|
||||
comes from having both move-support, and expression templates enabled.
|
||||
</p>
|
||||
<p>
|
||||
Note that while "moved-from" objects are left in a sane state, they
|
||||
have an unspecified value, and the only permitted operations on them are destruction
|
||||
or the assignment of a new value. Any other operation should be considered
|
||||
a programming error and all of our backends will trigger an assertion if any
|
||||
other operation is attempted. This behavior allows for optimal performance
|
||||
on move-construction (i.e. no allocation required, we just take ownership of
|
||||
the existing object's internal state), while maintaining usability in the standard
|
||||
library containers.
|
||||
</p>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.intro.h1"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.intro.expression_templates"></a></span><a class="link" href="intro.html#boost_multiprecision.intro.expression_templates">Expression
|
||||
Templates</a>
|
||||
</h5>
|
||||
<p>
|
||||
Class <code class="computeroutput"><span class="identifier">number</span></code> is expression-template-enabled:
|
||||
that means that rather than having a multiplication operator that looks like
|
||||
this:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Backend</span><span class="special">></span>
|
||||
<span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">></span> <span class="keyword">operator</span> <span class="special">*</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">></span> <span class="identifier">result</span><span class="special">(</span><span class="identifier">a</span><span class="special">);</span>
|
||||
<span class="identifier">result</span> <span class="special">*=</span> <span class="identifier">b</span><span class="special">;</span>
|
||||
<span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
Instead the operator looks more like this:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Backend</span><span class="special">></span>
|
||||
<span class="emphasis"><em>unmentionable-type</em></span> <span class="keyword">operator</span> <span class="special">*</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">>&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">>&</span> <span class="identifier">b</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Where the "unmentionable" return type is an implementation detail
|
||||
that, rather than containing the result of the multiplication, contains instructions
|
||||
on how to compute the result. In effect it's just a pair of references to the
|
||||
arguments of the function, plus some compile-time information that stores what
|
||||
the operation is.
|
||||
</p>
|
||||
<p>
|
||||
The great advantage of this method is the <span class="emphasis"><em>elimination of temporaries</em></span>:
|
||||
for example the "naive" implementation of <code class="computeroutput"><span class="keyword">operator</span><span class="special">*</span></code> above, requires one temporary for computing
|
||||
the result, and at least another one to return it. It's true that sometimes
|
||||
this overhead can be reduced by using move-semantics, but it can't be eliminated
|
||||
completely. For example, lets suppose we're evaluating a polynomial via Horner's
|
||||
method, something like this:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">T</span> <span class="identifier">a</span><span class="special">[</span><span class="number">7</span><span class="special">]</span> <span class="special">=</span> <span class="special">{</span> <span class="comment">/* some values */</span> <span class="special">};</span>
|
||||
<span class="comment">//....</span>
|
||||
<span class="identifier">y</span> <span class="special">=</span> <span class="special">(((((</span><span class="identifier">a</span><span class="special">[</span><span class="number">6</span><span class="special">]</span> <span class="special">*</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">a</span><span class="special">[</span><span class="number">5</span><span class="special">])</span> <span class="special">*</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">a</span><span class="special">[</span><span class="number">4</span><span class="special">])</span> <span class="special">*</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">a</span><span class="special">[</span><span class="number">3</span><span class="special">])</span> <span class="special">*</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">a</span><span class="special">[</span><span class="number">2</span><span class="special">])</span> <span class="special">*</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">a</span><span class="special">[</span><span class="number">1</span><span class="special">])</span> <span class="special">*</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">a</span><span class="special">[</span><span class="number">0</span><span class="special">];</span>
|
||||
</pre>
|
||||
<p>
|
||||
If type <code class="computeroutput"><span class="identifier">T</span></code> is a <code class="computeroutput"><span class="identifier">number</span></code>, then this expression is evaluated
|
||||
<span class="emphasis"><em>without creating a single temporary value</em></span>. In contrast,
|
||||
if we were using the <a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
C++ wrapper for <a href="http://www.mpfr.org" target="_top">MPFR</a> - then this expression
|
||||
would result in no less than 11 temporaries (this is true even though <a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a> does
|
||||
use expression templates to reduce the number of temporaries somewhat). Had
|
||||
we used an even simpler wrapper around <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
like <a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a> things
|
||||
would have been even worse and no less that 24 temporaries are created for
|
||||
this simple expression (note - we actually measure the number of memory allocations
|
||||
performed rather than the number of temporaries directly, note also that the
|
||||
<a href="http://gmplib.org/manual/C_002b_002b-Interface-Floats.html#C_002b_002b-Interface-Floats" target="_top">mpf_class</a>
|
||||
wrapper that will be supplied with GMP-5.1 reduces the number of temporaries
|
||||
to pretty much zero). Note that if we compile with expression templates disabled
|
||||
and rvalue-reference support on, then actually still have no wasted memory
|
||||
allocations as even though temporaries are created, their contents are moved
|
||||
rather than copied. <a href="#ftn.boost_multiprecision.intro.f0" class="footnote"><sup class="footnote"><a name="boost_multiprecision.intro.f0"></a>[1]</sup></a>
|
||||
</p>
|
||||
<div class="important"><table border="0" summary="Important">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../images/important.png"></td>
|
||||
<th align="left">Important</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top">
|
||||
<p>
|
||||
Expression templates can radically reorder the operations in an expression,
|
||||
for example:
|
||||
</p>
|
||||
<p>
|
||||
a = (b * c) * a;
|
||||
</p>
|
||||
<p>
|
||||
Will get transformed into:
|
||||
</p>
|
||||
<p>
|
||||
a *= c; a *= b;
|
||||
</p>
|
||||
<p>
|
||||
If this is likely to be an issue for a particular application, then they
|
||||
should be disabled.
|
||||
</p>
|
||||
</td></tr>
|
||||
</table></div>
|
||||
<p>
|
||||
This library also extends expression template support to standard library functions
|
||||
like <code class="computeroutput"><span class="identifier">abs</span></code> or <code class="computeroutput"><span class="identifier">sin</span></code>
|
||||
with <code class="computeroutput"><span class="identifier">number</span></code> arguments. This
|
||||
means that an expression such as:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">y</span> <span class="special">=</span> <span class="identifier">abs</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
can be evaluated without a single temporary being calculated. Even expressions
|
||||
like:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">y</span> <span class="special">=</span> <span class="identifier">sin</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
get this treatment, so that variable 'y' is used as "working storage"
|
||||
within the implementation of <code class="computeroutput"><span class="identifier">sin</span></code>,
|
||||
thus reducing the number of temporaries used by one. Of course, should you
|
||||
write:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">sin</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Then we clearly can't use <code class="computeroutput"><span class="identifier">x</span></code>
|
||||
as working storage during the calculation, so then a temporary variable is
|
||||
created in this case.
|
||||
</p>
|
||||
<p>
|
||||
Given the comments above, you might be forgiven for thinking that expression-templates
|
||||
are some kind of universal-panacea: sadly though, all tricks like this have
|
||||
their downsides. For one thing, expression template libraries like this one,
|
||||
tend to be slower to compile than their simpler cousins, they're also harder
|
||||
to debug (should you actually want to step through our code!), and rely on
|
||||
compiler optimizations being turned on to give really good performance. Also,
|
||||
since the return type from expressions involving <code class="computeroutput"><span class="identifier">number</span></code>s
|
||||
is an "unmentionable implementation detail", you have to be careful
|
||||
to cast the result of an expression to the actual number type when passing
|
||||
an expression to a template function. For example, given:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="keyword">void</span> <span class="identifier">my_proc</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Then calling:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">my_proc</span><span class="special">(</span><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Will very likely result in obscure error messages inside the body of <code class="computeroutput"><span class="identifier">my_proc</span></code> - since we've passed it an expression
|
||||
template type, and not a number type. Instead we probably need:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">my_proc</span><span class="special">(</span><span class="identifier">my_number_type</span><span class="special">(</span><span class="identifier">a</span><span class="special">+</span><span class="identifier">b</span><span class="special">));</span>
|
||||
</pre>
|
||||
<p>
|
||||
Having said that, these situations don't occur that often - or indeed not at
|
||||
all for non-template functions. In addition, all the functions in the Boost.Math
|
||||
library will automatically convert expression-template arguments to the underlying
|
||||
number type without you having to do anything, so:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">mpfr_float_100</span> <span class="identifier">a</span><span class="special">(</span><span class="number">20</span><span class="special">),</span> <span class="identifier">delta</span><span class="special">(</span><span class="number">0.125</span><span class="special">);</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gamma_p</span><span class="special">(</span><span class="identifier">a</span><span class="special">,</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">delta</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Will work just fine, with the <code class="computeroutput"><span class="identifier">a</span> <span class="special">+</span> <span class="identifier">delta</span></code> expression
|
||||
template argument getting converted to an <code class="computeroutput"><span class="identifier">mpfr_float_100</span></code>
|
||||
internally by the Boost.Math library.
|
||||
</p>
|
||||
<p>
|
||||
One other potential pitfall that's only possible in C++11: you should never
|
||||
store an expression template using:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">my_expression</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">+</span> <span class="identifier">b</span> <span class="special">-</span> <span class="identifier">c</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
unless you're absolutely sure that the lifetimes of <code class="computeroutput"><span class="identifier">a</span></code>,
|
||||
<code class="computeroutput"><span class="identifier">b</span></code> and <code class="computeroutput"><span class="identifier">c</span></code>
|
||||
will outlive that of <code class="computeroutput"><span class="identifier">my_expression</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
And finally... the performance improvements from an expression template library
|
||||
like this are often not as dramatic as the reduction in number of temporaries
|
||||
would suggest. For example if we compare this library with <a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
and <a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a>, with
|
||||
all three using the underlying <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
library at 50 decimal digits precision then we see the following typical results
|
||||
for polynomial execution:
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_multiprecision.intro.evaluation_of_order_6_polynomial_"></a><p class="title"><b>Table 1.1. Evaluation of Order 6 Polynomial.</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Evaluation of Order 6 Polynomial.">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Library
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative Time
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative number of memory allocations
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
number
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (0.00957s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (2996 total)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.1 (0.0102s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
4.3 (12976 total)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.6 (0.0151s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
9.3 (27947 total)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><p>
|
||||
As you can see, the execution time increases a lot more slowly than the number
|
||||
of memory allocations. There are a number of reasons for this:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
The cost of extended-precision multiplication and division is so great,
|
||||
that the times taken for these tend to swamp everything else.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The cost of an in-place multiplication (using <code class="computeroutput"><span class="keyword">operator</span><span class="special">*=</span></code>) tends to be more than an out-of-place
|
||||
<code class="computeroutput"><span class="keyword">operator</span><span class="special">*</span></code>
|
||||
(typically <code class="computeroutput"><span class="keyword">operator</span> <span class="special">*=</span></code>
|
||||
has to create a temporary workspace to carry out the multiplication, where
|
||||
as <code class="computeroutput"><span class="keyword">operator</span><span class="special">*</span></code>
|
||||
can use the target variable as workspace). Since the expression templates
|
||||
carry out their magic by converting out-of-place operators to in-place
|
||||
ones, we necessarily take this hit. Even so the transformation is more
|
||||
efficient than creating the extra temporary variable, just not by as much
|
||||
as one would hope.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
Finally, note that <code class="computeroutput"><span class="identifier">number</span></code> takes
|
||||
a second template argument, which, when set to <code class="computeroutput"><span class="identifier">et_off</span></code>
|
||||
disables all the expression template machinery. The result is much faster to
|
||||
compile, but slower at runtime.
|
||||
</p>
|
||||
<p>
|
||||
We'll conclude this section by providing some more performance comparisons
|
||||
between these three libraries, again, all are using <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
to carry out the underlying arithmetic, and all are operating at the same precision
|
||||
(50 decimal digits):
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_multiprecision.intro.evaluation_of_boost_math_s_bessel_function_test_data"></a><p class="title"><b>Table 1.2. Evaluation of Boost.Math's Bessel function test data</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Evaluation of Boost.Math's Bessel function test data">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Library
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative Time
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative Number of Memory Allocations
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpfr_float_50
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (5.78s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (1611963)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
number<mpfr_float_backend<50>, et_off><br> (but with
|
||||
rvalue reference support)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.1 (6.29s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.64 (4260868)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.1 (6.28s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.45 (3948316)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.65 (9.54s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
8.21 (13226029)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="boost_multiprecision.intro.evaluation_of_boost_math_s_non_central_t_distribution_test_data"></a><p class="title"><b>Table 1.3. Evaluation of Boost.Math's Non-Central T distribution test data</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Evaluation of Boost.Math's Non-Central T distribution test data">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Library
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative Time
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative Number of Memory Allocations
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
number
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (263s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (127710873)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
number<mpfr_float_backend<50>, et_off><br> (but with
|
||||
rvalue reference support)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (260s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.2 (156797871)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.1 (287s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.1 (268336640)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.5 (389s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
3.6 (466960653)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><p>
|
||||
The above results were generated on Win32 compiling with Visual C++ 2010, all
|
||||
optimizations on (/Ox), with MPFR 3.0 and MPIR 2.3.0.
|
||||
</p>
|
||||
<div class="footnotes">
|
||||
<br><hr style="width:100; align:left;">
|
||||
<div id="ftn.boost_multiprecision.intro.f0" class="footnote"><p><a href="#boost_multiprecision.intro.f0" class="para"><sup class="para">[1] </sup></a>
|
||||
The actual number generated will depend on the compiler, how well it optimises
|
||||
the code, and whether it supports rvalue references. The number of 11 temporaries
|
||||
was generated with Visual C++ 10
|
||||
</p></div>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../index.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="tut.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,40 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Roadmap</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="prev" href="perf/rational_performance.html" title="Rational Type Perfomance">
|
||||
<link rel="next" href="map/hist.html" title="History">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="perf/rational_performance.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="map/hist.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_map">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_multiprecision.map"></a><a class="link" href="map.html" title="Roadmap">Roadmap</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="map/hist.html">History</a></span></dt>
|
||||
<dt><span class="section"><a href="map/todo.html">TODO</a></span></dt>
|
||||
<dt><span class="section"><a href="map/faq.html">FAQ</a></span></dt>
|
||||
<dt><span class="section"><a href="map/ack.html">Acknowledgements</a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="perf/rational_performance.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="map/hist.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,55 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Acknowledgements</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../map.html" title="Roadmap">
|
||||
<link rel="prev" href="faq.html" title="FAQ">
|
||||
<link rel="next" href="../indexes.html" title="Indexes">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="faq.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../indexes.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_map_ack">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.map.ack"></a><a class="link" href="ack.html" title="Acknowledgements">Acknowledgements</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
This library would not have happened without:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Christopher Kormanyos' C++ decimal number code.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Paul Bristow for patiently testing, and commenting on the library.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
All the folks at GMP, MPFR and libtommath, for providing the "guts"
|
||||
that makes this library work.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<a href="http://www-cs-faculty.stanford.edu/~uno/taocp.html" target="_top">"The
|
||||
Art Of Computer Programming"</a>, Donald E. Knuth, Volume 2:
|
||||
Seminumerical Algorithms, Third Edition (Reading, Massachusetts: Addison-Wesley,
|
||||
1997), xiv+762pp. ISBN 0-201-89684-2
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="faq.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../indexes.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,111 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>FAQ</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../map.html" title="Roadmap">
|
||||
<link rel="prev" href="todo.html" title="TODO">
|
||||
<link rel="next" href="ack.html" title="Acknowledgements">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="todo.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="ack.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_map_faq">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.map.faq"></a><a class="link" href="faq.html" title="FAQ">FAQ</a>
|
||||
</h3></div></div></div>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">Why do I get compiler errors when passing a <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
to a template function?</span></dt>
|
||||
<dd><p>
|
||||
Most likely you are actually passing an expression template type to
|
||||
the function and template-argument-deduction deduces the "wrong"
|
||||
type. Try casting the arguments involving expressions to the actual
|
||||
number type, or as a last resort turning off expression template support
|
||||
in the number type you are using.
|
||||
</p></dd>
|
||||
<dt><span class="term">When is expression template support a performance gain?</span></dt>
|
||||
<dd><p>
|
||||
As a general rule, expression template support adds a small runtime
|
||||
overhead creating and unpacking the expression templates, but greatly
|
||||
reduces the number of temporaries created. So it's most effective in
|
||||
improving performance when the cost of creating a temporary is high:
|
||||
for example when creating a temporary involves a memory allocation.
|
||||
It is least effective (and may even be a dis-optimisation) when temporaries
|
||||
are cheap: for example if the number type is basically a thin wrapper
|
||||
around a native arithmetic type. In addition, since the library makes
|
||||
extensive use of thin inline wrapper functions, turning on compiler
|
||||
optimization is essential to achieving high performance.
|
||||
</p></dd>
|
||||
<dt><span class="term">Do expression templates reorder operations?</span></dt>
|
||||
<dd><p>
|
||||
Yes they do, sometimes quite radically so, if this is a concern then
|
||||
they should be turned off for the number type you are using.
|
||||
</p></dd>
|
||||
<dt><span class="term">I can't construct my number type from <span class="emphasis"><em>some other type</em></span>,
|
||||
but the docs indicate that the conversion should be allowed, what's up?</span></dt>
|
||||
<dd><p>
|
||||
Some conversions are <span class="emphasis"><em>explicit</em></span>, that includes construction
|
||||
from a string, or constructing from any type that may result in loss
|
||||
of precision (for example constructing an integer type from a float).
|
||||
</p></dd>
|
||||
<dt><span class="term">Why do I get an exception thrown (or the program crash due to an
|
||||
uncaught exception) when using the bitwise operators on a checked <code class="computeroutput"><span class="identifier">cpp_int</span></code>?</span></dt>
|
||||
<dd><p>
|
||||
Bitwise operations on negative values (or indeed any signed integer
|
||||
type) are unspecified by the standard. As a result any attempt to carry
|
||||
out a bitwise operation on a negative checked-integer will result in
|
||||
a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code> being thrown.
|
||||
</p></dd>
|
||||
<dt><span class="term">Why do I get compiler errors when trying to use the complement operator?</span></dt>
|
||||
<dd><p>
|
||||
Use of the complement operator on signed types is problematic as the
|
||||
result is unspecified by the standard, and is further complicated by
|
||||
the fact that most extended precision integer types use a sign-magnitude
|
||||
representation rather than the 2's complement one favored by most native
|
||||
integer types. As a result the complement operator is deliberately
|
||||
disabled for checked <code class="computeroutput"><span class="identifier">cpp_int</span></code>'s.
|
||||
Unchecked <code class="computeroutput"><span class="identifier">cpp_int</span></code>'s
|
||||
give the same valued result as a 2's complement type would, but not
|
||||
the same bit-pattern.
|
||||
</p></dd>
|
||||
<dt><span class="term">Why can't I negate an unsigned type?</span></dt>
|
||||
<dd><p>
|
||||
The unary negation operator is deliberately disabled for unsigned integer
|
||||
types as its use would almost always be a programming error.
|
||||
</p></dd>
|
||||
<dt><span class="term">Why doesn't the library use proto?</span></dt>
|
||||
<dd><p>
|
||||
A very early version of the library did use proto, but compile times
|
||||
became too slow for the library to be usable. Since the library only
|
||||
required a tiny fraction of what proto has to offer anyway, a lightweight
|
||||
expression template mechanism was used instead. Compile times are still
|
||||
too slow...
|
||||
</p></dd>
|
||||
<dt><span class="term">Why not abstract out addition/multiplication algorithms?</span></dt>
|
||||
<dd><p>
|
||||
This was deamed not to be practical: these algorithms are intimately
|
||||
tied to the actual data representation used.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="todo.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="ack.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,109 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>History</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../map.html" title="Roadmap">
|
||||
<link rel="prev" href="../map.html" title="Roadmap">
|
||||
<link rel="next" href="todo.html" title="TODO">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../map.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="todo.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_map_hist">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.map.hist"></a><a class="link" href="hist.html" title="History">History</a>
|
||||
</h3></div></div></div>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.map.hist.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.map.hist.post_review_changes"></a></span><a class="link" href="hist.html#boost_multiprecision.map.hist.post_review_changes">Post
|
||||
review changes</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Non-expression template operators further optimised with rvalue reference
|
||||
support.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Many functions made <code class="computeroutput"><span class="identifier">constexp</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Differentiate between explicit and implicit conversions in the number
|
||||
constructor.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Removed "mp_" prefix from types.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Allowed mixed precision arithmetic.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Changed ExpressionTemplates parameter to class <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
to use enumerated values rather than true/false.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Changed ExpressionTemplate parameter default value to use a traits class
|
||||
so that the default value depends on the backend used.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Added support for fused-multiply-add/subtract with GMP support.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Tweaked expression template unpacking to use fewer temporaries when the
|
||||
LHS also appears in the RHS.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Refactored <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>
|
||||
based on review comments with new template parameter structure.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Added additional template parameter to <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>
|
||||
to allow stack-based allocation.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Added section on mixed precision arithmetic, and added support for operations
|
||||
yielding a higher precision result than either of the arguments.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Added overloads of integer-specific functions for built in integer types.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.map.hist.h1"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.map.hist.pre_review_history"></a></span><a class="link" href="hist.html#boost_multiprecision.map.hist.pre_review_history">Pre-review
|
||||
history</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
2011-2012, John Maddock adds an expression template enabled front end
|
||||
to Christopher's code, and adds support for other backends.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
2011, Christopher Kormanyos publishes the decimal floating point code
|
||||
under the Boost Software Licence. The code is published as: <a href="http://doi.acm.org/10.1145/1916461.1916469" target="_top">"Algorithm
|
||||
910: A Portable C++ Multiple-Precision System for Special-Function Calculations"</a>,
|
||||
in ACM TOMS, {VOL 37, ISSUE 4, (February 2011)} (C) ACM, 2011.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
2002-2011, Christopher Kormanyos develops the all C++ decimal arithmetic
|
||||
floating point code.
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../map.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="todo.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,226 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>TODO</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../map.html" title="Roadmap">
|
||||
<link rel="prev" href="hist.html" title="History">
|
||||
<link rel="next" href="faq.html" title="FAQ">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="hist.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="faq.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_map_todo">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.map.todo"></a><a class="link" href="todo.html" title="TODO">TODO</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
More a list of what <span class="emphasis"><em>could</em></span> be done, rather than what
|
||||
<span class="emphasis"><em>should</em></span> be done (which may be a much smaller list!).
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Add back-end support for libdecNumber.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Add an adapter back-end for complex number types.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Add a back-end for MPFR interval arithmetic.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Add better multiplication routines (Karatsuba, FFT etc) to cpp_int_backend.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Add assembly level routines to cpp_int_backend.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Add an all C++ binary floating point type.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Can ring types (exact floating point types) be supported? The answer
|
||||
should be yes, but someone needs to write it, the hard part is IO and
|
||||
binary-decimal convertion.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Should there be a choice of rounding mode (probably MPFR specific)?
|
||||
</li>
|
||||
<li class="listitem">
|
||||
We can reuse temporaries in multiple subtrees (temporary caching).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
cpp_dec_float should round to nearest.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
A 2's complement fixed precision int that uses exactly N bits and no
|
||||
more.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
Things requested in review:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
The performances of mp_number<a_trivial_adaptor<float>, false>respect
|
||||
to float and mp_number<a_trivial_adaptor<int>, false> and
|
||||
int should be given to show the cost of using the generic interface (Mostly
|
||||
done, just need to update docs to the latest results).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Should we provide min/max overloads for expression templates? (Not done
|
||||
- we can't overload functions declared in the std namespace :-( ).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The rounding applied when converting must be documented (Done).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document why we don't abstract out addition/multiplication algorithms
|
||||
etc. (done - FAQ)
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document why we don't use proto (compile times) (Done).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
We can reuse temporaries in multiple subtrees (temporary caching) Moved
|
||||
to TODO list.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Emphasise in the docs that ET's may reorder operations (done 2012/10/31).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document what happens to small fixed precision cpp_int's (done 2012/10/31).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The use of bool in template parameters could be improved by the use of
|
||||
an enum class which will be more explicit. E.g <code class="computeroutput"><span class="keyword">enum</span>
|
||||
<span class="keyword">class</span> <span class="identifier">expression_template</span>
|
||||
<span class="special">{</span><span class="identifier">disabled</span><span class="special">,</span> <span class="identifier">enabled</span><span class="special">};</span> <span class="keyword">enum</span> <span class="keyword">class</span> <span class="identifier">sign</span>
|
||||
<span class="special">{</span><span class="keyword">unsigned</span><span class="special">,</span> <span class="keyword">signed</span><span class="special">};</span></code> (Partly done 2012/09/15, done 2012/10/31).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Each back-end should document the requirements it satisfies (not currently
|
||||
scheduled for inclusion: it's deliberately an implementation detail,
|
||||
and "optional" requirements are optimisations which can't be
|
||||
detected by the user). Not done: this is an implementation detail, the
|
||||
exact list of requirements satisfied is purely an optimimization, not
|
||||
something the user can detect.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
A backend for an overflow aware integers (done 2012/10/31).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
IIUC convert_to is used to emulate in c++98 compilers C++11 explicit
|
||||
conversions. Could the explicit conversion operator be added on compilers
|
||||
supporting it? (Done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The front-end should make the differences between implicit and explicit
|
||||
construction (Done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The tutorial should add more examples concerning implicit or explicit
|
||||
conversions. (Done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The documentation must explain how move semantics helps in this domain
|
||||
and what the backend needs to do to profit from this optimization. (Done
|
||||
2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The documentation should contain Throws specification on the mp_number
|
||||
and backend requirements operations. (Done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The library interface should use the noexcept (BOOST_NOEXCEPT, ...) facilities
|
||||
(Done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
It is unfortunate that the generic mp_number front end can not make use
|
||||
contexpr as not all the backends can ensure this (done - we can go quite
|
||||
a way).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
literals: The library doesn't provide some kind of literals. I think
|
||||
that the mp_number class should provide a way to create literals if the
|
||||
backend is able to. (Done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The ExpresionTemplate parameter could be defaulted to a traits class
|
||||
for more sensible defaults (done 2012/09/20).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
In a = exp1 op exp2 where a occurs inside one of exp1 or exp2 then we
|
||||
can optimise and eliminate one more temporary (done 2012/09/20).
|
||||
</li>
|
||||
</ul></div>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.map.todo.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.map.todo.pre_review_comments"></a></span><a class="link" href="todo.html#boost_multiprecision.map.todo.pre_review_comments">Pre-Review
|
||||
Comments</a>
|
||||
</h5>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Make fixed precision orthogonal to Allocator type in cpp_int. Possible
|
||||
solution - add an additional MaxBits template argument that defaults
|
||||
to 0 (meaning keep going till no more space/memory). Done.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Can ring types (exact floating point types) be supported? The answer
|
||||
should be yes, but someone needs to write it (Moved to TODO list).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Should there be a choice of rounding mode (probably MPFR specific)? Moved
|
||||
to TODO list.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Make the exponent type for cpp_dec_float a templare parameter, maybe
|
||||
include support for big-integer exponents. Open question - what should
|
||||
be the default - int32_t or int64_t? (done 2012/09/06)
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document the size requirements of fixed precision ints (done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document std lib function accuracy (done 2012/09/15).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Be a bit clearer on the effects of sign-magnitude representation of cpp_int
|
||||
- min == -max etc - done.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document cpp_dec_float precision, rounding, and exponent size (done 2012/09/06).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Can we be clearer in the docs that mixed arithmetic doesn't work (no
|
||||
longer applicable as of 2012/09/06)?
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document round functions behaviour better (they behave as in C++11) (added
|
||||
note 2012/09/06).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Document limits on size of cpp_dec_float (done 2012/09/06).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Add support for fused multiply add (and subtract). GMP mpz_t could use
|
||||
this (done 2012/09/20).
|
||||
</li>
|
||||
</ul></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="hist.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../map.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="faq.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,48 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Performance Comparison</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="prev" href="ref/headers.html" title="Header File Structure">
|
||||
<link rel="next" href="perf/overhead.html" title="The Overhead in the Number Class Wrapper">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="ref/headers.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="perf/overhead.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_perf">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_multiprecision.perf"></a><a class="link" href="perf.html" title="Performance Comparison">Performance Comparison</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="perf/overhead.html">The Overhead in the
|
||||
Number Class Wrapper</a></span></dt>
|
||||
<dt><span class="section"><a href="perf/realworld.html">Floating Point Real
|
||||
World Tests</a></span></dt>
|
||||
<dt><span class="section"><a href="perf/int_real_world.html">Integer Real
|
||||
World Tests</a></span></dt>
|
||||
<dt><span class="section"><a href="perf/float_performance.html">Float Algorithm
|
||||
Perfomance</a></span></dt>
|
||||
<dt><span class="section"><a href="perf/integer_performance.html">Integer
|
||||
Algorithm Perfomance</a></span></dt>
|
||||
<dt><span class="section"><a href="perf/rational_performance.html">Rational
|
||||
Type Perfomance</a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="ref/headers.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="perf/overhead.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,372 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Real World Tests</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../perf.html" title="Performance Comparison">
|
||||
<link rel="prev" href="realworld.html" title="Floating Point Real World Tests">
|
||||
<link rel="next" href="float_performance.html" title="Float Algorithm Perfomance">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="realworld.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="float_performance.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_perf_int_real_world">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.perf.int_real_world"></a><a class="link" href="int_real_world.html" title="Integer Real World Tests">Integer Real
|
||||
World Tests</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Test code was compiled with Microsoft Visual Studio 2010 with all optimisations
|
||||
turned on (/Ox), and used MPIR-2.3.0 and <a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>-0.42.0.
|
||||
The tests were run on 32-bit Windows Vista machine.
|
||||
</p>
|
||||
<p>
|
||||
The first set of <a href="../../../../performance/voronoi_performance.cpp" target="_top">tests</a>
|
||||
measure the times taken to execute the multiprecision part of the Voronoi-diagram
|
||||
builder from Boost.Polygon. The tests mainly create a large number of temporaries
|
||||
"just in case" multiprecision arithmetic is required, for comparison,
|
||||
also included in the tests is Boost.Polygon's own partial-multiprecision
|
||||
integer type which was custom written for this specific task:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Integer Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative Performance (Actual time in parenthesis)
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
polygon::detail::extended_int
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1(0.138831s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
int256_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.19247(0.165551s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
int512_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.23301(0.17118s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
int1024_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.21463(0.168628s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
checked_int256_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.31711(0.182855s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
checked_int512_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.57413(0.218538s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
checked_int1024_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.36992(0.190187s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.63244(0.226632s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpz_int
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
5.42511(0.753172s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tom_int
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
29.0793(4.03709s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
Note how for this use case, any dynamic allocation is a performance killer.
|
||||
</p>
|
||||
<p>
|
||||
The next <a href="../../../../performance/miller_rabin_performance.cpp" target="_top">tests</a>
|
||||
measure the time taken to generate 1000 128-bit random numbers and test for
|
||||
primality using the Miller Rabin test. This is primarily a test of modular-exponentiation
|
||||
since that is the rate limiting step:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Integer Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative Performance (Actual time in parenthesis)
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
5.25827(0.379597s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int (no Expression templates)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
5.15675(0.372268s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int (128-bit cache)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
5.10882(0.368808s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int (256-bit cache)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
5.50623(0.397497s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int (512-bit cache)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
4.82257(0.348144s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int (1024-bit cache)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
5.00053(0.360991s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
int1024_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
4.37589(0.315897s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
checked_int1024_t
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
4.52396(0.326587s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpz_int
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1(0.0721905s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpz_int (no Expression templates)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0248(0.0739806s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tom_int
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.60673(0.188181s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tom_int (no Expression templates)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.64997(0.191303s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
It's interesting to note that expression templates have little effect here
|
||||
- perhaps because the actual expressions involved are relatively trivial
|
||||
in this case - so the time taken for multiplication and division tends to
|
||||
dominate. Also note how increasing the internal cache size used by <code class="computeroutput"><span class="identifier">cpp_int</span></code> is quite effective in this case
|
||||
in cutting out memory allocations altogether - cutting about a third off
|
||||
the total runtime. Finally the much quicker times from GMP and tommath are
|
||||
down to their much better modular-exponentiation algorithms (GMP's is about
|
||||
5x faster). That's an issue which needs to be addressed in a future release
|
||||
for <a class="link" href="../tut/ints/cpp_int.html" title="cpp_int">cpp_int</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="realworld.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="float_performance.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,186 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>The Overhead in the Number Class Wrapper</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../perf.html" title="Performance Comparison">
|
||||
<link rel="prev" href="../perf.html" title="Performance Comparison">
|
||||
<link rel="next" href="realworld.html" title="Floating Point Real World Tests">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../perf.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="realworld.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_perf_overhead">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.perf.overhead"></a><a class="link" href="overhead.html" title="The Overhead in the Number Class Wrapper">The Overhead in the
|
||||
Number Class Wrapper</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Using a simple <a href="../../../../performance/arithmetic_backend.hpp" target="_top">backend
|
||||
class</a> that wraps any built in arithmetic type we can measure the
|
||||
overhead involved in wrapping a type inside the <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
frontend, and the effect that turning on expression templates has. The following
|
||||
table compares the performance between <code class="computeroutput"><span class="keyword">double</span></code>
|
||||
and a <code class="computeroutput"><span class="keyword">double</span></code> wrapped inside
|
||||
class <code class="computeroutput"><span class="identifier">number</span></code>:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Bessel Function Evaluation
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Non-Central T Evaluation
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="keyword">double</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="bold"><strong>1.0 (0.016s)</strong></span>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="bold"><strong>1.0</strong></span> (0.46s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">arithmetic_backend</span><span class="special"><</span><span class="keyword">double</span><span class="special">>,</span>
|
||||
<span class="identifier">et_off</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.2 (0.019s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="bold"><strong>1.0</strong></span>(0.46s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">arithmetic_backend</span><span class="special"><</span><span class="keyword">double</span><span class="special">>,</span>
|
||||
<span class="identifier">et_on</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.2 (0.019s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.7 (0.79s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
As you can see whether there is an overhead, and how large it is depends
|
||||
on the actual situation, but the overhead is in any cases small. Expression
|
||||
templates generally add a greater overhead the more complex the expression
|
||||
becomes due to the logic of figuring out how to best unpack and evaluate
|
||||
the expression, but of course this is also the situation where you save more
|
||||
temporaries. For a "trivial" backend like this, saving temporaries
|
||||
has no benefit, but for larger types it becomes a bigger win.
|
||||
</p>
|
||||
<p>
|
||||
The following table compares arithmetic using either <code class="computeroutput"><span class="keyword">long</span>
|
||||
<span class="keyword">long</span></code> or <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">arithmetic_backend</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">></span> <span class="special">></span></code> for the <a href="../../../../performance/voronoi_perfromance.cpp" target="_top">voronoi-diagram
|
||||
builder test</a>:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Relative time
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="keyword">long</span> <span class="keyword">long</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="bold"><strong>1.0</strong></span>(0.0823s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">arithmetic_backend</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">>,</span> <span class="identifier">et_off</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.05 (0.0875s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
This test involves mainly creating a lot of temporaries and performing a
|
||||
small amount of arithmetic on them, with very little difference in performance
|
||||
between the native and "wrapped" types.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../perf.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="realworld.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,276 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Floating Point Real World Tests</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../perf.html" title="Performance Comparison">
|
||||
<link rel="prev" href="overhead.html" title="The Overhead in the Number Class Wrapper">
|
||||
<link rel="next" href="int_real_world.html" title="Integer Real World Tests">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="overhead.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="int_real_world.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_perf_realworld">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.perf.realworld"></a><a class="link" href="realworld.html" title="Floating Point Real World Tests">Floating Point Real
|
||||
World Tests</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
These tests test the total time taken to execute all of Boost.Math's test
|
||||
cases for these functions. In each case the best performing library gets
|
||||
a relative score of 1, with the total execution time given in brackets. The
|
||||
first three libraries listed are the various floating point types provided
|
||||
by this library, while for comparison, two popular C++ front-ends to <a href="http://www.mpfr.org" target="_top">MPFR</a> ( <a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
and <a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a>) are
|
||||
also shown.
|
||||
</p>
|
||||
<p>
|
||||
Test code was compiled with Microsoft Visual Studio 2010 with all optimisations
|
||||
turned on (/Ox), and used MPIR-2.3.0 and <a href="http://www.mpfr.org" target="_top">MPFR</a>-3.0.0.
|
||||
The tests were run on 32-bit Windows Vista machine.
|
||||
</p>
|
||||
<div class="table">
|
||||
<a name="boost_multiprecision.perf.realworld.bessel_function_performance"></a><p class="title"><b>Table 1.8. Bessel Function Performance</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Bessel Function Performance">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Library
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
50 Decimal Digits
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
100 Decimal Digits
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpfr_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.2 (5.78s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.2 (9.56s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
static_mpfr_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.1 (5.47s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.1 (9.09s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpf_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="bold"><strong>1.0</strong></span> (4.82s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="bold"><strong>1.0</strong></span>(8.07s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_dec_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.8 (8.54s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.6 (20.66s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.3 (6.28s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.2(10.06s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.0 (9.54s)
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.7 (14.08s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="boost_multiprecision.perf.realworld.non_central_t_distribution_performance"></a><p class="title"><b>Table 1.9. Non-Central T Distribution Performance</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Non-Central T Distribution Performance">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Library
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
50 Decimal Digits
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpfr_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.3 (263.27s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
static_mpfr_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.2 (232.88s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpf_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<span class="bold"><strong>1.0</strong></span> (195.73s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_dec_float
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.9 (366.38s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://math.berkeley.edu/~wilken/code/gmpfrxx/" target="_top">mpfr_class</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.5 (286.94s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://www.holoborodko.com/pavel/mpfr/" target="_top">mpreal</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2.0 (388.70s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="overhead.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../perf.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="int_real_world.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,47 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Reference</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="prev" href="tut/mixed.html" title="Mixed Precision Arithmetic">
|
||||
<link rel="next" href="ref/number.html" title="number">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tut/mixed.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="ref/number.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_multiprecision.ref"></a><a class="link" href="ref.html" title="Reference">Reference</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="ref/number.html">number</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/cpp_int_ref.html">cpp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/gmp_int_ref.html">gmp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/tom_int_ref.html">tom_int</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/mpf_ref.html">gmp_float</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/mpfr_ref.html">mpfr_float_backend</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/cpp_dec_ref.html">cpp_dec_float</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/internals.html">Internal Support
|
||||
Code</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/backendconc.html">Backend Requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="ref/headers.html">Header File Structure</a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tut/mixed.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="ref/number.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,64 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>cpp_dec_float</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="mpfr_ref.html" title="mpfr_float_backend">
|
||||
<link rel="next" href="internals.html" title="Internal Support Code">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mpfr_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="internals.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_cpp_dec_ref">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.cpp_dec_ref"></a><a class="link" href="cpp_dec_ref.html" title="cpp_dec_float">cpp_dec_float</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">cpp_dec_float</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">cpp_dec_float_50</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">cpp_dec_float_100</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
Class template <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
|
||||
fulfills all of the requirements for a <a class="link" href="backendconc.html" title="Backend Requirements">Backend</a>
|
||||
type. Its members and non-member functions are deliberately not documented:
|
||||
these are considered implementation details that are subject to change.
|
||||
</p>
|
||||
<p>
|
||||
The class takes a single template parameter - <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
||||
- which is the number of decimal digits precision the type should support.
|
||||
Note that this type does not ever perform any dynamic memory allocation,
|
||||
as a result the <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
||||
template argument should not be set too high or the class's size will grow
|
||||
unreasonably large.
|
||||
</p>
|
||||
<p>
|
||||
The type of <code class="computeroutput"><span class="identifier">number_category</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special"><</span><span class="identifier">Args</span><span class="special">...></span> <span class="special">>::</span><span class="identifier">type</span></code> is <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">number_kind_floating_point</span><span class="special">></span></code>.
|
||||
</p>
|
||||
<p>
|
||||
More information on this type can be found in the <a class="link" href="../tut/floats/cpp_dec_float.html" title="cpp_dec_float">tutorial</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mpfr_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="internals.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,148 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>cpp_int</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="number.html" title="number">
|
||||
<link rel="next" href="gmp_int_ref.html" title="gmp_int">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="number.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_int_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_cpp_int_ref">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.cpp_int_ref"></a><a class="link" href="cpp_int_ref.html" title="cpp_int">cpp_int</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">unspecified</span><span class="special">-</span><span class="identifier">type</span> <span class="identifier">limb_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">cpp_integer_type</span> <span class="special">{</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span> <span class="special">};</span>
|
||||
<span class="keyword">enum</span> <span class="identifier">cpp_int_check_type</span> <span class="special">{</span> <span class="identifier">checked</span><span class="special">,</span> <span class="identifier">unchecked</span> <span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">MinDigits</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span>
|
||||
<span class="keyword">unsigned</span> <span class="identifier">MaxDits</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span>
|
||||
<span class="identifier">cpp_integer_type</span> <span class="identifier">SignType</span> <span class="special">=</span> <span class="identifier">signed_magnitude</span><span class="special">,</span>
|
||||
<span class="identifier">cpp_int_check_type</span> <span class="identifier">Checked</span> <span class="special">=</span> <span class="identifier">unchecked</span><span class="special">,</span>
|
||||
<span class="keyword">class</span> <span class="identifier">Allocator</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span><span class="special"><</span><span class="identifier">limb_type</span><span class="special">></span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">cpp_int_backend</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Expression templates default to et_off if there is no allocator:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">MinDigits</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">MaxDigits</span><span class="special">,</span> <span class="identifier">cpp_integer_type</span> <span class="identifier">SignType</span><span class="special">,</span> <span class="identifier">cpp_int_check_type</span> <span class="identifier">Checked</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">expression_template_default</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="identifier">MinDigits</span><span class="special">,</span> <span class="identifier">MaxDigits</span><span class="special">,</span> <span class="identifier">SignType</span><span class="special">,</span> <span class="identifier">Checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span>
|
||||
<span class="special">{</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">expression_template_option</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">et_off</span><span class="special">;</span> <span class="special">};</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><></span> <span class="special">></span> <span class="identifier">cpp_int</span><span class="special">;</span> <span class="comment">// arbitrary precision integer</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">rational_adapter</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><></span> <span class="special">></span> <span class="identifier">cpp_rational_backend</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_rational_backend</span><span class="special">></span> <span class="identifier">cpp_rational</span><span class="special">;</span> <span class="comment">// arbitrary precision rational number</span>
|
||||
|
||||
<span class="comment">// Fixed precision unsigned types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Fixed precision signed types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Over again, but with checking enabled this time:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_cpp_int</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">rational_adapter</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_cpp_rational_backend</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_rational_backend</span><span class="special">></span> <span class="identifier">checked_cpp_rational</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Checked fixed precision unsigned types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Fixed precision signed types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
Class template <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>
|
||||
fulfills all of the requirements for a <a class="link" href="backendconc.html" title="Backend Requirements">Backend</a>
|
||||
type. Its members and non-member functions are deliberately not documented:
|
||||
these are considered implementation details that are subject to change.
|
||||
</p>
|
||||
<p>
|
||||
The template arguments are:
|
||||
</p>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">MinBits</span></dt>
|
||||
<dd><p>
|
||||
Determines the number of Bits to store directly within the object before
|
||||
resorting to dynamic memory allocation. When zero, this field is determined
|
||||
automatically based on how many bits can be stored in union with the
|
||||
dynamic storage header: setting a larger value may improve performance
|
||||
as larger integer values will be stored internally before memory allocation
|
||||
is required.
|
||||
</p></dd>
|
||||
<dt><span class="term">MaxBits</span></dt>
|
||||
<dd><p>
|
||||
Determines the maximum number of bits to be stored in the type: resulting
|
||||
in a fixed precision type. When this value is the same as MinBits,
|
||||
then the Allocator parameter is ignored, as no dynamic memory allocation
|
||||
will ever be performed: in this situation the Allocator parameter should
|
||||
be set to type <code class="computeroutput"><span class="keyword">void</span></code>. Note
|
||||
that this parameter should not be used simply to prevent large memory
|
||||
allocations, not only is that role better performed by the allocator,
|
||||
but fixed precision integers have a tendency to allocate all of MaxBits
|
||||
of storage more often than one would expect.
|
||||
</p></dd>
|
||||
<dt><span class="term">SignType</span></dt>
|
||||
<dd><p>
|
||||
Determines whether the resulting type is signed or not. Note that for
|
||||
<a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_top">arbitrary
|
||||
precision</a> types this parameter must be <code class="computeroutput"><span class="identifier">signed_magnitude</span></code>.
|
||||
For fixed precision types then this type may be either <code class="computeroutput"><span class="identifier">signed_magnitude</span></code> or <code class="computeroutput"><span class="identifier">unsigned_magnitude</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Checked</span></dt>
|
||||
<dd><p>
|
||||
This parameter has two values: <code class="computeroutput"><span class="identifier">checked</span></code>
|
||||
or <code class="computeroutput"><span class="identifier">unchecked</span></code>. See the
|
||||
<a class="link" href="../tut/ints/cpp_int.html" title="cpp_int">tutorial</a>
|
||||
for more information.
|
||||
</p></dd>
|
||||
<dt><span class="term">Allocator</span></dt>
|
||||
<dd><p>
|
||||
The allocator to use for dynamic memory allocation, or type <code class="computeroutput"><span class="keyword">void</span></code> if MaxBits == MinBits.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
The type of <code class="computeroutput"><span class="identifier">number_category</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special"><</span><span class="identifier">Args</span><span class="special">...></span> <span class="special">>::</span><span class="identifier">type</span></code> is <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">number_kind_integer</span><span class="special">></span></code>.
|
||||
</p>
|
||||
<p>
|
||||
More information on this type can be found in the <a class="link" href="../tut/ints/cpp_int.html" title="cpp_int">tutorial</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="number.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_int_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,54 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>gmp_int</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="cpp_int_ref.html" title="cpp_int">
|
||||
<link rel="next" href="tom_int_ref.html" title="tom_int">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_int_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="tom_int_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_gmp_int_ref">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.gmp_int_ref"></a><a class="link" href="gmp_int_ref.html" title="gmp_int">gmp_int</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">gmp_int</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_int</span> <span class="special">></span> <span class="identifier">mpz_int</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
Class template <code class="computeroutput"><span class="identifier">gmp_int</span></code> fulfills
|
||||
all of the requirements for a <a class="link" href="backendconc.html" title="Backend Requirements">Backend</a>
|
||||
type. Its members and non-member functions are deliberately not documented:
|
||||
these are considered implementation details that are subject to change.
|
||||
</p>
|
||||
<p>
|
||||
The type of <code class="computeroutput"><span class="identifier">number_category</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special"><</span><span class="identifier">Args</span><span class="special">...></span> <span class="special">>::</span><span class="identifier">type</span></code> is <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">number_kind_integer</span><span class="special">></span></code>.
|
||||
</p>
|
||||
<p>
|
||||
More information on this type can be found in the <a class="link" href="../tut/ints/gmp_int.html" title="gmp_int">tutorial</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_int_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="tom_int_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,415 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Header File Structure</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="backendconc.html" title="Backend Requirements">
|
||||
<link rel="next" href="../perf.html" title="Performance Comparison">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="backendconc.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../perf.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_headers">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.headers"></a><a class="link" href="headers.html" title="Header File Structure">Header File Structure</a>
|
||||
</h3></div></div></div>
|
||||
<div class="table">
|
||||
<a name="boost_multiprecision.ref.headers.top_level_headers"></a><p class="title"><b>Table 1.6. Top level headers</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Top level headers">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Header
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Contains
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">cpp_int</span></code> backend
|
||||
type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
gmp.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines all <a href="http://gmplib.org" target="_top">GMP</a> related
|
||||
backends.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
miller_rabin.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Miller Rabin primality testing code.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
number.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines the <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
backend, is included by all the backend headers.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
mpfr.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines the mpfr_float_backend backend.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
random.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines code to interoperate with Boost.Random.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
rational_adapter.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines the <code class="computeroutput"><span class="identifier">rational_adapter</span></code>
|
||||
backend.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_dec_float.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines the <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
|
||||
backend.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
tommath.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines the <code class="computeroutput"><span class="identifier">tommath_int</span></code>
|
||||
backend.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
concepts/number_archetypes.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines a backend concept architypes for testing use.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break"><div class="table">
|
||||
<a name="boost_multiprecision.ref.headers.implementation_headers_"></a><p class="title"><b>Table 1.7. Implementation Headers]</b></p>
|
||||
<div class="table-contents"><table class="table" summary="Implementation Headers]">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Header
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Contains
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/add.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Add and subtract operators for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/bitwise.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Bitwise operators for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/checked.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Helper functions for checked arithmetic for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/comparison.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Comparison operators for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/cpp_int_config.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Basic setup and configuration for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/divide.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Division and modulus operators for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/limits.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">numeric_limits</span></code>
|
||||
support for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/misc.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Miscellaneous operators for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
cpp_int/multiply.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Multiply operators for <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
detail/big_lanczos.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Lanczos support for Boost.Math integration.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
detail/default_ops.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Default versions of the optional backend non-member functions.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
detail/generic_interconvert.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Generic interconversion routines.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
detail/number_base.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
All the expression template code, metaprogramming, and operator
|
||||
overloads for <code class="computeroutput"><span class="identifier">number</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
detail/no_et_ops.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The non-expression template operators.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
defail/functions/constants.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines constants used by the floating point functions.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
detail/functions/pow.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines default versions of the power and exponential related floating
|
||||
point functions.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
detail/functions/trig.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Defines default versions of the trigonometric related floating
|
||||
point functions.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<br class="table-break">
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="backendconc.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../perf.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,105 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Internal Support Code</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="cpp_dec_ref.html" title="cpp_dec_float">
|
||||
<link rel="next" href="backendconc.html" title="Backend Requirements">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_dec_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="backendconc.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_internals">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.internals"></a><a class="link" href="internals.html" title="Internal Support Code">Internal Support
|
||||
Code</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
There are some traits classes which authors of new backends should be aware
|
||||
of:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">detail</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">From</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">To</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">is_explicitly_convertible</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}}</span>
|
||||
</pre>
|
||||
<p>
|
||||
Inherits from <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">integral_constant</span><span class="special"><</span><span class="keyword">bool</span><span class="special">,</span><span class="keyword">true</span><span class="special">></span></code> if type <code class="computeroutput"><span class="identifier">From</span></code>
|
||||
has an explicit conversion from <code class="computeroutput"><span class="identifier">To</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
For compilers that support C++11 SFINAE-expressions this trait should "just
|
||||
work". Otherwise it inherits from <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">is_convertible</span><span class="special"><</span><span class="identifier">From</span><span class="special">,</span> <span class="identifier">To</span><span class="special">>::</span><span class="identifier">type</span></code>, and will need to be specialised for
|
||||
Backends that have constructors marked as <code class="computeroutput"><span class="keyword">explicit</span></code>.
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">From</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">To</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">is_lossy_conversion</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">see</span> <span class="identifier">below</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
Member <code class="computeroutput"><span class="identifier">value</span></code> is true if the
|
||||
conversion from <code class="computeroutput"><span class="identifier">From</span></code> to
|
||||
<code class="computeroutput"><span class="identifier">To</span></code> would result in a loss
|
||||
of precision, and <code class="computeroutput"><span class="keyword">false</span></code> otherwise.
|
||||
</p>
|
||||
<p>
|
||||
The default version of this trait simply checks whether the <span class="emphasis"><em>kind</em></span>
|
||||
of conversion (for example from a floating point to an integer type) is inherently
|
||||
lossy. Note that if either of the types <code class="computeroutput"><span class="identifier">From</span></code>
|
||||
or <code class="computeroutput"><span class="identifier">To</span></code> are of an unknown number
|
||||
category (because <code class="computeroutput"><span class="identifier">number_category</span></code>
|
||||
is not specialised for that type) then this trait will be <code class="computeroutput"><span class="keyword">true</span></code>.
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">From</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">To</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">is_restricted_conversion</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">see</span> <span class="identifier">below</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
Member <code class="computeroutput"><span class="identifier">value</span></code> is <code class="computeroutput"><span class="keyword">true</span></code> if <code class="computeroutput"><span class="identifier">From</span></code>
|
||||
is only explicitly convertible to <code class="computeroutput"><span class="identifier">To</span></code>
|
||||
and not implicitly convertible, or if <code class="computeroutput"><span class="identifier">is_lossy_conversion</span><span class="special"><</span><span class="identifier">From</span><span class="special">,</span> <span class="identifier">To</span><span class="special">>::</span><span class="identifier">value</span></code> is <code class="computeroutput"><span class="keyword">true</span></code>.
|
||||
Otherwise <code class="computeroutput"><span class="keyword">false</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Note that while this trait is the ultimate arbiter of which constructors
|
||||
are marked as <code class="computeroutput"><span class="keyword">explicit</span></code> in class
|
||||
<code class="computeroutput"><span class="identifier">number</span></code>, authors of backend
|
||||
types should generally specialise one of the traits above, rather than this
|
||||
one directly.
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="identifier">is_signed_number</span><span class="special">;</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="identifier">is_unsigned_number</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
These two traits inherit from either <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">true_</span></code>
|
||||
or <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">false_</span></code>, by default types are assumed to
|
||||
be signed unless <code class="computeroutput"><span class="identifier">is_unsigned_number</span></code>
|
||||
is specialized for that type.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_dec_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="backendconc.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,70 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>gmp_float</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="tom_int_ref.html" title="tom_int">
|
||||
<link rel="next" href="mpfr_ref.html" title="mpfr_float_backend">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tom_int_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="mpfr_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_mpf_ref">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.mpf_ref"></a><a class="link" href="mpf_ref.html" title="gmp_float">gmp_float</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">gmp_float</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_50</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_100</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">500</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_500</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">1000</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_1000</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
Class template <code class="computeroutput"><span class="identifier">gmp_float</span></code>
|
||||
fulfills all of the requirements for a <a class="link" href="backendconc.html" title="Backend Requirements">Backend</a>
|
||||
type. Its members and non-member functions are deliberately not documented:
|
||||
these are considered implementation details that are subject to change.
|
||||
</p>
|
||||
<p>
|
||||
The class takes a single template parameter - <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
||||
- which is the number of decimal digits precision the type should support.
|
||||
When this parameter is zero, then the precision can be set at runtime via
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special">::</span><span class="identifier">default_precision</span></code> and <code class="computeroutput"><span class="identifier">number</span><span class="special">::</span><span class="identifier">precision</span></code>.
|
||||
Note that this type does not in any way change the GMP library's global state
|
||||
(for example it does not change the default precision of the mpf_t data type),
|
||||
therefore you can safely mix this type with existing code that uses GMP,
|
||||
and also mix <code class="computeroutput"><span class="identifier">gmp_float</span></code>s of
|
||||
differing precision.
|
||||
</p>
|
||||
<p>
|
||||
The type of <code class="computeroutput"><span class="identifier">number_category</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special"><</span><span class="identifier">Args</span><span class="special">...></span> <span class="special">>::</span><span class="identifier">type</span></code> is <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">number_kind_floating_point</span><span class="special">></span></code>.
|
||||
</p>
|
||||
<p>
|
||||
More information on this type can be found in the <a class="link" href="../tut/floats/gmp_float.html" title="gmp_float">tutorial</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tom_int_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="mpfr_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,70 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>mpfr_float_backend</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="mpf_ref.html" title="gmp_float">
|
||||
<link rel="next" href="cpp_dec_ref.html" title="cpp_dec_float">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mpf_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="cpp_dec_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_mpfr_ref">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.mpfr_ref"></a><a class="link" href="mpfr_ref.html" title="mpfr_float_backend">mpfr_float_backend</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">mpfr_float_backend</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_50</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_100</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">500</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_500</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">1000</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_1000</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
Class template <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>
|
||||
fulfills all of the requirements for a <a class="link" href="backendconc.html" title="Backend Requirements">Backend</a>
|
||||
type. Its members and non-member functions are deliberately not documented:
|
||||
these are considered implementation details that are subject to change.
|
||||
</p>
|
||||
<p>
|
||||
The class takes a single template parameter - <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
||||
- which is the number of decimal digits precision the type should support.
|
||||
When this parameter is zero, then the precision can be set at runtime via
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special">::</span><span class="identifier">default_precision</span></code> and <code class="computeroutput"><span class="identifier">number</span><span class="special">::</span><span class="identifier">precision</span></code>.
|
||||
Note that this type does not in any way change the GMP or MPFR library's
|
||||
global state (for example it does not change the default precision of the
|
||||
mpfr_t data type), therefore you can safely mix this type with existing code
|
||||
that uses GMP or MPFR, and also mix <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>s
|
||||
of differing precision.
|
||||
</p>
|
||||
<p>
|
||||
The type of <code class="computeroutput"><span class="identifier">number_category</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special"><</span><span class="identifier">Args</span><span class="special">...></span> <span class="special">>::</span><span class="identifier">type</span></code> is <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">number_kind_floating_point</span><span class="special">></span></code>.
|
||||
</p>
|
||||
<p>
|
||||
More information on this type can be found in the <a class="link" href="../tut/floats/mpfr_float.html" title="mpfr_float">tutorial</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mpf_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="cpp_dec_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,54 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>tom_int</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ref.html" title="Reference">
|
||||
<link rel="prev" href="gmp_int_ref.html" title="gmp_int">
|
||||
<link rel="next" href="mpf_ref.html" title="gmp_float">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_int_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="mpf_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_ref_tom_int_ref">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.ref.tom_int_ref"></a><a class="link" href="tom_int_ref.html" title="tom_int">tom_int</a>
|
||||
</h3></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">tommath_int</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">tommath_int</span> <span class="special">></span> <span class="identifier">tom_int</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
Class template <code class="computeroutput"><span class="identifier">tommath_int</span></code>
|
||||
fulfills all of the requirements for a <a class="link" href="backendconc.html" title="Backend Requirements">Backend</a>
|
||||
type. Its members and non-member functions are deliberately not documented:
|
||||
these are considered implementation details that are subject to change.
|
||||
</p>
|
||||
<p>
|
||||
The type of <code class="computeroutput"><span class="identifier">number_category</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special"><</span><span class="identifier">Args</span><span class="special">...></span> <span class="special">>::</span><span class="identifier">type</span></code> is <code class="computeroutput"><span class="identifier">mpl</span><span class="special">::</span><span class="identifier">int_</span><span class="special"><</span><span class="identifier">number_kind_integer</span><span class="special">></span></code>.
|
||||
</p>
|
||||
<p>
|
||||
More information on this type can be found in the <a class="link" href="../tut/ints/tom_int.html" title="tom_int">tutorial</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_int_ref.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ref.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="mpf_ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,86 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Tutorial</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="prev" href="intro.html" title="Introduction">
|
||||
<link rel="next" href="tut/ints.html" title="Integer Types">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="intro.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="tut/ints.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut">
|
||||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||||
<a name="boost_multiprecision.tut"></a><a class="link" href="tut.html" title="Tutorial">Tutorial</a>
|
||||
</h2></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="tut/ints.html">Integer Types</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="tut/ints/cpp_int.html">cpp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/ints/gmp_int.html">gmp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/ints/tom_int.html">tom_int</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/ints/egs.html">Examples</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="tut/ints/egs/factorials.html">Factorials</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/ints/egs/bitops.html">Bit Operations</a></span></dt>
|
||||
</dl></dd>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="tut/floats.html">Floating Point Numbers</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="tut/floats/cpp_dec_float.html">cpp_dec_float</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/floats/gmp_float.html">gmp_float</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/floats/mpfr_float.html">mpfr_float</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/floats/fp_eg.html">Examples</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="tut/floats/fp_eg/aos.html">Area of
|
||||
Circle</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/floats/fp_eg/jel.html">Defining
|
||||
a Lambda Function.</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/floats/fp_eg/nd.html">Calculating
|
||||
a Derivative</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/floats/fp_eg/gi.html">Calculating
|
||||
an Integral</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/floats/fp_eg/poly_eg.html">Polynomial
|
||||
Evaluation</a></span></dt>
|
||||
</dl></dd>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="tut/rational.html">Rational Number Types</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="tut/rational/cpp_rational.html">cpp_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/rational/gmp_rational.html">gmp_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/rational/tommath_rational.html">tommath_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/rational/br.html">Use With Boost.Rational</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/rational/rational_adapter.html">rational_adapter</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="tut/conversions.html">Constructing and
|
||||
Interconverting Between Number Types</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/random.html">Generating Random Numbers</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/primetest.html">Primality Testing</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/lits.html">Literal Types and <code class="computeroutput"><span class="identifier">constexpr</span></code> Support</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/rounding.html">Rounding Rules for
|
||||
Conversions</a></span></dt>
|
||||
<dt><span class="section"><a href="tut/mixed.html">Mixed Precision Arithmetic</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
In order to use this library you need to make two choices: what kind of number
|
||||
do I want, and which back-end do I want to perform the actual arithmetic?
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="intro.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="tut/ints.html"><img src="../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,168 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Constructing and Interconverting Between Number Types</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="rational/rational_adapter.html" title="rational_adapter">
|
||||
<link rel="next" href="random.html" title="Generating Random Numbers">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="rational/rational_adapter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="random.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_conversions">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.conversions"></a><a class="link" href="conversions.html" title="Constructing and Interconverting Between Number Types">Constructing and
|
||||
Interconverting Between Number Types</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
All of the number types that are based on <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
have certain conversion rules in common. In particular:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Any number type can be constructed (or assigned) from any builtin arithmetic
|
||||
type, as long as the conversion isn't lossy (for example float to int
|
||||
conversion):
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">cpp_dec_float_50</span> <span class="identifier">df</span><span class="special">(</span><span class="number">0.5</span><span class="special">);</span> <span class="comment">// OK construction from double</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">i</span><span class="special">(</span><span class="number">450</span><span class="special">);</span> <span class="comment">// OK constructs from signed int</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">3.14</span><span class="special">;</span> <span class="comment">// Error, lossy conversion.</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
A number can be explicitly constructed from an arithmetic type, even
|
||||
when the conversion is lossy:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">cpp_int</span> <span class="identifier">i</span><span class="special">(</span><span class="number">3.14</span><span class="special">);</span> <span class="comment">// OK explicit conversion</span>
|
||||
<span class="identifier">i</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special">>(</span><span class="number">3.14</span><span class="special">)</span> <span class="comment">// OK explicit conversion</span>
|
||||
<span class="identifier">i</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="number">3.14</span><span class="special">);</span> <span class="comment">// OK, explicit assign and avoid a temporary from the cast above</span>
|
||||
<span class="identifier">i</span> <span class="special">=</span> <span class="number">3.14</span><span class="special">;</span> <span class="comment">// Error, no implicit assignment operator for lossy conversion.</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">3.14</span><span class="special">;</span> <span class="comment">// Error, no implicit constructor for lossy conversion.</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
A <code class="computeroutput"><span class="identifier">number</span></code> can be converted
|
||||
to any built in type, via the <code class="computeroutput"><span class="identifier">convert_to</span></code>
|
||||
member function:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">mpz_int</span> <span class="identifier">z</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>
|
||||
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">z</span><span class="special">.</span><span class="keyword">template</span> <span class="identifier">convert_to</span><span class="special"><</span><span class="keyword">int</span><span class="special">>();</span> <span class="comment">// sets i to 2</span>
|
||||
</pre>
|
||||
<p>
|
||||
Additional conversions may be supported by particular backends.
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
A <code class="computeroutput"><span class="identifier">number</span></code> can be converted
|
||||
to any built in type, via an explicit conversion operator: this functionality
|
||||
is only available on compilers supporting C++11's explicit conversion
|
||||
syntax.
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">mpz_int</span> <span class="identifier">z</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>
|
||||
<span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">z</span><span class="special">;</span> <span class="comment">// Error, implicit conversion not allowed.</span>
|
||||
<span class="keyword">int</span> <span class="identifier">j</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">int</span><span class="special">>(</span><span class="identifier">z</span><span class="special">);</span> <span class="comment">// OK explicit conversion.</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Any number type can be <span class="emphasis"><em>explicitly</em></span> constructed (or
|
||||
assigned) from a <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">char</span><span class="special">*</span></code>
|
||||
or a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="comment">// pi to 50 places from a string:</span>
|
||||
<span class="identifier">cpp_dec_float_50</span> <span class="identifier">df</span><span class="special">(</span><span class="string">"3.14159265358979323846264338327950288419716939937510"</span><span class="special">);</span>
|
||||
<span class="comment">// Integer type will automatically detect "0x" and "0" prefixes and parse the string accordingly:</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">i</span><span class="special">(</span><span class="string">"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000"</span><span class="special">);</span>
|
||||
<span class="comment">// Invalid input always results in a std::runtime_error being thrown:</span>
|
||||
<span class="identifier">i</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special">>(</span><span class="string">"3.14"</span><span class="special">);</span>
|
||||
<span class="comment">// implicit conversions from strings are not allowed:</span>
|
||||
<span class="identifier">i</span> <span class="special">=</span> <span class="string">"23"</span><span class="special">;</span> <span class="comment">// Error, no assignment operator for implicit conversion from string</span>
|
||||
<span class="comment">// assign member function, avoids having to create a temporary via a static_cast:</span>
|
||||
<span class="identifier">i</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span><span class="string">"23"</span><span class="special">);</span> <span class="comment">// OK</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Any number type will interoperate with the builtin types in arithmetic
|
||||
expressions as long as the conversions are not lossy:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="comment">// pi to 50 places from a string:</span>
|
||||
<span class="identifier">cpp_dec_float_50</span> <span class="identifier">df</span> <span class="special">=</span> <span class="string">"3.14159265358979323846264338327950288419716939937510"</span><span class="special">;</span>
|
||||
<span class="comment">// Multiply by 2 - using an integer literal here is usually more efficient</span>
|
||||
<span class="comment">// than constructing a temporary:</span>
|
||||
<span class="identifier">df</span> <span class="special">*=</span> <span class="number">2</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// You can't mix integer types with floats though:</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">i</span> <span class="special">*=</span> <span class="number">3.14</span><span class="special">;</span> <span class="comment">// Error, no *= operator will be found.</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Any number type can be streamed to and from the C++ iostreams:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">cpp_dec_float_50</span> <span class="identifier">df</span> <span class="special">=</span> <span class="string">"3.14159265358979323846264338327950288419716939937510"</span><span class="special">;</span>
|
||||
<span class="comment">// Now print at full precision:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>::</span><span class="identifier">max_digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">df</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="identifier">i</span> <span class="special"><<=</span> <span class="number">256</span><span class="special">;</span>
|
||||
<span class="comment">// Now print in hex format with prefix:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">i</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Interconversions between number types of the same family are allowed
|
||||
and are implicit conversions if no loss of precision is involved, and
|
||||
explicit if it is:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">int128_t</span> <span class="identifier">i128</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="identifier">int266_t</span> <span class="identifier">i256</span> <span class="special">=</span> <span class="identifier">i128</span><span class="special">;</span> <span class="comment">// OK implicit widening conversion</span>
|
||||
<span class="identifier">i128_t</span> <span class="special">=</span> <span class="identifier">i256</span><span class="special">;</span> <span class="comment">// Error, no assignment operator found, narrowing conversion is explict</span>
|
||||
<span class="identifier">i128_t</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">int128_t</span><span class="special">>(</span><span class="identifier">i256</span><span class="special">);</span> <span class="comment">// OK, explicit narrowing conversion</span>
|
||||
|
||||
<span class="identifier">mpz_int</span> <span class="identifier">z</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="identifier">mpf_float</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">z</span><span class="special">;</span> <span class="comment">// OK, GMP handles this conversion natively, and it's not lossy and therefore implicit</span>
|
||||
|
||||
<span class="identifier">mpf_float_50</span> <span class="identifier">f50</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">f</span> <span class="special">=</span> <span class="identifier">f50</span><span class="special">;</span> <span class="comment">// OK, conversion from fixed to variable precision, f will have 50 digits precision.</span>
|
||||
<span class="identifier">f50</span> <span class="special">=</span> <span class="identifier">f</span><span class="special">;</span> <span class="comment">// Error, conversion from variable to fixed precision is potentially lossy, explicit cast required.</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Some interconversions between number types are completely generic, and
|
||||
are always available, albeit the conversions are always <span class="emphasis"><em>explicit</em></span>:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">cpp_int</span> <span class="identifier">cppi</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>
|
||||
<span class="comment">// We can always convert between numbers of the same category - </span>
|
||||
<span class="comment">// int to int, rational to rational, or float to float, so this is OK</span>
|
||||
<span class="comment">// as long as we use an explicit conversion:</span>
|
||||
<span class="identifier">mpz_int</span> <span class="identifier">z</span><span class="special">(</span><span class="identifier">cppi</span><span class="special">);</span>
|
||||
<span class="comment">// We can always promote from int to rational, int to float, or rational to float:</span>
|
||||
<span class="identifier">cpp_rational</span> <span class="identifier">cppr</span><span class="special">(</span><span class="identifier">cppi</span><span class="special">);</span> <span class="comment">// OK, int to rational</span>
|
||||
<span class="identifier">cpp_dec_float_50</span> <span class="identifier">df</span><span class="special">(</span><span class="identifier">cppi</span><span class="special">);</span> <span class="comment">// OK, int to float</span>
|
||||
<span class="identifier">df</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>(</span><span class="identifier">cppr</span><span class="special">);</span> <span class="comment">// OK, explicit rational to float conversion</span>
|
||||
<span class="comment">// However narrowing and/or implicit conversions always fail:</span>
|
||||
<span class="identifier">cppi</span> <span class="special">=</span> <span class="identifier">df</span><span class="special">;</span> <span class="comment">// Compiler error, conversion not allowed</span>
|
||||
</pre>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
|
||||
Other interconversions may be allowed as special cases, whenever the
|
||||
backend allows it:
|
||||
</li></ul></div>
|
||||
<pre class="programlisting"><span class="identifier">mpf_t</span> <span class="identifier">m</span><span class="special">;</span> <span class="comment">// Native GMP type.</span>
|
||||
<span class="identifier">mpf_init_set_ui</span><span class="special">(</span><span class="identifier">m</span><span class="special">,</span> <span class="number">0</span><span class="special">);</span> <span class="comment">// set to a value;</span>
|
||||
<span class="identifier">mpf_float</span> <span class="identifier">i</span><span class="special">(</span><span class="identifier">m</span><span class="special">);</span> <span class="comment">// copies the value of the native type.</span>
|
||||
</pre>
|
||||
<p>
|
||||
More information on what additional types a backend supports conversions
|
||||
from are given in the tutorial for each backend. The converting constructor
|
||||
will be implict if the backend's converting constructor is also implicit,
|
||||
and explicit if the backends converting constructor is also explicit.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="rational/rational_adapter.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="random.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,199 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Floating Point Numbers</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="ints/egs/bitops.html" title="Bit Operations">
|
||||
<link rel="next" href="floats/cpp_dec_float.html" title="cpp_dec_float">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="ints/egs/bitops.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="floats/cpp_dec_float.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.floats"></a><a class="link" href="floats.html" title="Floating Point Numbers">Floating Point Numbers</a>
|
||||
</h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="floats/cpp_dec_float.html">cpp_dec_float</a></span></dt>
|
||||
<dt><span class="section"><a href="floats/gmp_float.html">gmp_float</a></span></dt>
|
||||
<dt><span class="section"><a href="floats/mpfr_float.html">mpfr_float</a></span></dt>
|
||||
<dt><span class="section"><a href="floats/fp_eg.html">Examples</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="floats/fp_eg/aos.html">Area of
|
||||
Circle</a></span></dt>
|
||||
<dt><span class="section"><a href="floats/fp_eg/jel.html">Defining
|
||||
a Lambda Function.</a></span></dt>
|
||||
<dt><span class="section"><a href="floats/fp_eg/nd.html">Calculating
|
||||
a Derivative</a></span></dt>
|
||||
<dt><span class="section"><a href="floats/fp_eg/gi.html">Calculating
|
||||
an Integral</a></span></dt>
|
||||
<dt><span class="section"><a href="floats/fp_eg/poly_eg.html">Polynomial
|
||||
Evaluation</a></span></dt>
|
||||
</dl></dd>
|
||||
</dl></div>
|
||||
<p>
|
||||
The following back-ends provide floating point arithmetic:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Backend Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Header
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Radix
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Dependencies
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Pros
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Cons
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/cpp_dec_float.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
10
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
None
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Header only, all C++ implementation. Boost licence.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Approximately 2x slower than the <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
or <a href="http://gmplib.org" target="_top">GMP</a> libraries.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">mpf_float</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/gmp.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://gmplib.org" target="_top">GMP</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Very fast and efficient back-end.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Dependency on GNU licensed <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
library.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">mpfr_float</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/mpfr.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://gmplib.org" target="_top">GMP</a> and <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Very fast and efficient back-end, with its own standard library
|
||||
implementation.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Dependency on GNU licensed <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
and <a href="http://www.mpfr.org" target="_top">MPFR</a> libraries.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="ints/egs/bitops.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="floats/cpp_dec_float.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,164 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>cpp_dec_float</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../floats.html" title="Floating Point Numbers">
|
||||
<link rel="prev" href="../floats.html" title="Floating Point Numbers">
|
||||
<link rel="next" href="gmp_float.html" title="gmp_float">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../floats.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_float.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_cpp_dec_float">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.cpp_dec_float"></a><a class="link" href="cpp_dec_float.html" title="cpp_dec_float">cpp_dec_float</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">cpp_dec_float</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">ExponentType</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">int32_t</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Allocator</span> <span class="special">=</span> <span class="keyword">void</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">cpp_dec_float</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">cpp_dec_float_50</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">cpp_dec_float_100</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code> back-end
|
||||
is used in conjunction with <code class="computeroutput"><span class="identifier">number</span></code>:
|
||||
It acts as an entirely C++ (header only and dependency free) floating-point
|
||||
number type that is a drop-in replacement for the native C++ floating-point
|
||||
types, but with much greater precision.
|
||||
</p>
|
||||
<p>
|
||||
Type <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code> can
|
||||
be used at fixed precision by specifying a non-zero <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
||||
template parameter. The typedefs <code class="computeroutput"><span class="identifier">cpp_dec_float_50</span></code>
|
||||
and <code class="computeroutput"><span class="identifier">cpp_dec_float_100</span></code> provide
|
||||
arithmetic types at 50 and 100 decimal digits precision respectively. Optionally,
|
||||
you can specify an integer type to use for the exponent, this defaults
|
||||
to a 32-bit integer type which is more than large enough for the vast majority
|
||||
of use cases, but larger types such as <code class="computeroutput"><span class="keyword">long</span>
|
||||
<span class="keyword">long</span></code> can also be specified if you
|
||||
need a truely huge exponent range.
|
||||
</p>
|
||||
<p>
|
||||
Normally <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
|
||||
allocates no memory: all of the space required for its digits are allocated
|
||||
directly within the class. As a result care should be taken not to use
|
||||
the class with too high a digit count as stack space requirements can grow
|
||||
out of control. If that represents a problem then providing an allocator
|
||||
as the final template parameter causes <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
|
||||
to dynamically allocate the memory it needs: this significantly reduces
|
||||
the size of <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
|
||||
and increases the viable upper limit on the number of digits at the expense
|
||||
of performance. However, please bear in mind that arithmetic operations
|
||||
rapidly become <span class="emphasis"><em>very</em></span> expensive as the digit count grows:
|
||||
the current implementation really isn't optimized or designed for large
|
||||
digit counts.
|
||||
</p>
|
||||
<p>
|
||||
There is full standard library and <code class="computeroutput"><span class="identifier">numeric_limits</span></code>
|
||||
support available for this type.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Default constructed <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>s
|
||||
have a value of zero.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The radix of this type is 10. As a result it can behave subtly differently
|
||||
from base-2 types.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The type has a number of internal guard digits over and above those
|
||||
specified in the template argument. Normally these should not be visible
|
||||
to the user.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The type supports both infinities and NaN's. An infinity is generated
|
||||
whenever the result would overflow, and a NaN is generated for any
|
||||
mathematically undefined operation.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
There is a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span></code> specialisation for
|
||||
this type.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Any <code class="computeroutput"><span class="identifier">number</span></code> instantiated
|
||||
on this type, is convertible to any other <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
instantiated on this type - for example you can convert from <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span></code> to <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="identifier">SomeOtherValue</span><span class="special">></span> <span class="special">></span></code>.
|
||||
Narrowing conversions are truncating and <code class="computeroutput"><span class="keyword">explicit</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid floating
|
||||
point number.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The actual precision of a <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
|
||||
is always slightly higher than the number of digits specified in the
|
||||
template parameter, actually how much higher is an implementation detail
|
||||
but is always at least 8 decimal digits.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Operations involving <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
|
||||
are always truncating. However, note that since their are guard digits
|
||||
in effect, in practice this has no real impact on accuracy for most
|
||||
use cases.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.floats.cpp_dec_float.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.floats.cpp_dec_float.cpp_dec_float_example_"></a></span><a class="link" href="cpp_dec_float.html#boost_multiprecision.tut.floats.cpp_dec_float.cpp_dec_float_example_">cpp_dec_float
|
||||
example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">cpp_dec_float</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Operations at fixed precision and full numeric_limits support:</span>
|
||||
<span class="identifier">cpp_dec_float_100</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_100</span><span class="special">>::</span><span class="identifier">digits</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// Note that digits10 is the same as digits, since we're base 10! :</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_100</span><span class="special">>::</span><span class="identifier">digits10</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// We can use any C++ std lib function, lets print all the digits as well:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_100</span><span class="special">>::</span><span class="identifier">max_digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// print log(2)</span>
|
||||
<span class="comment">// We can also use any function from Boost.Math:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// These even work when the argument is an expression template:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">b</span> <span class="special">*</span> <span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// And since we have an extended exponent range we can generate some really large </span>
|
||||
<span class="comment">// numbers here (4.0238726007709377354370243e+2564):</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">cpp_dec_float_100</span><span class="special">(</span><span class="number">1000</span><span class="special">))</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../floats.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_float.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,46 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Examples</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../floats.html" title="Floating Point Numbers">
|
||||
<link rel="prev" href="mpfr_float.html" title="mpfr_float">
|
||||
<link rel="next" href="fp_eg/aos.html" title="Area of Circle">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mpfr_float.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="fp_eg/aos.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_fp_eg">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.fp_eg"></a><a class="link" href="fp_eg.html" title="Examples">Examples</a>
|
||||
</h4></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="fp_eg/aos.html">Area of
|
||||
Circle</a></span></dt>
|
||||
<dt><span class="section"><a href="fp_eg/jel.html">Defining
|
||||
a Lambda Function.</a></span></dt>
|
||||
<dt><span class="section"><a href="fp_eg/nd.html">Calculating
|
||||
a Derivative</a></span></dt>
|
||||
<dt><span class="section"><a href="fp_eg/gi.html">Calculating
|
||||
an Integral</a></span></dt>
|
||||
<dt><span class="section"><a href="fp_eg/poly_eg.html">Polynomial
|
||||
Evaluation</a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="mpfr_float.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="fp_eg/aos.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,118 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Area of Circle</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../fp_eg.html" title="Examples">
|
||||
<link rel="prev" href="../fp_eg.html" title="Examples">
|
||||
<link rel="next" href="jel.html" title="Defining a Lambda Function.">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../fp_eg.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="jel.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_fp_eg_aos">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.fp_eg.aos"></a><a class="link" href="aos.html" title="Area of Circle">Area of
|
||||
Circle</a>
|
||||
</h5></div></div></div>
|
||||
<p>
|
||||
Generic numeric programming employs templates to use the same code for
|
||||
different floating-point types and functions. Consider the area of a
|
||||
circle a of radius r, given by
|
||||
</p>
|
||||
<div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<span class="emphasis"><em>a = π * r<sup>2</sup></em></span>
|
||||
</p></blockquote></div>
|
||||
<p>
|
||||
The area of a circle can be computed in generic programming using Boost.Math
|
||||
for the constant π as shown below:
|
||||
</p>
|
||||
<p>
|
||||
</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">math</span><span class="special">/</span><span class="identifier">constants</span><span class="special">/</span><span class="identifier">constants</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">></span>
|
||||
<span class="keyword">inline</span> <span class="identifier">T</span> <span class="identifier">area_of_a_circle</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">r</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special">;</span>
|
||||
<span class="keyword">return</span> <span class="identifier">pi</span><span class="special"><</span><span class="identifier">T</span><span class="special">>()</span> <span class="special">*</span> <span class="identifier">r</span> <span class="special">*</span> <span class="identifier">r</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
It is possible to use <code class="computeroutput"><span class="identifier">area_of_a_circle</span><span class="special">()</span></code> with built-in floating-point types
|
||||
as well as floating-point types from Boost.Multiprecision. In particular,
|
||||
consider a system with 4-byte single-precision float, 8-byte double-precision
|
||||
double and also the <code class="computeroutput"><span class="identifier">cpp_dec_float_50</span></code>
|
||||
data type from Boost.Multiprecision with 50 decimal digits of precision.
|
||||
</p>
|
||||
<p>
|
||||
We can compute and print the approximate area of a circle with radius
|
||||
123/100 for <code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code> and <code class="computeroutput"><span class="identifier">cpp_dec_float_50</span></code>
|
||||
with the program below.
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iomanip</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">cpp_dec_float</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float_50</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">**)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">const</span> <span class="keyword">float</span> <span class="identifier">r_f</span><span class="special">(</span><span class="keyword">float</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">/</span> <span class="number">100</span><span class="special">);</span>
|
||||
<span class="keyword">const</span> <span class="keyword">float</span> <span class="identifier">a_f</span> <span class="special">=</span> <span class="identifier">area_of_a_circle</span><span class="special">(</span><span class="identifier">r_f</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="keyword">double</span> <span class="identifier">r_d</span><span class="special">(</span><span class="keyword">double</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">/</span> <span class="number">100</span><span class="special">);</span>
|
||||
<span class="keyword">const</span> <span class="keyword">double</span> <span class="identifier">a_d</span> <span class="special">=</span> <span class="identifier">area_of_a_circle</span><span class="special">(</span><span class="identifier">r_d</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">cpp_dec_float_50</span> <span class="identifier">r_mp</span><span class="special">(</span><span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">/</span> <span class="number">100</span><span class="special">);</span>
|
||||
<span class="keyword">const</span> <span class="identifier">cpp_dec_float_50</span> <span class="identifier">a_mp</span> <span class="special">=</span> <span class="identifier">area_of_a_circle</span><span class="special">(</span><span class="identifier">r_mp</span><span class="special">);</span>
|
||||
|
||||
<span class="comment">// 4.75292</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">float</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">a_f</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// 4.752915525616</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">double</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">a_d</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// 4.7529155256159981904701331745635599135018975843146</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">a_mp</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
In the next example we'll look at calling both standard library and Boost.Math
|
||||
functions from within generic code. We'll also show how to cope with
|
||||
template arguments which are expression-templates rather than number
|
||||
types.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../fp_eg.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="jel.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,161 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Calculating an Integral</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../fp_eg.html" title="Examples">
|
||||
<link rel="prev" href="nd.html" title="Calculating a Derivative">
|
||||
<link rel="next" href="poly_eg.html" title="Polynomial Evaluation">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="nd.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="poly_eg.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_fp_eg_gi">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.fp_eg.gi"></a><a class="link" href="gi.html" title="Calculating an Integral">Calculating
|
||||
an Integral</a>
|
||||
</h5></div></div></div>
|
||||
<p>
|
||||
Similar to the generic derivative example, we can calculate integrals
|
||||
in a similar manner:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">value_type</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">function_type</span><span class="special">></span>
|
||||
<span class="keyword">inline</span> <span class="identifier">value_type</span> <span class="identifier">integral</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">a</span><span class="special">,</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">b</span><span class="special">,</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">tol</span><span class="special">,</span>
|
||||
<span class="identifier">function_type</span> <span class="identifier">func</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">unsigned</span> <span class="identifier">n</span> <span class="special">=</span> <span class="number">1U</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">value_type</span> <span class="identifier">h</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">b</span> <span class="special">-</span> <span class="identifier">a</span><span class="special">);</span>
|
||||
<span class="identifier">value_type</span> <span class="identifier">I</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">func</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">func</span><span class="special">(</span><span class="identifier">b</span><span class="special">))</span> <span class="special">*</span> <span class="special">(</span><span class="identifier">h</span> <span class="special">/</span> <span class="number">2</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">k</span> <span class="special">=</span> <span class="number">0U</span><span class="special">;</span> <span class="identifier">k</span> <span class="special"><</span> <span class="number">8U</span><span class="special">;</span> <span class="identifier">k</span><span class="special">++)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">h</span> <span class="special">/=</span> <span class="number">2</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">value_type</span> <span class="identifier">sum</span><span class="special">(</span><span class="number">0</span><span class="special">);</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">1U</span><span class="special">;</span> <span class="identifier">j</span> <span class="special"><=</span> <span class="identifier">n</span><span class="special">;</span> <span class="identifier">j</span><span class="special">++)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">func</span><span class="special">(</span><span class="identifier">a</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">value_type</span><span class="special">((</span><span class="identifier">j</span> <span class="special">*</span> <span class="number">2</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">h</span><span class="special">));</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">I0</span> <span class="special">=</span> <span class="identifier">I</span><span class="special">;</span>
|
||||
<span class="identifier">I</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">I</span> <span class="special">/</span> <span class="number">2</span><span class="special">)</span> <span class="special">+</span> <span class="special">(</span><span class="identifier">h</span> <span class="special">*</span> <span class="identifier">sum</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">ratio</span> <span class="special">=</span> <span class="identifier">I0</span> <span class="special">/</span> <span class="identifier">I</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">delta</span> <span class="special">=</span> <span class="identifier">ratio</span> <span class="special">-</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">delta_abs</span> <span class="special">=</span> <span class="special">((</span><span class="identifier">delta</span> <span class="special"><</span> <span class="number">0</span><span class="special">)</span> <span class="special">?</span> <span class="special">-</span><span class="identifier">delta</span> <span class="special">:</span> <span class="identifier">delta</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">if</span><span class="special">((</span><span class="identifier">k</span> <span class="special">></span> <span class="number">1U</span><span class="special">)</span> <span class="special">&&</span> <span class="special">(</span><span class="identifier">delta_abs</span> <span class="special"><</span> <span class="identifier">tol</span><span class="special">))</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">break</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="identifier">n</span> <span class="special">*=</span> <span class="number">2U</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="keyword">return</span> <span class="identifier">I</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
The following sample program shows how the function can be called, we
|
||||
begin by defining a function object, which when integrated should yield
|
||||
the Bessel J function:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">value_type</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">cyl_bessel_j_integral_rep</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">public</span><span class="special">:</span>
|
||||
<span class="identifier">cyl_bessel_j_integral_rep</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="identifier">N</span><span class="special">,</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span><span class="special">&</span> <span class="identifier">X</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">n</span><span class="special">(</span><span class="identifier">N</span><span class="special">),</span> <span class="identifier">x</span><span class="special">(</span><span class="identifier">X</span><span class="special">)</span> <span class="special">{</span> <span class="special">}</span>
|
||||
|
||||
<span class="identifier">value_type</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="identifier">value_type</span><span class="special">&</span> <span class="identifier">t</span><span class="special">)</span> <span class="keyword">const</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// pi * Jn(x) = Int_0^pi [cos(x * sin(t) - n*t) dt]</span>
|
||||
<span class="keyword">return</span> <span class="identifier">cos</span><span class="special">(</span><span class="identifier">x</span> <span class="special">*</span> <span class="identifier">sin</span><span class="special">(</span><span class="identifier">t</span><span class="special">)</span> <span class="special">-</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">*</span> <span class="identifier">t</span><span class="special">));</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="keyword">private</span><span class="special">:</span>
|
||||
<span class="keyword">const</span> <span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">x</span><span class="special">;</span>
|
||||
<span class="special">};</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"> <span class="comment">/* The function can now be called as follows: */</span>
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">**)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float_50</span> <span class="identifier">mp_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="keyword">float</span> <span class="identifier">j2_f</span> <span class="special">=</span>
|
||||
<span class="identifier">integral</span><span class="special">(</span><span class="number">0.0F</span><span class="special">,</span>
|
||||
<span class="identifier">pi</span><span class="special"><</span><span class="keyword">float</span><span class="special">>(),</span>
|
||||
<span class="number">0.01F</span><span class="special">,</span>
|
||||
<span class="identifier">cyl_bessel_j_integral_rep</span><span class="special"><</span><span class="keyword">float</span><span class="special">>(</span><span class="number">2U</span><span class="special">,</span> <span class="number">1.23F</span><span class="special">))</span> <span class="special">/</span> <span class="identifier">pi</span><span class="special"><</span><span class="keyword">float</span><span class="special">>();</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="keyword">double</span> <span class="identifier">j2_d</span> <span class="special">=</span>
|
||||
<span class="identifier">integral</span><span class="special">(</span><span class="number">0.0</span><span class="special">,</span>
|
||||
<span class="identifier">pi</span><span class="special"><</span><span class="keyword">double</span><span class="special">>(),</span>
|
||||
<span class="number">0.0001</span><span class="special">,</span>
|
||||
<span class="identifier">cyl_bessel_j_integral_rep</span><span class="special"><</span><span class="keyword">double</span><span class="special">>(</span><span class="number">2U</span><span class="special">,</span> <span class="number">1.23</span><span class="special">))</span> <span class="special">/</span> <span class="identifier">pi</span><span class="special"><</span><span class="keyword">double</span><span class="special">>();</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">mp_type</span> <span class="identifier">j2_mp</span> <span class="special">=</span>
|
||||
<span class="identifier">integral</span><span class="special">(</span><span class="identifier">mp_type</span><span class="special">(</span><span class="number">0</span><span class="special">),</span>
|
||||
<span class="identifier">pi</span><span class="special"><</span><span class="identifier">mp_type</span><span class="special">>(),</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="number">1.0E-20</span><span class="special">),</span>
|
||||
<span class="identifier">cyl_bessel_j_integral_rep</span><span class="special"><</span><span class="identifier">mp_type</span><span class="special">>(</span><span class="number">2U</span><span class="special">,</span> <span class="identifier">mp_type</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">/</span> <span class="number">100</span><span class="special">))</span> <span class="special">/</span> <span class="identifier">pi</span><span class="special"><</span><span class="identifier">mp_type</span><span class="special">>();</span>
|
||||
|
||||
<span class="comment">// 0.166369</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">float</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">j2_f</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// 0.166369383786814</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">double</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">j2_d</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// 0.16636938378681407351267852431513159437103348245333</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">mp_type</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">j2_mp</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Print true value for comparison:</span>
|
||||
<span class="comment">// 0.166369383786814073512678524315131594371033482453329</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">cyl_bessel_j</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="identifier">mp_type</span><span class="special">(</span><span class="number">123</span><span class="special">)</span> <span class="special">/</span> <span class="number">100</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="nd.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="poly_eg.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,222 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Defining a Lambda Function.</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../fp_eg.html" title="Examples">
|
||||
<link rel="prev" href="aos.html" title="Area of Circle">
|
||||
<link rel="next" href="nd.html" title="Calculating a Derivative">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="aos.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="nd.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_fp_eg_jel">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.fp_eg.jel"></a><a class="link" href="jel.html" title="Defining a Lambda Function.">Defining
|
||||
a Lambda Function.</a>
|
||||
</h5></div></div></div>
|
||||
<p>
|
||||
In this example we'll show several implementations of the <a href="http://mathworld.wolfram.com/LambdaFunction.html" target="_top">Jahnke
|
||||
and Emden Lambda function</a>, each implementation a little more
|
||||
sophisticated than the last.
|
||||
</p>
|
||||
<p>
|
||||
The Jahnke-Emden Lambda function is defined by the equation:
|
||||
</p>
|
||||
<div class="blockquote"><blockquote class="blockquote"><p>
|
||||
<span class="emphasis"><em>JahnkeEmden(v, z) = Γ(v+1) * J<sub>v</sub>(z) / (z / 2)<sup>v</sup></em></span>
|
||||
</p></blockquote></div>
|
||||
<p>
|
||||
If we were to implement this at double precision using Boost.Math's facilities
|
||||
for the Gamma and Bessel function calls it would look like this:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">JEL1</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">v</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">z</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">v</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">cyl_bessel_j</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span><span class="special">(</span><span class="identifier">z</span> <span class="special">/</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">v</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Calling this function as:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">scientific</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">double</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">JEL1</span><span class="special">(</span><span class="number">2.5</span><span class="special">,</span> <span class="number">0.5</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
Yields the output:
|
||||
</p>
|
||||
<pre class="programlisting">9.822663964796047e-001</pre>
|
||||
<p>
|
||||
Now let's implement the function again, but this time using the multiprecision
|
||||
type <code class="computeroutput"><span class="identifier">cpp_dec_float_50</span></code>
|
||||
as the argument type:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float_50</span>
|
||||
<span class="identifier">JEL2</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float_50</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float_50</span> <span class="identifier">z</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">v</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">cyl_bessel_j</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">pow</span><span class="special">(</span><span class="identifier">z</span> <span class="special">/</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">v</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
The implementation is almost the same as before, but with one key difference
|
||||
- we can no longer call <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span></code>,
|
||||
instead we must call the version inside the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span></code>
|
||||
namespace. In point of fact, we could have omitted the namespace prefix
|
||||
on the call to <code class="computeroutput"><span class="identifier">pow</span></code> since
|
||||
the right overload would have been found via <a href="http://en.wikipedia.org/wiki/Argument-dependent_name_lookup" target="_top">argument
|
||||
dependent lookup</a> in any case.
|
||||
</p>
|
||||
<p>
|
||||
Note also that the first argument to <code class="computeroutput"><span class="identifier">pow</span></code>
|
||||
along with the argument to <code class="computeroutput"><span class="identifier">tgamma</span></code>
|
||||
in the above code are actually expression templates. The <code class="computeroutput"><span class="identifier">pow</span></code> and <code class="computeroutput"><span class="identifier">tgamma</span></code>
|
||||
functions will handle these arguments just fine.
|
||||
</p>
|
||||
<p>
|
||||
Here's an example of how the function may be called:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">scientific</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">JEL2</span><span class="special">(</span><span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">2.5</span><span class="special">),</span> <span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">0.5</span><span class="special">))</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
Which outputs:
|
||||
</p>
|
||||
<pre class="programlisting">9.82266396479604757017335009796882833995903762577173e-01</pre>
|
||||
<p>
|
||||
Now that we've seen some non-template examples, lets repeat the code
|
||||
again, but this time as a template that can be called either with a builtin
|
||||
type (<code class="computeroutput"><span class="keyword">float</span></code>, <code class="computeroutput"><span class="keyword">double</span></code> etc), or with a multiprecision
|
||||
type:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Float</span><span class="special">></span>
|
||||
<span class="identifier">Float</span> <span class="identifier">JEL3</span><span class="special">(</span><span class="identifier">Float</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">Float</span> <span class="identifier">z</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span><span class="special">;</span>
|
||||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">v</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">cyl_bessel_j</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">pow</span><span class="special">(</span><span class="identifier">z</span> <span class="special">/</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">v</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Once again the code is almost the same as before, but the call to <code class="computeroutput"><span class="identifier">pow</span></code> has changed yet again. We need
|
||||
the call to resolve to either <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span></code>
|
||||
(when the argument is a builtin type), or to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">pow</span></code>
|
||||
(when the argument is a multiprecision type). We do that by making the
|
||||
call unqualified so that versions of <code class="computeroutput"><span class="identifier">pow</span></code>
|
||||
defined in the same namespace as type <code class="computeroutput"><span class="identifier">Float</span></code>
|
||||
are found via argument dependent lookup, while the <code class="computeroutput"><span class="keyword">using</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span></code> directive makes the standard library
|
||||
versions visible for builtin floating point types.
|
||||
</p>
|
||||
<p>
|
||||
Let's call the function with both <code class="computeroutput"><span class="keyword">double</span></code>
|
||||
and multiprecision arguments:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">scientific</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">double</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">JEL3</span><span class="special">(</span><span class="number">2.5</span><span class="special">,</span> <span class="number">0.5</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">scientific</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">JEL3</span><span class="special">(</span><span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">2.5</span><span class="special">),</span> <span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">0.5</span><span class="special">))</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
Which outputs:
|
||||
</p>
|
||||
<pre class="programlisting">9.822663964796047e-001
|
||||
9.82266396479604757017335009796882833995903762577173e-01
|
||||
</pre>
|
||||
<p>
|
||||
Unfortunately there is a problem with this version: if we were to call
|
||||
it like this:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float_50</span> <span class="identifier">v</span><span class="special">(</span><span class="number">2</span><span class="special">),</span> <span class="identifier">z</span><span class="special">(</span><span class="number">0.5</span><span class="special">);</span>
|
||||
<span class="identifier">JEL3</span><span class="special">(</span><span class="identifier">v</span> <span class="special">+</span> <span class="number">0.5</span><span class="special">,</span> <span class="identifier">z</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
Then we would get a long and inscrutable error message from the compiler:
|
||||
the problem here is that the first argument to <code class="computeroutput"><span class="identifier">JEL3</span></code>
|
||||
is not a number type, but an expression template. We could obviously
|
||||
add a typecast to fix the issue:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">JEL</span><span class="special">(</span><span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="identifier">v</span> <span class="special">+</span> <span class="number">0.5</span><span class="special">),</span> <span class="identifier">z</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
However, if we want the function JEL to be truely reusable, then a better
|
||||
solution might be preferred. To achieve this we can borrow some code
|
||||
from Boost.Math which calculates the return type of mixed-argument functions,
|
||||
here's how the new code looks now:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Float1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Float2</span><span class="special">></span>
|
||||
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">promote_args</span><span class="special"><</span><span class="identifier">Float1</span><span class="special">,</span> <span class="identifier">Float2</span><span class="special">>::</span><span class="identifier">type</span>
|
||||
<span class="identifier">JEL4</span><span class="special">(</span><span class="identifier">Float1</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">Float2</span> <span class="identifier">z</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span><span class="special">;</span>
|
||||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">v</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">cyl_bessel_j</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">pow</span><span class="special">(</span><span class="identifier">z</span> <span class="special">/</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">v</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
As you can see the two arguments to the function are now separate template
|
||||
types, and the return type is computed using the <code class="computeroutput"><span class="identifier">promote_args</span></code>
|
||||
metafunction from Boost.Math.
|
||||
</p>
|
||||
<p>
|
||||
Now we can call:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">scientific</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_100</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">JEL4</span><span class="special">(</span><span class="identifier">cpp_dec_float_100</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special">+</span> <span class="number">0.5</span><span class="special">,</span> <span class="identifier">cpp_dec_float_100</span><span class="special">(</span><span class="number">0.5</span><span class="special">))</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
And get 100 digits of output:
|
||||
</p>
|
||||
<pre class="programlisting">9.8226639647960475701733500979688283399590376257717309069410413822165082248153638454147004236848917775e-01</pre>
|
||||
<p>
|
||||
As a bonus, we can now call the function not just with expression templates,
|
||||
but with other mixed types as well: for example <code class="computeroutput"><span class="keyword">float</span></code>
|
||||
and <code class="computeroutput"><span class="keyword">double</span></code> or <code class="computeroutput"><span class="keyword">int</span></code> and <code class="computeroutput"><span class="keyword">double</span></code>,
|
||||
and the correct return type will be computed in each case.
|
||||
</p>
|
||||
<p>
|
||||
Note that while in this case we didn't have to change the body of the
|
||||
function, in the general case any function like this which creates local
|
||||
variables internally would have to use <code class="computeroutput"><span class="identifier">promote_args</span></code>
|
||||
to work out what type those variables should be, for example:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Float1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Float2</span><span class="special">></span>
|
||||
<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">promote_args</span><span class="special"><</span><span class="identifier">Float1</span><span class="special">,</span> <span class="identifier">Float2</span><span class="special">>::</span><span class="identifier">type</span>
|
||||
<span class="identifier">JEL5</span><span class="special">(</span><span class="identifier">Float1</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">Float2</span> <span class="identifier">z</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">pow</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tools</span><span class="special">::</span><span class="identifier">promote_args</span><span class="special"><</span><span class="identifier">Float1</span><span class="special">,</span> <span class="identifier">Float2</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">variable_type</span><span class="special">;</span>
|
||||
<span class="identifier">variable_type</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">pow</span><span class="special">(</span><span class="identifier">z</span> <span class="special">/</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">v</span><span class="special">);</span>
|
||||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">v</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">cyl_bessel_j</span><span class="special">(</span><span class="identifier">v</span><span class="special">,</span> <span class="identifier">z</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">t</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="aos.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="nd.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,202 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Calculating a Derivative</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../fp_eg.html" title="Examples">
|
||||
<link rel="prev" href="jel.html" title="Defining a Lambda Function.">
|
||||
<link rel="next" href="gi.html" title="Calculating an Integral">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="jel.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="gi.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_fp_eg_nd">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.fp_eg.nd"></a><a class="link" href="nd.html" title="Calculating a Derivative">Calculating
|
||||
a Derivative</a>
|
||||
</h5></div></div></div>
|
||||
<p>
|
||||
In this example we'll add even more power to generic numeric programming
|
||||
using not only different floating-point types but also function objects
|
||||
as template parameters. Consider some well-known central difference rules
|
||||
for numerically computing the first derivative of a function <span class="emphasis"><em>f′(x)</em></span>
|
||||
with <span class="emphasis"><em>x ∈ ℜ</em></span>:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../../../floating_point_eg1.png"></span>
|
||||
</p>
|
||||
<p>
|
||||
Where the difference terms <span class="emphasis"><em>m<sub>n</sub></em></span> are given by:
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../../../floating_point_eg2.png"></span>
|
||||
</p>
|
||||
<p>
|
||||
and <span class="emphasis"><em>dx</em></span> is the step-size of the derivative.
|
||||
</p>
|
||||
<p>
|
||||
The third formula in Equation 1 is a three-point central difference rule.
|
||||
It calculates the first derivative of <span class="emphasis"><em>f′(x)</em></span> to <span class="emphasis"><em>O(dx<sup>6</sup>)</em></span>,
|
||||
where <span class="emphasis"><em>dx</em></span> is the given step-size. For example, if
|
||||
the step-size is 0.01 this derivative calculation has about 6 decimal
|
||||
digits of precision - just about right for the 7 decimal digits of single-precision
|
||||
float. Let's make a generic template subroutine using this three-point
|
||||
central difference rule. In particular:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">value_type</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">function_type</span><span class="special">></span>
|
||||
<span class="identifier">value_type</span> <span class="identifier">derivative</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">dx</span><span class="special">,</span> <span class="identifier">function_type</span> <span class="identifier">func</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// Compute d/dx[func(*first)] using a three-point</span>
|
||||
<span class="comment">// central difference rule of O(dx^6).</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">dx1</span> <span class="special">=</span> <span class="identifier">dx</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">dx2</span> <span class="special">=</span> <span class="identifier">dx1</span> <span class="special">*</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">dx3</span> <span class="special">=</span> <span class="identifier">dx1</span> <span class="special">*</span> <span class="number">3</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">m1</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">func</span><span class="special">(</span><span class="identifier">x</span> <span class="special">+</span> <span class="identifier">dx1</span><span class="special">)</span> <span class="special">-</span> <span class="identifier">func</span><span class="special">(</span><span class="identifier">x</span> <span class="special">-</span> <span class="identifier">dx1</span><span class="special">))</span> <span class="special">/</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">m2</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">func</span><span class="special">(</span><span class="identifier">x</span> <span class="special">+</span> <span class="identifier">dx2</span><span class="special">)</span> <span class="special">-</span> <span class="identifier">func</span><span class="special">(</span><span class="identifier">x</span> <span class="special">-</span> <span class="identifier">dx2</span><span class="special">))</span> <span class="special">/</span> <span class="number">4</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">m3</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">func</span><span class="special">(</span><span class="identifier">x</span> <span class="special">+</span> <span class="identifier">dx3</span><span class="special">)</span> <span class="special">-</span> <span class="identifier">func</span><span class="special">(</span><span class="identifier">x</span> <span class="special">-</span> <span class="identifier">dx3</span><span class="special">))</span> <span class="special">/</span> <span class="number">6</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">fifteen_m1</span> <span class="special">=</span> <span class="number">15</span> <span class="special">*</span> <span class="identifier">m1</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">six_m2</span> <span class="special">=</span> <span class="number">6</span> <span class="special">*</span> <span class="identifier">m2</span><span class="special">;</span>
|
||||
<span class="keyword">const</span> <span class="identifier">value_type</span> <span class="identifier">ten_dx1</span> <span class="special">=</span> <span class="number">10</span> <span class="special">*</span> <span class="identifier">dx1</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">return</span> <span class="special">((</span><span class="identifier">fifteen_m1</span> <span class="special">-</span> <span class="identifier">six_m2</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">m3</span><span class="special">)</span> <span class="special">/</span> <span class="identifier">ten_dx1</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">derivative</span><span class="special">()</span></code>
|
||||
template function can be used to compute the first derivative of any
|
||||
function to <span class="emphasis"><em>O(dx<sup>6</sup>)</em></span>. For example, consider the first
|
||||
derivative of <span class="emphasis"><em>sin(x)</em></span> evaluated at <span class="emphasis"><em>x =
|
||||
π/3</em></span>. In other words,
|
||||
</p>
|
||||
<p>
|
||||
<span class="inlinemediaobject"><img src="../../../../../floating_point_eg3.png"></span>
|
||||
</p>
|
||||
<p>
|
||||
The code below computes the derivative in Equation 3 for float, double
|
||||
and boost's multiple-precision type cpp_dec_float_50.
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iomanip</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">cpp_dec_float</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">constants</span><span class="special">/</span><span class="identifier">constants</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">char</span><span class="special">**)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float_50</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// We'll pass a function pointer for the function object passed to derivative,</span>
|
||||
<span class="comment">// the typecast is needed to select the correct overload of std::sin:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">const</span> <span class="keyword">float</span> <span class="identifier">d_f</span> <span class="special">=</span> <span class="identifier">derivative</span><span class="special">(</span>
|
||||
<span class="identifier">pi</span><span class="special"><</span><span class="keyword">float</span><span class="special">>()</span> <span class="special">/</span> <span class="number">3</span><span class="special">,</span>
|
||||
<span class="number">0.01F</span><span class="special">,</span>
|
||||
<span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">float</span><span class="special">(*)(</span><span class="keyword">float</span><span class="special">)>(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">sin</span><span class="special">)</span>
|
||||
<span class="special">);</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="keyword">double</span> <span class="identifier">d_d</span> <span class="special">=</span> <span class="identifier">derivative</span><span class="special">(</span>
|
||||
<span class="identifier">pi</span><span class="special"><</span><span class="keyword">double</span><span class="special">>()</span> <span class="special">/</span> <span class="number">3</span><span class="special">,</span>
|
||||
<span class="number">0.001</span><span class="special">,</span>
|
||||
<span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">double</span><span class="special">(*)(</span><span class="keyword">double</span><span class="special">)>(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">sin</span><span class="special">)</span>
|
||||
<span class="special">);</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// In the cpp_dec_float_50 case, the sin function is multiply overloaded</span>
|
||||
<span class="comment">// to handle expression templates etc. As a result it's hard to take its</span>
|
||||
<span class="comment">// address without knowing about its implementation details. We'll use a </span>
|
||||
<span class="comment">// C++11 lambda expression to capture the call.</span>
|
||||
<span class="comment">// We also need a typecast on the first argument so we don't accidently pass</span>
|
||||
<span class="comment">// an expression template to a template function:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">const</span> <span class="identifier">cpp_dec_float_50</span> <span class="identifier">d_mp</span> <span class="special">=</span> <span class="identifier">derivative</span><span class="special">(</span>
|
||||
<span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="identifier">pi</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>()</span> <span class="special">/</span> <span class="number">3</span><span class="special">),</span>
|
||||
<span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">1.0E-9</span><span class="special">),</span>
|
||||
<span class="special">[](</span><span class="keyword">const</span> <span class="identifier">cpp_dec_float_50</span><span class="special">&</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">-></span> <span class="identifier">cpp_dec_float_50</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">return</span> <span class="identifier">sin</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
<span class="special">);</span>
|
||||
|
||||
<span class="comment">// 5.000029e-001</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">float</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">d_f</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// 4.999999999998876e-001</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="keyword">double</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">d_d</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// 4.99999999999999999999999999999999999999999999999999e-01</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">d_mp</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
The expected value of the derivative is 0.5. This central difference
|
||||
rule in this example is ill-conditioned, meaning it suffers from slight
|
||||
loss of precision. With that in mind, the results agree with the expected
|
||||
value of 0.5.
|
||||
</p>
|
||||
<p>
|
||||
We can take this a step further and use our derivative function to compute
|
||||
a partial derivative. For example if we take the incomplete gamma function
|
||||
<span class="emphasis"><em>P(a, z)</em></span>, and take the derivative with respect to
|
||||
<span class="emphasis"><em>z</em></span> at <span class="emphasis"><em>(2,2)</em></span> then we can calculate
|
||||
the result as shown below, for good measure we'll compare with the "correct"
|
||||
result obtained from a call to <span class="emphasis"><em>gamma_p_derivative</em></span>,
|
||||
the results agree to approximately 44 digits:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">cpp_dec_float_50</span> <span class="identifier">gd</span> <span class="special">=</span> <span class="identifier">derivative</span><span class="special">(</span>
|
||||
<span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">2</span><span class="special">),</span>
|
||||
<span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">1.0E-9</span><span class="special">),</span>
|
||||
<span class="special">[](</span><span class="keyword">const</span> <span class="identifier">cpp_dec_float_50</span><span class="special">&</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">-></span><span class="identifier">cpp_dec_float_50</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">return</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gamma_p</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="identifier">x</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
<span class="special">);</span>
|
||||
<span class="comment">// 2.70670566473225383787998989944968806815263091819151e-01</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">cpp_dec_float_50</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span>
|
||||
<span class="special"><<</span> <span class="identifier">gd</span>
|
||||
<span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// 2.70670566473225383787998989944968806815253190143120e-01</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">gamma_p_derivative</span><span class="special">(</span><span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">2</span><span class="special">),</span> <span class="identifier">cpp_dec_float_50</span><span class="special">(</span><span class="number">2</span><span class="special">))</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="jel.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="gi.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,147 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Polynomial Evaluation</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../fp_eg.html" title="Examples">
|
||||
<link rel="prev" href="gi.html" title="Calculating an Integral">
|
||||
<link rel="next" href="../../rational.html" title="Rational Number Types">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gi.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../rational.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_fp_eg_poly_eg">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.fp_eg.poly_eg"></a><a class="link" href="poly_eg.html" title="Polynomial Evaluation">Polynomial
|
||||
Evaluation</a>
|
||||
</h5></div></div></div>
|
||||
<p>
|
||||
In this example we'll look at polynomial evaluation, this is not only
|
||||
an important use case, but it's one that <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
performs particularly well at because the expression templates <span class="emphasis"><em>completely
|
||||
eliminate all temporaries</em></span> from a <a href="http://en.wikipedia.org/wiki/Horner%27s_method" target="_top">Horner
|
||||
polynomial evaluation scheme</a>.
|
||||
</p>
|
||||
<p>
|
||||
The following code evaluates <code class="computeroutput"><span class="identifier">sin</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span></code> as a polynomial, accurate to at least
|
||||
64 decimal places:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_dec_float</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_dec_float</span><span class="special"><</span><span class="number">64</span><span class="special">></span> <span class="special">></span> <span class="identifier">mp_type</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">mp_type</span> <span class="identifier">mysin</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mp_type</span><span class="special">&</span> <span class="identifier">x</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// Approximation of sin(x * pi/2) for -1 <= x <= 1, using an order 63 polynomial.</span>
|
||||
<span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">array</span><span class="special"><</span><span class="identifier">mp_type</span><span class="special">,</span> <span class="number">32U</span><span class="special">></span> <span class="identifier">coefs</span> <span class="special">=</span>
|
||||
<span class="special">{{</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126711"</span><span class="special">),</span> <span class="comment">//"),</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-0.64596409750624625365575656389794573337969351178927307696134454382929989411386887578263960484"</span><span class="special">),</span> <span class="comment">// ^3</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+0.07969262624616704512050554949047802252091164235106119545663865720995702920146198554317279"</span><span class="special">),</span> <span class="comment">// ^5</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-0.0046817541353186881006854639339534378594950280185010575749538605102665157913157426229824"</span><span class="special">),</span> <span class="comment">// ^7</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+0.00016044118478735982187266087016347332970280754062061156858775174056686380286868007443"</span><span class="special">),</span> <span class="comment">// ^9</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-3.598843235212085340458540018208389404888495232432127661083907575106196374913134E-6"</span><span class="special">),</span> <span class="comment">// ^11</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+5.692172921967926811775255303592184372902829756054598109818158853197797542565E-8"</span><span class="special">),</span> <span class="comment">// ^13</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-6.688035109811467232478226335783138689956270985704278659373558497256423498E-10"</span><span class="special">),</span> <span class="comment">// ^15</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+6.066935731106195667101445665327140070166203261129845646380005577490472E-12"</span><span class="special">),</span> <span class="comment">// ^17</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-4.377065467313742277184271313776319094862897030084226361576452003432E-14"</span><span class="special">),</span> <span class="comment">// ^19</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+2.571422892860473866153865950420487369167895373255729246889168337E-16"</span><span class="special">),</span> <span class="comment">// ^21</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-1.253899540535457665340073300390626396596970180355253776711660E-18"</span><span class="special">),</span> <span class="comment">// ^23</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+5.15645517658028233395375998562329055050964428219501277474E-21"</span><span class="special">),</span> <span class="comment">// ^25</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-1.812399312848887477410034071087545686586497030654642705E-23"</span><span class="special">),</span> <span class="comment">// ^27</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+5.50728578652238583570585513920522536675023562254864E-26"</span><span class="special">),</span> <span class="comment">// ^29</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-1.461148710664467988723468673933026649943084902958E-28"</span><span class="special">),</span> <span class="comment">// ^31</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+3.41405297003316172502972039913417222912445427E-31"</span><span class="special">),</span> <span class="comment">// ^33</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-7.07885550810745570069916712806856538290251E-34"</span><span class="special">),</span> <span class="comment">// ^35</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+1.31128947968267628970845439024155655665E-36"</span><span class="special">),</span> <span class="comment">// ^37</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-2.18318293181145698535113946654065918E-39"</span><span class="special">),</span> <span class="comment">// ^39</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+3.28462680978498856345937578502923E-42"</span><span class="special">),</span> <span class="comment">// ^41</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-4.48753699028101089490067137298E-45"</span><span class="special">),</span> <span class="comment">// ^43</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+5.59219884208696457859353716E-48"</span><span class="special">),</span> <span class="comment">// ^45</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-6.38214503973500471720565E-51"</span><span class="special">),</span> <span class="comment">// ^47</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+6.69528558381794452556E-54"</span><span class="special">),</span> <span class="comment">// ^49</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-6.47841373182350206E-57"</span><span class="special">),</span> <span class="comment">// ^51</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+5.800016389666445E-60"</span><span class="special">),</span> <span class="comment">// ^53</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-4.818507347289E-63"</span><span class="special">),</span> <span class="comment">// ^55</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+3.724683686E-66"</span><span class="special">),</span> <span class="comment">// ^57</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-2.6856479E-69"</span><span class="special">),</span> <span class="comment">// ^59</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"+1.81046E-72"</span><span class="special">),</span> <span class="comment">// ^61</span>
|
||||
<span class="identifier">mp_type</span><span class="special">(</span><span class="string">"-1.133E-75"</span><span class="special">),</span> <span class="comment">// ^63</span>
|
||||
<span class="special">}};</span>
|
||||
|
||||
<span class="keyword">const</span> <span class="identifier">mp_type</span> <span class="identifier">v</span> <span class="special">=</span> <span class="identifier">x</span> <span class="special">*</span> <span class="number">2</span> <span class="special">/</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special"><</span><span class="identifier">mp_type</span><span class="special">>();</span>
|
||||
<span class="keyword">const</span> <span class="identifier">mp_type</span> <span class="identifier">x2</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">v</span> <span class="special">*</span> <span class="identifier">v</span><span class="special">);</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Polynomial evaluation follows, if mp_type allocates memory then</span>
|
||||
<span class="comment">// just one such allocation occurs - to initialize the variable "sum" -</span>
|
||||
<span class="comment">// and no temporaries are created at all.</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">const</span> <span class="identifier">mp_type</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="special">(((((((((((((((((((((((((((((((</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">31U</span><span class="special">]</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">30U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">29U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">28U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">27U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">26U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">25U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">24U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">23U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">22U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">21U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">20U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">19U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">18U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">17U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">16U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">15U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">14U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">13U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">12U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">11U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">10U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">9U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">8U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">7U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">6U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">5U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">4U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">3U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">2U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">1U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">x2</span> <span class="special">+</span> <span class="identifier">coefs</span><span class="special">[</span><span class="number">0U</span><span class="special">])</span>
|
||||
<span class="special">*</span> <span class="identifier">v</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">return</span> <span class="identifier">sum</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Calling the function like so:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">mp_type</span> <span class="identifier">pid4</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">constants</span><span class="special">::</span><span class="identifier">pi</span><span class="special"><</span><span class="identifier">mp_type</span><span class="special">>()</span> <span class="special">/</span> <span class="number">4</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span> <span class="special">::</span><span class="identifier">mp_type</span><span class="special">>::</span><span class="identifier">digits10</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">scientific</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">mysin</span><span class="special">(</span><span class="identifier">pid4</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
Yields the expected output:
|
||||
</p>
|
||||
<pre class="programlisting">7.0710678118654752440084436210484903928483593768847403658833986900e-01</pre>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gi.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../fp_eg.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../rational.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,183 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>gmp_float</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../floats.html" title="Floating Point Numbers">
|
||||
<link rel="prev" href="cpp_dec_float.html" title="cpp_dec_float">
|
||||
<link rel="next" href="mpfr_float.html" title="mpfr_float">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_dec_float.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="mpfr_float.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_gmp_float">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.gmp_float"></a><a class="link" href="gmp_float.html" title="gmp_float">gmp_float</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">gmp_float</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_50</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_100</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">500</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_500</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">1000</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float_1000</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpf_float</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">gmp_float</span></code> back-end
|
||||
is used in conjunction with <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
: it acts as a thin wrapper around the <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
<code class="computeroutput"><span class="identifier">mpf_t</span></code> to provide an real-number
|
||||
type that is a drop-in replacement for the native C++ floating-point types,
|
||||
but with much greater precision.
|
||||
</p>
|
||||
<p>
|
||||
Type <code class="computeroutput"><span class="identifier">gmp_float</span></code> can be used
|
||||
at fixed precision by specifying a non-zero <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
||||
template parameter, or at variable precision by setting the template argument
|
||||
to zero. The typedefs mpf_float_50, mpf_float_100, mpf_float_500, mpf_float_1000
|
||||
provide arithmetic types at 50, 100, 500 and 1000 decimal digits precision
|
||||
respectively. The typedef mpf_float provides a variable precision type
|
||||
whose precision can be controlled via the <code class="computeroutput"><span class="identifier">number</span></code>s
|
||||
member functions.
|
||||
</p>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
This type only provides standard library and <code class="computeroutput"><span class="identifier">numeric_limits</span></code>
|
||||
support when the precision is fixed at compile time.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<p>
|
||||
As well as the usual conversions from arithmetic and string types, instances
|
||||
of <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpf_float</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">></span></code> are copy constructible and assignable
|
||||
from:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
The <a href="http://gmplib.org" target="_top">GMP</a> native types <code class="computeroutput"><span class="identifier">mpf_t</span></code>, <code class="computeroutput"><span class="identifier">mpz_t</span></code>,
|
||||
<code class="computeroutput"><span class="identifier">mpq_t</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The <code class="computeroutput"><span class="identifier">number</span></code> wrappers
|
||||
around those types: <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpf_float</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>,
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_int</span><span class="special">></span></code>,
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_rational</span><span class="special">></span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpf_t</span></code>
|
||||
via the <code class="computeroutput"><span class="identifier">data</span><span class="special">()</span></code>
|
||||
member function of <code class="computeroutput"><span class="identifier">gmp_float</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Default constructed <code class="computeroutput"><span class="identifier">gmp_float</span></code>s
|
||||
have the value zero (this is the <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
library's default behavior).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
No changes are made to the <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
library's global settings, so this type can be safely mixed with existing
|
||||
<a href="http://gmplib.org" target="_top">GMP</a> code.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
This backend supports rvalue-references and is move-aware, making instantiations
|
||||
of <code class="computeroutput"><span class="identifier">number</span></code> on this backend
|
||||
move aware.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
It is not possible to round-trip objects of this type to and from a
|
||||
string and get back exactly the same value. This appears to be a limitation
|
||||
of <a href="http://gmplib.org" target="_top">GMP</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Since the underlying <a href="http://gmplib.org" target="_top">GMP</a> types
|
||||
have no notion of infinities or NaN's, care should be taken to avoid
|
||||
numeric overflow or division by zero. That latter will result in a
|
||||
std::overflow_error being thrown, while generating excessively large
|
||||
exponents may result in instability of the underlying <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
library (in testing, converting a number with an excessively large
|
||||
or small exponent to a string caused <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
to segfault).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
This type can equally be used with <a href="http://mpir.org/" target="_top">MPIR</a>
|
||||
as the underlying implementation - indeed that is the recommended option
|
||||
on Win32.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid floating
|
||||
point number.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
|
||||
being thrown.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.floats.gmp_float.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.floats.gmp_float.__ulink_url__http___gmplib_org__gmp__ulink__example_"></a></span><a class="link" href="gmp_float.html#boost_multiprecision.tut.floats.gmp_float.__ulink_url__http___gmplib_org__gmp__ulink__example_">
|
||||
GMP example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Operations at variable precision and limited standard library support:</span>
|
||||
<span class="identifier">mpf_float</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">mpf_float</span><span class="special">::</span><span class="identifier">default_precision</span><span class="special">(</span><span class="number">1000</span><span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">mpf_float</span><span class="special">::</span><span class="identifier">default_precision</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// print root-2</span>
|
||||
|
||||
<span class="comment">// Operations at fixed precision and full standard library support:</span>
|
||||
<span class="identifier">mpf_float_100</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">mpf_float_100</span><span class="special">>::</span><span class="identifier">digits</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// We can use any C++ std lib function:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// print log(2)</span>
|
||||
<span class="comment">// We can also use any function from Boost.Math:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// These even work when the argument is an expression template:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">b</span> <span class="special">*</span> <span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Access the underlying representation:</span>
|
||||
<span class="identifier">mpf_t</span> <span class="identifier">f</span><span class="special">;</span>
|
||||
<span class="identifier">mpf_init</span><span class="special">(</span><span class="identifier">f</span><span class="special">);</span>
|
||||
<span class="identifier">mpf_set</span><span class="special">(</span><span class="identifier">f</span><span class="special">,</span> <span class="identifier">a</span><span class="special">.</span><span class="identifier">backend</span><span class="special">().</span><span class="identifier">data</span><span class="special">());</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_dec_float.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="mpfr_float.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,272 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>mpfr_float</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../floats.html" title="Floating Point Numbers">
|
||||
<link rel="prev" href="gmp_float.html" title="gmp_float">
|
||||
<link rel="next" href="fp_eg.html" title="Examples">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_float.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="fp_eg.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_floats_mpfr_float">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.floats.mpfr_float"></a><a class="link" href="mpfr_float.html" title="mpfr_float">mpfr_float</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">mpfr_float</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">mpfr_allocation_type</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">allocate_stack</span><span class="special">,</span>
|
||||
<span class="identifier">allocate_dynamic</span>
|
||||
<span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">Digits10</span><span class="special">,</span> <span class="identifier">mpfr_allocation_type</span> <span class="identifier">AllocateType</span> <span class="special">=</span> <span class="identifier">allocate_dynamic</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">mpfr_float_backend</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_50</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">100</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_100</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">500</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_500</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">1000</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float_1000</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">mpfr_float</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">,</span> <span class="identifier">allocate_stack</span><span class="special">></span> <span class="special">></span> <span class="identifier">static_mpfr_float_50</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">100</span><span class="special">,</span> <span class="identifier">allocate_stack</span><span class="special">></span> <span class="special">></span> <span class="identifier">static_mpfr_float_100</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>
|
||||
type is used in conjunction with <code class="computeroutput"><span class="identifier">number</span></code>:
|
||||
It acts as a thin wrapper around the <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
<code class="computeroutput"><span class="identifier">mpfr_t</span></code> to provide an real-number
|
||||
type that is a drop-in replacement for the native C++ floating-point types,
|
||||
but with much greater precision.
|
||||
</p>
|
||||
<p>
|
||||
Type <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>
|
||||
can be used at fixed precision by specifying a non-zero <code class="computeroutput"><span class="identifier">Digits10</span></code>
|
||||
template parameter, or at variable precision by setting the template argument
|
||||
to zero. The typedefs mpfr_float_50, mpfr_float_100, mpfr_float_500, mpfr_float_1000
|
||||
provide arithmetic types at 50, 100, 500 and 1000 decimal digits precision
|
||||
respectively. The typedef mpfr_float provides a variable precision type
|
||||
whose precision can be controlled via the <code class="computeroutput"><span class="identifier">number</span></code>s
|
||||
member functions.
|
||||
</p>
|
||||
<p>
|
||||
In addition the second template parameter lets you choose between dynamic
|
||||
allocation (the default, and uses MPFR's normal allocation routines), or
|
||||
stack allocation (where all the memory required for the underlying data
|
||||
types is stored within <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>).
|
||||
The latter option can result in significantly faster code, at the expense
|
||||
of growing the size of <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>.
|
||||
It can only be used at fixed precision, and should only be used for lower
|
||||
digit counts. Note that we can not guarentee that using <code class="computeroutput"><span class="identifier">allocate_stack</span></code>
|
||||
won't cause any calls to mpfr's allocation routines, as mpfr may call these
|
||||
inside it's own code. The following table gives an idea of the performance
|
||||
tradeoff's at 50 decimal digits precision<a href="#ftn.boost_multiprecision.tut.floats.mpfr_float.f0" class="footnote"><sup class="footnote"><a name="boost_multiprecision.tut.floats.mpfr_float.f0"></a>[2]</sup></a>:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Bessel function evaluation, relative times
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">,</span> <span class="identifier">allocate_static</span><span class="special">>,</span>
|
||||
<span class="identifier">et_on</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.0 (5.5s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">,</span> <span class="identifier">allocate_static</span><span class="special">>,</span>
|
||||
<span class="identifier">et_off</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.05 (5.8s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">,</span> <span class="identifier">allocate_dynamic</span><span class="special">>,</span>
|
||||
<span class="identifier">et_on</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.05 (5.8s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="number">50</span><span class="special">,</span> <span class="identifier">allocate_dynamic</span><span class="special">>,</span>
|
||||
<span class="identifier">et_off</span><span class="special">></span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
1.16 (6.4s)
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<div class="note"><table border="0" summary="Note">
|
||||
<tr>
|
||||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../images/note.png"></td>
|
||||
<th align="left">Note</th>
|
||||
</tr>
|
||||
<tr><td align="left" valign="top"><p>
|
||||
This type only provides <code class="computeroutput"><span class="identifier">numeric_limits</span></code>
|
||||
support when the precision is fixed at compile time.
|
||||
</p></td></tr>
|
||||
</table></div>
|
||||
<p>
|
||||
As well as the usual conversions from arithmetic and string types, instances
|
||||
of <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">></span></code> are copy constructible and assignable
|
||||
from:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
The <a href="http://gmplib.org" target="_top">GMP</a> native types <code class="computeroutput"><span class="identifier">mpf_t</span></code>, <code class="computeroutput"><span class="identifier">mpz_t</span></code>,
|
||||
<code class="computeroutput"><span class="identifier">mpq_t</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The <a href="http://www.mpfr.org" target="_top">MPFR</a> native type <code class="computeroutput"><span class="identifier">mpfr_t</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The <code class="computeroutput"><span class="identifier">number</span></code> wrappers
|
||||
around those types: <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpfr_float_backend</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>,
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">mpf_float</span><span class="special"><</span><span class="identifier">M</span><span class="special">></span> <span class="special">></span></code>, <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_int</span><span class="special">></span></code>, <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_rational</span><span class="special">></span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpf_t</span></code>
|
||||
via the data() member function of <code class="computeroutput"><span class="identifier">gmp_float</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
A default constructed <code class="computeroutput"><span class="identifier">mpfr_float_backend</span></code>
|
||||
is set to a NaN (this is the default <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
behavior).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
All operations use round to nearest.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
No changes are made to <a href="http://gmplib.org" target="_top">GMP</a> or
|
||||
<a href="http://www.mpfr.org" target="_top">MPFR</a> global settings, so this
|
||||
type can coexist with existing <a href="http://www.mpfr.org" target="_top">MPFR</a>
|
||||
or <a href="http://gmplib.org" target="_top">GMP</a> code.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The code can equally use <a href="http://mpir.org/" target="_top">MPIR</a>
|
||||
in place of <a href="http://gmplib.org" target="_top">GMP</a> - indeed that
|
||||
is the preferred option on Win32.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
This backend supports rvalue-references and is move-aware, making instantiations
|
||||
of <code class="computeroutput"><span class="identifier">number</span></code> on this backend
|
||||
move aware.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid floating
|
||||
point number.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in an infinity.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.floats.mpfr_float.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.floats.mpfr_float.__ulink_url__http___www_mpfr_org__mpfr__ulink__example_"></a></span><a class="link" href="mpfr_float.html#boost_multiprecision.tut.floats.mpfr_float.__ulink_url__http___www_mpfr_org__mpfr__ulink__example_">
|
||||
MPFR example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">mpfr</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Operations at variable precision and no numeric_limits support:</span>
|
||||
<span class="identifier">mpfr_float</span> <span class="identifier">a</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">mpfr_float</span><span class="special">::</span><span class="identifier">default_precision</span><span class="special">(</span><span class="number">1000</span><span class="special">);</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">mpfr_float</span><span class="special">::</span><span class="identifier">default_precision</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">sqrt</span><span class="special">(</span><span class="identifier">a</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// print root-2</span>
|
||||
|
||||
<span class="comment">// Operations at fixed precision and full numeric_limits support:</span>
|
||||
<span class="identifier">mpfr_float_100</span> <span class="identifier">b</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">mpfr_float_100</span><span class="special">>::</span><span class="identifier">digits</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// We can use any C++ std lib function:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">log</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// print log(2)</span>
|
||||
<span class="comment">// We can also use any function from Boost.Math:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">// These even work when the argument is an expression template:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">tgamma</span><span class="special">(</span><span class="identifier">b</span> <span class="special">*</span> <span class="identifier">b</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Access the underlying data:</span>
|
||||
<span class="identifier">mpfr_t</span> <span class="identifier">r</span><span class="special">;</span>
|
||||
<span class="identifier">mpfr_init</span><span class="special">(</span><span class="identifier">r</span><span class="special">);</span>
|
||||
<span class="identifier">mpfr_set</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">b</span><span class="special">.</span><span class="identifier">backend</span><span class="special">().</span><span class="identifier">data</span><span class="special">(),</span> <span class="identifier">GMP_RNDN</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<div class="footnotes">
|
||||
<br><hr style="width:100; align:left;">
|
||||
<div id="ftn.boost_multiprecision.tut.floats.mpfr_float.f0" class="footnote"><p><a href="#boost_multiprecision.tut.floats.mpfr_float.f0" class="para"><sup class="para">[2] </sup></a>
|
||||
Compiled with VC++10 and /Ox, with MPFR-3.0.0 and MPIR-2.3.0
|
||||
</p></div>
|
||||
</div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_float.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../floats.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="fp_eg.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,191 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Integer Types</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="../tut.html" title="Tutorial">
|
||||
<link rel="next" href="ints/cpp_int.html" title="cpp_int">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../tut.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="ints/cpp_int.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_ints">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.ints"></a><a class="link" href="ints.html" title="Integer Types">Integer Types</a>
|
||||
</h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="ints/cpp_int.html">cpp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="ints/gmp_int.html">gmp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="ints/tom_int.html">tom_int</a></span></dt>
|
||||
<dt><span class="section"><a href="ints/egs.html">Examples</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="ints/egs/factorials.html">Factorials</a></span></dt>
|
||||
<dt><span class="section"><a href="ints/egs/bitops.html">Bit Operations</a></span></dt>
|
||||
</dl></dd>
|
||||
</dl></div>
|
||||
<p>
|
||||
The following back-ends provide integer arithmetic:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Backend Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Header
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Radix
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Dependencies
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Pros
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Cons
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">cpp_int</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/cpp_int.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
None
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Very versatile, Boost licensed, all C++ integer type which support
|
||||
both <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_top">arbitrary
|
||||
precision</a> and fixed precision integer types.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Slower than <a href="http://gmplib.org" target="_top">GMP</a>, though
|
||||
typically not as slow as <a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">gmp_int</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/gmp.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://gmplib.org" target="_top">GMP</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Very fast and efficient back-end.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Dependency on GNU licensed <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
library.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">tom_int</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/tommath.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Public domain back-end with no licence restrictions.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Slower than <a href="http://gmplib.org" target="_top">GMP</a>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../tut.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="ints/cpp_int.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,366 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>cpp_int</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ints.html" title="Integer Types">
|
||||
<link rel="prev" href="../ints.html" title="Integer Types">
|
||||
<link rel="next" href="gmp_int.html" title="gmp_int">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../ints.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_int.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_ints_cpp_int">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.ints.cpp_int"></a><a class="link" href="cpp_int.html" title="cpp_int">cpp_int</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">unspecified</span><span class="special">-</span><span class="identifier">type</span> <span class="identifier">limb_type</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">enum</span> <span class="identifier">cpp_integer_type</span> <span class="special">{</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span> <span class="special">};</span>
|
||||
<span class="keyword">enum</span> <span class="identifier">cpp_int_check_type</span> <span class="special">{</span> <span class="identifier">checked</span><span class="special">,</span> <span class="identifier">unchecked</span> <span class="special">};</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">MinDigits</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span>
|
||||
<span class="keyword">unsigned</span> <span class="identifier">MaxDits</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span>
|
||||
<span class="identifier">cpp_integer_type</span> <span class="identifier">SignType</span> <span class="special">=</span> <span class="identifier">signed_magnitude</span><span class="special">,</span>
|
||||
<span class="identifier">cpp_int_check_type</span> <span class="identifier">Checked</span> <span class="special">=</span> <span class="identifier">unchecked</span><span class="special">,</span>
|
||||
<span class="keyword">class</span> <span class="identifier">Allocator</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span><span class="special"><</span><span class="identifier">limb_type</span><span class="special">></span> <span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">cpp_int_backend</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Expression templates default to et_off if there is no allocator:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">unsigned</span> <span class="identifier">MinDigits</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">MaxDigits</span><span class="special">,</span> <span class="identifier">cpp_integer_type</span> <span class="identifier">SignType</span><span class="special">,</span> <span class="identifier">cpp_int_check_type</span> <span class="identifier">Checked</span><span class="special">></span>
|
||||
<span class="keyword">struct</span> <span class="identifier">expression_template_default</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="identifier">MinDigits</span><span class="special">,</span> <span class="identifier">MaxDigits</span><span class="special">,</span> <span class="identifier">SignType</span><span class="special">,</span> <span class="identifier">Checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span>
|
||||
<span class="special">{</span> <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">expression_template_option</span> <span class="identifier">value</span> <span class="special">=</span> <span class="identifier">et_off</span><span class="special">;</span> <span class="special">};</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><></span> <span class="special">></span> <span class="identifier">cpp_int</span><span class="special">;</span> <span class="comment">// arbitrary precision integer</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">rational_adapter</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><></span> <span class="special">></span> <span class="identifier">cpp_rational_backend</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_rational_backend</span><span class="special">></span> <span class="identifier">cpp_rational</span><span class="special">;</span> <span class="comment">// arbitrary precision rational number</span>
|
||||
|
||||
<span class="comment">// Fixed precision unsigned types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">uint1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Fixed precision signed types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">unchecked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">int1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Over again, but with checking enabled this time:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_cpp_int</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">rational_adapter</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">0</span><span class="special">,</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_cpp_rational_backend</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_rational_backend</span><span class="special">></span> <span class="identifier">checked_cpp_rational</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Checked fixed precision unsigned types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">unsigned_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_uint1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Fixed precision signed types:</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">128</span><span class="special">,</span> <span class="number">128</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int128_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">256</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int256_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">512</span><span class="special">,</span> <span class="number">512</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int512_t</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><</span><span class="number">1024</span><span class="special">,</span> <span class="number">1024</span><span class="special">,</span> <span class="identifier">signed_magnitude</span><span class="special">,</span> <span class="identifier">checked</span><span class="special">,</span> <span class="keyword">void</span><span class="special">></span> <span class="special">></span> <span class="identifier">checked_int1024_t</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code> type
|
||||
is normally used via one of the convenience typedefs given above.
|
||||
</p>
|
||||
<p>
|
||||
This back-end is the "Swiss Army Knife" of integer types as it
|
||||
can represent both fixed and <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_top">arbitrary
|
||||
precision</a> integer types, and both signed and unsigned types. There
|
||||
are five template arguments:
|
||||
</p>
|
||||
<div class="variablelist">
|
||||
<p class="title"><b></b></p>
|
||||
<dl class="variablelist">
|
||||
<dt><span class="term">MinBits</span></dt>
|
||||
<dd><p>
|
||||
Determines the number of Bits to store directly within the object
|
||||
before resorting to dynamic memory allocation. When zero, this field
|
||||
is determined automatically based on how many bits can be stored
|
||||
in union with the dynamic storage header: setting a larger value
|
||||
may improve performance as larger integer values will be stored internally
|
||||
before memory allocation is required.
|
||||
</p></dd>
|
||||
<dt><span class="term">MaxBits</span></dt>
|
||||
<dd><p>
|
||||
Determines the maximum number of bits to be stored in the type: resulting
|
||||
in a fixed precision type. When this value is the same as MinBits,
|
||||
then the Allocator parameter is ignored, as no dynamic memory allocation
|
||||
will ever be performed: in this situation the Allocator parameter
|
||||
should be set to type <code class="computeroutput"><span class="keyword">void</span></code>.
|
||||
Note that this parameter should not be used simply to prevent large
|
||||
memory allocations, not only is that role better performed by the
|
||||
allocator, but fixed precision integers have a tendency to allocate
|
||||
all of MaxBits of storage more often than one would expect.
|
||||
</p></dd>
|
||||
<dt><span class="term">SignType</span></dt>
|
||||
<dd><p>
|
||||
Determines whether the resulting type is signed or not. Note that
|
||||
for <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_top">arbitrary
|
||||
precision</a> types this parameter must be <code class="computeroutput"><span class="identifier">signed_magnitude</span></code>.
|
||||
For fixed precision types then this type may be either <code class="computeroutput"><span class="identifier">signed_magnitude</span></code> or <code class="computeroutput"><span class="identifier">unsigned_magnitude</span></code>.
|
||||
</p></dd>
|
||||
<dt><span class="term">Checked</span></dt>
|
||||
<dd><p>
|
||||
This parameter has two values: <code class="computeroutput"><span class="identifier">checked</span></code>
|
||||
or <code class="computeroutput"><span class="identifier">unchecked</span></code>. See
|
||||
below.
|
||||
</p></dd>
|
||||
<dt><span class="term">Allocator</span></dt>
|
||||
<dd><p>
|
||||
The allocator to use for dynamic memory allocation, or type <code class="computeroutput"><span class="keyword">void</span></code> if MaxBits == MinBits.
|
||||
</p></dd>
|
||||
</dl>
|
||||
</div>
|
||||
<p>
|
||||
When the template parameter Checked is set to <code class="computeroutput"><span class="identifier">checked</span></code>
|
||||
then the result is a <span class="emphasis"><em>checked-integer</em></span>, checked and
|
||||
unchecked integers have the following properties:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Condition
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Checked-Integer
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Unchecked-Integer
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
Numeric overflow in fixed precision arithmetic
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Performs arithmetic modulo 2<sup>MaxBits</sup>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
Constructing an integer from a value that can not be represented
|
||||
in the target type
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Converts the value modulo 2<sup>MaxBits</sup>, signed to unsigned conversions
|
||||
extract the last MaxBits bits of the 2's complement representation
|
||||
of the input value.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
Unsigned subtraction yielding a negative value.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Yields the value that would result from treating the unsigned
|
||||
type as a 2's complement signed type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
Attempting a bitwise operation on a negative value.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Throws a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Yields the value, but not the bit pattern, that would result
|
||||
from performing the operation on a 2's complement integer type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Default constructed <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>s
|
||||
have the value zero.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
|
||||
being thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Construction from a string that contains invalid non-numeric characters
|
||||
results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code> being thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Since the precision of <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>
|
||||
is necessarily limited when the allocator parameter is void, care should
|
||||
be taken to avoid numeric overflow when using this type unless you
|
||||
actually want modulo-arithmetic behavior.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The type uses a sign-magnitude representation internally, so type
|
||||
<code class="computeroutput"><span class="identifier">int128_t</span></code> has 128-bits
|
||||
of precision plus an extra sign bit. In this respect the behaviour
|
||||
of these types differs from built-in 2's complement types. In might
|
||||
be tempting to use a 127-bit type instead, and indeed this does work,
|
||||
but behaviour is still slightly different from a 2's complement built-in
|
||||
type as the min and max values are identical (apart from the sign),
|
||||
where as they differ by one for a true 2's complement type. That said
|
||||
it should be noted that there's no requirement for built-in types to
|
||||
be 2's complement either - it's simply that this is the most common
|
||||
format by far.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Attempting to print negative values as either an Octal or Hexadecimal
|
||||
string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown, this is a direct consequence of the sign-magnitude representation.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The fixed precision types <code class="computeroutput"><span class="special">[</span><span class="identifier">checked_</span><span class="special">][</span><span class="identifier">u</span><span class="special">]</span><span class="identifier">intXXX_t</span></code> have expression template
|
||||
support turned off - it seems to make little difference to the performance
|
||||
of these types either way - so we may as well have the faster compile
|
||||
times by turning the feature off.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Unsigned types support subtraction - the result is "as if"
|
||||
a 2's complement operation had been performed as long as they are not
|
||||
<span class="emphasis"><em>checked-integers</em></span> (see above). In other words they
|
||||
behave pretty much as a built in integer type would in this situation.
|
||||
So for example if we were using <code class="computeroutput"><span class="identifier">uint128_t</span></code>
|
||||
then <code class="computeroutput"><span class="identifier">uint128_t</span><span class="special">(</span><span class="number">1</span><span class="special">)-</span><span class="number">4</span></code>
|
||||
would result in the value <code class="computeroutput"><span class="number">0</span><span class="identifier">xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFD</span></code>
|
||||
of type <code class="computeroutput"><span class="identifier">uint128_t</span></code>.
|
||||
However, had this operation been performed on <code class="computeroutput"><span class="identifier">checked_uint128_t</span></code>
|
||||
then a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">range_error</span></code> would have been thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Unary negation of unsigned types results in a compiler error (static
|
||||
assertion).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
This backend supports rvalue-references and is move-aware, making instantiations
|
||||
of <code class="computeroutput"><span class="identifier">number</span></code> on this backend
|
||||
move aware.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
When used at fixed precision, the size of this type is always one machine
|
||||
word larger than you would expect for an N-bit integer: the extra word
|
||||
stores both the sign, and how many machine words in the integer are
|
||||
actually in use. The latter is an optimisation for larger fixed precision
|
||||
integers, so that a 1024-bit integer has almost the same performance
|
||||
characterists as a 128-bit integer, rather than being 4 times slower
|
||||
for addition and 16 times slower for multiplication (assuming the values
|
||||
involved would always fit in 128 bits). Typically this means you can
|
||||
use an integer type wide enough for the "worst case senario"
|
||||
with only minor performance degradation even if most of the time the
|
||||
arithmetic could in fact be done with a narrower type.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
When used at fixed precision and MaxBits is smaller than the number
|
||||
of bits in the largest native integer type, then internally <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code> switches to a "trivial"
|
||||
implementation where it is just a thin wrapper around a single integer.
|
||||
Note that it will still be slightly slower than a bare native integer,
|
||||
as it emulates a signed-magnitude representation rather than simply
|
||||
using the platforms native sign representation: this ensures there
|
||||
is no step change in behavior as a cpp_int grows in size.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.ints.cpp_int.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.ints.cpp_int.example_"></a></span><a class="link" href="cpp_int.html#boost_multiprecision.tut.ints.cpp_int.example_">Example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">int128_t</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Do some fixed precision arithmetic:</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><=</span> <span class="number">20</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">v</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 20!</span>
|
||||
|
||||
<span class="comment">// Repeat at arbitrary precision:</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">u</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><=</span> <span class="number">100</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">u</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">u</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 100!</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../ints.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_int.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,38 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Examples</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ints.html" title="Integer Types">
|
||||
<link rel="prev" href="tom_int.html" title="tom_int">
|
||||
<link rel="next" href="egs/factorials.html" title="Factorials">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tom_int.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="egs/factorials.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_ints_egs">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.ints.egs"></a><a class="link" href="egs.html" title="Examples">Examples</a>
|
||||
</h4></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="egs/factorials.html">Factorials</a></span></dt>
|
||||
<dt><span class="section"><a href="egs/bitops.html">Bit Operations</a></span></dt>
|
||||
</dl></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tom_int.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="egs/factorials.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,94 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Bit Operations</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../egs.html" title="Examples">
|
||||
<link rel="prev" href="factorials.html" title="Factorials">
|
||||
<link rel="next" href="../../floats.html" title="Floating Point Numbers">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="factorials.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../egs.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../floats.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_ints_egs_bitops">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="boost_multiprecision.tut.ints.egs.bitops"></a><a class="link" href="bitops.html" title="Bit Operations">Bit Operations</a>
|
||||
</h5></div></div></div>
|
||||
<p>
|
||||
In this example we'll show how individual bits within an integer may
|
||||
be manipulated, we'll start with an often needed calculation of <span class="emphasis"><em>2<sup>n</sup> -
|
||||
1</em></span>, which we could obviously implement like this:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_int</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">b1</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">r</span><span class="special">(</span><span class="number">1</span><span class="special">);</span>
|
||||
<span class="keyword">return</span> <span class="special">(</span><span class="identifier">r</span> <span class="special"><<</span> <span class="identifier">n</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Calling:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">b1</span><span class="special">(</span><span class="number">200</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
Yields as expected:
|
||||
</p>
|
||||
<pre class="programlisting">0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF</pre>
|
||||
<p>
|
||||
However, we could equally just set the n'th bit in the result, like this:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">cpp_int</span> <span class="identifier">b2</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">n</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">r</span><span class="special">(</span><span class="number">0</span><span class="special">);</span>
|
||||
<span class="keyword">return</span> <span class="special">--</span><span class="identifier">bit_set</span><span class="special">(</span><span class="identifier">r</span><span class="special">,</span> <span class="identifier">n</span><span class="special">);</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Note how the <code class="computeroutput"><span class="identifier">bit_set</span></code>
|
||||
function sets the specified bit in its argument and then returns a reference
|
||||
to the result - which we can then simply decrement. The result from a
|
||||
call to <code class="computeroutput"><span class="identifier">b2</span></code> is the same
|
||||
as that to <code class="computeroutput"><span class="identifier">b1</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
We can equally test bits, so for example the n'th bit of the result returned
|
||||
from <code class="computeroutput"><span class="identifier">b2</span></code> shouldn't be
|
||||
set unless we increment it first:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">assert</span><span class="special">(!</span><span class="identifier">bit_test</span><span class="special">(</span><span class="identifier">b1</span><span class="special">(</span><span class="number">200</span><span class="special">),</span> <span class="number">200</span><span class="special">));</span> <span class="comment">// OK</span>
|
||||
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">bit_test</span><span class="special">(++</span><span class="identifier">b1</span><span class="special">(</span><span class="number">200</span><span class="special">),</span> <span class="number">200</span><span class="special">));</span> <span class="comment">// OK</span>
|
||||
</pre>
|
||||
<p>
|
||||
And of course if we flip the n'th bit after increment, then we should
|
||||
get back to zero:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">assert</span><span class="special">(!</span><span class="identifier">bit_flip</span><span class="special">(++</span><span class="identifier">b1</span><span class="special">(</span><span class="number">200</span><span class="special">),</span> <span class="number">200</span><span class="special">));</span> <span class="comment">// OK</span>
|
||||
</pre>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="factorials.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../egs.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="../../floats.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,145 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Factorials</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../egs.html" title="Examples">
|
||||
<link rel="prev" href="../egs.html" title="Examples">
|
||||
<link rel="next" href="bitops.html" title="Bit Operations">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../egs.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../egs.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="bitops.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_ints_egs_factorials">
|
||||
<div class="titlepage"><div><div><h5 class="title">
|
||||
<a name="boost_multiprecision.tut.ints.egs.factorials"></a><a class="link" href="factorials.html" title="Factorials">Factorials</a>
|
||||
</h5></div></div></div>
|
||||
<p>
|
||||
In this simple example, we'll write a routine to print out all of the
|
||||
factorials which will fit into a 128-bit integer. At the end of the routine
|
||||
we do some fancy iostream formatting of the results:
|
||||
</p>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iomanip</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">vector</span><span class="special">></span>
|
||||
|
||||
|
||||
<span class="keyword">void</span> <span class="identifier">print_factorials</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_int</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Print all the factorials that will fit inside a 128-bit integer.</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Begin by building a big table of factorials, once we know just how </span>
|
||||
<span class="comment">// large the largest is, we'll be able to "pretty format" the results.</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Calculate the largest number that will fit inside 128 bits, we could</span>
|
||||
<span class="comment">// also have used numeric_limits<int128_t>::max() for this value:</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">limit</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">cpp_int</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="number">128</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="comment">// </span>
|
||||
<span class="comment">// Our table of values:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special"><</span><span class="identifier">cpp_int</span><span class="special">></span> <span class="identifier">results</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Initial values:</span>
|
||||
<span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">factorial</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Cycle through the factorials till we reach the limit:</span>
|
||||
<span class="keyword">while</span><span class="special">(</span><span class="identifier">factorial</span> <span class="special"><</span> <span class="identifier">limit</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">factorial</span><span class="special">);</span>
|
||||
<span class="special">++</span><span class="identifier">i</span><span class="special">;</span>
|
||||
<span class="identifier">factorial</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Lets see how many digits the largest factorial was:</span>
|
||||
<span class="keyword">unsigned</span> <span class="identifier">digits</span> <span class="special">=</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">back</span><span class="special">().</span><span class="identifier">str</span><span class="special">().</span><span class="identifier">size</span><span class="special">();</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Now print them out, using right justification, while we're at it</span>
|
||||
<span class="comment">// we'll indicate the limit of each integer type, so begin by defining</span>
|
||||
<span class="comment">// the limits for 16, 32, 64 etc bit integers:</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">limits</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span>
|
||||
<span class="special">(</span><span class="identifier">cpp_int</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="number">16</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span>
|
||||
<span class="special">(</span><span class="identifier">cpp_int</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="number">32</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span>
|
||||
<span class="special">(</span><span class="identifier">cpp_int</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="number">64</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span>
|
||||
<span class="special">(</span><span class="identifier">cpp_int</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="number">128</span><span class="special">)</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span>
|
||||
<span class="special">};</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">bit_counts</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span> <span class="string">"16"</span><span class="special">,</span> <span class="string">"32"</span><span class="special">,</span> <span class="string">"64"</span><span class="special">,</span> <span class="string">"128"</span> <span class="special">};</span>
|
||||
<span class="keyword">unsigned</span> <span class="identifier">current_limit</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">j</span> <span class="special"><</span> <span class="identifier">results</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span> <span class="special">++</span><span class="identifier">j</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">if</span><span class="special">(</span><span class="identifier">limits</span><span class="special">[</span><span class="identifier">current_limit</span><span class="special">]</span> <span class="special"><</span> <span class="identifier">results</span><span class="special">[</span><span class="identifier">j</span><span class="special">])</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">message</span> <span class="special">=</span> <span class="string">"Limit of "</span> <span class="special">+</span> <span class="identifier">bit_counts</span><span class="special">[</span><span class="identifier">current_limit</span><span class="special">]</span> <span class="special">+</span> <span class="string">" bit integers"</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setfill</span><span class="special">(</span><span class="char">'.'</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setw</span><span class="special">(</span><span class="identifier">digits</span><span class="special">+</span><span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">right</span> <span class="special"><<</span> <span class="identifier">message</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setfill</span><span class="special">(</span><span class="char">' '</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="special">++</span><span class="identifier">current_limit</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setw</span><span class="special">(</span><span class="identifier">digits</span> <span class="special">+</span> <span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">right</span> <span class="special"><<</span> <span class="identifier">results</span><span class="special">[</span><span class="identifier">j</span><span class="special">]</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
The output from this routine is:
|
||||
</p>
|
||||
<a name="fix%20for%20quickbook%20bug"></a><pre class="programlisting">
|
||||
1
|
||||
2
|
||||
6
|
||||
24
|
||||
120
|
||||
720
|
||||
5040
|
||||
40320
|
||||
................Limit of 16 bit integers
|
||||
362880
|
||||
3628800
|
||||
39916800
|
||||
479001600
|
||||
................Limit of 32 bit integers
|
||||
6227020800
|
||||
87178291200
|
||||
1307674368000
|
||||
20922789888000
|
||||
355687428096000
|
||||
6402373705728000
|
||||
121645100408832000
|
||||
2432902008176640000
|
||||
................Limit of 64 bit integers
|
||||
51090942171709440000
|
||||
1124000727777607680000
|
||||
25852016738884976640000
|
||||
620448401733239439360000
|
||||
15511210043330985984000000
|
||||
403291461126605635584000000
|
||||
10888869450418352160768000000
|
||||
304888344611713860501504000000
|
||||
8841761993739701954543616000000
|
||||
265252859812191058636308480000000
|
||||
8222838654177922817725562880000000
|
||||
263130836933693530167218012160000000
|
||||
8683317618811886495518194401280000000
|
||||
295232799039604140847618609643520000000
|
||||
</pre>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../egs.html"><img src="../../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../egs.html"><img src="../../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../../index.html"><img src="../../../../images/home.png" alt="Home"></a><a accesskey="n" href="bitops.html"><img src="../../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,137 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>gmp_int</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ints.html" title="Integer Types">
|
||||
<link rel="prev" href="cpp_int.html" title="cpp_int">
|
||||
<link rel="next" href="tom_int.html" title="tom_int">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_int.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="tom_int.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_ints_gmp_int">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.ints.gmp_int"></a><a class="link" href="gmp_int.html" title="gmp_int">gmp_int</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">gmp_int</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_int</span> <span class="special">></span> <span class="identifier">mpz_int</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">gmp_int</span></code> back-end is
|
||||
used via the typedef <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">mpz_int</span></code>.
|
||||
It acts as a thin wrapper around the <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
<code class="computeroutput"><span class="identifier">mpz_t</span></code> to provide an integer
|
||||
type that is a drop-in replacement for the native C++ integer types, but
|
||||
with unlimited precision.
|
||||
</p>
|
||||
<p>
|
||||
As well as the usual conversions from arithmetic and string types, type
|
||||
<code class="computeroutput"><span class="identifier">mpz_int</span></code> is copy constructible
|
||||
and assignable from:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
The <a href="http://gmplib.org" target="_top">GMP</a> native types: <code class="computeroutput"><span class="identifier">mpf_t</span></code>, <code class="computeroutput"><span class="identifier">mpz_t</span></code>,
|
||||
<code class="computeroutput"><span class="identifier">mpq_t</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Instances of <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> that are wrappers around those
|
||||
types: <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_float</span><span class="special"><</span><span class="identifier">N</span><span class="special">></span> <span class="special">></span></code>, <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_rational</span><span class="special">></span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpz_t</span></code>
|
||||
via the <code class="computeroutput"><span class="identifier">data</span><span class="special">()</span></code>
|
||||
member function of <code class="computeroutput"><span class="identifier">gmp_int</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
No changes are made to the GMP library's global settings - so you can
|
||||
safely mix this type with existing code that uses <a href="http://gmplib.org" target="_top">GMP</a>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Default constructed <code class="computeroutput"><span class="identifier">gmp_int</span></code>s
|
||||
have the value zero (this is GMP's default behavior).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Formatted IO for this type does not support octal or hexadecimal notation
|
||||
for negative values, as a result performing formatted output on this
|
||||
type when the argument is negative and either of the flags <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">oct</span></code> or <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">hex</span></code>
|
||||
are set, will result in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
will be thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid integer.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
|
||||
being thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Although this type is a wrapper around <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
it will work equally well with <a href="http://mpir.org/" target="_top">MPIR</a>.
|
||||
Indeed use of <a href="http://mpir.org/" target="_top">MPIR</a> is recommended
|
||||
on Win32.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
This backend supports rvalue-references and is move-aware, making instantiations
|
||||
of <code class="computeroutput"><span class="identifier">number</span></code> on this backend
|
||||
move aware.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.ints.gmp_int.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.ints.gmp_int.example_"></a></span><a class="link" href="gmp_int.html#boost_multiprecision.tut.ints.gmp_int.example_">Example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">mpz_int</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Do some arithmetic:</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><=</span> <span class="number">1000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">v</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1000!</span>
|
||||
|
||||
<span class="comment">// Access the underlying representation:</span>
|
||||
<span class="identifier">mpz_t</span> <span class="identifier">z</span><span class="special">;</span>
|
||||
<span class="identifier">mpz_init</span><span class="special">(</span><span class="identifier">z</span><span class="special">);</span>
|
||||
<span class="identifier">mpz_set</span><span class="special">(</span><span class="identifier">z</span><span class="special">,</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">backend</span><span class="special">().</span><span class="identifier">data</span><span class="special">());</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_int.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="tom_int.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,123 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>tom_int</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../ints.html" title="Integer Types">
|
||||
<link rel="prev" href="gmp_int.html" title="gmp_int">
|
||||
<link rel="next" href="egs.html" title="Examples">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_int.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="egs.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_ints_tom_int">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.ints.tom_int"></a><a class="link" href="tom_int.html" title="tom_int">tom_int</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">tommath</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">tommath_int</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">tommath_int</span> <span class="special">></span> <span class="identifier">tom_int</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">tommath_int</span></code> back-end
|
||||
is used via the typedef <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">tom_int</span></code>.
|
||||
It acts as a thin wrapper around the <a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>
|
||||
<code class="computeroutput"><span class="identifier">tom_int</span></code> to provide an integer
|
||||
type that is a drop-in replacement for the native C++ integer types, but
|
||||
with unlimited precision.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Default constructed objects have the value zero (this is <a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>'s
|
||||
default behavior).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Although <code class="computeroutput"><span class="identifier">tom_int</span></code> is
|
||||
mostly a drop in replacement for the builtin integer types, it should
|
||||
be noted that it is a rather strange beast as it's a signed type that
|
||||
is not a 2's complement type. As a result the bitwise operations <code class="computeroutput"><span class="special">|</span> <span class="special">&</span> <span class="special">^</span></code> will throw a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
exception if either of the arguments is negative. Similarly the complement
|
||||
operator<code class="computeroutput"><span class="special">~</span></code> is deliberately
|
||||
not implemented for this type.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Formatted IO for this type does not support octal or hexadecimal notation
|
||||
for negative values, as a result performing formatted output on this
|
||||
type when the argument is negative and either of the flags <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">oct</span></code> or <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios_base</span><span class="special">::</span><span class="identifier">hex</span></code>
|
||||
are set, will result in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
will be thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid integer.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
|
||||
being thrown.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.ints.tom_int.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.ints.tom_int.example_"></a></span><a class="link" href="tom_int.html#boost_multiprecision.tut.ints.tom_int.example_">Example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">tommath</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">tom_int</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Do some arithmetic:</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><=</span> <span class="number">1000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">v</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1000!</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1000! in hex format</span>
|
||||
|
||||
<span class="keyword">try</span><span class="special">{</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="special">-</span><span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// Ooops! can't print a negative value in hex format!</span>
|
||||
<span class="special">}</span>
|
||||
<span class="keyword">catch</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
|
||||
<span class="keyword">try</span><span class="special">{</span>
|
||||
<span class="comment">// v is not a 2's complement type, bitwise operations are only supported</span>
|
||||
<span class="comment">// on positive values:</span>
|
||||
<span class="identifier">v</span> <span class="special">=</span> <span class="special">-</span><span class="identifier">v</span> <span class="special">&</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
<span class="keyword">catch</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span><span class="special">&</span> <span class="identifier">e</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">e</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_int.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../ints.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="egs.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,63 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Literal Types and constexpr Support</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="primetest.html" title="Primality Testing">
|
||||
<link rel="next" href="rounding.html" title="Rounding Rules for Conversions">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="primetest.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="rounding.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_lits">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.lits"></a><a class="link" href="lits.html" title="Literal Types and constexpr Support">Literal Types and <code class="computeroutput"><span class="identifier">constexpr</span></code> Support</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
There is limited support for <code class="computeroutput"><span class="identifier">constexpr</span></code>
|
||||
in the library, currently the <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
front end supports <code class="computeroutput"><span class="identifier">constexpr</span></code>
|
||||
on default construction and all forwarding constructors, but not on any of
|
||||
the non-member operators. So if some type <code class="computeroutput"><span class="identifier">B</span></code>
|
||||
is a literal type, then <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">B</span><span class="special">></span></code>
|
||||
is also a literal type, and you will be able to compile-time-construct such
|
||||
a type from any literal that <code class="computeroutput"><span class="identifier">B</span></code>
|
||||
is compile-time-constructible from. However, you will not be able to perform
|
||||
compile-time arithmetic on such types.
|
||||
</p>
|
||||
<p>
|
||||
Currently the only backend type provided by the library that is also a literal
|
||||
type are instantiations of <code class="computeroutput"><span class="identifier">cpp_int_backend</span></code>
|
||||
where the Allocator parameter is type <code class="computeroutput"><span class="keyword">void</span></code>,
|
||||
and the Checked parameter is <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">unchecked</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
For example:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">constexpr</span> <span class="identifier">int128_t</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="comment">// OK, fixed precision int128_t has no allocator.</span>
|
||||
<span class="identifier">constexpr</span> <span class="identifier">uint1024_t</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">0</span><span class="identifier">xFFFFFFFF00000000uLL</span><span class="special">;</span> <span class="comment">// OK, fixed precision uint1024_t has no allocator.</span>
|
||||
|
||||
<span class="identifier">constexpr</span> <span class="identifier">checked_uint128_t</span> <span class="identifier">k</span> <span class="special">=</span> <span class="special">-</span><span class="number">1</span><span class="special">;</span> <span class="comment">// Error, checked type is not a literal type as we need runtime error checking.</span>
|
||||
<span class="identifier">constexpr</span> <span class="identifier">cpp_int</span> <span class="identifier">l</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span> <span class="comment">// Error, type is not a literal as it performs memory management.</span>
|
||||
</pre>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="primetest.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="rounding.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,169 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Mixed Precision Arithmetic</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="rounding.html" title="Rounding Rules for Conversions">
|
||||
<link rel="next" href="../ref.html" title="Reference">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="rounding.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_mixed">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.mixed"></a><a class="link" href="mixed.html" title="Mixed Precision Arithmetic">Mixed Precision Arithmetic</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Mixed precision arithmetic is fully supported by the library, there are two
|
||||
different forms:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Where the operands are of different precision.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Where the operands are of the same precision, but yield a higher precision
|
||||
result.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.tut.mixed.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.mixed.mixing_operands_of_differing_precision"></a></span><a class="link" href="mixed.html#boost_multiprecision.tut.mixed.mixing_operands_of_differing_precision">Mixing
|
||||
Operands of Differing Precision</a>
|
||||
</h5>
|
||||
<p>
|
||||
If the arguments to a binary operator are of different precision, then the
|
||||
operation is allowed as long as there is an unambiguous implicit conversion
|
||||
from one argument type to the other. In all cases the arithmetic is performed
|
||||
"as if" the lower precision type is promoted to the higher precision
|
||||
type before applying the operator. However, particular backends may optimise
|
||||
this and avoid actually creating a temporary if they are able to do so.
|
||||
</p>
|
||||
<p>
|
||||
For example:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">mpfr_float_50</span> <span class="identifier">a</span><span class="special">(</span><span class="number">2</span><span class="special">),</span> <span class="identifier">b</span><span class="special">;</span>
|
||||
<span class="identifier">mpfr_float_100</span> <span class="identifier">c</span><span class="special">(</span><span class="number">3</span><span class="special">),</span> <span class="identifier">d</span><span class="special">;</span>
|
||||
<span class="identifier">static_mpfr_float_50</span> <span class="identifier">e</span><span class="special">(</span><span class="number">5</span><span class="special">),</span> <span class="identifier">f</span><span class="special">;</span>
|
||||
<span class="identifier">mpz_int</span> <span class="identifier">i</span><span class="special">(</span><span class="number">20</span><span class="special">);</span>
|
||||
|
||||
<span class="identifier">d</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">c</span><span class="special">;</span> <span class="comment">// OK, result of operand is an mpfr_float_100.</span>
|
||||
<span class="identifier">b</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">c</span><span class="special">;</span> <span class="comment">// Error, can't convert the result to an mpfr_float_50 as it will lose digits.</span>
|
||||
<span class="identifier">f</span> <span class="special">=</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">e</span><span class="special">;</span> <span class="comment">// Error, operator is ambiguous, result could be of either type.</span>
|
||||
<span class="identifier">f</span> <span class="special">=</span> <span class="identifier">e</span> <span class="special">*</span> <span class="identifier">i</span><span class="special">;</span> <span class="comment">// OK, unambiguous conversion from mpz_int to static_mpfr_float_50</span>
|
||||
</pre>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.tut.mixed.h1"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.mixed.operands_of_the_same_precision"></a></span><a class="link" href="mixed.html#boost_multiprecision.tut.mixed.operands_of_the_same_precision">Operands
|
||||
of the Same Precision</a>
|
||||
</h5>
|
||||
<p>
|
||||
Sometimes you want to apply an operator to two arguments of the same precision
|
||||
in such a way as to obtain a result of higher precision. The most common
|
||||
situation occurs with fixed precision integers, where you want to multiply
|
||||
two N-bit numbers to obtain a 2N-bit result. This is supported in this library
|
||||
by the following free functions:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ResultType</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Source1</span> <span class="keyword">class</span> <span class="identifier">Source2</span><span class="special">></span>
|
||||
<span class="identifier">ResultType</span><span class="special">&</span> <span class="identifier">add</span><span class="special">(</span><span class="identifier">ResultType</span><span class="special">&</span> <span class="identifier">result</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Source1</span><span class="special">&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Source2</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ResultType</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Source1</span> <span class="keyword">class</span> <span class="identifier">Source2</span><span class="special">></span>
|
||||
<span class="identifier">ResultType</span><span class="special">&</span> <span class="identifier">subtract</span><span class="special">(</span><span class="identifier">ResultType</span><span class="special">&</span> <span class="identifier">result</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Source1</span><span class="special">&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Source2</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ResultType</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Source1</span> <span class="keyword">class</span> <span class="identifier">Source2</span><span class="special">></span>
|
||||
<span class="identifier">ResultType</span><span class="special">&</span> <span class="identifier">multiply</span><span class="special">(</span><span class="identifier">ResultType</span><span class="special">&</span> <span class="identifier">result</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Source1</span><span class="special">&</span> <span class="identifier">a</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">Source2</span><span class="special">&</span> <span class="identifier">b</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
These functions apply the named operator to the arguments <span class="emphasis"><em>a</em></span>
|
||||
and <span class="emphasis"><em>b</em></span> and store the result in <span class="emphasis"><em>result</em></span>,
|
||||
returning <span class="emphasis"><em>result</em></span>. In all cases they behave "as
|
||||
if" arguments <span class="emphasis"><em>a</em></span> and <span class="emphasis"><em>b</em></span> were
|
||||
first promoted to type <code class="computeroutput"><span class="identifier">ResultType</span></code>
|
||||
before applying the operator, though particular backends may well avoid that
|
||||
step by way of an optimization.
|
||||
</p>
|
||||
<p>
|
||||
The type <code class="computeroutput"><span class="identifier">ResultType</span></code> must
|
||||
be an instance of class <code class="computeroutput"><span class="identifier">number</span></code>,
|
||||
and the types <code class="computeroutput"><span class="identifier">Source1</span></code> and
|
||||
<code class="computeroutput"><span class="identifier">Source2</span></code> may be either instances
|
||||
of class <code class="computeroutput"><span class="identifier">number</span></code> or native
|
||||
integer types. The latter is an optimization that allows arithmetic to be
|
||||
performed on native integer types producing an extended precision result.
|
||||
</p>
|
||||
<p>
|
||||
For example:
|
||||
</p>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint64_t</span> <span class="identifier">i</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint64_t</span><span class="special">>::</span><span class="identifier">max</span><span class="special">)();</span>
|
||||
<span class="identifier">boost</span><span class="special">::</span><span class="identifier">uint64_t</span> <span class="identifier">j</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">uint128_t</span> <span class="identifier">ui128</span><span class="special">;</span>
|
||||
<span class="identifier">uint256_t</span> <span class="identifier">ui256</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Start by performing arithmetic on 64-bit integers to yield 128-bit results:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">i</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">add</span><span class="special">(</span><span class="identifier">ui128</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">j</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">multiply</span><span class="special">(</span><span class="identifier">ui128</span><span class="special">,</span> <span class="identifier">i</span><span class="special">,</span> <span class="identifier">i</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// The try squaring a 128-bit integer to yield a 256-bit result:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">ui128</span> <span class="special">=</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special"><</span><span class="identifier">uint128_t</span><span class="special">>::</span><span class="identifier">max</span><span class="special">)();</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">multiply</span><span class="special">(</span><span class="identifier">ui256</span><span class="special">,</span> <span class="identifier">ui128</span><span class="special">,</span> <span class="identifier">ui128</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Produces the output:
|
||||
</p>
|
||||
<p>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="number">0</span><span class="identifier">xffffffffffffffff</span>
|
||||
<span class="number">0</span><span class="identifier">x10000000000000000</span>
|
||||
<span class="number">0</span><span class="identifier">xFFFFFFFFFFFFFFFE0000000000000001</span>
|
||||
<span class="number">0</span><span class="identifier">xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE00000000000000000000000000000001</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<h5>
|
||||
<a name="boost_multiprecision.tut.mixed.h2"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.mixed.backends_with_optimized_mixed_precision_arithmetic"></a></span><a class="link" href="mixed.html#boost_multiprecision.tut.mixed.backends_with_optimized_mixed_precision_arithmetic">Backends
|
||||
With Optimized Mixed Precision Arithmetic</a>
|
||||
</h5>
|
||||
<p>
|
||||
The following backends have at least some direct support for mixed precision
|
||||
arithmetic, and therefore avoid creating unnecessary temporaries when using
|
||||
the interfaces above. Therefore when using these types it's more efficient
|
||||
to use mixed precision arithmetic, than it is to explicitly cast the operands
|
||||
to the result type:
|
||||
</p>
|
||||
<p>
|
||||
<a class="link" href="floats/mpfr_float.html" title="mpfr_float">mpfr_float</a>,
|
||||
<a class="link" href="floats/gmp_float.html" title="gmp_float">gmp_float</a>,
|
||||
<a class="link" href="ints/cpp_int.html" title="cpp_int">cpp_int</a>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="rounding.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="../ref.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,109 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Primality Testing</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="random.html" title="Generating Random Numbers">
|
||||
<link rel="next" href="lits.html" title="Literal Types and constexpr Support">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="random.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="lits.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_primetest">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.primetest"></a><a class="link" href="primetest.html" title="Primality Testing">Primality Testing</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
The library implements a Miller-Rabin test for primality:
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">miller_rabin</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Backend</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Engine</span><span class="special">></span>
|
||||
<span class="keyword">bool</span> <span class="identifier">miller_rabin_test</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">trials</span><span class="special">,</span> <span class="identifier">Engine</span><span class="special">&</span> <span class="identifier">gen</span><span class="special">);</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Backend</span><span class="special">,</span> <span class="identifier">expression_template_option</span> <span class="identifier">ExpressionTemplates</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Engine</span><span class="special">></span>
|
||||
<span class="keyword">bool</span> <span class="identifier">miller_rabin_test</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">Backend</span><span class="special">,</span> <span class="identifier">ExpressionTemplates</span><span class="special">>&</span> <span class="identifier">n</span><span class="special">,</span> <span class="keyword">unsigned</span> <span class="identifier">trials</span><span class="special">);</span>
|
||||
</pre>
|
||||
<p>
|
||||
These functions perform a Miller-Rabin test for primality, if the result
|
||||
is <code class="computeroutput"><span class="keyword">false</span></code> then <span class="emphasis"><em>n</em></span>
|
||||
is definitely composite, while if the result is <code class="computeroutput"><span class="keyword">true</span></code>
|
||||
then <span class="emphasis"><em>n</em></span> is prime with probability <span class="emphasis"><em>0.25^trials</em></span>.
|
||||
The algorithm used performs some trial divisions to exclude small prime factors,
|
||||
does one Fermat test to exclude many more composites, and then uses the Miller-Rabin
|
||||
algorithm straight out of Knuth Vol 2, which recommends 25 trials for a pretty
|
||||
strong likelihood that <span class="emphasis"><em>n</em></span> is prime.
|
||||
</p>
|
||||
<p>
|
||||
The third optional argument is for a Uniform Random Number Generator from
|
||||
Boost.Random. When not provided the <code class="computeroutput"><span class="identifier">mt19937</span></code>
|
||||
generator is used. Note that when producing random primes then you should
|
||||
probably use a different random number generator to produce candidate prime
|
||||
numbers for testing, than is used internally by <code class="computeroutput"><span class="identifier">miller_rabin_test</span></code>
|
||||
for determining whether the value is prime. It also helps of course to seed
|
||||
the generators with some source of randomness.
|
||||
</p>
|
||||
<p>
|
||||
The following example searches for a prime <code class="computeroutput"><span class="identifier">p</span></code>
|
||||
for which <code class="computeroutput"><span class="special">(</span><span class="identifier">p</span><span class="special">-</span><span class="number">1</span><span class="special">)/</span><span class="number">2</span></code> is also probably prime:
|
||||
</p>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">miller_rabin</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iomanip</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
|
||||
<span class="special">{</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">random</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">cpp_int</span> <span class="identifier">int_type</span><span class="special">;</span>
|
||||
<span class="identifier">mt11213b</span> <span class="identifier">base_gen</span><span class="special">(</span><span class="identifier">clock</span><span class="special">());</span>
|
||||
<span class="identifier">independent_bits_engine</span><span class="special"><</span><span class="identifier">mt11213b</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">int_type</span><span class="special">></span> <span class="identifier">gen</span><span class="special">(</span><span class="identifier">base_gen</span><span class="special">);</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// We must use a different generator for the tests and number generation, otherwise</span>
|
||||
<span class="comment">// we get false positives.</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">mt19937</span> <span class="identifier">gen2</span><span class="special">(</span><span class="identifier">clock</span><span class="special">());</span>
|
||||
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">100000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">int_type</span> <span class="identifier">n</span> <span class="special">=</span> <span class="identifier">gen</span><span class="special">();</span>
|
||||
<span class="keyword">if</span><span class="special">(</span><span class="identifier">miller_rabin_test</span><span class="special">(</span><span class="identifier">n</span><span class="special">,</span> <span class="number">25</span><span class="special">,</span> <span class="identifier">gen2</span><span class="special">))</span>
|
||||
<span class="special">{</span>
|
||||
<span class="comment">// Value n is probably prime, see if (n-1)/2 is also prime:</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"We have a probable prime with value: "</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">n</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="keyword">if</span><span class="special">(</span><span class="identifier">miller_rabin_test</span><span class="special">((</span><span class="identifier">n</span><span class="special">-</span><span class="number">1</span><span class="special">)/</span><span class="number">2</span><span class="special">,</span> <span class="number">25</span><span class="special">,</span> <span class="identifier">gen2</span><span class="special">))</span>
|
||||
<span class="special">{</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"We have a safe prime with value: "</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span> <span class="special"><<</span> <span class="identifier">n</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
<span class="special">}</span>
|
||||
<span class="special">}</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Ooops, no safe primes were found"</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
|
||||
<span class="special">}</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="random.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="lits.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,157 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Generating Random Numbers</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="conversions.html" title="Constructing and Interconverting Between Number Types">
|
||||
<link rel="next" href="primetest.html" title="Primality Testing">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="conversions.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="primetest.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_random">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.random"></a><a class="link" href="random.html" title="Generating Random Numbers">Generating Random Numbers</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
Random numbers are generated in conjunction with Boost.Random. However, since
|
||||
Boost.Random is unaware of <a href="http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic" target="_top">arbitrary
|
||||
precision</a> numbers, it's necessary to include the header:
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">random</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
</pre>
|
||||
<p>
|
||||
In order to act as a bridge between the two libraries.
|
||||
</p>
|
||||
<p>
|
||||
Integers with <span class="emphasis"><em>N</em></span> random bits are generated using <code class="computeroutput"><span class="identifier">independent_bits_engine</span></code>:
|
||||
</p>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">random</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">random</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Declare our random number generator type, the underlying generator</span>
|
||||
<span class="comment">// is the Mersenne twister mt19937 engine, and 256 bits are generated:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">independent_bits_engine</span><span class="special"><</span><span class="identifier">mt19937</span><span class="special">,</span> <span class="number">256</span><span class="special">,</span> <span class="identifier">mpz_int</span><span class="special">></span> <span class="identifier">generator_type</span><span class="special">;</span>
|
||||
<span class="identifier">generator_type</span> <span class="identifier">gen</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Generate some values:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span><span class="special">;</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">gen</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Alternatively we can generate integers in a given range using <code class="computeroutput"><span class="identifier">uniform_int_distribution</span></code>, this will invoke
|
||||
the underlying engine multiple times to build up the required number of bits
|
||||
in the result:
|
||||
</p>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">random</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">random</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Generate integers in a given range using uniform_int,</span>
|
||||
<span class="comment">// the underlying generator is invoked multiple times</span>
|
||||
<span class="comment">// to generate enough bits:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">mt19937</span> <span class="identifier">mt</span><span class="special">;</span>
|
||||
<span class="identifier">uniform_int_distribution</span><span class="special"><</span><span class="identifier">mpz_int</span><span class="special">></span> <span class="identifier">ui</span><span class="special">(</span><span class="number">0</span><span class="special">,</span> <span class="identifier">mpz_int</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special"><<</span> <span class="number">256</span><span class="special">);</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Generate the numbers:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">hex</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">showbase</span><span class="special">;</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ui</span><span class="special">(</span><span class="identifier">mt</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Floating point values in [0,1) are generated using <code class="computeroutput"><span class="identifier">uniform_01</span></code>,
|
||||
the trick here is to ensure that the underlying generator produces as many
|
||||
random bits as there are digits in the floating point type. As above <code class="computeroutput"><span class="identifier">independent_bits_engine</span></code> can be used for
|
||||
this purpose, note that we also have to convert decimal digits (in the floating
|
||||
point type) to bits (in the random number generator):
|
||||
</p>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">random</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">random</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// We need an underlying generator with at least as many bits as the</span>
|
||||
<span class="comment">// floating point type to generate numbers in [0, 1) with all the bits</span>
|
||||
<span class="comment">// in the floating point type randomly filled:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">uniform_01</span><span class="special"><</span><span class="identifier">mpf_float_50</span><span class="special">></span> <span class="identifier">uf</span><span class="special">;</span>
|
||||
<span class="identifier">independent_bits_engine</span><span class="special"><</span><span class="identifier">mt19937</span><span class="special">,</span> <span class="number">50L</span><span class="special">*</span><span class="number">1000L</span><span class="special">/</span><span class="number">301L</span><span class="special">,</span> <span class="identifier">mpz_int</span><span class="special">></span> <span class="identifier">gen</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Generate the values:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="number">50</span><span class="special">);</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">20</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">uf</span><span class="special">(</span><span class="identifier">gen</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
</p>
|
||||
<p>
|
||||
Finally, we can modify the above example to produce numbers distributed according
|
||||
to some distribution:
|
||||
</p>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">random</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">random</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// We can repeat the above example, with other distributions:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">uniform_real_distribution</span><span class="special"><</span><span class="identifier">mpf_float_50</span><span class="special">></span> <span class="identifier">ur</span><span class="special">(-</span><span class="number">20</span><span class="special">,</span> <span class="number">20</span><span class="special">);</span>
|
||||
<span class="identifier">gamma_distribution</span><span class="special"><</span><span class="identifier">mpf_float_50</span><span class="special">></span> <span class="identifier">gd</span><span class="special">(</span><span class="number">20</span><span class="special">);</span>
|
||||
<span class="identifier">independent_bits_engine</span><span class="special"><</span><span class="identifier">mt19937</span><span class="special">,</span> <span class="number">50L</span><span class="special">*</span><span class="number">1000L</span><span class="special">/</span><span class="number">301L</span><span class="special">,</span> <span class="identifier">mpz_int</span><span class="special">></span> <span class="identifier">gen</span><span class="special">;</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="comment">// Generate some values:</span>
|
||||
<span class="comment">//</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="number">50</span><span class="special">);</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">20</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ur</span><span class="special">(</span><span class="identifier">gen</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">20</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">gd</span><span class="special">(</span><span class="identifier">gen</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="conversions.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="primetest.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,252 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Rational Number Types</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="floats/fp_eg/poly_eg.html" title="Polynomial Evaluation">
|
||||
<link rel="next" href="rational/cpp_rational.html" title="cpp_rational">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="floats/fp_eg/poly_eg.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="rational/cpp_rational.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_rational">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.rational"></a><a class="link" href="rational.html" title="Rational Number Types">Rational Number Types</a>
|
||||
</h3></div></div></div>
|
||||
<div class="toc"><dl>
|
||||
<dt><span class="section"><a href="rational/cpp_rational.html">cpp_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="rational/gmp_rational.html">gmp_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="rational/tommath_rational.html">tommath_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="rational/br.html">Use With Boost.Rational</a></span></dt>
|
||||
<dt><span class="section"><a href="rational/rational_adapter.html">rational_adapter</a></span></dt>
|
||||
</dl></div>
|
||||
<p>
|
||||
The following back-ends provide rational number arithmetic:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Backend Type
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Header
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Radix
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Dependencies
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Pros
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Cons
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">cpp_rational</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/cpp_int.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
None
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
An all C++ Boost-licensed implementation.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Slower than <a href="http://gmplib.org" target="_top">GMP</a>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">gmp_rational</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/gmp.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://gmplib.org" target="_top">GMP</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Very fast and efficient back-end.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Dependency on GNU licensed <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
library.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">tommath_rational</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/tommath.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
2
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
<a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
All C/C++ implementation that's Boost Software Licence compatible.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Slower than <a href="http://gmplib.org" target="_top">GMP</a>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">rational_adapter</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/multiprecision/rational_adapter.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
N/A
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
none
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
All C++ adapter that allows any integer back-end type to be used
|
||||
as a rational type.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Requires an underlying integer back-end type.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">rational</span></code>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
boost/rational.hpp
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
N/A
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
None
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
A C++ rational number type that can used with any <code class="computeroutput"><span class="identifier">number</span></code> integer type.
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
The expression templates used by <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
end up being "hidden" inside <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">rational</span></code>:
|
||||
performance may well suffer as a result.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="floats/fp_eg/poly_eg.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="rational/cpp_rational.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,42 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Use With Boost.Rational</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../rational.html" title="Rational Number Types">
|
||||
<link rel="prev" href="tommath_rational.html" title="tommath_rational">
|
||||
<link rel="next" href="rational_adapter.html" title="rational_adapter">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tommath_rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="rational_adapter.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_rational_br">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.rational.br"></a><a class="link" href="br.html" title="Use With Boost.Rational">Use With Boost.Rational</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
All of the integer types in this library can be used as template arguments
|
||||
to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">rational</span><span class="special"><</span><span class="identifier">IntType</span><span class="special">></span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Note that using the library in this way largely negates the effect of the
|
||||
expression templates in <code class="computeroutput"><span class="identifier">number</span></code>.
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="tommath_rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="rational_adapter.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,113 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>cpp_rational</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../rational.html" title="Rational Number Types">
|
||||
<link rel="prev" href="../rational.html" title="Rational Number Types">
|
||||
<link rel="next" href="gmp_rational.html" title="gmp_rational">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_rational.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_rational_cpp_rational">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.rational.cpp_rational"></a><a class="link" href="cpp_rational.html" title="cpp_rational">cpp_rational</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">rational_adapter</span><span class="special"><</span><span class="identifier">cpp_int_backend</span><span class="special"><></span> <span class="special">></span> <span class="identifier">cpp_rational_backend</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">cpp_rational_backend</span><span class="special">></span> <span class="identifier">cpp_rational</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">cpp_rational_backend</span></code>
|
||||
type is used via the typedef <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">cpp_rational</span></code>.
|
||||
It provides a rational number type that is a drop-in replacement for the
|
||||
native C++ number types, but with unlimited precision.
|
||||
</p>
|
||||
<p>
|
||||
As well as the usual conversions from arithmetic and string types, instances
|
||||
of <code class="computeroutput"><span class="identifier">cpp_rational</span></code> are copy
|
||||
constructible and assignable from type <code class="computeroutput"><span class="identifier">cpp_int</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
There is also a two argument constructor that accepts a numerator and denominator:
|
||||
both of type <code class="computeroutput"><span class="identifier">cpp_int</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
There are also non-member functions:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">cpp_int</span> <span class="identifier">numerator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">cpp_rational</span><span class="special">&);</span>
|
||||
<span class="identifier">cpp_int</span> <span class="identifier">denominator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">cpp_rational</span><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
which return the numerator and denominator of the number.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Default constructed <code class="computeroutput"><span class="identifier">cpp_rational</span></code>s
|
||||
have the value zero.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
|
||||
being thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid rational
|
||||
number.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.rational.cpp_rational.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.rational.cpp_rational.example_"></a></span><a class="link" href="cpp_rational.html#boost_multiprecision.tut.rational.cpp_rational.example_">Example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">cpp_int</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">cpp_rational</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Do some arithmetic:</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><=</span> <span class="number">1000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">v</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
<span class="identifier">v</span> <span class="special">/=</span> <span class="number">10</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1000! / 10</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">numerator</span><span class="special">(</span><span class="identifier">v</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">denominator</span><span class="special">(</span><span class="identifier">v</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">cpp_rational</span> <span class="identifier">w</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span> <span class="comment">// component wise constructor</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">w</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 2/3</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="../rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="gmp_rational.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,144 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>gmp_rational</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../rational.html" title="Rational Number Types">
|
||||
<link rel="prev" href="cpp_rational.html" title="cpp_rational">
|
||||
<link rel="next" href="tommath_rational.html" title="tommath_rational">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="tommath_rational.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_rational_gmp_rational">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.rational.gmp_rational"></a><a class="link" href="gmp_rational.html" title="gmp_rational">gmp_rational</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">class</span> <span class="identifier">gmp_rational</span><span class="special">;</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_rational</span> <span class="special">></span> <span class="identifier">mpq_rational</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">gmp_rational</span></code> back-end
|
||||
is used via the typedef <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">mpq_rational</span></code>.
|
||||
It acts as a thin wrapper around the <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
<code class="computeroutput"><span class="identifier">mpq_t</span></code> to provide a rational
|
||||
number type that is a drop-in replacement for the native C++ number types,
|
||||
but with unlimited precision.
|
||||
</p>
|
||||
<p>
|
||||
As well as the usual conversions from arithmetic and string types, instances
|
||||
of <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_rational</span><span class="special">></span></code>
|
||||
are copy constructible and assignable from:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
The <a href="http://gmplib.org" target="_top">GMP</a> native types: <code class="computeroutput"><span class="identifier">mpz_t</span></code>, <code class="computeroutput"><span class="identifier">mpq_t</span></code>.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
<code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_int</span><span class="special">></span></code>.
|
||||
</li>
|
||||
</ul></div>
|
||||
<p>
|
||||
There is also a two-argument constructor that accepts a numerator and denominator
|
||||
(both of type <code class="computeroutput"><span class="identifier">number</span><span class="special"><</span><span class="identifier">gmp_int</span><span class="special">></span></code>).
|
||||
</p>
|
||||
<p>
|
||||
There are also non-member functions:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">mpz_int</span> <span class="identifier">numerator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpq_rational</span><span class="special">&);</span>
|
||||
<span class="identifier">mpz_int</span> <span class="identifier">denominator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">mpq_rational</span><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
which return the numerator and denominator of the number.
|
||||
</p>
|
||||
<p>
|
||||
It's also possible to access the underlying <code class="computeroutput"><span class="identifier">mpq_t</span></code>
|
||||
via the <code class="computeroutput"><span class="identifier">data</span><span class="special">()</span></code>
|
||||
member function of <code class="computeroutput"><span class="identifier">mpq_rational</span></code>.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Default constructed <code class="computeroutput"><span class="identifier">mpq_rational</span></code>s
|
||||
have the value zero (this is the <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
default behavior).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
|
||||
being thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid rational
|
||||
number.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
No changes are made to the <a href="http://gmplib.org" target="_top">GMP</a>
|
||||
library's global settings, so this type can coexist with existing
|
||||
<a href="http://gmplib.org" target="_top">GMP</a> code.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
The code can equally be used with <a href="http://mpir.org/" target="_top">MPIR</a>
|
||||
as the underlying library - indeed that is the preferred option on
|
||||
Win32.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.rational.gmp_rational.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.rational.gmp_rational.example_"></a></span><a class="link" href="gmp_rational.html#boost_multiprecision.tut.rational.gmp_rational.example_">Example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">gmp</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">mpq_rational</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Do some arithmetic:</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><=</span> <span class="number">1000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">v</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
<span class="identifier">v</span> <span class="special">/=</span> <span class="number">10</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1000! / 10</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">numerator</span><span class="special">(</span><span class="identifier">v</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">denominator</span><span class="special">(</span><span class="identifier">v</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">mpq_rational</span> <span class="identifier">w</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span> <span class="comment">// component wise constructor</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">w</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 2/3</span>
|
||||
|
||||
<span class="comment">// Access the underlying data:</span>
|
||||
<span class="identifier">mpq_t</span> <span class="identifier">q</span><span class="special">;</span>
|
||||
<span class="identifier">mpq_init</span><span class="special">(</span><span class="identifier">q</span><span class="special">);</span>
|
||||
<span class="identifier">mpq_set</span><span class="special">(</span><span class="identifier">q</span><span class="special">,</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">backend</span><span class="special">().</span><span class="identifier">data</span><span class="special">());</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="cpp_rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="tommath_rational.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,58 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>rational_adapter</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../rational.html" title="Rational Number Types">
|
||||
<link rel="prev" href="br.html" title="Use With Boost.Rational">
|
||||
<link rel="next" href="../conversions.html" title="Constructing and Interconverting Between Number Types">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="br.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../conversions.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_rational_rational_adapter">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.rational.rational_adapter"></a><a class="link" href="rational_adapter.html" title="rational_adapter">rational_adapter</a>
|
||||
</h4></div></div></div>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">IntBackend</span><span class="special">></span>
|
||||
<span class="keyword">class</span> <span class="identifier">rational_adpater</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span>
|
||||
</pre>
|
||||
<p>
|
||||
The class template <code class="computeroutput"><span class="identifier">rational_adapter</span></code>
|
||||
is a back-end for <code class="computeroutput"><span class="identifier">number</span></code>
|
||||
which converts any existing integer back-end into a rational-number back-end.
|
||||
</p>
|
||||
<p>
|
||||
So for example, given an integer back-end type <code class="computeroutput"><span class="identifier">MyIntegerBackend</span></code>,
|
||||
the use would be something like:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">MyIntegerBackend</span><span class="special">></span> <span class="identifier">MyInt</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">rational_adapter</span><span class="special"><</span><span class="identifier">MyIntegerBackend</span><span class="special">></span> <span class="special">></span> <span class="identifier">MyRational</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">MyRational</span> <span class="identifier">r</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
|
||||
<span class="identifier">r</span> <span class="special">/=</span> <span class="number">3</span><span class="special">;</span>
|
||||
<span class="identifier">MyInt</span> <span class="identifier">i</span> <span class="special">=</span> <span class="identifier">numerator</span><span class="special">(</span><span class="identifier">r</span><span class="special">);</span>
|
||||
<span class="identifier">assert</span><span class="special">(</span><span class="identifier">i</span> <span class="special">==</span> <span class="number">2</span><span class="special">);</span>
|
||||
</pre>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="br.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="../conversions.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,119 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>tommath_rational</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../rational.html" title="Rational Number Types">
|
||||
<link rel="prev" href="gmp_rational.html" title="gmp_rational">
|
||||
<link rel="next" href="br.html" title="Use With Boost.Rational">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="br.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_rational_tommath_rational">
|
||||
<div class="titlepage"><div><div><h4 class="title">
|
||||
<a name="boost_multiprecision.tut.rational.tommath_rational"></a><a class="link" href="tommath_rational.html" title="tommath_rational">tommath_rational</a>
|
||||
</h4></div></div></div>
|
||||
<p>
|
||||
<code class="computeroutput"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">tommath</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code>
|
||||
</p>
|
||||
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">multiprecision</span><span class="special">{</span>
|
||||
|
||||
<span class="keyword">typedef</span> <span class="identifier">rational_adpater</span><span class="special"><</span><span class="identifier">tommath_int</span><span class="special">></span> <span class="identifier">tommath_rational</span><span class="special">;</span>
|
||||
<span class="keyword">typedef</span> <span class="identifier">number</span><span class="special"><</span><span class="identifier">tommath_rational</span> <span class="special">></span> <span class="identifier">tom_rational</span><span class="special">;</span>
|
||||
|
||||
<span class="special">}}</span> <span class="comment">// namespaces</span>
|
||||
</pre>
|
||||
<p>
|
||||
The <code class="computeroutput"><span class="identifier">tommath_rational</span></code> back-end
|
||||
is used via the typedef <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">::</span><span class="identifier">tom_rational</span></code>.
|
||||
It acts as a thin wrapper around <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">rational</span><span class="special"><</span><span class="identifier">tom_int</span><span class="special">></span></code> to provide a rational number type that
|
||||
is a drop-in replacement for the native C++ number types, but with unlimited
|
||||
precision.
|
||||
</p>
|
||||
<p>
|
||||
The advantage of using this type rather than <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">rational</span><span class="special"><</span><span class="identifier">tom_int</span><span class="special">></span></code> directly, is that it is expression-template
|
||||
enabled, greatly reducing the number of temporaries created in complex
|
||||
expressions.
|
||||
</p>
|
||||
<p>
|
||||
There are also non-member functions:
|
||||
</p>
|
||||
<pre class="programlisting"><span class="identifier">tom_int</span> <span class="identifier">numerator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">tom_rational</span><span class="special">&);</span>
|
||||
<span class="identifier">tom_int</span> <span class="identifier">denominator</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">tom_rational</span><span class="special">&);</span>
|
||||
</pre>
|
||||
<p>
|
||||
which return the numerator and denominator of the number.
|
||||
</p>
|
||||
<p>
|
||||
Things you should know when using this type:
|
||||
</p>
|
||||
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
|
||||
<li class="listitem">
|
||||
Default constructed <code class="computeroutput"><span class="identifier">tom_rational</span></code>s
|
||||
have the value zero (this the inherited Boost.Rational behavior).
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Division by zero results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">overflow_error</span></code>
|
||||
being thrown.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Conversion from a string results in a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">runtime_error</span></code>
|
||||
being thrown if the string can not be interpreted as a valid rational
|
||||
number.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
No changes are made to <a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>'s
|
||||
global state, so this type can safely coexist with other <a href="http://libtom.org/?page=features&newsitems=5&whatfile=ltm" target="_top">libtommath</a>
|
||||
code.
|
||||
</li>
|
||||
<li class="listitem">
|
||||
Performance of this type has been found to be pretty poor - this need
|
||||
further investigation - but it appears that Boost.Rational needs some
|
||||
improvement in this area.
|
||||
</li>
|
||||
</ul></div>
|
||||
<h6>
|
||||
<a name="boost_multiprecision.tut.rational.tommath_rational.h0"></a>
|
||||
<span class="phrase"><a name="boost_multiprecision.tut.rational.tommath_rational.example_"></a></span><a class="link" href="tommath_rational.html#boost_multiprecision.tut.rational.tommath_rational.example_">Example:</a>
|
||||
</h6>
|
||||
<p>
|
||||
</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">multiprecision</span><span class="special">/</span><span class="identifier">tommath</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
|
||||
|
||||
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">tom_rational</span> <span class="identifier">v</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
|
||||
|
||||
<span class="comment">// Do some arithmetic:</span>
|
||||
<span class="keyword">for</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><=</span> <span class="number">1000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span>
|
||||
<span class="identifier">v</span> <span class="special">*=</span> <span class="identifier">i</span><span class="special">;</span>
|
||||
<span class="identifier">v</span> <span class="special">/=</span> <span class="number">10</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">v</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 1000! / 10</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">numerator</span><span class="special">(</span><span class="identifier">v</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">denominator</span><span class="special">(</span><span class="identifier">v</span><span class="special">)</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
|
||||
|
||||
<span class="identifier">tom_rational</span> <span class="identifier">w</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span> <span class="comment">// Component wise constructor</span>
|
||||
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">w</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span> <span class="comment">// prints 2/3</span>
|
||||
</pre>
|
||||
<p>
|
||||
</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 © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="gmp_rational.html"><img src="../../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../rational.html"><img src="../../../images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../images/home.png" alt="Home"></a><a accesskey="n" href="br.html"><img src="../../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,182 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Rounding Rules for Conversions</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="up" href="../tut.html" title="Tutorial">
|
||||
<link rel="prev" href="lits.html" title="Literal Types and constexpr Support">
|
||||
<link rel="next" href="mixed.html" title="Mixed Precision Arithmetic">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="lits.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="mixed.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
<div class="section boost_multiprecision_tut_rounding">
|
||||
<div class="titlepage"><div><div><h3 class="title">
|
||||
<a name="boost_multiprecision.tut.rounding"></a><a class="link" href="rounding.html" title="Rounding Rules for Conversions">Rounding Rules for
|
||||
Conversions</a>
|
||||
</h3></div></div></div>
|
||||
<p>
|
||||
As a general rule, all conversions between unrelated types are performed
|
||||
using basic arithmetic operations, therefore conversions are either exact,
|
||||
or follow the same rounding rules as arithmetic for the type in question.
|
||||
</p>
|
||||
<p>
|
||||
The following table summarises the situation for conversions from native
|
||||
types:
|
||||
</p>
|
||||
<div class="informaltable"><table class="table">
|
||||
<colgroup>
|
||||
<col>
|
||||
<col>
|
||||
</colgroup>
|
||||
<thead><tr>
|
||||
<th>
|
||||
<p>
|
||||
Backend
|
||||
</p>
|
||||
</th>
|
||||
<th>
|
||||
<p>
|
||||
Rounding Rules
|
||||
</p>
|
||||
</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="ints/cpp_int.html" title="cpp_int">cpp_int</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Conversions from integer types are exact if the target has sufficient
|
||||
precision, otherwise they truncate to the first 2^MaxBits bits
|
||||
(modulo arithmetic). Conversions from floating point types are
|
||||
truncating to the nearest integer.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="ints/gmp_int.html" title="gmp_int">gmp_int</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Conversions are performed by the GMP library except for conversion
|
||||
from <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>
|
||||
which is truncating.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="ints/tom_int.html" title="tom_int">tom_int</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Conversions from floating point types are truncating, all others
|
||||
are performed by libtommath and are exact.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="floats/gmp_float.html" title="gmp_float">gmp_float</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
Conversions are performed by the GMP library except for conversion
|
||||
from <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>
|
||||
which should be exact provided the target type has as much precision
|
||||
as a <code class="computeroutput"><span class="keyword">long</span> <span class="keyword">double</span></code>.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="floats/mpfr_float.html" title="mpfr_float">mpfr_float</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
All conversions are performed by the underlying MPFR library.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="floats/cpp_dec_float.html" title="cpp_dec_float">cpp_dec_float</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
All conversions are performed using basic arithmetic operations
|
||||
and are truncating.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="rational/gmp_rational.html" title="gmp_rational">gmp_rational</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
See <a class="link" href="ints/gmp_int.html" title="gmp_int">gmp_int</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="rational/cpp_rational.html" title="cpp_rational">cpp_rational</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
See <a class="link" href="ints/cpp_int.html" title="cpp_int">cpp_int</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<p>
|
||||
<a class="link" href="rational/tommath_rational.html" title="tommath_rational">tommath_rational</a>
|
||||
</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>
|
||||
See <a class="link" href="ints/tom_int.html" title="tom_int">tom_int</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table></div>
|
||||
</div>
|
||||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||||
<td align="left"></td>
|
||||
<td align="right"><div class="copyright-footer">Copyright © 2002-2012 John Maddock and Christopher Kormanyos<p>
|
||||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
||||
</p>
|
||||
</div></td>
|
||||
</tr></table>
|
||||
<hr>
|
||||
<div class="spirit-nav">
|
||||
<a accesskey="p" href="lits.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../tut.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="mixed.html"><img src="../../images/next.png" alt="Next"></a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,136 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
||||
<title>Chapter 1. Boost.Multiprecision</title>
|
||||
<link rel="stylesheet" href="http://www.boost.org/doc/libs/release/doc/src/boostbook.css" type="text/css">
|
||||
<meta name="generator" content="DocBook XSL Stylesheets V1.77.1">
|
||||
<link rel="home" href="index.html" title="Chapter 1. Boost.Multiprecision">
|
||||
<link rel="next" href="boost_multiprecision/intro.html" title="Introduction">
|
||||
</head>
|
||||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||||
<div class="spirit-nav"><a accesskey="n" href="boost_multiprecision/intro.html"><img src="images/next.png" alt="Next"></a></div>
|
||||
<div class="chapter">
|
||||
<div class="titlepage"><div>
|
||||
<div><h2 class="title">
|
||||
<a name="boost_multiprecision"></a>Chapter 1. Boost.Multiprecision</h2></div>
|
||||
<div><div class="author"><h3 class="author">
|
||||
<span class="firstname">John</span> <span class="surname">Maddock</span>
|
||||
</h3></div></div>
|
||||
<div><div class="author"><h3 class="author">
|
||||
<span class="firstname">Christopher</span> <span class="surname">Kormanyos</span>
|
||||
</h3></div></div>
|
||||
<div><p class="copyright">Copyright © 2002-2012 John Maddock and Christopher Kormanyos</p></div>
|
||||
<div><div class="legalnotice">
|
||||
<a name="boost_multiprecision.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>
|
||||
</div></div>
|
||||
</div></div>
|
||||
<div class="toc">
|
||||
<p><b>Table of Contents</b></p>
|
||||
<dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/intro.html">Introduction</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut.html">Tutorial</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/ints.html">Integer Types</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/ints/cpp_int.html">cpp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/ints/gmp_int.html">gmp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/ints/tom_int.html">tom_int</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/ints/egs.html">Examples</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/ints/egs/factorials.html">Factorials</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/ints/egs/bitops.html">Bit Operations</a></span></dt>
|
||||
</dl></dd>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats.html">Floating Point Numbers</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/cpp_dec_float.html">cpp_dec_float</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/gmp_float.html">gmp_float</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/mpfr_float.html">mpfr_float</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/fp_eg.html">Examples</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/fp_eg/aos.html">Area of
|
||||
Circle</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/fp_eg/jel.html">Defining
|
||||
a Lambda Function.</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/fp_eg/nd.html">Calculating
|
||||
a Derivative</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/fp_eg/gi.html">Calculating
|
||||
an Integral</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/floats/fp_eg/poly_eg.html">Polynomial
|
||||
Evaluation</a></span></dt>
|
||||
</dl></dd>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/rational.html">Rational Number Types</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/rational/cpp_rational.html">cpp_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/rational/gmp_rational.html">gmp_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/rational/tommath_rational.html">tommath_rational</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/rational/br.html">Use With Boost.Rational</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/rational/rational_adapter.html">rational_adapter</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/conversions.html">Constructing and
|
||||
Interconverting Between Number Types</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/random.html">Generating Random Numbers</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/primetest.html">Primality Testing</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/lits.html">Literal Types and <code class="computeroutput"><span class="identifier">constexpr</span></code> Support</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/rounding.html">Rounding Rules for
|
||||
Conversions</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/tut/mixed.html">Mixed Precision Arithmetic</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref.html">Reference</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/number.html">number</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/cpp_int_ref.html">cpp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/gmp_int_ref.html">gmp_int</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/tom_int_ref.html">tom_int</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/mpf_ref.html">gmp_float</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/mpfr_ref.html">mpfr_float_backend</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/cpp_dec_ref.html">cpp_dec_float</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/internals.html">Internal Support
|
||||
Code</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/backendconc.html">Backend Requirements</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/ref/headers.html">Header File Structure</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="boost_multiprecision/perf.html">Performance Comparison</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/perf/overhead.html">The Overhead in the
|
||||
Number Class Wrapper</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/perf/realworld.html">Floating Point Real
|
||||
World Tests</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/perf/int_real_world.html">Integer Real
|
||||
World Tests</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/perf/float_performance.html">Float Algorithm
|
||||
Perfomance</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/perf/integer_performance.html">Integer
|
||||
Algorithm Perfomance</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/perf/rational_performance.html">Rational
|
||||
Type Perfomance</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="boost_multiprecision/map.html">Roadmap</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/map/hist.html">History</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/map/todo.html">TODO</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/map/faq.html">FAQ</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/map/ack.html">Acknowledgements</a></span></dt>
|
||||
</dl></dd>
|
||||
<dt><span class="section"><a href="boost_multiprecision/indexes.html">Indexes</a></span></dt>
|
||||
<dd><dl>
|
||||
<dt><span class="section"><a href="boost_multiprecision/indexes/s01.html">Function Index</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/indexes/s02.html">Class Index</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/indexes/s03.html">Typedef Index</a></span></dt>
|
||||
<dt><span class="section"><a href="boost_multiprecision/indexes/s04.html">Index</a></span></dt>
|
||||
</dl></dd>
|
||||
</dl>
|
||||
</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: November 18, 2012 at 15:59:30 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_multiprecision/intro.html"><img src="images/next.png" alt="Next"></a></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,215 @@
|
||||
[/ Symbols and Greek letters (about 120) from HTML4.]
|
||||
[/ File HTML4_symbols.qbk]
|
||||
[/ See http://www.htmlhelp.com/reference/html40/entities/symbols.html]
|
||||
[/ See also http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references]
|
||||
[/ http://www.alanwood.net/demos/ent4_frame.html]
|
||||
[/ http://www.unicode.org/charts/PDF/U2200.pdf and others]
|
||||
[/ All (except 2 angle brackets) show OK on Firefox 2.0]
|
||||
|
||||
[/ See also Latin-1 aka Western (ISO-8859-1) in latin1_symbols.qbk]
|
||||
[/ http://www.htmlhelp.com/reference/html40/entities/latin1.html]
|
||||
[/Unicode Latin extended http://www.unicode.org/charts/U0080.pdf]
|
||||
|
||||
[/ Also some miscellaneous math charaters added to this list - see the end.]
|
||||
[/ For others see also math_symbols.qbk]
|
||||
|
||||
[/ To use, enclose the template name in square brackets.]
|
||||
|
||||
[template fnof[]'''ƒ'''] [/ ƒ Latin small f with hook = function = florin]
|
||||
[/ Capital Greek start with capital letter, lower case all small.]
|
||||
[template Alpha[]'''Α'''] [/ ? Greek capital letter alpha]
|
||||
[template Beta[]'''Β'''] [/ ? Greek capital letter beta]
|
||||
[template Gamma[]'''Γ'''] [/ G Greek capital letter gamma]
|
||||
[template Delta[]'''Δ'''] [/ ? Greek capital letter delta]
|
||||
[template Epsilon[]'''Ε'''] [/ ? Greek capital letter epsilon]
|
||||
[template Zeta[]'''Ζ'''] [/ ? Greek capital letter zeta]
|
||||
[template Eta[]'''Η'''] [/ ? Greek capital letter eta]
|
||||
[template Theta[]'''Θ'''] [/ T Greek capital letter theta]
|
||||
[template Iota[]'''Ι'''] [/ ? Greek capital letter iota]
|
||||
[template Kappa[]'''Κ'''] [/ ? Greek capital letter kappa]
|
||||
[template Lambda[]'''Λ'''] [/ ? Greek capital letter lambda]
|
||||
[template Mu[]'''Μ'''] [/ ? Greek capital letter mu]
|
||||
[template Nu[]'''Ν'''] [/ ? Greek capital letter nu]
|
||||
[template Xi[]'''Ξ'''] [/ ? Greek capital letter xi]
|
||||
[template Omicron[]'''Ο'''] [/ ? Greek capital letter omicron]
|
||||
[template Pi[]'''Π'''] [/ ? Greek capital letter pi]
|
||||
[template Rho[]'''Ρ'''] [/ ? Greek capital letter rho]
|
||||
[template Sigma[]'''Σ'''] [/ S Greek capital letter sigma]
|
||||
[template Tau[]'''Τ'''] [/ ? Greek capital letter tau]
|
||||
[template Upsilon[]'''Υ'''] [/ ? Greek capital letter upsilon]
|
||||
[template Phi[]'''Φ'''] [/ F Greek capital letter phi]
|
||||
[template Chi[]'''Χ'''] [/ ? Greek capital letter chi]
|
||||
[template Psi[]'''Ψ'''] [/ ? Greek capital letter psi]
|
||||
[template Omega[]'''Ω'''] [/ O Greek capital letter omega]
|
||||
[template alpha[]'''α'''] [/ a Greek small letter alpha]
|
||||
[template beta[]'''β'''] [/ ß Greek small letter beta]
|
||||
[template gamma[]'''γ'''] [/ ? Greek small letter gamma]
|
||||
[template delta[]'''δ'''] [/ d Greek small letter delta]
|
||||
[template epsilon[]'''ε'''] [/ e Greek small letter epsilon]
|
||||
[template zeta[]'''ζ'''] [/ ? Greek small letter zeta]
|
||||
[template eta[]'''η'''] [/ ? Greek small letter eta]
|
||||
[template theta[]'''θ'''] [/ ? Greek small letter theta]
|
||||
[template iota[]'''ι'''] [/ ? Greek small letter iota]
|
||||
[template kappa[]'''κ'''] [/ ? Greek small letter kappa]
|
||||
[template lambda[]'''λ'''] [/ ? Greek small letter lambda]
|
||||
[template mu[]'''μ'''] [/ µ Greek small letter mu]
|
||||
[template nu[]'''ν'''] [/ ? Greek small letter nu]
|
||||
[template xi[]'''ξ'''] [/ ? Greek small letter xi]
|
||||
[template omicron[]'''ο'''] [/ ? Greek small letter omicron]
|
||||
[template pi[]'''π'''] [/ p Greek small letter pi]
|
||||
[template rho[]'''ρ'''] [/ ? Greek small letter rho]
|
||||
[template sigmaf[]'''ς'''] [/ ? Greek small letter final sigma]
|
||||
[template sigma[]'''σ'''] [/ s Greek small letter sigma]
|
||||
[template tau[]'''τ'''] [/ t Greek small letter tau]
|
||||
[template upsilon[]'''υ'''] [/ ? Greek small letter upsilon]
|
||||
[template phi[]'''φ'''] [/ f Greek small letter phi]
|
||||
[template chi[]'''χ'''] [/ ? Greek small letter chi]
|
||||
[template psi[]'''ψ'''] [/ ? Greek small letter psi]
|
||||
[template omega[]'''ω'''] [/ ? Greek small letter omega]
|
||||
[template thetasym[]'''ϑ'''] [/ ? Greek small letter theta symbol]
|
||||
[template upsih[]'''ϒ'''] [/ ? Greek upsilon with hook symbol]
|
||||
[template piv[]'''ϖ'''] [/ ? Greek pi symbol]
|
||||
|
||||
[template bull[]'''•'''] [/ • bullet = black small circle]
|
||||
[template hellip[]'''…'''] [/ … horizontal ellipsis = three dot leader]
|
||||
[template prime[]'''′'''] [/ ' prime = minutes = feet]
|
||||
[template Prime[]'''″'''] [/ ? double prime = seconds = inches]
|
||||
[template oline[]'''‾'''] [/ ? overline = spacing overscore]
|
||||
[template frasl[]'''⁄'''] [/ / fraction slash]
|
||||
[template weierp[]'''℘'''] [/ P script capital P = power set = Weierstrass p]
|
||||
[template image[]'''ℑ'''] [/ I blackletter capital I = imaginary part]
|
||||
[template real[]'''ℜ'''] [/ R blackletter capital R = real part symbol]
|
||||
[template trade[]'''™'''] [/ ™ trade mark sign]
|
||||
[template alefsym[]'''ℵ'''] [/ ? alef symbol = first transfinite cardinal]
|
||||
[template larr[]'''←'''] [/ ? leftwards arrow]
|
||||
[template uarr[]'''↑'''] [/ ? upwards arrow]
|
||||
[template rarr[]'''→'''] [/ ? rightwards arrow]
|
||||
[template darr[]'''↓'''] [/ ? downwards arrow]
|
||||
[template harr[]'''↔'''] [/ ? left right arrow]
|
||||
[template crarr[]'''↵'''] [/ ? downwards arrow with corner leftwards = CR]
|
||||
[template lArr[]'''⇐'''] [/ ? leftwards double arrow]
|
||||
[template uArr[]'''⇑'''] [/ ? upwards double arrow]
|
||||
[template rArr[]'''⇒'''] [/ ? rightwards double arrow]
|
||||
[template dArr[]'''⇓'''] [/ ? downwards double arrow]
|
||||
[template hArr[]'''⇔'''] [/ ? left right double arrow]
|
||||
[template forall[]'''∀'''] [/ ? for all]
|
||||
[template part[]'''∂'''] [/ ? partial differential]
|
||||
[template exist[]'''∃'''] [/ ? there exists]
|
||||
[template empty[]'''∅'''] [/ Ø empty set = null set = diameter]
|
||||
[template nabla[]'''∇'''] [/ ? nabla = backward difference]
|
||||
[template isin[]'''∈'''] [/ ? element of]
|
||||
[template notin[]'''∉'''] [/ ? not an element of]
|
||||
[template ni[]'''∋'''] [/ ? contains as member]
|
||||
[template prod[]'''∏'''] [/ ? n-ary product = product sign]
|
||||
[template sum[]'''∑'''] [/ ? n-ary sumation]
|
||||
[template minus[]'''−'''] [/ - minus sign]
|
||||
[template lowast[]'''∗'''] [/ * asterisk operator]
|
||||
[template radic[]'''√'''] [/ v square root = radical sign]
|
||||
[template prop[]'''∝'''] [/ ? proportional to]
|
||||
[template infin[]'''∞'''] [/ 8 infinity]
|
||||
[template ang[]'''∠'''] [/ ? angle]
|
||||
[template and[]'''∧'''] [/ ? logical and = wedge]
|
||||
[template or[]'''∨'''] [/ ? logical or = vee]
|
||||
[template cap[]'''∩'''] [/ n intersection = cap]
|
||||
[template cup[]'''∪'''] [/ ? union = cup]
|
||||
[template int[]'''∫'''] [/ ? integral]
|
||||
[template there4[]'''∴'''] [/ ? therefore]
|
||||
[template sim[]'''∼'''] [/ ~ tilde operator = varies with = similar to]
|
||||
[template cong[]'''≅'''] [/ ? approximately equal to]
|
||||
[template asymp[]'''≈'''] [/ ˜ almost equal to = asymptotic to]
|
||||
[template ne[]'''≠'''] [/ ? not equal to]
|
||||
[template equiv[]'''≡'''] [/ = identical to]
|
||||
[template le[]'''≤'''] [/ = less-than or equal to]
|
||||
[template ge[]'''≥'''] [/ = greater-than or equal to]
|
||||
[template subset[]'''⊂'''] [/ ? subset of]
|
||||
[template superset[]'''⊃'''] [/ ? superset of]
|
||||
[template nsubset[]'''⊄'''] [/ ? not a subset of]
|
||||
[template sube[]'''⊆'''] [/ ? subset of or equal to]
|
||||
[template supe[]'''⊇'''] [/ ? superset of or equal to]
|
||||
[template oplus[]'''⊕'''] [/ ? circled plus = direct sum]
|
||||
[template otimes[]'''⊗'''] [/ ? circled times = vector product]
|
||||
[template perp[]'''⊥'''] [/ ? up tack = orthogonal to = perpendicular]
|
||||
[template sdot[]'''⋅'''] [/ · dot operator]
|
||||
[template lceil[]'''⌈'''] [/ ? left ceiling = APL upstile]
|
||||
[template rceil[]'''⌉'''] [/ ? right ceiling]
|
||||
[template lfloor[]'''⌊'''] [/ ? left floor = APL downstile]
|
||||
[template rfloor[]'''⌋'''] [/ ? right floor]
|
||||
[template lang[]'''〈'''] [/ < left-pointing angle bracket = bra (Firefox shows ?)]
|
||||
[template rang[]'''〉'''] [/ > right-pointing angle bracket = ket (Firefox shows ?)]
|
||||
[template loz[]'''◊'''] [/ ? lozenge]
|
||||
[template spades[]'''♠'''] [/ ? black spade suit]
|
||||
[template clubs[]'''♣'''] [/ ? black club suit = shamrock]
|
||||
[template hearts[]'''♥'''] [/ ? black heart suit = valentine]
|
||||
[template diams[]'''♦'''] [/ ? black diamond suit]
|
||||
[template euro[]'''€'''] [/ ? Euro currency symbol]
|
||||
[template lchev[]'''⟨'''] [/ ? left chevron]
|
||||
[template rchev[]'''⟩'''] [/ right chevron]
|
||||
[template rflat[]'''⟮'''] [/ right flat bracket Misc Math Symbol A]
|
||||
[template lflat[]'''⟮'''] [/ left flat bracket]
|
||||
[/ U2000.pdf punctuation]
|
||||
[template endash[]'''–'''] [/ em width dash]
|
||||
[template emdash[]'''—'''] [/ en width dash]
|
||||
[template hbar[]'''―'''] [/ ? horizontal bar - introducing quoted text]
|
||||
[template vert2bar[]'''‖'''] [/ ? double vertical bar]
|
||||
[template line2[]'''‖'''] [/ ? double low line bar]
|
||||
[template dagger[]'''†'''] [/ ? dagger]
|
||||
[template dagger2[]'''‡'''] [/ ? double dagger]
|
||||
[template dot[]'''․'''] [/ dot leader]
|
||||
[template dot2[]'''‥'''] [/ ? dots leader]
|
||||
[template ellipsis[]'''…'''] [/ horizontal ellipsis]
|
||||
|
||||
[template dotover[]'''̇'''] [/ dot over symbol]
|
||||
[template recur[]''' ̇'''] [/ math recurring symbol, eg after 0.333]
|
||||
[/ Note use of a thin space before digit, so that dot isn't placed directly over the digit.]
|
||||
[/ Use:1[recur]]
|
||||
|
||||
[/ Other symbols, not in the HTML4 list:]
|
||||
[template enquad[] ''' '''] [/ en quad space]
|
||||
[template emquad[] ''' '''] [/ em quad space]
|
||||
[template enspace[] ''' '''] [/ em half en space]
|
||||
[template emspace[] ''' '''] [/ em space type size in points]
|
||||
[template thickspace[] ''' '''] [/ 3 per em space]
|
||||
[template midspace[] ''' '''] [/ 4 per em space]
|
||||
[template sixemspace[] ''' '''] [/ 6 em space]
|
||||
[template figspace[] ''' '''] [/ space = width fixed font digit]
|
||||
[template punctspace[] ''' '''] [/ space = width punctuation]
|
||||
[template thin[] ''' '''] [/ thin space ]
|
||||
[template hair[] ''' '''] [/ hair space]
|
||||
[template nbsp[] ''' '''] [/ non-breaking space]
|
||||
[template space[] ''' '''] [/ plain non-breaking space]
|
||||
|
||||
[template nospace[] '''​'''] [/ zero width space]
|
||||
[template wordjoin[] '''⁠'''] [/ word joiner - no line break either side]
|
||||
[template narrownbsp[] ''' '''] [/ narrow non-breaking space]
|
||||
[template hyphen[] '''‐'''] [/ soft hyphen]
|
||||
[template nbhyphen[] '''‑'''] [/ non-breaking hyphen]
|
||||
|
||||
[template plusminus[]'''±'''] [/ ? plus or minus sign]
|
||||
[template sqrt[]'''√'''] [/ ? square root sqrt symbol]
|
||||
[/template pow2[]'''⁳'''] [/ 2073 is NOT superscript 2 character]
|
||||
[template pow2[]'''²'''] [/ superscript 2 character]
|
||||
[template pow3[]'''³'''] [/ superscript 3 character]
|
||||
[template pown[]'''ⁿ'''] [/ superscript n character]
|
||||
[template frac12[]'''½'''] [/ fraction half]
|
||||
[template frac14[]'''¼'''] [/ fraction quarter]
|
||||
[template frac34[]'''¾'''] [/ fraction three quarter]
|
||||
[template sup1[]'''¹'''] [/ superscript one = superscript digit one ]
|
||||
[template sup2[]'''²'''] [/ superscript two = superscript digit two = squared ]
|
||||
[template cubed[]'''³'''] [/ superscript three = superscript digit three = cubed ]
|
||||
[template macron[]'''¯'''] [/ macron = spacing macron = overline = APL overbar ]
|
||||
[template deg[]'''°'''] [/ degree sign ]
|
||||
[template plusmn[]'''±'''] [/ plus-minus sign = plus-or-minus sign ]
|
||||
[template micro[]'''µ'''] [/ micro sign ]
|
||||
[template cedil[]'''¸'''] [/ cedilla = spacing cedilla ]
|
||||
[template ordm[]'''º'''] [/ masculine ordinal indicator ]
|
||||
[template ordf[]'''ª'''] [/ feminine ordinal indicator ]
|
||||
[template laquo[]'''«'''] [/ left-pointing double angle quotation mark = left pointing guillemet ]
|
||||
[template raquo[]'''»'''] [/ right-pointing double angle quotation mark = right pointing guillemet ]
|
||||
|
||||
[/
|
||||
Copyright 2007, 2010 Paul A. Bristow.
|
||||
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).
|
||||
]
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Copyright 2011 John Maddock. 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)
|
||||
#
|
||||
# Rewrite the class scanner to accept declarations, not just definitions,
|
||||
# as the docs don't include full definitions.
|
||||
#
|
||||
!define-scanner class_name "^[[:space:]]*(template[[:space:]]*<[^;:{]+>[[:space:]]*)?(class|struct)[[:space:]]*(\<\w+\>([[:blank:]]*\([^)]*\))?[[:space:]]*)*(\<\w*\>)[[:space:]]*(<[^;:{]+>)?[[:space:]]*(\{|:[^;\{()]*\{)" "(?:class|struct)[^;{]+\\<\5\\>\\s*[;{]" \5
|
||||
|
||||
!scan-path boost/multiprecision .*\.hpp true
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2011 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
#include <boost/math/special_functions/gamma.hpp>
|
||||
#include <iostream>
|
||||
|
||||
void t1()
|
||||
{
|
||||
//[cpp_dec_float_eg
|
||||
//=#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
// Operations at fixed precision and full numeric_limits support:
|
||||
cpp_dec_float_100 b = 2;
|
||||
std::cout << std::numeric_limits<cpp_dec_float_100>::digits << std::endl;
|
||||
// Note that digits10 is the same as digits, since we're base 10! :
|
||||
std::cout << std::numeric_limits<cpp_dec_float_100>::digits10 << std::endl;
|
||||
// We can use any C++ std lib function, lets print all the digits as well:
|
||||
std::cout << std::setprecision(std::numeric_limits<cpp_dec_float_100>::max_digits10)
|
||||
<< log(b) << std::endl; // print log(2)
|
||||
// We can also use any function from Boost.Math:
|
||||
std::cout << boost::math::tgamma(b) << std::endl;
|
||||
// These even work when the argument is an expression template:
|
||||
std::cout << boost::math::tgamma(b * b) << std::endl;
|
||||
// And since we have an extended exponent range we can generate some really large
|
||||
// numbers here (4.0238726007709377354370243e+2564):
|
||||
std::cout << boost::math::tgamma(cpp_dec_float_100(1000)) << std::endl;
|
||||
//]
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
t1();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2011 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <iostream>
|
||||
|
||||
void t1()
|
||||
{
|
||||
//[cpp_int_eg
|
||||
//=#include <boost/multiprecision/cpp_int.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
int128_t v = 1;
|
||||
|
||||
// Do some fixed precision arithmetic:
|
||||
for(unsigned i = 1; i <= 20; ++i)
|
||||
v *= i;
|
||||
|
||||
std::cout << v << std::endl; // prints 20!
|
||||
|
||||
// Repeat at arbitrary precision:
|
||||
cpp_int u = 1;
|
||||
for(unsigned i = 1; i <= 100; ++i)
|
||||
u *= i;
|
||||
|
||||
std::cout << u << std::endl; // prints 100!
|
||||
|
||||
//]
|
||||
}
|
||||
|
||||
void t3()
|
||||
{
|
||||
//[cpp_rational_eg
|
||||
//=#include <boost/multiprecision/cpp_int.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
cpp_rational v = 1;
|
||||
|
||||
// Do some arithmetic:
|
||||
for(unsigned i = 1; i <= 1000; ++i)
|
||||
v *= i;
|
||||
v /= 10;
|
||||
|
||||
std::cout << v << std::endl; // prints 1000! / 10
|
||||
std::cout << numerator(v) << std::endl;
|
||||
std::cout << denominator(v) << std::endl;
|
||||
|
||||
cpp_rational w(2, 3); // component wise constructor
|
||||
std::cout << w << std::endl; // prints 2/3
|
||||
//]
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
t1();
|
||||
t3();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,687 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
#include <boost/math/special_functions/gamma.hpp>
|
||||
#include <boost/math/special_functions/bessel.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <array>
|
||||
|
||||
//[AOS1
|
||||
|
||||
/*`Generic numeric programming employs templates to use the same code for different
|
||||
floating-point types and functions. Consider the area of a circle a of radius r, given by
|
||||
|
||||
[:['a = [pi] * r[super 2]]]
|
||||
|
||||
The area of a circle can be computed in generic programming using Boost.Math
|
||||
for the constant [pi] as shown below:
|
||||
|
||||
*/
|
||||
|
||||
//=#include <boost/math/constants/constants.hpp>
|
||||
|
||||
template<typename T>
|
||||
inline T area_of_a_circle(T r)
|
||||
{
|
||||
using boost::math::constants::pi;
|
||||
return pi<T>() * r * r;
|
||||
}
|
||||
|
||||
/*`
|
||||
It is possible to use `area_of_a_circle()` with built-in floating-point types as
|
||||
well as floating-point types from Boost.Multiprecision. In particular, consider a
|
||||
system with 4-byte single-precision float, 8-byte double-precision double and also the
|
||||
`cpp_dec_float_50` data type from Boost.Multiprecision with 50 decimal digits
|
||||
of precision.
|
||||
|
||||
We can compute and print the approximate area of a circle with radius 123/100 for
|
||||
`float`, `double` and `cpp_dec_float_50` with the program below.
|
||||
|
||||
*/
|
||||
|
||||
//]
|
||||
|
||||
//[AOS3
|
||||
|
||||
/*`In the next example we'll look at calling both standard library and Boost.Math functions from within generic code.
|
||||
We'll also show how to cope with template arguments which are expression-templates rather than number types.*/
|
||||
|
||||
//]
|
||||
|
||||
//[JEL
|
||||
|
||||
/*`
|
||||
In this example we'll show several implementations of the
|
||||
[@http://mathworld.wolfram.com/LambdaFunction.html Jahnke and Emden Lambda function],
|
||||
each implementation a little more sophisticated than the last.
|
||||
|
||||
The Jahnke-Emden Lambda function is defined by the equation:
|
||||
|
||||
[:['JahnkeEmden(v, z) = [Gamma](v+1) * J[sub v](z) / (z / 2)[super v]]]
|
||||
|
||||
If we were to implement this at double precision using Boost.Math's facilities for the Gamma and Bessel
|
||||
function calls it would look like this:
|
||||
|
||||
*/
|
||||
|
||||
double JEL1(double v, double z)
|
||||
{
|
||||
return boost::math::tgamma(v + 1) * boost::math::cyl_bessel_j(v, z) / std::pow(z / 2, v);
|
||||
}
|
||||
|
||||
/*`
|
||||
Calling this function as:
|
||||
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<double>::digits10);
|
||||
std::cout << JEL1(2.5, 0.5) << std::endl;
|
||||
|
||||
Yields the output:
|
||||
|
||||
[pre 9.822663964796047e-001]
|
||||
|
||||
Now let's implement the function again, but this time using the multiprecision type
|
||||
`cpp_dec_float_50` as the argument type:
|
||||
|
||||
*/
|
||||
|
||||
boost::multiprecision::cpp_dec_float_50
|
||||
JEL2(boost::multiprecision::cpp_dec_float_50 v, boost::multiprecision::cpp_dec_float_50 z)
|
||||
{
|
||||
return boost::math::tgamma(v + 1) * boost::math::cyl_bessel_j(v, z) / boost::multiprecision::pow(z / 2, v);
|
||||
}
|
||||
|
||||
/*`
|
||||
The implementation is almost the same as before, but with one key difference - we can no longer call
|
||||
`std::pow`, instead we must call the version inside the `boost::multiprecision` namespace. In point of
|
||||
fact, we could have omitted the namespace prefix on the call to `pow` since the right overload would
|
||||
have been found via [@http://en.wikipedia.org/wiki/Argument-dependent_name_lookup
|
||||
argument dependent lookup] in any case.
|
||||
|
||||
Note also that the first argument to `pow` along with the argument to `tgamma` in the above code
|
||||
are actually expression templates. The `pow` and `tgamma` functions will handle these arguments
|
||||
just fine.
|
||||
|
||||
Here's an example of how the function may be called:
|
||||
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<cpp_dec_float_50>::digits10);
|
||||
std::cout << JEL2(cpp_dec_float_50(2.5), cpp_dec_float_50(0.5)) << std::endl;
|
||||
|
||||
Which outputs:
|
||||
|
||||
[pre 9.82266396479604757017335009796882833995903762577173e-01]
|
||||
|
||||
Now that we've seen some non-template examples, lets repeat the code again, but this time as a template
|
||||
that can be called either with a builtin type (`float`, `double` etc), or with a multiprecision type:
|
||||
|
||||
*/
|
||||
|
||||
template <class Float>
|
||||
Float JEL3(Float v, Float z)
|
||||
{
|
||||
using std::pow;
|
||||
return boost::math::tgamma(v + 1) * boost::math::cyl_bessel_j(v, z) / pow(z / 2, v);
|
||||
}
|
||||
|
||||
/*`
|
||||
|
||||
Once again the code is almost the same as before, but the call to `pow` has changed yet again.
|
||||
We need the call to resolve to either `std::pow` (when the argument is a builtin type), or
|
||||
to `boost::multiprecision::pow` (when the argument is a multiprecision type). We do that by
|
||||
making the call unqualified so that versions of `pow` defined in the same namespace as type
|
||||
`Float` are found via argument dependent lookup, while the `using std::pow` directive makes
|
||||
the standard library versions visible for builtin floating point types.
|
||||
|
||||
Let's call the function with both `double` and multiprecision arguments:
|
||||
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<double>::digits10);
|
||||
std::cout << JEL3(2.5, 0.5) << std::endl;
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<cpp_dec_float_50>::digits10);
|
||||
std::cout << JEL3(cpp_dec_float_50(2.5), cpp_dec_float_50(0.5)) << std::endl;
|
||||
|
||||
Which outputs:
|
||||
|
||||
[pre
|
||||
9.822663964796047e-001
|
||||
9.82266396479604757017335009796882833995903762577173e-01
|
||||
]
|
||||
|
||||
Unfortunately there is a problem with this version: if we were to call it like this:
|
||||
|
||||
boost::multiprecision::cpp_dec_float_50 v(2), z(0.5);
|
||||
JEL3(v + 0.5, z);
|
||||
|
||||
Then we would get a long and inscrutable error message from the compiler: the problem here is that the first
|
||||
argument to `JEL3` is not a number type, but an expression template. We could obviously add a typecast to
|
||||
fix the issue:
|
||||
|
||||
JEL(cpp_dec_float_50(v + 0.5), z);
|
||||
|
||||
However, if we want the function JEL to be truely reusable, then a better solution might be preferred.
|
||||
To achieve this we can borrow some code from Boost.Math which calculates the return type of mixed-argument
|
||||
functions, here's how the new code looks now:
|
||||
|
||||
*/
|
||||
|
||||
template <class Float1, class Float2>
|
||||
typename boost::math::tools::promote_args<Float1, Float2>::type
|
||||
JEL4(Float1 v, Float2 z)
|
||||
{
|
||||
using std::pow;
|
||||
return boost::math::tgamma(v + 1) * boost::math::cyl_bessel_j(v, z) / pow(z / 2, v);
|
||||
}
|
||||
|
||||
/*`
|
||||
|
||||
As you can see the two arguments to the function are now separate template types, and
|
||||
the return type is computed using the `promote_args` metafunction from Boost.Math.
|
||||
|
||||
Now we can call:
|
||||
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<cpp_dec_float_100>::digits10);
|
||||
std::cout << JEL4(cpp_dec_float_100(2) + 0.5, cpp_dec_float_100(0.5)) << std::endl;
|
||||
|
||||
And get 100 digits of output:
|
||||
|
||||
[pre 9.8226639647960475701733500979688283399590376257717309069410413822165082248153638454147004236848917775e-01]
|
||||
|
||||
As a bonus, we can now call the function not just with expression templates, but with other mixed types as well:
|
||||
for example `float` and `double` or `int` and `double`, and the correct return type will be computed in each case.
|
||||
|
||||
Note that while in this case we didn't have to change the body of the function, in the general case
|
||||
any function like this which creates local variables internally would have to use `promote_args`
|
||||
to work out what type those variables should be, for example:
|
||||
|
||||
template <class Float1, class Float2>
|
||||
typename boost::math::tools::promote_args<Float1, Float2>::type
|
||||
JEL5(Float1 v, Float2 z)
|
||||
{
|
||||
using std::pow;
|
||||
typedef typename boost::math::tools::promote_args<Float1, Float2>::type variable_type;
|
||||
variable_type t = pow(z / 2, v);
|
||||
return boost::math::tgamma(v + 1) * boost::math::cyl_bessel_j(v, z) / t;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
//]
|
||||
|
||||
//[ND1
|
||||
|
||||
/*`
|
||||
In this example we'll add even more power to generic numeric programming using not only different
|
||||
floating-point types but also function objects as template parameters. Consider
|
||||
some well-known central difference rules for numerically computing the first derivative
|
||||
of a function ['f[prime](x)] with ['x [isin] [real]]:
|
||||
|
||||
[equation floating_point_eg1]
|
||||
|
||||
Where the difference terms ['m[sub n]] are given by:
|
||||
|
||||
[equation floating_point_eg2]
|
||||
|
||||
and ['dx] is the step-size of the derivative.
|
||||
|
||||
The third formula in Equation 1 is a three-point central difference rule. It calculates
|
||||
the first derivative of ['f[prime](x)] to ['O(dx[super 6])], where ['dx] is the given step-size.
|
||||
For example, if
|
||||
the step-size is 0.01 this derivative calculation has about 6 decimal digits of precision -
|
||||
just about right for the 7 decimal digits of single-precision float.
|
||||
Let's make a generic template subroutine using this three-point central difference
|
||||
rule. In particular:
|
||||
*/
|
||||
|
||||
template<typename value_type, typename function_type>
|
||||
value_type derivative(const value_type x, const value_type dx, function_type func)
|
||||
{
|
||||
// Compute d/dx[func(*first)] using a three-point
|
||||
// central difference rule of O(dx^6).
|
||||
|
||||
const value_type dx1 = dx;
|
||||
const value_type dx2 = dx1 * 2;
|
||||
const value_type dx3 = dx1 * 3;
|
||||
|
||||
const value_type m1 = (func(x + dx1) - func(x - dx1)) / 2;
|
||||
const value_type m2 = (func(x + dx2) - func(x - dx2)) / 4;
|
||||
const value_type m3 = (func(x + dx3) - func(x - dx3)) / 6;
|
||||
|
||||
const value_type fifteen_m1 = 15 * m1;
|
||||
const value_type six_m2 = 6 * m2;
|
||||
const value_type ten_dx1 = 10 * dx1;
|
||||
|
||||
return ((fifteen_m1 - six_m2) + m3) / ten_dx1;
|
||||
}
|
||||
|
||||
/*`The `derivative()` template function can be used to compute the first derivative
|
||||
of any function to ['O(dx[super 6])]. For example, consider the first derivative of ['sin(x)] evaluated
|
||||
at ['x = [pi]/3]. In other words,
|
||||
|
||||
[equation floating_point_eg3]
|
||||
|
||||
The code below computes the derivative in Equation 3 for float, double and boost's
|
||||
multiple-precision type cpp_dec_float_50.
|
||||
*/
|
||||
|
||||
//]
|
||||
|
||||
//[GI1
|
||||
|
||||
/*`
|
||||
Similar to the generic derivative example, we can calculate integrals in a similar manner:
|
||||
*/
|
||||
|
||||
template<typename value_type, typename function_type>
|
||||
inline value_type integral(const value_type a,
|
||||
const value_type b,
|
||||
const value_type tol,
|
||||
function_type func)
|
||||
{
|
||||
unsigned n = 1U;
|
||||
|
||||
value_type h = (b - a);
|
||||
value_type I = (func(a) + func(b)) * (h / 2);
|
||||
|
||||
for(unsigned k = 0U; k < 8U; k++)
|
||||
{
|
||||
h /= 2;
|
||||
|
||||
value_type sum(0);
|
||||
for(unsigned j = 1U; j <= n; j++)
|
||||
{
|
||||
sum += func(a + (value_type((j * 2) - 1) * h));
|
||||
}
|
||||
|
||||
const value_type I0 = I;
|
||||
I = (I / 2) + (h * sum);
|
||||
|
||||
const value_type ratio = I0 / I;
|
||||
const value_type delta = ratio - 1;
|
||||
const value_type delta_abs = ((delta < 0) ? -delta : delta);
|
||||
|
||||
if((k > 1U) && (delta_abs < tol))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
n *= 2U;
|
||||
}
|
||||
|
||||
return I;
|
||||
}
|
||||
|
||||
/*`
|
||||
The following sample program shows how the function can be called, we begin
|
||||
by defining a function object, which when integrated should yield the Bessel J
|
||||
function:
|
||||
*/
|
||||
|
||||
template<typename value_type>
|
||||
class cyl_bessel_j_integral_rep
|
||||
{
|
||||
public:
|
||||
cyl_bessel_j_integral_rep(const unsigned N,
|
||||
const value_type& X) : n(N), x(X) { }
|
||||
|
||||
value_type operator()(const value_type& t) const
|
||||
{
|
||||
// pi * Jn(x) = Int_0^pi [cos(x * sin(t) - n*t) dt]
|
||||
return cos(x * sin(t) - (n * t));
|
||||
}
|
||||
|
||||
private:
|
||||
const unsigned n;
|
||||
const value_type x;
|
||||
};
|
||||
|
||||
|
||||
//]
|
||||
|
||||
//[POLY
|
||||
|
||||
/*`
|
||||
In this example we'll look at polynomial evaluation, this is not only an important
|
||||
use case, but it's one that `number` performs particularly well at because the
|
||||
expression templates ['completely eliminate all temporaries] from a
|
||||
[@http://en.wikipedia.org/wiki/Horner%27s_method Horner polynomial
|
||||
evaluation scheme].
|
||||
|
||||
The following code evaluates `sin(x)` as a polynomial, accurate to at least 64 decimal places:
|
||||
|
||||
*/
|
||||
|
||||
using boost::multiprecision::cpp_dec_float;
|
||||
typedef boost::multiprecision::number<cpp_dec_float<64> > mp_type;
|
||||
|
||||
mp_type mysin(const mp_type& x)
|
||||
{
|
||||
// Approximation of sin(x * pi/2) for -1 <= x <= 1, using an order 63 polynomial.
|
||||
static const std::array<mp_type, 32U> coefs =
|
||||
{{
|
||||
mp_type("+1.5707963267948966192313216916397514420985846996875529104874722961539082031431044993140174126711"), //"),
|
||||
mp_type("-0.64596409750624625365575656389794573337969351178927307696134454382929989411386887578263960484"), // ^3
|
||||
mp_type("+0.07969262624616704512050554949047802252091164235106119545663865720995702920146198554317279"), // ^5
|
||||
mp_type("-0.0046817541353186881006854639339534378594950280185010575749538605102665157913157426229824"), // ^7
|
||||
mp_type("+0.00016044118478735982187266087016347332970280754062061156858775174056686380286868007443"), // ^9
|
||||
mp_type("-3.598843235212085340458540018208389404888495232432127661083907575106196374913134E-6"), // ^11
|
||||
mp_type("+5.692172921967926811775255303592184372902829756054598109818158853197797542565E-8"), // ^13
|
||||
mp_type("-6.688035109811467232478226335783138689956270985704278659373558497256423498E-10"), // ^15
|
||||
mp_type("+6.066935731106195667101445665327140070166203261129845646380005577490472E-12"), // ^17
|
||||
mp_type("-4.377065467313742277184271313776319094862897030084226361576452003432E-14"), // ^19
|
||||
mp_type("+2.571422892860473866153865950420487369167895373255729246889168337E-16"), // ^21
|
||||
mp_type("-1.253899540535457665340073300390626396596970180355253776711660E-18"), // ^23
|
||||
mp_type("+5.15645517658028233395375998562329055050964428219501277474E-21"), // ^25
|
||||
mp_type("-1.812399312848887477410034071087545686586497030654642705E-23"), // ^27
|
||||
mp_type("+5.50728578652238583570585513920522536675023562254864E-26"), // ^29
|
||||
mp_type("-1.461148710664467988723468673933026649943084902958E-28"), // ^31
|
||||
mp_type("+3.41405297003316172502972039913417222912445427E-31"), // ^33
|
||||
mp_type("-7.07885550810745570069916712806856538290251E-34"), // ^35
|
||||
mp_type("+1.31128947968267628970845439024155655665E-36"), // ^37
|
||||
mp_type("-2.18318293181145698535113946654065918E-39"), // ^39
|
||||
mp_type("+3.28462680978498856345937578502923E-42"), // ^41
|
||||
mp_type("-4.48753699028101089490067137298E-45"), // ^43
|
||||
mp_type("+5.59219884208696457859353716E-48"), // ^45
|
||||
mp_type("-6.38214503973500471720565E-51"), // ^47
|
||||
mp_type("+6.69528558381794452556E-54"), // ^49
|
||||
mp_type("-6.47841373182350206E-57"), // ^51
|
||||
mp_type("+5.800016389666445E-60"), // ^53
|
||||
mp_type("-4.818507347289E-63"), // ^55
|
||||
mp_type("+3.724683686E-66"), // ^57
|
||||
mp_type("-2.6856479E-69"), // ^59
|
||||
mp_type("+1.81046E-72"), // ^61
|
||||
mp_type("-1.133E-75"), // ^63
|
||||
}};
|
||||
|
||||
const mp_type v = x * 2 / boost::math::constants::pi<mp_type>();
|
||||
const mp_type x2 = (v * v);
|
||||
//
|
||||
// Polynomial evaluation follows, if mp_type allocates memory then
|
||||
// just one such allocation occurs - to initialize the variable "sum" -
|
||||
// and no temporaries are created at all.
|
||||
//
|
||||
const mp_type sum = ((((((((((((((((((((((((((((((( + coefs[31U]
|
||||
* x2 + coefs[30U])
|
||||
* x2 + coefs[29U])
|
||||
* x2 + coefs[28U])
|
||||
* x2 + coefs[27U])
|
||||
* x2 + coefs[26U])
|
||||
* x2 + coefs[25U])
|
||||
* x2 + coefs[24U])
|
||||
* x2 + coefs[23U])
|
||||
* x2 + coefs[22U])
|
||||
* x2 + coefs[21U])
|
||||
* x2 + coefs[20U])
|
||||
* x2 + coefs[19U])
|
||||
* x2 + coefs[18U])
|
||||
* x2 + coefs[17U])
|
||||
* x2 + coefs[16U])
|
||||
* x2 + coefs[15U])
|
||||
* x2 + coefs[14U])
|
||||
* x2 + coefs[13U])
|
||||
* x2 + coefs[12U])
|
||||
* x2 + coefs[11U])
|
||||
* x2 + coefs[10U])
|
||||
* x2 + coefs[9U])
|
||||
* x2 + coefs[8U])
|
||||
* x2 + coefs[7U])
|
||||
* x2 + coefs[6U])
|
||||
* x2 + coefs[5U])
|
||||
* x2 + coefs[4U])
|
||||
* x2 + coefs[3U])
|
||||
* x2 + coefs[2U])
|
||||
* x2 + coefs[1U])
|
||||
* x2 + coefs[0U])
|
||||
* v;
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
/*`
|
||||
Calling the function like so:
|
||||
|
||||
mp_type pid4 = boost::math::constants::pi<mp_type>() / 4;
|
||||
std::cout << std::setprecision(std::numeric_limits< ::mp_type>::digits10) << std::scientific;
|
||||
std::cout << mysin(pid4) << std::endl;
|
||||
|
||||
Yields the expected output:
|
||||
|
||||
[pre 7.0710678118654752440084436210484903928483593768847403658833986900e-01]
|
||||
|
||||
*/
|
||||
|
||||
//]
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::multiprecision;
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<double>::digits10);
|
||||
std::cout << JEL1(2.5, 0.5) << std::endl;
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<cpp_dec_float_50>::digits10);
|
||||
std::cout << JEL2(cpp_dec_float_50(2.5), cpp_dec_float_50(0.5)) << std::endl;
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<double>::digits10);
|
||||
std::cout << JEL3(2.5, 0.5) << std::endl;
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<cpp_dec_float_50>::digits10);
|
||||
std::cout << JEL3(cpp_dec_float_50(2.5), cpp_dec_float_50(0.5)) << std::endl;
|
||||
std::cout << std::scientific << std::setprecision(std::numeric_limits<cpp_dec_float_100>::digits10);
|
||||
std::cout << JEL4(cpp_dec_float_100(2) + 0.5, cpp_dec_float_100(0.5)) << std::endl;
|
||||
|
||||
//[AOS2
|
||||
|
||||
/*=#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
|
||||
using boost::multiprecision::cpp_dec_float_50;
|
||||
|
||||
int main(int, char**)
|
||||
{*/
|
||||
const float r_f(float(123) / 100);
|
||||
const float a_f = area_of_a_circle(r_f);
|
||||
|
||||
const double r_d(double(123) / 100);
|
||||
const double a_d = area_of_a_circle(r_d);
|
||||
|
||||
const cpp_dec_float_50 r_mp(cpp_dec_float_50(123) / 100);
|
||||
const cpp_dec_float_50 a_mp = area_of_a_circle(r_mp);
|
||||
|
||||
// 4.75292
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<float>::digits10)
|
||||
<< a_f
|
||||
<< std::endl;
|
||||
|
||||
// 4.752915525616
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<double>::digits10)
|
||||
<< a_d
|
||||
<< std::endl;
|
||||
|
||||
// 4.7529155256159981904701331745635599135018975843146
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<cpp_dec_float_50>::digits10)
|
||||
<< a_mp
|
||||
<< std::endl;
|
||||
/*=}*/
|
||||
|
||||
//]
|
||||
|
||||
//[ND2
|
||||
/*=
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <boost/multiprecision/cpp_dec_float.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
|
||||
int main(int, char**)
|
||||
{*/
|
||||
using boost::math::constants::pi;
|
||||
using boost::multiprecision::cpp_dec_float_50;
|
||||
//
|
||||
// We'll pass a function pointer for the function object passed to derivative,
|
||||
// the typecast is needed to select the correct overload of std::sin:
|
||||
//
|
||||
const float d_f = derivative(
|
||||
pi<float>() / 3,
|
||||
0.01F,
|
||||
static_cast<float(*)(float)>(std::sin)
|
||||
);
|
||||
|
||||
const double d_d = derivative(
|
||||
pi<double>() / 3,
|
||||
0.001,
|
||||
static_cast<double(*)(double)>(std::sin)
|
||||
);
|
||||
//
|
||||
// In the cpp_dec_float_50 case, the sin function is multiply overloaded
|
||||
// to handle expression templates etc. As a result it's hard to take its
|
||||
// address without knowing about its implementation details. We'll use a
|
||||
// C++11 lambda expression to capture the call.
|
||||
// We also need a typecast on the first argument so we don't accidently pass
|
||||
// an expression template to a template function:
|
||||
//
|
||||
const cpp_dec_float_50 d_mp = derivative(
|
||||
cpp_dec_float_50(pi<cpp_dec_float_50>() / 3),
|
||||
cpp_dec_float_50(1.0E-9),
|
||||
[](const cpp_dec_float_50& x) -> cpp_dec_float_50
|
||||
{
|
||||
return sin(x);
|
||||
}
|
||||
);
|
||||
|
||||
// 5.000029e-001
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<float>::digits10)
|
||||
<< d_f
|
||||
<< std::endl;
|
||||
|
||||
// 4.999999999998876e-001
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<double>::digits10)
|
||||
<< d_d
|
||||
<< std::endl;
|
||||
|
||||
// 4.99999999999999999999999999999999999999999999999999e-01
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<cpp_dec_float_50>::digits10)
|
||||
<< d_mp
|
||||
<< std::endl;
|
||||
//=}
|
||||
|
||||
/*`
|
||||
The expected value of the derivative is 0.5. This central difference rule in this
|
||||
example is ill-conditioned, meaning it suffers from slight loss of precision. With that
|
||||
in mind, the results agree with the expected value of 0.5.*/
|
||||
|
||||
//]
|
||||
|
||||
//[ND3
|
||||
|
||||
/*`
|
||||
We can take this a step further and use our derivative function to compute
|
||||
a partial derivative. For example if we take the incomplete gamma function
|
||||
['P(a, z)], and take the derivative with respect to /z/ at /(2,2)/ then we
|
||||
can calculate the result as shown below, for good measure we'll compare with
|
||||
the "correct" result obtained from a call to ['gamma_p_derivative], the results
|
||||
agree to approximately 44 digits:
|
||||
*/
|
||||
|
||||
cpp_dec_float_50 gd = derivative(
|
||||
cpp_dec_float_50(2),
|
||||
cpp_dec_float_50(1.0E-9),
|
||||
[](const cpp_dec_float_50& x) ->cpp_dec_float_50
|
||||
{
|
||||
return boost::math::gamma_p(2, x);
|
||||
}
|
||||
);
|
||||
// 2.70670566473225383787998989944968806815263091819151e-01
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<cpp_dec_float_50>::digits10)
|
||||
<< gd
|
||||
<< std::endl;
|
||||
// 2.70670566473225383787998989944968806815253190143120e-01
|
||||
std::cout << boost::math::gamma_p_derivative(cpp_dec_float_50(2), cpp_dec_float_50(2)) << std::endl;
|
||||
//]
|
||||
|
||||
//[GI2
|
||||
|
||||
/* The function can now be called as follows: */
|
||||
/*=int main(int, char**)
|
||||
{*/
|
||||
using boost::math::constants::pi;
|
||||
typedef boost::multiprecision::cpp_dec_float_50 mp_type;
|
||||
|
||||
const float j2_f =
|
||||
integral(0.0F,
|
||||
pi<float>(),
|
||||
0.01F,
|
||||
cyl_bessel_j_integral_rep<float>(2U, 1.23F)) / pi<float>();
|
||||
|
||||
const double j2_d =
|
||||
integral(0.0,
|
||||
pi<double>(),
|
||||
0.0001,
|
||||
cyl_bessel_j_integral_rep<double>(2U, 1.23)) / pi<double>();
|
||||
|
||||
const mp_type j2_mp =
|
||||
integral(mp_type(0),
|
||||
pi<mp_type>(),
|
||||
mp_type(1.0E-20),
|
||||
cyl_bessel_j_integral_rep<mp_type>(2U, mp_type(123) / 100)) / pi<mp_type>();
|
||||
|
||||
// 0.166369
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<float>::digits10)
|
||||
<< j2_f
|
||||
<< std::endl;
|
||||
|
||||
// 0.166369383786814
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<double>::digits10)
|
||||
<< j2_d
|
||||
<< std::endl;
|
||||
|
||||
// 0.16636938378681407351267852431513159437103348245333
|
||||
std::cout
|
||||
<< std::setprecision(std::numeric_limits<mp_type>::digits10)
|
||||
<< j2_mp
|
||||
<< std::endl;
|
||||
|
||||
//
|
||||
// Print true value for comparison:
|
||||
// 0.166369383786814073512678524315131594371033482453329
|
||||
std::cout << boost::math::cyl_bessel_j(2, mp_type(123) / 100) << std::endl;
|
||||
//=}
|
||||
|
||||
//]
|
||||
|
||||
std::cout << std::setprecision(std::numeric_limits< ::mp_type>::digits10) << std::scientific;
|
||||
std::cout << mysin(boost::math::constants::pi< ::mp_type>() / 4) << std::endl;
|
||||
std::cout << boost::multiprecision::sin(boost::math::constants::pi< ::mp_type>() / 4) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Program output:
|
||||
|
||||
9.822663964796047e-001
|
||||
9.82266396479604757017335009796882833995903762577173e-01
|
||||
9.822663964796047e-001
|
||||
9.82266396479604757017335009796882833995903762577173e-01
|
||||
9.8226639647960475701733500979688283399590376257717309069410413822165082248153638454147004236848917775e-01
|
||||
4.752916e+000
|
||||
4.752915525615998e+000
|
||||
4.75291552561599819047013317456355991350189758431460e+00
|
||||
5.000029e-001
|
||||
4.999999999998876e-001
|
||||
4.99999999999999999999999999999999999999999999999999e-01
|
||||
2.70670566473225383787998989944968806815263091819151e-01
|
||||
2.70670566473225383787998989944968806815253190143120e-01
|
||||
7.0710678118654752440084436210484903928483593768847403658833986900e-01
|
||||
7.0710678118654752440084436210484903928483593768847403658833986900e-01
|
||||
*/
|
||||
@@ -0,0 +1,97 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2011 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/gmp.hpp>
|
||||
#include <boost/math/special_functions/gamma.hpp>
|
||||
#include <iostream>
|
||||
|
||||
void t1()
|
||||
{
|
||||
//[mpz_eg
|
||||
//=#include <boost/multiprecision/gmp.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
mpz_int v = 1;
|
||||
|
||||
// Do some arithmetic:
|
||||
for(unsigned i = 1; i <= 1000; ++i)
|
||||
v *= i;
|
||||
|
||||
std::cout << v << std::endl; // prints 1000!
|
||||
|
||||
// Access the underlying representation:
|
||||
mpz_t z;
|
||||
mpz_init(z);
|
||||
mpz_set(z, v.backend().data());
|
||||
//]
|
||||
}
|
||||
|
||||
void t2()
|
||||
{
|
||||
//[mpf_eg
|
||||
//=#include <boost/multiprecision/gmp.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
// Operations at variable precision and limited standard library support:
|
||||
mpf_float a = 2;
|
||||
mpf_float::default_precision(1000);
|
||||
std::cout << mpf_float::default_precision() << std::endl;
|
||||
std::cout << sqrt(a) << std::endl; // print root-2
|
||||
|
||||
// Operations at fixed precision and full standard library support:
|
||||
mpf_float_100 b = 2;
|
||||
std::cout << std::numeric_limits<mpf_float_100>::digits << std::endl;
|
||||
// We can use any C++ std lib function:
|
||||
std::cout << log(b) << std::endl; // print log(2)
|
||||
// We can also use any function from Boost.Math:
|
||||
std::cout << boost::math::tgamma(b) << std::endl;
|
||||
// These even work when the argument is an expression template:
|
||||
std::cout << boost::math::tgamma(b * b) << std::endl;
|
||||
|
||||
// Access the underlying representation:
|
||||
mpf_t f;
|
||||
mpf_init(f);
|
||||
mpf_set(f, a.backend().data());
|
||||
//]
|
||||
}
|
||||
|
||||
void t3()
|
||||
{
|
||||
//[mpq_eg
|
||||
//=#include <boost/multiprecision/gmp.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
mpq_rational v = 1;
|
||||
|
||||
// Do some arithmetic:
|
||||
for(unsigned i = 1; i <= 1000; ++i)
|
||||
v *= i;
|
||||
v /= 10;
|
||||
|
||||
std::cout << v << std::endl; // prints 1000! / 10
|
||||
std::cout << numerator(v) << std::endl;
|
||||
std::cout << denominator(v) << std::endl;
|
||||
|
||||
mpq_rational w(2, 3); // component wise constructor
|
||||
std::cout << w << std::endl; // prints 2/3
|
||||
|
||||
// Access the underlying data:
|
||||
mpq_t q;
|
||||
mpq_init(q);
|
||||
mpq_set(q, v.backend().data());
|
||||
//]
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
t1();
|
||||
t2();
|
||||
t3();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
|
||||
//[FAC1
|
||||
|
||||
/*`
|
||||
In this simple example, we'll write a routine to print out all of the factorials
|
||||
which will fit into a 128-bit integer. At the end of the routine we do some
|
||||
fancy iostream formatting of the results:
|
||||
*/
|
||||
/*=
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
*/
|
||||
|
||||
void print_factorials()
|
||||
{
|
||||
using boost::multiprecision::cpp_int;
|
||||
//
|
||||
// Print all the factorials that will fit inside a 128-bit integer.
|
||||
//
|
||||
// Begin by building a big table of factorials, once we know just how
|
||||
// large the largest is, we'll be able to "pretty format" the results.
|
||||
//
|
||||
// Calculate the largest number that will fit inside 128 bits, we could
|
||||
// also have used numeric_limits<int128_t>::max() for this value:
|
||||
cpp_int limit = (cpp_int(1) << 128) - 1;
|
||||
//
|
||||
// Our table of values:
|
||||
std::vector<cpp_int> results;
|
||||
//
|
||||
// Initial values:
|
||||
unsigned i = 1;
|
||||
cpp_int factorial = 1;
|
||||
//
|
||||
// Cycle through the factorials till we reach the limit:
|
||||
while(factorial < limit)
|
||||
{
|
||||
results.push_back(factorial);
|
||||
++i;
|
||||
factorial *= i;
|
||||
}
|
||||
//
|
||||
// Lets see how many digits the largest factorial was:
|
||||
unsigned digits = results.back().str().size();
|
||||
//
|
||||
// Now print them out, using right justification, while we're at it
|
||||
// we'll indicate the limit of each integer type, so begin by defining
|
||||
// the limits for 16, 32, 64 etc bit integers:
|
||||
cpp_int limits[] = {
|
||||
(cpp_int(1) << 16) - 1,
|
||||
(cpp_int(1) << 32) - 1,
|
||||
(cpp_int(1) << 64) - 1,
|
||||
(cpp_int(1) << 128) - 1,
|
||||
};
|
||||
std::string bit_counts[] = { "16", "32", "64", "128" };
|
||||
unsigned current_limit = 0;
|
||||
for(unsigned j = 0; j < results.size(); ++j)
|
||||
{
|
||||
if(limits[current_limit] < results[j])
|
||||
{
|
||||
std::string message = "Limit of " + bit_counts[current_limit] + " bit integers";
|
||||
std::cout << std::setfill('.') << std::setw(digits+1) << std::right << message << std::setfill(' ') << std::endl;
|
||||
++current_limit;
|
||||
}
|
||||
std::cout << std::setw(digits + 1) << std::right << results[j] << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/*`
|
||||
The output from this routine is:
|
||||
[template nul[]] [# fix for quickbook bug]
|
||||
[pre [nul]
|
||||
1
|
||||
2
|
||||
6
|
||||
24
|
||||
120
|
||||
720
|
||||
5040
|
||||
40320
|
||||
................Limit of 16 bit integers
|
||||
362880
|
||||
3628800
|
||||
39916800
|
||||
479001600
|
||||
................Limit of 32 bit integers
|
||||
6227020800
|
||||
87178291200
|
||||
1307674368000
|
||||
20922789888000
|
||||
355687428096000
|
||||
6402373705728000
|
||||
121645100408832000
|
||||
2432902008176640000
|
||||
................Limit of 64 bit integers
|
||||
51090942171709440000
|
||||
1124000727777607680000
|
||||
25852016738884976640000
|
||||
620448401733239439360000
|
||||
15511210043330985984000000
|
||||
403291461126605635584000000
|
||||
10888869450418352160768000000
|
||||
304888344611713860501504000000
|
||||
8841761993739701954543616000000
|
||||
265252859812191058636308480000000
|
||||
8222838654177922817725562880000000
|
||||
263130836933693530167218012160000000
|
||||
8683317618811886495518194401280000000
|
||||
295232799039604140847618609643520000000
|
||||
]
|
||||
*/
|
||||
|
||||
//]
|
||||
|
||||
//[BITOPS
|
||||
|
||||
/*`
|
||||
In this example we'll show how individual bits within an integer may be manipulated,
|
||||
we'll start with an often needed calculation of ['2[super n] - 1], which we could obviously
|
||||
implement like this:
|
||||
*/
|
||||
|
||||
using boost::multiprecision::cpp_int;
|
||||
|
||||
cpp_int b1(unsigned n)
|
||||
{
|
||||
cpp_int r(1);
|
||||
return (r << n) - 1;
|
||||
}
|
||||
|
||||
/*`
|
||||
Calling:
|
||||
|
||||
std::cout << std::hex << std::showbase << b1(200) << std::endl;
|
||||
|
||||
Yields as expected:
|
||||
|
||||
[pre 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF]
|
||||
|
||||
However, we could equally just set the n'th bit in the result, like this:
|
||||
*/
|
||||
|
||||
cpp_int b2(unsigned n)
|
||||
{
|
||||
cpp_int r(0);
|
||||
return --bit_set(r, n);
|
||||
}
|
||||
|
||||
/*`
|
||||
Note how the `bit_set` function sets the specified bit in its argument and then returns a reference to the result -
|
||||
which we can then simply decrement. The result from a call to `b2` is the same as that to `b1`.
|
||||
|
||||
We can equally test bits, so for example the n'th bit of the result returned from `b2` shouldn't be set
|
||||
unless we increment it first:
|
||||
|
||||
assert(!bit_test(b1(200), 200)); // OK
|
||||
assert(bit_test(++b1(200), 200)); // OK
|
||||
|
||||
And of course if we flip the n'th bit after increment, then we should get back to zero:
|
||||
|
||||
assert(!bit_flip(++b1(200), 200)); // OK
|
||||
*/
|
||||
|
||||
//]
|
||||
|
||||
int main()
|
||||
{
|
||||
print_factorials();
|
||||
|
||||
std::cout << std::hex << std::showbase << b1(200) << std::endl;
|
||||
std::cout << std::hex << std::showbase << b2(200) << std::endl;
|
||||
assert(!bit_test(b1(200), 200)); // OK
|
||||
assert(bit_test(++b1(200), 200)); // OK
|
||||
assert(!bit_flip(++b1(200), 200)); // OK
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Program output:
|
||||
|
||||
1
|
||||
2
|
||||
6
|
||||
24
|
||||
120
|
||||
720
|
||||
5040
|
||||
40320
|
||||
................Limit of 16 bit integers
|
||||
362880
|
||||
3628800
|
||||
39916800
|
||||
479001600
|
||||
................Limit of 32 bit integers
|
||||
6227020800
|
||||
87178291200
|
||||
1307674368000
|
||||
20922789888000
|
||||
355687428096000
|
||||
6402373705728000
|
||||
121645100408832000
|
||||
2432902008176640000
|
||||
................Limit of 64 bit integers
|
||||
51090942171709440000
|
||||
1124000727777607680000
|
||||
25852016738884976640000
|
||||
620448401733239439360000
|
||||
15511210043330985984000000
|
||||
403291461126605635584000000
|
||||
10888869450418352160768000000
|
||||
304888344611713860501504000000
|
||||
8841761993739701954543616000000
|
||||
265252859812191058636308480000000
|
||||
8222838654177922817725562880000000
|
||||
263130836933693530167218012160000000
|
||||
8683317618811886495518194401280000000
|
||||
295232799039604140847618609643520000000
|
||||
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
|
||||
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
|
||||
*/
|
||||
@@ -0,0 +1,58 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
|
||||
//
|
||||
// Compare arithmetic results using fixed_int to GMP results.
|
||||
//
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# define _SCL_SECURE_NO_WARNINGS
|
||||
#endif
|
||||
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
//[mixed_eg
|
||||
//=#include <boost/multiprecision/cpp_int.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
boost::uint64_t i = (std::numeric_limits<boost::uint64_t>::max)();
|
||||
boost::uint64_t j = 1;
|
||||
|
||||
uint128_t ui128;
|
||||
uint256_t ui256;
|
||||
//
|
||||
// Start by performing arithmetic on 64-bit integers to yield 128-bit results:
|
||||
//
|
||||
std::cout << std::hex << std::showbase << i << std::endl;
|
||||
std::cout << std::hex << std::showbase << add(ui128, i, j) << std::endl;
|
||||
std::cout << std::hex << std::showbase << multiply(ui128, i, i) << std::endl;
|
||||
//
|
||||
// The try squaring a 128-bit integer to yield a 256-bit result:
|
||||
//
|
||||
ui128 = (std::numeric_limits<uint128_t>::max)();
|
||||
std::cout << std::hex << std::showbase << multiply(ui256, ui128, ui128) << std::endl;
|
||||
|
||||
//]
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Program output:
|
||||
|
||||
//[mixed_output
|
||||
|
||||
0xffffffffffffffff
|
||||
0x10000000000000000
|
||||
0xFFFFFFFFFFFFFFFE0000000000000001
|
||||
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE00000000000000000000000000000001
|
||||
|
||||
//]
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2011 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/mpfr.hpp>
|
||||
#include <boost/math/special_functions/gamma.hpp>
|
||||
#include <iostream>
|
||||
|
||||
void t1()
|
||||
{
|
||||
//[mpfr_eg
|
||||
//=#include <boost/multiprecision/mpfr.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
// Operations at variable precision and no numeric_limits support:
|
||||
mpfr_float a = 2;
|
||||
mpfr_float::default_precision(1000);
|
||||
std::cout << mpfr_float::default_precision() << std::endl;
|
||||
std::cout << sqrt(a) << std::endl; // print root-2
|
||||
|
||||
// Operations at fixed precision and full numeric_limits support:
|
||||
mpfr_float_100 b = 2;
|
||||
std::cout << std::numeric_limits<mpfr_float_100>::digits << std::endl;
|
||||
// We can use any C++ std lib function:
|
||||
std::cout << log(b) << std::endl; // print log(2)
|
||||
// We can also use any function from Boost.Math:
|
||||
std::cout << boost::math::tgamma(b) << std::endl;
|
||||
// These even work when the argument is an expression template:
|
||||
std::cout << boost::math::tgamma(b * b) << std::endl;
|
||||
|
||||
// Access the underlying data:
|
||||
mpfr_t r;
|
||||
mpfr_init(r);
|
||||
mpfr_set(r, b.backend().data(), GMP_RNDN);
|
||||
//]
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
t1();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2011 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/gmp.hpp>
|
||||
#include <boost/multiprecision/random.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
void t1()
|
||||
{
|
||||
//[random_eg1
|
||||
//=#include <boost/multiprecision/gmp.hpp>
|
||||
//=#include <boost/multiprecision/random.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
using namespace boost::random;
|
||||
|
||||
//
|
||||
// Declare our random number generator type, the underlying generator
|
||||
// is the Mersenne twister mt19937 engine, and 256 bits are generated:
|
||||
//
|
||||
typedef independent_bits_engine<mt19937, 256, mpz_int> generator_type;
|
||||
generator_type gen;
|
||||
//
|
||||
// Generate some values:
|
||||
//
|
||||
std::cout << std::hex << std::showbase;
|
||||
for(unsigned i = 0; i < 10; ++i)
|
||||
std::cout << gen() << std::endl;
|
||||
//]
|
||||
}
|
||||
|
||||
void t2()
|
||||
{
|
||||
//[random_eg2
|
||||
//=#include <boost/multiprecision/gmp.hpp>
|
||||
//=#include <boost/multiprecision/random.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
using namespace boost::random;
|
||||
|
||||
//
|
||||
// Generate integers in a given range using uniform_int,
|
||||
// the underlying generator is invoked multiple times
|
||||
// to generate enough bits:
|
||||
//
|
||||
mt19937 mt;
|
||||
uniform_int_distribution<mpz_int> ui(0, mpz_int(1) << 256);
|
||||
//
|
||||
// Generate the numbers:
|
||||
//
|
||||
std::cout << std::hex << std::showbase;
|
||||
for(unsigned i = 0; i < 10; ++i)
|
||||
std::cout << ui(mt) << std::endl;
|
||||
|
||||
//]
|
||||
}
|
||||
|
||||
void t3()
|
||||
{
|
||||
//[random_eg3
|
||||
//=#include <boost/multiprecision/gmp.hpp>
|
||||
//=#include <boost/multiprecision/random.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
using namespace boost::random;
|
||||
//
|
||||
// We need an underlying generator with at least as many bits as the
|
||||
// floating point type to generate numbers in [0, 1) with all the bits
|
||||
// in the floating point type randomly filled:
|
||||
//
|
||||
uniform_01<mpf_float_50> uf;
|
||||
independent_bits_engine<mt19937, 50L*1000L/301L, mpz_int> gen;
|
||||
//
|
||||
// Generate the values:
|
||||
//
|
||||
std::cout << std::setprecision(50);
|
||||
for(unsigned i = 0; i < 20; ++i)
|
||||
std::cout << uf(gen) << std::endl;
|
||||
//]
|
||||
}
|
||||
|
||||
void t4()
|
||||
{
|
||||
//[random_eg4
|
||||
//=#include <boost/multiprecision/gmp.hpp>
|
||||
//=#include <boost/multiprecision/random.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
using namespace boost::random;
|
||||
//
|
||||
// We can repeat the above example, with other distributions:
|
||||
//
|
||||
uniform_real_distribution<mpf_float_50> ur(-20, 20);
|
||||
gamma_distribution<mpf_float_50> gd(20);
|
||||
independent_bits_engine<mt19937, 50L*1000L/301L, mpz_int> gen;
|
||||
//
|
||||
// Generate some values:
|
||||
//
|
||||
std::cout << std::setprecision(50);
|
||||
for(unsigned i = 0; i < 20; ++i)
|
||||
std::cout << ur(gen) << std::endl;
|
||||
for(unsigned i = 0; i < 20; ++i)
|
||||
std::cout << gd(gen) << std::endl;
|
||||
//]
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
t1();
|
||||
t2();
|
||||
t3();
|
||||
t4();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
|
||||
//[safe_prime
|
||||
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <boost/multiprecision/miller_rabin.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace boost::random;
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
typedef cpp_int int_type;
|
||||
mt11213b base_gen(clock());
|
||||
independent_bits_engine<mt11213b, 256, int_type> gen(base_gen);
|
||||
//
|
||||
// We must use a different generator for the tests and number generation, otherwise
|
||||
// we get false positives.
|
||||
//
|
||||
mt19937 gen2(clock());
|
||||
|
||||
for(unsigned i = 0; i < 100000; ++i)
|
||||
{
|
||||
int_type n = gen();
|
||||
if(miller_rabin_test(n, 25, gen2))
|
||||
{
|
||||
// Value n is probably prime, see if (n-1)/2 is also prime:
|
||||
std::cout << "We have a probable prime with value: " << std::hex << std::showbase << n << std::endl;
|
||||
if(miller_rabin_test((n-1)/2, 25, gen2))
|
||||
{
|
||||
std::cout << "We have a safe prime with value: " << std::hex << std::showbase << n << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << "Ooops, no safe primes were found" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//]
|
||||
@@ -0,0 +1,73 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2011 John Maddock. 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_
|
||||
|
||||
#include <boost/multiprecision/tommath.hpp>
|
||||
#include <iostream>
|
||||
|
||||
void t1()
|
||||
{
|
||||
//[tommath_eg
|
||||
//=#include <boost/multiprecision/tommath.hpp>
|
||||
|
||||
boost::multiprecision::tom_int v = 1;
|
||||
|
||||
// Do some arithmetic:
|
||||
for(unsigned i = 1; i <= 1000; ++i)
|
||||
v *= i;
|
||||
|
||||
std::cout << v << std::endl; // prints 1000!
|
||||
std::cout << std::hex << v << std::endl; // prints 1000! in hex format
|
||||
|
||||
try{
|
||||
std::cout << std::hex << -v << std::endl; // Ooops! can't print a negative value in hex format!
|
||||
}
|
||||
catch(const std::runtime_error& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
try{
|
||||
// v is not a 2's complement type, bitwise operations are only supported
|
||||
// on positive values:
|
||||
v = -v & 2;
|
||||
}
|
||||
catch(const std::runtime_error& e)
|
||||
{
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
//]
|
||||
}
|
||||
|
||||
void t3()
|
||||
{
|
||||
//[mp_rat_eg
|
||||
//=#include <boost/multiprecision/tommath.hpp>
|
||||
|
||||
using namespace boost::multiprecision;
|
||||
|
||||
tom_rational v = 1;
|
||||
|
||||
// Do some arithmetic:
|
||||
for(unsigned i = 1; i <= 1000; ++i)
|
||||
v *= i;
|
||||
v /= 10;
|
||||
|
||||
std::cout << v << std::endl; // prints 1000! / 10
|
||||
std::cout << numerator(v) << std::endl;
|
||||
std::cout << denominator(v) << std::endl;
|
||||
|
||||
tom_rational w(2, 3); // Component wise constructor
|
||||
std::cout << w << std::endl; // prints 2/3
|
||||
|
||||
//]
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
t1();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2011 John Maddock. 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_
|
||||
|
||||
#ifndef BOOST_MATH_CONCEPTS_ER_HPP
|
||||
#define BOOST_MATH_CONCEPTS_ER_HPP
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/multiprecision/number.hpp>
|
||||
#include <boost/math/special_functions/fpclassify.hpp>
|
||||
#include <boost/mpl/list.hpp>
|
||||
|
||||
namespace boost{
|
||||
namespace multiprecision{
|
||||
namespace concepts{
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4244)
|
||||
#endif
|
||||
|
||||
struct number_backend_float_architype
|
||||
{
|
||||
typedef mpl::list<long long> signed_types;
|
||||
typedef mpl::list<unsigned long long> unsigned_types;
|
||||
typedef mpl::list<long double> float_types;
|
||||
typedef int exponent_type;
|
||||
|
||||
number_backend_float_architype()
|
||||
{
|
||||
std::cout << "Default construct" << std::endl;
|
||||
}
|
||||
number_backend_float_architype(const number_backend_float_architype& o)
|
||||
{
|
||||
std::cout << "Copy construct" << std::endl;
|
||||
m_value = o.m_value;
|
||||
}
|
||||
number_backend_float_architype& operator = (const number_backend_float_architype& o)
|
||||
{
|
||||
m_value = o.m_value;
|
||||
std::cout << "Assignment (" << m_value << ")" << std::endl;
|
||||
return *this;
|
||||
}
|
||||
number_backend_float_architype& operator = (unsigned long long i)
|
||||
{
|
||||
m_value = i;
|
||||
std::cout << "UInt Assignment (" << i << ")" << std::endl;
|
||||
return *this;
|
||||
}
|
||||
number_backend_float_architype& operator = (long long i)
|
||||
{
|
||||
m_value = i;
|
||||
std::cout << "Int Assignment (" << i << ")" << std::endl;
|
||||
return *this;
|
||||
}
|
||||
number_backend_float_architype& operator = (long double d)
|
||||
{
|
||||
m_value = d;
|
||||
std::cout << "long double Assignment (" << d << ")" << std::endl;
|
||||
return *this;
|
||||
}
|
||||
number_backend_float_architype& operator = (const char* s)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_value = boost::lexical_cast<long double>(s);
|
||||
}
|
||||
catch(const std::exception&)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::runtime_error(std::string("Unable to parse input string: \"") + s + std::string("\" as a valid floating point number.")));
|
||||
}
|
||||
std::cout << "const char* Assignment (" << s << ")" << std::endl;
|
||||
return *this;
|
||||
}
|
||||
void swap(number_backend_float_architype& o)
|
||||
{
|
||||
std::cout << "Swapping (" << m_value << " with " << o.m_value << ")" << std::endl;
|
||||
std::swap(m_value, o.m_value);
|
||||
}
|
||||
std::string str(std::streamsize digits, std::ios_base::fmtflags f)const
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss.flags(f);
|
||||
if(digits)
|
||||
ss.precision(digits);
|
||||
else
|
||||
ss.precision(std::numeric_limits<long double>::digits10 + 2);
|
||||
boost::intmax_t i = m_value;
|
||||
boost::uintmax_t u = m_value;
|
||||
if(!(f & std::ios_base::scientific) && m_value == i)
|
||||
ss << i;
|
||||
else if(!(f & std::ios_base::scientific) && m_value == u)
|
||||
ss << u;
|
||||
else
|
||||
ss << m_value;
|
||||
std::string s = ss.str();
|
||||
std::cout << "Converting to string (" << s << ")" << std::endl;
|
||||
return s;
|
||||
}
|
||||
void negate()
|
||||
{
|
||||
std::cout << "Negating (" << m_value << ")" << std::endl;
|
||||
m_value = -m_value;
|
||||
}
|
||||
int compare(const number_backend_float_architype& o)const
|
||||
{
|
||||
std::cout << "Comparison" << std::endl;
|
||||
return m_value > o.m_value ? 1 : (m_value < o.m_value ? -1 : 0);
|
||||
}
|
||||
int compare(long long i)const
|
||||
{
|
||||
std::cout << "Comparison with int" << std::endl;
|
||||
return m_value > i ? 1 : (m_value < i ? -1 : 0);
|
||||
}
|
||||
int compare(unsigned long long i)const
|
||||
{
|
||||
std::cout << "Comparison with unsigned" << std::endl;
|
||||
return m_value > i ? 1 : (m_value < i ? -1 : 0);
|
||||
}
|
||||
int compare(long double d)const
|
||||
{
|
||||
std::cout << "Comparison with long double" << std::endl;
|
||||
return m_value > d ? 1 : (m_value < d ? -1 : 0);
|
||||
}
|
||||
long double m_value;
|
||||
};
|
||||
|
||||
inline void eval_add(number_backend_float_architype& result, const number_backend_float_architype& o)
|
||||
{
|
||||
std::cout << "Addition (" << result.m_value << " += " << o.m_value << ")" << std::endl;
|
||||
result.m_value += o.m_value;
|
||||
}
|
||||
inline void eval_subtract(number_backend_float_architype& result, const number_backend_float_architype& o)
|
||||
{
|
||||
std::cout << "Subtraction (" << result.m_value << " -= " << o.m_value << ")" << std::endl;
|
||||
result.m_value -= o.m_value;
|
||||
}
|
||||
inline void eval_multiply(number_backend_float_architype& result, const number_backend_float_architype& o)
|
||||
{
|
||||
std::cout << "Multiplication (" << result.m_value << " *= " << o.m_value << ")" << std::endl;
|
||||
result.m_value *= o.m_value;
|
||||
}
|
||||
inline void eval_divide(number_backend_float_architype& result, const number_backend_float_architype& o)
|
||||
{
|
||||
std::cout << "Division (" << result.m_value << " /= " << o.m_value << ")" << std::endl;
|
||||
result.m_value /= o.m_value;
|
||||
}
|
||||
|
||||
inline void eval_convert_to(unsigned long long* result, const number_backend_float_architype& val)
|
||||
{
|
||||
*result = static_cast<unsigned long long>(val.m_value);
|
||||
}
|
||||
inline void eval_convert_to(long long* result, const number_backend_float_architype& val)
|
||||
{
|
||||
*result = static_cast<long long>(val.m_value);
|
||||
}
|
||||
inline void eval_convert_to(long double* result, number_backend_float_architype& val)
|
||||
{
|
||||
*result = val.m_value;
|
||||
}
|
||||
|
||||
inline void eval_frexp(number_backend_float_architype& result, const number_backend_float_architype& arg, int* exp)
|
||||
{
|
||||
result = std::frexp(arg.m_value, exp);
|
||||
}
|
||||
|
||||
inline void eval_ldexp(number_backend_float_architype& result, const number_backend_float_architype& arg, int exp)
|
||||
{
|
||||
result = std::ldexp(arg.m_value, exp);
|
||||
}
|
||||
|
||||
inline void eval_floor(number_backend_float_architype& result, const number_backend_float_architype& arg)
|
||||
{
|
||||
result = std::floor(arg.m_value);
|
||||
}
|
||||
|
||||
inline void eval_ceil(number_backend_float_architype& result, const number_backend_float_architype& arg)
|
||||
{
|
||||
result = std::ceil(arg.m_value);
|
||||
}
|
||||
|
||||
inline void eval_sqrt(number_backend_float_architype& result, const number_backend_float_architype& arg)
|
||||
{
|
||||
result = std::sqrt(arg.m_value);
|
||||
}
|
||||
|
||||
inline int eval_fpclassify(const number_backend_float_architype& arg)
|
||||
{
|
||||
return (boost::math::fpclassify)(arg.m_value);
|
||||
}
|
||||
|
||||
typedef boost::multiprecision::number<number_backend_float_architype> mp_number_float_architype;
|
||||
|
||||
} // namespace
|
||||
|
||||
template<>
|
||||
struct number_category<concepts::number_backend_float_architype> : public mpl::int_<number_kind_floating_point>{};
|
||||
|
||||
}} // namespaces
|
||||
|
||||
namespace std{
|
||||
|
||||
template <boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
class numeric_limits<boost::multiprecision::number<boost::multiprecision::concepts::number_backend_float_architype, ExpressionTemplates> > : public std::numeric_limits<long double>
|
||||
{
|
||||
typedef std::numeric_limits<long double> base_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::concepts::number_backend_float_architype, ExpressionTemplates> number_type;
|
||||
public:
|
||||
static number_type (min)() BOOST_NOEXCEPT { return (base_type::min)(); }
|
||||
static number_type (max)() BOOST_NOEXCEPT { return (base_type::max)(); }
|
||||
static number_type lowest() BOOST_NOEXCEPT { return -(max)(); }
|
||||
static number_type epsilon() BOOST_NOEXCEPT { return base_type::epsilon(); }
|
||||
static number_type round_error() BOOST_NOEXCEPT { return epsilon() / 2; }
|
||||
static number_type infinity() BOOST_NOEXCEPT { return base_type::infinity(); }
|
||||
static number_type quiet_NaN() BOOST_NOEXCEPT { return base_type::quiet_NaN(); }
|
||||
static number_type signaling_NaN() BOOST_NOEXCEPT { return base_type::signaling_NaN(); }
|
||||
static number_type denorm_min() BOOST_NOEXCEPT { return base_type::denorm_min(); }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,509 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
//
|
||||
// Comparison operators for cpp_int_backend:
|
||||
//
|
||||
#ifndef BOOST_MP_CPP_INT_ADD_HPP
|
||||
#define BOOST_MP_CPP_INT_ADD_HPP
|
||||
|
||||
namespace boost{ namespace multiprecision{ namespace backends{
|
||||
|
||||
//
|
||||
// This is the key addition routine where all the argument types are non-trivial cpp_int's:
|
||||
//
|
||||
template <class CppInt1, class CppInt2, class CppInt3>
|
||||
inline void add_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
|
||||
{
|
||||
using std::swap;
|
||||
|
||||
// Nothing fancy, just let uintmax_t take the strain:
|
||||
double_limb_type carry = 0;
|
||||
unsigned m, x;
|
||||
unsigned as = a.size();
|
||||
unsigned bs = b.size();
|
||||
minmax(as, bs, m, x);
|
||||
if(x == 1)
|
||||
{
|
||||
bool s = a.sign();
|
||||
result = static_cast<double_limb_type>(*a.limbs()) + static_cast<double_limb_type>(*b.limbs());
|
||||
result.sign(s);
|
||||
return;
|
||||
}
|
||||
result.resize(x, x);
|
||||
typename CppInt2::const_limb_pointer pa = a.limbs();
|
||||
typename CppInt3::const_limb_pointer pb = b.limbs();
|
||||
typename CppInt1::limb_pointer pr = result.limbs();
|
||||
typename CppInt1::limb_pointer pr_end = pr + m;
|
||||
|
||||
if(as < bs)
|
||||
swap(pa, pb);
|
||||
|
||||
// First where a and b overlap:
|
||||
while(pr != pr_end)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(*pa) + static_cast<double_limb_type>(*pb);
|
||||
*pr = static_cast<limb_type>(carry);
|
||||
carry >>= CppInt1::limb_bits;
|
||||
++pr, ++pa, ++pb;
|
||||
}
|
||||
pr_end += x - m;
|
||||
// Now where only a has digits:
|
||||
while(pr != pr_end)
|
||||
{
|
||||
if(!carry)
|
||||
{
|
||||
if(pa != pr)
|
||||
std::copy(pa, pa + (pr_end - pr), pr);
|
||||
break;
|
||||
}
|
||||
carry += static_cast<double_limb_type>(*pa);
|
||||
*pr = static_cast<limb_type>(carry);
|
||||
carry >>= CppInt1::limb_bits;
|
||||
++pr, ++pa;
|
||||
}
|
||||
if(carry)
|
||||
{
|
||||
// We overflowed, need to add one more limb:
|
||||
result.resize(x + 1, x + 1);
|
||||
if(CppInt1::variable || (result.size() > x))
|
||||
result.limbs()[x] = static_cast<limb_type>(carry);
|
||||
}
|
||||
result.normalize();
|
||||
result.sign(a.sign());
|
||||
}
|
||||
//
|
||||
// As above, but for adding a single limb to a non-trivial cpp_int:
|
||||
//
|
||||
template <class CppInt1, class CppInt2>
|
||||
inline void add_unsigned(CppInt1& result, const CppInt2& a, const limb_type& o) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
|
||||
{
|
||||
// Addition using modular arithmatic.
|
||||
// Nothing fancy, just let uintmax_t take the strain:
|
||||
if(&result != &a)
|
||||
result.resize(a.size(), a.size());
|
||||
double_limb_type carry = o;
|
||||
typename CppInt1::limb_pointer pr = result.limbs();
|
||||
typename CppInt2::const_limb_pointer pa = a.limbs();
|
||||
unsigned i = 0;
|
||||
// Addition with carry until we either run out of digits or carry is zero:
|
||||
for(; carry && (i < result.size()); ++i)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(pa[i]);
|
||||
pr[i] = static_cast<limb_type>(carry);
|
||||
carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
// Just copy any remaining digits:
|
||||
if(&a != &result)
|
||||
{
|
||||
for(; i < result.size(); ++i)
|
||||
pr[i] = pa[i];
|
||||
}
|
||||
if(carry)
|
||||
{
|
||||
// We overflowed, need to add one more limb:
|
||||
unsigned x = result.size();
|
||||
result.resize(x + 1, x + 1);
|
||||
if(CppInt1::variable || (result.size() > x))
|
||||
result.limbs()[x] = static_cast<limb_type>(carry);
|
||||
}
|
||||
result.normalize();
|
||||
result.sign(a.sign());
|
||||
}
|
||||
//
|
||||
// Core subtraction routine for all non-trivial cpp_int's:
|
||||
//
|
||||
template <class CppInt1, class CppInt2, class CppInt3>
|
||||
inline void subtract_unsigned(CppInt1& result, const CppInt2& a, const CppInt3& b) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
|
||||
{
|
||||
using std::swap;
|
||||
|
||||
// Nothing fancy, just let uintmax_t take the strain:
|
||||
double_limb_type borrow = 0;
|
||||
unsigned m, x;
|
||||
minmax(a.size(), b.size(), m, x);
|
||||
//
|
||||
// special cases for small limb counts:
|
||||
//
|
||||
if(x == 1)
|
||||
{
|
||||
bool s = a.sign();
|
||||
limb_type al = *a.limbs();
|
||||
limb_type bl = *b.limbs();
|
||||
if(bl > al)
|
||||
{
|
||||
std::swap(al, bl);
|
||||
s = !s;
|
||||
}
|
||||
result = al - bl;
|
||||
result.sign(s);
|
||||
return;
|
||||
}
|
||||
// This isn't used till later, but comparison has to occur before we resize the result,
|
||||
// as that may also resize a or b if this is an inplace operation:
|
||||
int c = a.compare_unsigned(b);
|
||||
// Set up the result vector:
|
||||
result.resize(x, x);
|
||||
// Now that a, b, and result are stable, get pointers to their limbs:
|
||||
typename CppInt2::const_limb_pointer pa = a.limbs();
|
||||
typename CppInt3::const_limb_pointer pb = b.limbs();
|
||||
typename CppInt1::limb_pointer pr = result.limbs();
|
||||
bool swapped = false;
|
||||
if(c < 0)
|
||||
{
|
||||
swap(pa, pb);
|
||||
swapped = true;
|
||||
}
|
||||
else if(c == 0)
|
||||
{
|
||||
result = static_cast<limb_type>(0);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned i = 0;
|
||||
// First where a and b overlap:
|
||||
while(i < m)
|
||||
{
|
||||
borrow = static_cast<double_limb_type>(pa[i]) - static_cast<double_limb_type>(pb[i]) - borrow;
|
||||
pr[i] = static_cast<limb_type>(borrow);
|
||||
borrow = (borrow >> CppInt1::limb_bits) & 1u;
|
||||
++i;
|
||||
}
|
||||
// Now where only a has digits, only as long as we've borrowed:
|
||||
while(borrow && (i < x))
|
||||
{
|
||||
borrow = static_cast<double_limb_type>(pa[i]) - borrow;
|
||||
pr[i] = static_cast<limb_type>(borrow);
|
||||
borrow = (borrow >> CppInt1::limb_bits) & 1u;
|
||||
++i;
|
||||
}
|
||||
// Any remaining digits are the same as those in pa:
|
||||
if((x != i) && (pa != pr))
|
||||
std::copy(pa + i, pa + x, pr + i);
|
||||
BOOST_ASSERT(0 == borrow);
|
||||
|
||||
//
|
||||
// We may have lost digits, if so update limb usage count:
|
||||
//
|
||||
result.normalize();
|
||||
result.sign(a.sign());
|
||||
if(swapped)
|
||||
result.negate();
|
||||
}
|
||||
//
|
||||
// And again to subtract a single limb:
|
||||
//
|
||||
template <class CppInt1, class CppInt2>
|
||||
inline void subtract_unsigned(CppInt1& result, const CppInt2& a, const limb_type& b) BOOST_NOEXCEPT_IF(is_non_throwing_cpp_int<CppInt1>::value)
|
||||
{
|
||||
// Subtract one limb.
|
||||
// Nothing fancy, just let uintmax_t take the strain:
|
||||
BOOST_STATIC_CONSTANT(double_limb_type, borrow = static_cast<double_limb_type>(CppInt1::max_limb_value) + 1);
|
||||
result.resize(a.size(), a.size());
|
||||
typename CppInt1::limb_pointer pr = result.limbs();
|
||||
typename CppInt2::const_limb_pointer pa = a.limbs();
|
||||
if(*pa > b)
|
||||
{
|
||||
*pr = *pa - b;
|
||||
if(&result != &a)
|
||||
{
|
||||
std::copy(pa + 1, pa + a.size(), pr + 1);
|
||||
result.sign(a.sign());
|
||||
}
|
||||
}
|
||||
else if(result.size() == 1)
|
||||
{
|
||||
*pr = b - *pa;
|
||||
result.sign(!a.sign());
|
||||
}
|
||||
else
|
||||
{
|
||||
*pr = static_cast<limb_type>((borrow + *pa) - b);
|
||||
unsigned i = 1;
|
||||
while(!pa[i])
|
||||
{
|
||||
pr[i] = CppInt1::max_limb_value;
|
||||
++i;
|
||||
}
|
||||
pr[i] = pa[i] - 1;
|
||||
if(&result != &a)
|
||||
{
|
||||
++i;
|
||||
std::copy(pa + i, pa + a.size(), pr + i);
|
||||
}
|
||||
result.normalize();
|
||||
result.sign(a.sign());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Now the actual functions called by the front end, all of which forward to one of the above:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_add(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
eval_add(result, result, o);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2, unsigned MinBits3, unsigned MaxBits3, cpp_integer_type SignType3, cpp_int_check_type Checked3, class Allocator3>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3> >::value >::type
|
||||
eval_add(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(a.sign() != b.sign())
|
||||
{
|
||||
subtract_unsigned(result, a, b);
|
||||
return;
|
||||
}
|
||||
add_unsigned(result, a, b);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(result.sign())
|
||||
{
|
||||
subtract_unsigned(result, result, o);
|
||||
}
|
||||
else
|
||||
add_unsigned(result, result, o);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_add(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(a.sign())
|
||||
{
|
||||
subtract_unsigned(result, a, o);
|
||||
}
|
||||
else
|
||||
add_unsigned(result, a, o);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_add(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(o < 0)
|
||||
eval_subtract(result, static_cast<limb_type>(-o));
|
||||
else if(o > 0)
|
||||
eval_add(result, static_cast<limb_type>(o));
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_add(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(o < 0)
|
||||
eval_subtract(result, a, static_cast<limb_type>(-o));
|
||||
else if(o > 0)
|
||||
eval_add(result, a, static_cast<limb_type>(o));
|
||||
else if(&result != &a)
|
||||
result = a;
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(result.sign())
|
||||
{
|
||||
add_unsigned(result, result, o);
|
||||
}
|
||||
else
|
||||
subtract_unsigned(result, result, o);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(a.sign())
|
||||
{
|
||||
add_unsigned(result, a, o);
|
||||
}
|
||||
else
|
||||
{
|
||||
subtract_unsigned(result, a, o);
|
||||
}
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(o)
|
||||
{
|
||||
if(o < 0)
|
||||
eval_add(result, static_cast<limb_type>(-o));
|
||||
else
|
||||
eval_subtract(result, static_cast<limb_type>(o));
|
||||
}
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const signed_limb_type& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(o)
|
||||
{
|
||||
if(o < 0)
|
||||
eval_add(result, a, static_cast<limb_type>(-o));
|
||||
else
|
||||
eval_subtract(result, a, static_cast<limb_type>(o));
|
||||
}
|
||||
else if(&result != &a)
|
||||
result = a;
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_increment(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
static const limb_type one = 1;
|
||||
if(!result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
|
||||
++result.limbs()[0];
|
||||
else if(result.sign() && result.limbs()[0])
|
||||
--result.limbs()[0];
|
||||
else
|
||||
eval_add(result, one);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_decrement(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
static const limb_type one = 1;
|
||||
if(!result.sign() && result.limbs()[0])
|
||||
--result.limbs()[0];
|
||||
else if(result.sign() && (result.limbs()[0] < cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value))
|
||||
++result.limbs()[0];
|
||||
else
|
||||
eval_subtract(result, one);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
eval_subtract(result, result, o);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2, unsigned MinBits3, unsigned MaxBits3, cpp_integer_type SignType3, cpp_int_check_type Checked3, class Allocator3>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3> >::value >::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(a.sign() != b.sign())
|
||||
{
|
||||
add_unsigned(result, a, b);
|
||||
return;
|
||||
}
|
||||
subtract_unsigned(result, a, b);
|
||||
}
|
||||
|
||||
//
|
||||
// Simple addition and subtraction routine for trivial cpp_int's come last:
|
||||
//
|
||||
// One of the arguments is signed:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
|
||||
>::type
|
||||
eval_add(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(result.sign() != o.sign())
|
||||
{
|
||||
if(*o.limbs() > *result.limbs())
|
||||
{
|
||||
*result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.negate();
|
||||
}
|
||||
else
|
||||
*result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
}
|
||||
else
|
||||
*result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.normalize();
|
||||
}
|
||||
// Simple version for two unsigned arguments:
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_add(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
// signed subtraction:
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
|
||||
>::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(result.sign() != o.sign())
|
||||
{
|
||||
*result.limbs() = detail::checked_add(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
}
|
||||
else if(*result.limbs() < *o.limbs())
|
||||
{
|
||||
*result.limbs() = detail::checked_subtract(*o.limbs(), *result.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.negate();
|
||||
}
|
||||
else
|
||||
*result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_subtract(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = detail::checked_subtract(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,567 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
//
|
||||
// Comparison operators for cpp_int_backend:
|
||||
//
|
||||
#ifndef BOOST_MP_CPP_INT_BIT_HPP
|
||||
#define BOOST_MP_CPP_INT_BIT_HPP
|
||||
|
||||
namespace boost{ namespace multiprecision{ namespace backends{
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
void is_valid_bitwise_op(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o, const mpl::int_<checked>&)
|
||||
{
|
||||
if(result.sign() || o.sign())
|
||||
BOOST_THROW_EXCEPTION(std::range_error("Bitwise operations on negative values results in undefined behavior."));
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
void is_valid_bitwise_op(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>&,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& , const mpl::int_<unchecked>&){}
|
||||
|
||||
template <class CppInt1, class CppInt2, class Op>
|
||||
void bitwise_op(
|
||||
CppInt1& result,
|
||||
const CppInt2& o,
|
||||
Op op) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<CppInt1>::value))
|
||||
{
|
||||
//
|
||||
// There are 4 cases:
|
||||
// * Both positive.
|
||||
// * result negative, o positive.
|
||||
// * o negative, result positive.
|
||||
// * Both negative.
|
||||
//
|
||||
// When one arg is negative we convert to 2's complement form "on the fly",
|
||||
// and then convert back to signed-magnitude form at the end.
|
||||
//
|
||||
// Note however, that if the type is checked, then bitwise ops on negative values
|
||||
// are not permitted and an exception will result.
|
||||
//
|
||||
is_valid_bitwise_op(result, o, typename CppInt1::checked_type());
|
||||
//
|
||||
// First figure out how big the result needs to be and set up some data:
|
||||
//
|
||||
unsigned rs = result.size();
|
||||
unsigned os = o.size();
|
||||
unsigned m, x;
|
||||
minmax(rs, os, m, x);
|
||||
result.resize(x, x);
|
||||
typename CppInt1::limb_pointer pr = result.limbs();
|
||||
typename CppInt2::const_limb_pointer po = o.limbs();
|
||||
for(unsigned i = rs; i < x; ++i)
|
||||
pr[i] = 0;
|
||||
|
||||
limb_type next_limb = 0;
|
||||
|
||||
if(!result.sign())
|
||||
{
|
||||
if(!o.sign())
|
||||
{
|
||||
for(unsigned i = 0; i < os; ++i)
|
||||
pr[i] = op(pr[i], po[i]);
|
||||
for(unsigned i = os; i < x; ++i)
|
||||
pr[i] = op(pr[i], limb_type(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
// "o" is negative:
|
||||
double_limb_type carry = 1;
|
||||
for(unsigned i = 0; i < os; ++i)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(~po[i]);
|
||||
pr[i] = op(pr[i], static_cast<limb_type>(carry));
|
||||
carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
for(unsigned i = os; i < x; ++i)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(~limb_type(0));
|
||||
pr[i] = op(pr[i], static_cast<limb_type>(carry));
|
||||
carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
// Set the overflow into the "extra" limb:
|
||||
carry += static_cast<double_limb_type>(~limb_type(0));
|
||||
next_limb = op(limb_type(0), static_cast<limb_type>(carry));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!o.sign())
|
||||
{
|
||||
// "result" is negative:
|
||||
double_limb_type carry = 1;
|
||||
for(unsigned i = 0; i < os; ++i)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(~pr[i]);
|
||||
pr[i] = op(static_cast<limb_type>(carry), po[i]);
|
||||
carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
for(unsigned i = os; i < x; ++i)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(~pr[i]);
|
||||
pr[i] = op(static_cast<limb_type>(carry), limb_type(0));
|
||||
carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
// Set the overflow into the "extra" limb:
|
||||
carry += static_cast<double_limb_type>(~limb_type(0));
|
||||
next_limb = op(static_cast<limb_type>(carry), limb_type(0));
|
||||
}
|
||||
else
|
||||
{
|
||||
// both are negative:
|
||||
double_limb_type r_carry = 1;
|
||||
double_limb_type o_carry = 1;
|
||||
for(unsigned i = 0; i < os; ++i)
|
||||
{
|
||||
r_carry += static_cast<double_limb_type>(~pr[i]);
|
||||
o_carry += static_cast<double_limb_type>(~po[i]);
|
||||
pr[i] = op(static_cast<limb_type>(r_carry), static_cast<limb_type>(o_carry));
|
||||
r_carry >>= CppInt1::limb_bits;
|
||||
o_carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
for(unsigned i = os; i < x; ++i)
|
||||
{
|
||||
r_carry += static_cast<double_limb_type>(~pr[i]);
|
||||
o_carry += static_cast<double_limb_type>(~limb_type(0));
|
||||
pr[i] = op(static_cast<limb_type>(r_carry), static_cast<limb_type>(o_carry));
|
||||
r_carry >>= CppInt1::limb_bits;
|
||||
o_carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
// Set the overflow into the "extra" limb:
|
||||
r_carry += static_cast<double_limb_type>(~limb_type(0));
|
||||
o_carry += static_cast<double_limb_type>(~limb_type(0));
|
||||
next_limb = op(static_cast<limb_type>(r_carry), static_cast<limb_type>(o_carry));
|
||||
}
|
||||
}
|
||||
//
|
||||
// See if the result is negative or not:
|
||||
//
|
||||
if(static_cast<signed_limb_type>(next_limb) < 0)
|
||||
{
|
||||
result.sign(true);
|
||||
double_limb_type carry = 1;
|
||||
for(unsigned i = 0; i < x; ++i)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(~pr[i]);
|
||||
pr[i] = static_cast<limb_type>(carry);
|
||||
carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
}
|
||||
else
|
||||
result.sign(false);
|
||||
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
struct bit_and{ limb_type operator()(limb_type a, limb_type b)const BOOST_NOEXCEPT { return a & b; } };
|
||||
struct bit_or { limb_type operator()(limb_type a, limb_type b)const BOOST_NOEXCEPT { return a | b; } };
|
||||
struct bit_xor{ limb_type operator()(limb_type a, limb_type b)const BOOST_NOEXCEPT { return a ^ b; } };
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_bitwise_and(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
bitwise_op(result, o, bit_and());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_bitwise_or(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
bitwise_op(result, o, bit_or());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_bitwise_xor(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
bitwise_op(result, o, bit_xor());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_complement(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(((Checked1 != checked) || (Checked2 != checked)), "Attempt to take the complement of a signed type results in undefined behavior.");
|
||||
// Increment and negate:
|
||||
result = o;
|
||||
eval_increment(result);
|
||||
result.negate();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value >::type
|
||||
eval_complement(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
unsigned os = o.size();
|
||||
result.resize(UINT_MAX, os);
|
||||
for(unsigned i = 0; i < os; ++i)
|
||||
result.limbs()[i] = ~o.limbs()[i];
|
||||
for(unsigned i = os; i < result.size(); ++i)
|
||||
result.limbs()[i] = ~static_cast<limb_type>(0);
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_left_shift(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
double_limb_type s) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(!s)
|
||||
return;
|
||||
|
||||
limb_type offset = static_cast<limb_type>(s / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits);
|
||||
limb_type shift = static_cast<limb_type>(s % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits);
|
||||
|
||||
/*
|
||||
static const unsigned max_bits = max_bits<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value;
|
||||
static const unsigned max_limbs = max_bits / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits
|
||||
+ (max_bits % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits ? 1 : 0);
|
||||
*/
|
||||
|
||||
unsigned ors = result.size();
|
||||
if((ors == 1) && (!*result.limbs()))
|
||||
return; // shifting zero yields zero.
|
||||
unsigned rs = ors;
|
||||
if(shift && (result.limbs()[ors - 1] >> (cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits - shift)))
|
||||
++rs; // Most significant limb will overflow when shifted
|
||||
rs += offset;
|
||||
result.resize(rs, rs);
|
||||
bool truncated = result.size() != rs;
|
||||
if(truncated)
|
||||
rs = result.size();
|
||||
typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_pointer pr = result.limbs();
|
||||
|
||||
if(offset > rs)
|
||||
{
|
||||
// The result is shifted past the end of the result:
|
||||
result = static_cast<limb_type>(0);
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned i = 0;
|
||||
if(shift)
|
||||
{
|
||||
// This code only works when shift is non-zero, otherwise we invoke undefined behaviour!
|
||||
i = 0;
|
||||
if(!truncated)
|
||||
{
|
||||
if(rs > ors + offset)
|
||||
{
|
||||
pr[rs - 1 - i] = pr[ors - 1 - i] >> (cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits - shift);
|
||||
--rs;
|
||||
}
|
||||
else
|
||||
{
|
||||
pr[rs - 1 - i] = pr[ors - 1 - i] << shift;
|
||||
if(ors > 1)
|
||||
pr[rs - 1 - i] |= pr[ors - 2 - i] >> (cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits - shift);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
for(; ors > 1 + i; ++i)
|
||||
{
|
||||
pr[rs - 1 - i] = pr[ors - 1 - i] << shift;
|
||||
pr[rs - 1 - i] |= pr[ors - 2 - i] >> (cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits - shift);
|
||||
}
|
||||
if(ors >= 1 + i)
|
||||
{
|
||||
pr[rs - 1 - i] = pr[ors - 1 - i] << shift;
|
||||
++i;
|
||||
}
|
||||
for(; i < rs; ++i)
|
||||
pr[rs - 1 - i] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(; i < ors; ++i)
|
||||
pr[rs - 1 - i] = pr[ors - 1 - i];
|
||||
for(; i < rs; ++i)
|
||||
pr[rs - 1 - i] = 0;
|
||||
}
|
||||
//
|
||||
// We may have shifted off the end and have leading zeros:
|
||||
//
|
||||
if(truncated)
|
||||
{
|
||||
result.normalize();
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_right_shift(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
double_limb_type s) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(!s)
|
||||
return;
|
||||
|
||||
limb_type offset = static_cast<limb_type>(s / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits);
|
||||
limb_type shift = static_cast<limb_type>(s % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits);
|
||||
unsigned ors = result.size();
|
||||
unsigned rs = ors;
|
||||
if(offset >= rs)
|
||||
{
|
||||
result = limb_type(0);
|
||||
return;
|
||||
}
|
||||
rs -= offset;
|
||||
typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_pointer pr = result.limbs();
|
||||
if((pr[ors - 1] >> shift) == 0)
|
||||
--rs;
|
||||
if(rs == 0)
|
||||
{
|
||||
result = limb_type(0);
|
||||
return;
|
||||
}
|
||||
unsigned i = 0;
|
||||
if(shift)
|
||||
{
|
||||
// This code only works for non-zero shift, otherwise we invoke undefined behaviour!
|
||||
for(; i + offset + 1 < ors; ++i)
|
||||
{
|
||||
pr[i] = pr[i + offset] >> shift;
|
||||
pr[i] |= pr[i + offset + 1] << (cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits - shift);
|
||||
}
|
||||
pr[i] = pr[i + offset] >> shift;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(; i < rs; ++i)
|
||||
pr[i] = pr[i + offset];
|
||||
}
|
||||
result.resize(rs, rs);
|
||||
}
|
||||
|
||||
//
|
||||
// Over agin for trivial cpp_int's:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, class T>
|
||||
BOOST_FORCEINLINE typename enable_if<is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> > >::type
|
||||
eval_left_shift(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, T s) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = detail::checked_left_shift(*result.limbs(), s, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, class T>
|
||||
BOOST_FORCEINLINE typename enable_if<is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> > >::type
|
||||
eval_right_shift(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, T s) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
// Nothing to check here... just make sure we don't invoke undefined behavior:
|
||||
*result.limbs() = (static_cast<unsigned>(s) >= sizeof(*result.limbs()) * CHAR_BIT) ? 0 : *result.limbs() >>= s;
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value)
|
||||
>::type
|
||||
eval_bitwise_and(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
is_valid_bitwise_op(result, o, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
|
||||
using default_ops::eval_bit_test;
|
||||
using default_ops::eval_increment;
|
||||
|
||||
if(result.sign() || o.sign())
|
||||
{
|
||||
static const unsigned m = static_unsigned_max<static_unsigned_max<MinBits1, MinBits2>::value, static_unsigned_max<MaxBits1, MaxBits2>::value>::value;
|
||||
cpp_int_backend<m + 1, m + 1, unsigned_magnitude, unchecked, void> t1(result);
|
||||
cpp_int_backend<m + 1, m + 1, unsigned_magnitude, unchecked, void> t2(o);
|
||||
eval_bitwise_and(t1, t2);
|
||||
bool s = eval_bit_test(t1, m + 1);
|
||||
if(s)
|
||||
{
|
||||
eval_complement(t1, t1);
|
||||
eval_increment(t1);
|
||||
}
|
||||
result = t1;
|
||||
result.sign(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
*result.limbs() &= *o.limbs();
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
>::type
|
||||
eval_bitwise_and(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() &= *o.limbs();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value)
|
||||
>::type
|
||||
eval_bitwise_or(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
is_valid_bitwise_op(result, o, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
|
||||
using default_ops::eval_bit_test;
|
||||
using default_ops::eval_increment;
|
||||
|
||||
if(result.sign() || o.sign())
|
||||
{
|
||||
static const unsigned m = static_unsigned_max<static_unsigned_max<MinBits1, MinBits2>::value, static_unsigned_max<MaxBits1, MaxBits2>::value>::value;
|
||||
cpp_int_backend<m + 1, m + 1, unsigned_magnitude, unchecked, void> t1(result);
|
||||
cpp_int_backend<m + 1, m + 1, unsigned_magnitude, unchecked, void> t2(o);
|
||||
eval_bitwise_or(t1, t2);
|
||||
bool s = eval_bit_test(t1, m + 1);
|
||||
if(s)
|
||||
{
|
||||
eval_complement(t1, t1);
|
||||
eval_increment(t1);
|
||||
}
|
||||
result = t1;
|
||||
result.sign(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
*result.limbs() |= *o.limbs();
|
||||
result.normalize();
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
>::type
|
||||
eval_bitwise_or(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() |= *o.limbs();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value)
|
||||
>::type
|
||||
eval_bitwise_xor(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
is_valid_bitwise_op(result, o, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
|
||||
using default_ops::eval_bit_test;
|
||||
using default_ops::eval_increment;
|
||||
|
||||
if(result.sign() || o.sign())
|
||||
{
|
||||
static const unsigned m = static_unsigned_max<static_unsigned_max<MinBits1, MinBits2>::value, static_unsigned_max<MaxBits1, MaxBits2>::value>::value;
|
||||
cpp_int_backend<m + 1, m + 1, unsigned_magnitude, unchecked, void> t1(result);
|
||||
cpp_int_backend<m + 1, m + 1, unsigned_magnitude, unchecked, void> t2(o);
|
||||
eval_bitwise_xor(t1, t2);
|
||||
bool s = eval_bit_test(t1, m + 1);
|
||||
if(s)
|
||||
{
|
||||
eval_complement(t1, t1);
|
||||
eval_increment(t1);
|
||||
}
|
||||
result = t1;
|
||||
result.sign(s);
|
||||
}
|
||||
else
|
||||
{
|
||||
*result.limbs() ^= *o.limbs();
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
>::type
|
||||
eval_bitwise_xor(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() ^= *o.limbs();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value || is_signed_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value)
|
||||
>::type
|
||||
eval_complement(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
BOOST_STATIC_ASSERT_MSG(((Checked1 != checked) || (Checked2 != checked)), "Attempt to take the complement of a signed type results in undefined behavior.");
|
||||
//
|
||||
// If we're not checked then emulate 2's complement behavior:
|
||||
//
|
||||
if(o.sign())
|
||||
{
|
||||
*result.limbs() = *o.limbs() - 1;
|
||||
result.sign(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
*result.limbs() = 1 + *o.limbs();
|
||||
result.sign(true);
|
||||
}
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
>::type
|
||||
eval_complement(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = ~*o.limbs();
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,149 @@
|
||||
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
|
||||
#ifndef BOOST_MP_CPP_INT_CHECKED_HPP
|
||||
#define BOOST_MP_CPP_INT_CHECKED_HPP
|
||||
|
||||
namespace boost{ namespace multiprecision{ namespace backends{ namespace detail{
|
||||
|
||||
//
|
||||
// Simple routines for performing checked arithmetic with a builtin arithmetic type.
|
||||
// Note that is is not a complete header, it must be included as part of boost/multiprecision/cpp_int.hpp.
|
||||
//
|
||||
|
||||
inline void raise_overflow(std::string op)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("overflow in " + op));
|
||||
}
|
||||
inline void raise_add_overflow()
|
||||
{
|
||||
raise_overflow("addition");
|
||||
}
|
||||
inline void raise_subtract_overflow()
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::range_error("Subtraction resulted in a negative value, but the type is unsigned"));
|
||||
}
|
||||
inline void raise_mul_overflow()
|
||||
{
|
||||
raise_overflow("multiplication");
|
||||
}
|
||||
inline void raise_div_overflow()
|
||||
{
|
||||
raise_overflow("division");
|
||||
}
|
||||
|
||||
template <class A>
|
||||
inline A checked_add_imp(A a, A b, const mpl::true_&)
|
||||
{
|
||||
if(a > 0)
|
||||
{
|
||||
if((b > 0) && ((integer_traits<A>::const_max - b) < a))
|
||||
raise_add_overflow();
|
||||
}
|
||||
else
|
||||
{
|
||||
if((b < 0) && ((integer_traits<A>::const_min - b) > a))
|
||||
raise_add_overflow();
|
||||
}
|
||||
return a + b;
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_add_imp(A a, A b, const mpl::false_&)
|
||||
{
|
||||
if((integer_traits<A>::const_max - b) < a)
|
||||
raise_add_overflow();
|
||||
return a + b;
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_add(A a, A b, const mpl::int_<checked>&)
|
||||
{
|
||||
return checked_add_imp(a, b, boost::is_signed<A>());
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_add(A a, A b, const mpl::int_<unchecked>&)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
template <class A>
|
||||
inline A checked_subtract_imp(A a, A b, const mpl::true_&)
|
||||
{
|
||||
if(a > 0)
|
||||
{
|
||||
if((b < 0) && ((integer_traits<A>::const_max + b) < a))
|
||||
raise_subtract_overflow();
|
||||
}
|
||||
else
|
||||
{
|
||||
if((b > 0) && ((integer_traits<A>::const_min + b) > a))
|
||||
raise_subtract_overflow();
|
||||
}
|
||||
return a - b;
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_subtract_imp(A a, A b, const mpl::false_&)
|
||||
{
|
||||
if(a < b)
|
||||
raise_subtract_overflow();
|
||||
return a - b;
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_subtract(A a, A b, const mpl::int_<checked>&)
|
||||
{
|
||||
return checked_subtract_imp(a, b, boost::is_signed<A>());
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_subtract(A a, A b, const mpl::int_<unchecked>&)
|
||||
{
|
||||
return a - b;
|
||||
}
|
||||
|
||||
template <class A>
|
||||
inline A checked_multiply(A a, A b, const mpl::int_<checked>&)
|
||||
{
|
||||
BOOST_MP_USING_ABS
|
||||
if(a && (integer_traits<A>::const_max / abs(a) < abs(b)))
|
||||
raise_mul_overflow();
|
||||
return a * b;
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_multiply(A a, A b, const mpl::int_<unchecked>&)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
||||
template <class A>
|
||||
inline A checked_divide(A a, A b, const mpl::int_<checked>&)
|
||||
{
|
||||
if(b == 0)
|
||||
raise_div_overflow();
|
||||
return a / b;
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_divide(A a, A b, const mpl::int_<unchecked>&)
|
||||
{
|
||||
return a / b;
|
||||
}
|
||||
|
||||
template <class A>
|
||||
inline A checked_left_shift(A a, unsigned long long shift, const mpl::int_<checked>&)
|
||||
{
|
||||
if(a && shift)
|
||||
{
|
||||
if((shift > sizeof(A) * CHAR_BIT) || (a >> (sizeof(A) * CHAR_BIT - shift)))
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Shift out of range"));
|
||||
}
|
||||
return a << shift;
|
||||
}
|
||||
template <class A>
|
||||
inline A checked_left_shift(A a, unsigned long long shift, const mpl::int_<unchecked>&)
|
||||
{
|
||||
return (shift >= sizeof(A) * CHAR_BIT) ? 0 : a << shift;
|
||||
}
|
||||
|
||||
}}}} // namespaces
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,389 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
//
|
||||
// Comparison operators for cpp_int_backend:
|
||||
//
|
||||
#ifndef BOOST_MP_CPP_INT_COMPARISON_HPP
|
||||
#define BOOST_MP_CPP_INT_COMPARISON_HPP
|
||||
|
||||
#include <boost/type_traits/make_unsigned.hpp>
|
||||
|
||||
namespace boost{ namespace multiprecision{ namespace backends{
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4018 4389 4996)
|
||||
#endif
|
||||
|
||||
//
|
||||
// Start with non-trivial cpp_int's:
|
||||
//
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type
|
||||
eval_eq(const cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>& a, const cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (a.sign() == b.sign())
|
||||
&& (a.size() == b.size())
|
||||
&& std::equal(a.limbs(), a.limbs() + a.size(), b.limbs());
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value,
|
||||
bool
|
||||
>::type
|
||||
eval_eq(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& a, const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (a.sign() == b.sign())
|
||||
&& (a.size() == b.size())
|
||||
&& std::equal(a.limbs(), a.limbs() + a.size(), b.limbs());
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (a.sign() == false)
|
||||
&& (a.size() == 1)
|
||||
&& (*a.limbs() == b);
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (a.sign() == (b < 0))
|
||||
&& (a.size() == 1)
|
||||
&& (*a.limbs() == static_cast<limb_type>(std::abs(b)));
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (a.size() == 1)
|
||||
&& (*a.limbs() == b);
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (b < 0) ? eval_eq(a, cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>(b)) : eval_eq(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.sign())
|
||||
return true;
|
||||
if(a.size() > 1)
|
||||
return false;
|
||||
return *a.limbs() < b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
inline typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
if((b == 0) || (a.sign() != (b < 0)))
|
||||
return a.sign();
|
||||
if(a.sign())
|
||||
{
|
||||
if(a.size() > 1)
|
||||
return true;
|
||||
return *a.limbs() > static_cast<limb_type>(std::abs(b));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(a.size() > 1)
|
||||
return false;
|
||||
return *a.limbs() < static_cast<limb_type>(b);
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.size() > 1)
|
||||
return false;
|
||||
return *a.limbs() < b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (b < 0) ? a.compare(b) < 0 : eval_lt(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.sign())
|
||||
return false;
|
||||
if(a.size() > 1)
|
||||
return true;
|
||||
return *a.limbs() > b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
inline typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(b == 0)
|
||||
return !a.sign() && ((a.size() > 1) || *a.limbs());
|
||||
if(a.sign() != (b < 0))
|
||||
return !a.sign();
|
||||
if(a.sign())
|
||||
{
|
||||
if(a.size() > 1)
|
||||
return false;
|
||||
return *a.limbs() < static_cast<limb_type>(std::abs(b));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(a.size() > 1)
|
||||
return true;
|
||||
return *a.limbs() > static_cast<limb_type>(b);
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.size() > 1)
|
||||
return true;
|
||||
return *a.limbs() > b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class Allocator>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, Allocator>& a, signed_limb_type b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (b < 0) ? a.compare(b) > 0 : eval_gt(a, static_cast<limb_type>(b)); // Use bit pattern of b for comparison.
|
||||
}
|
||||
//
|
||||
// And again for trivial cpp_ints:
|
||||
//
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::value eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return (a.sign() == b.sign()) && (*a.limbs() == *b.limbs());
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::value eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return *a.limbs() == *b.limbs();
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
||||
{
|
||||
return !a.sign() && (*a.limbs() == b);
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename make_unsigned<S>::type ui_type;
|
||||
return (a.sign() == (b < 0)) && (*a.limbs() == static_cast<ui_type>(std::abs(b)));
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
||||
{
|
||||
return *a.limbs() == b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_eq(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename make_unsigned<S>::type ui_type;
|
||||
if(b < 0)
|
||||
{
|
||||
cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
|
||||
return *a.limbs() == *t.limbs();
|
||||
}
|
||||
else
|
||||
{
|
||||
return *a.limbs() == static_cast<ui_type>(b);
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.sign() != b.sign())
|
||||
return a.sign();
|
||||
return a.sign() ? *a.limbs() > *b.limbs() : *a.limbs() < *b.limbs();
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return *a.limbs() < *b.limbs();
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.sign())
|
||||
return true;
|
||||
return *a.limbs() < b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename make_unsigned<S>::type ui_type;
|
||||
if(a.sign() != (b < 0))
|
||||
return a.sign();
|
||||
return a.sign() ? (*a.limbs() > static_cast<ui_type>(std::abs(b))) : (*a.limbs() < static_cast<ui_type>(std::abs(b)));
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
||||
{
|
||||
return *a.limbs() < b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_lt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename make_unsigned<S>::type ui_type;
|
||||
if(b < 0)
|
||||
{
|
||||
cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
|
||||
return *a.limbs() < *t.limbs();
|
||||
}
|
||||
else
|
||||
{
|
||||
return *a.limbs() < static_cast<ui_type>(b);
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.sign() != b.sign())
|
||||
return !a.sign();
|
||||
return a.sign() ? *a.limbs() < *b.limbs() : *a.limbs() > *b.limbs();
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
return *a.limbs() > *b.limbs();
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
||||
{
|
||||
if(a.sign())
|
||||
return false;
|
||||
return *a.limbs() > b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, signed_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename make_unsigned<S>::type ui_type;
|
||||
if(a.sign() != (b < 0))
|
||||
return !a.sign();
|
||||
return a.sign() ? (*a.limbs() < static_cast<ui_type>(std::abs(b))) : (*a.limbs() > static_cast<ui_type>(std::abs(b)));
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class U>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_unsigned<U>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, U b) BOOST_NOEXCEPT
|
||||
{
|
||||
return *a.limbs() > b;
|
||||
}
|
||||
template <unsigned MinBits, unsigned MaxBits, cpp_int_check_type Checked, class S>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_signed<S>::value && is_trivial_cpp_int<cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> >::value,
|
||||
bool
|
||||
>::type eval_gt(const cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void>& a, S b) BOOST_NOEXCEPT
|
||||
{
|
||||
typedef typename make_unsigned<S>::type ui_type;
|
||||
if(b < 0)
|
||||
{
|
||||
cpp_int_backend<MinBits, MaxBits, unsigned_magnitude, Checked, void> t(b);
|
||||
return *a.limbs() > *t.limbs();
|
||||
}
|
||||
else
|
||||
{
|
||||
return *a.limbs() > static_cast<ui_type>(b);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,155 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
|
||||
#ifndef BOOST_MP_CPP_INT_CORE_HPP
|
||||
#define BOOST_MP_CPP_INT_CORE_HPP
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
#include <boost/integer_traits.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
namespace boost{ namespace multiprecision{
|
||||
|
||||
namespace detail{
|
||||
|
||||
//
|
||||
// These traits calculate the largest type in the list
|
||||
// [unsigned] ong long, long, int, which has the specified number
|
||||
// of bits. Note that intN_t and boost::int_t<N> find the first
|
||||
// member of the above list, not the last. We want the last in the
|
||||
// list to ensure that mixed arithmetic operations are as efficient
|
||||
// as possible.
|
||||
//
|
||||
template <unsigned N>
|
||||
struct largest_signed_type
|
||||
{
|
||||
typedef typename mpl::if_c<
|
||||
1 + std::numeric_limits<long long>::digits == N,
|
||||
long long,
|
||||
typename mpl::if_c<
|
||||
1 + std::numeric_limits<long>::digits == N,
|
||||
long,
|
||||
typename mpl::if_c<
|
||||
1 + std::numeric_limits<int>::digits == N,
|
||||
int,
|
||||
typename boost::int_t<N>::exact
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <unsigned N>
|
||||
struct largest_unsigned_type
|
||||
{
|
||||
typedef typename mpl::if_c<
|
||||
std::numeric_limits<unsigned long long>::digits == N,
|
||||
unsigned long long,
|
||||
typename mpl::if_c<
|
||||
std::numeric_limits<unsigned long>::digits == N,
|
||||
unsigned long,
|
||||
typename mpl::if_c<
|
||||
std::numeric_limits<unsigned int>::digits == N,
|
||||
unsigned int,
|
||||
typename boost::uint_t<N>::exact
|
||||
>::type
|
||||
>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
} // namepsace detail
|
||||
|
||||
#if defined(BOOST_HAS_INT128)
|
||||
|
||||
typedef detail::largest_unsigned_type<64>::type limb_type;
|
||||
typedef detail::largest_signed_type<64>::type signed_limb_type;
|
||||
typedef boost::uint128_type double_limb_type;
|
||||
typedef boost::int128_type signed_double_limb_type;
|
||||
static const limb_type max_block_10 = 1000000000000000000uLL;
|
||||
static const limb_type digits_per_block_10 = 18;
|
||||
|
||||
inline limb_type block_multiplier(unsigned count)
|
||||
{
|
||||
static const limb_type values[digits_per_block_10]
|
||||
= { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000, 100000000000000000, 1000000000000000000 };
|
||||
BOOST_ASSERT(count < digits_per_block_10);
|
||||
return values[count];
|
||||
}
|
||||
|
||||
// Can't do formatted IO on an __int128
|
||||
#define BOOST_MP_NO_DOUBLE_LIMB_TYPE_IO
|
||||
|
||||
// Need to specialise integer_traits for __int128 as it's not a normal native type:
|
||||
} // namespace multiprecision
|
||||
|
||||
template<>
|
||||
class integer_traits<multiprecision::double_limb_type>
|
||||
: public std::numeric_limits<multiprecision::double_limb_type>,
|
||||
public detail::integer_traits_base<multiprecision::double_limb_type, 0, ~static_cast<multiprecision::double_limb_type>(0)>
|
||||
{ };
|
||||
template<>
|
||||
class integer_traits<multiprecision::signed_double_limb_type>
|
||||
: public std::numeric_limits<multiprecision::signed_double_limb_type>,
|
||||
public detail::integer_traits_base<multiprecision::signed_double_limb_type, static_cast<multiprecision::signed_double_limb_type>((static_cast<multiprecision::double_limb_type>(1) << 127)), static_cast<multiprecision::signed_double_limb_type>(((~static_cast<multiprecision::double_limb_type>(0)) >> 1))>
|
||||
{ };
|
||||
|
||||
namespace multiprecision{
|
||||
|
||||
#else
|
||||
|
||||
typedef detail::largest_unsigned_type<32>::type limb_type;
|
||||
typedef detail::largest_signed_type<32>::type signed_limb_type;
|
||||
typedef boost::uint64_t double_limb_type;
|
||||
typedef boost::int64_t signed_double_limb_type;
|
||||
static const limb_type max_block_10 = 1000000000;
|
||||
static const limb_type digits_per_block_10 = 9;
|
||||
|
||||
inline limb_type block_multiplier(unsigned count)
|
||||
{
|
||||
static const limb_type values[digits_per_block_10]
|
||||
= { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
|
||||
BOOST_ASSERT(count < digits_per_block_10);
|
||||
return values[count];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static const unsigned bits_per_limb = sizeof(limb_type) * CHAR_BIT;
|
||||
|
||||
template <class T>
|
||||
inline void minmax(const T& a, const T& b, T& aa, T& bb)
|
||||
{
|
||||
if(a < b)
|
||||
{
|
||||
aa = a;
|
||||
bb = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
aa = b;
|
||||
bb = a;
|
||||
}
|
||||
}
|
||||
|
||||
enum cpp_integer_type
|
||||
{
|
||||
signed_magnitude = 1,
|
||||
unsigned_magnitude = 0,
|
||||
signed_packed = 3,
|
||||
unsigned_packed = 2
|
||||
};
|
||||
|
||||
enum cpp_int_check_type
|
||||
{
|
||||
checked = 1,
|
||||
unchecked = 0
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // BOOST_MP_CPP_INT_CORE_HPP
|
||||
|
||||
@@ -0,0 +1,626 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
//
|
||||
// Comparison operators for cpp_int_backend:
|
||||
//
|
||||
#ifndef BOOST_MP_CPP_INT_DIV_HPP
|
||||
#define BOOST_MP_CPP_INT_DIV_HPP
|
||||
|
||||
namespace boost{ namespace multiprecision{ namespace backends{
|
||||
|
||||
template <class CppInt1, class CppInt2, class CppInt3>
|
||||
void divide_unsigned_helper(
|
||||
CppInt1* result,
|
||||
const CppInt2& x,
|
||||
const CppInt3& y,
|
||||
CppInt1& r)
|
||||
{
|
||||
if(((void*)result == (void*)&x) || ((void*)&r == (void*)&x))
|
||||
{
|
||||
CppInt2 t(x);
|
||||
divide_unsigned_helper(result, t, y, r);
|
||||
return;
|
||||
}
|
||||
if(((void*)result == (void*)&y) || ((void*)&r == (void*)&y))
|
||||
{
|
||||
CppInt3 t(y);
|
||||
divide_unsigned_helper(result, x, t, r);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
Very simple, fairly braindead long division.
|
||||
Start by setting the remainder equal to x, and the
|
||||
result equal to 0. Then in each loop we calculate our
|
||||
"best guess" for how many times y divides into r,
|
||||
add our guess to the result, and subtract guess*y
|
||||
from the remainder r. One wrinkle is that the remainder
|
||||
may go negative, in which case we subtract the current guess
|
||||
from the result rather than adding. The value of the guess
|
||||
is determined by dividing the most-significant-limb of the
|
||||
current remainder by the most-significant-limb of y.
|
||||
|
||||
Note that there are more efficient algorithms than this
|
||||
available, in particular see Knuth Vol 2. However for small
|
||||
numbers of limbs this generally outperforms the alternatives
|
||||
and avoids the normalisation step which would require extra storage.
|
||||
*/
|
||||
|
||||
|
||||
using default_ops::eval_subtract;
|
||||
|
||||
if(result == &r)
|
||||
{
|
||||
CppInt1 rem;
|
||||
divide_unsigned_helper(result, x, y, rem);
|
||||
r = rem;
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Find the most significant words of numerator and denominator.
|
||||
//
|
||||
limb_type y_order = y.size() - 1;
|
||||
|
||||
if(y_order == 0)
|
||||
{
|
||||
//
|
||||
// Only a single non-zero limb in the denominator, in this case
|
||||
// we can use a specialized divide-by-single-limb routine which is
|
||||
// much faster. This also handles division by zero:
|
||||
//
|
||||
divide_unsigned_helper(result, x, y.limbs()[y_order], r);
|
||||
return;
|
||||
}
|
||||
|
||||
typename CppInt2::const_limb_pointer px = x.limbs();
|
||||
typename CppInt3::const_limb_pointer py = y.limbs();
|
||||
|
||||
limb_type r_order = x.size() - 1;
|
||||
if((r_order == 0) && (*px == 0))
|
||||
{
|
||||
// x is zero, so is the result:
|
||||
r = y;
|
||||
if(result)
|
||||
*result = x;
|
||||
return;
|
||||
}
|
||||
|
||||
r = x;
|
||||
r.sign(false);
|
||||
if(result)
|
||||
*result = static_cast<limb_type>(0u);
|
||||
//
|
||||
// Check if the remainder is already less than the divisor, if so
|
||||
// we already have the result. Note we try and avoid a full compare
|
||||
// if we can:
|
||||
//
|
||||
if(r_order <= y_order)
|
||||
{
|
||||
if((r_order < y_order) || (r.compare_unsigned(y) < 0))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CppInt1 t;
|
||||
bool r_neg = false;
|
||||
|
||||
//
|
||||
// See if we can short-circuit long division, and use basic arithmetic instead:
|
||||
//
|
||||
if(r_order == 0)
|
||||
{
|
||||
if(result)
|
||||
*result = px[0] / py[0];
|
||||
r = px[0] % py[0];
|
||||
return;
|
||||
}
|
||||
else if(r_order == 1)
|
||||
{
|
||||
double_limb_type a, b;
|
||||
a = (static_cast<double_limb_type>(px[1]) << CppInt1::limb_bits) | px[0];
|
||||
b = y_order ?
|
||||
(static_cast<double_limb_type>(py[1]) << CppInt1::limb_bits) | py[0]
|
||||
: py[0];
|
||||
if(result)
|
||||
*result = a / b;
|
||||
r = a % b;
|
||||
return;
|
||||
}
|
||||
//
|
||||
// prepare result:
|
||||
//
|
||||
if(result)
|
||||
result->resize(1 + r_order - y_order, 1 + r_order - y_order);
|
||||
typename CppInt1::const_limb_pointer prem = r.limbs();
|
||||
// This is initialised just to keep the compiler from emitting useless warnings later on:
|
||||
typename CppInt1::limb_pointer pr
|
||||
= typename CppInt1::limb_pointer();
|
||||
if(result)
|
||||
{
|
||||
pr = result->limbs();
|
||||
for(unsigned i = 1; i < 1 + r_order - y_order; ++i)
|
||||
pr[i] = 0;
|
||||
}
|
||||
bool first_pass = true;
|
||||
|
||||
do
|
||||
{
|
||||
//
|
||||
// Calculate our best guess for how many times y divides into r:
|
||||
//
|
||||
limb_type guess;
|
||||
if((prem[r_order] <= py[y_order]) && (r_order > 0))
|
||||
{
|
||||
double_limb_type a, b, v;
|
||||
a = (static_cast<double_limb_type>(prem[r_order]) << CppInt1::limb_bits) | prem[r_order - 1];
|
||||
b = py[y_order];
|
||||
v = a / b;
|
||||
if(v > CppInt1::max_limb_value)
|
||||
guess = 1;
|
||||
else
|
||||
{
|
||||
guess = static_cast<limb_type>(v);
|
||||
--r_order;
|
||||
}
|
||||
}
|
||||
else if(r_order == 0)
|
||||
{
|
||||
guess = prem[0] / py[y_order];
|
||||
}
|
||||
else
|
||||
{
|
||||
double_limb_type a, b, v;
|
||||
a = (static_cast<double_limb_type>(prem[r_order]) << CppInt1::limb_bits) | prem[r_order - 1];
|
||||
b = (y_order > 0) ? (static_cast<double_limb_type>(py[y_order]) << CppInt1::limb_bits) | py[y_order - 1] : (static_cast<double_limb_type>(py[y_order]) << CppInt1::limb_bits);
|
||||
v = a / b;
|
||||
guess = static_cast<limb_type>(v);
|
||||
}
|
||||
BOOST_ASSERT(guess); // If the guess ever gets to zero we go on forever....
|
||||
//
|
||||
// Update result:
|
||||
//
|
||||
limb_type shift = r_order - y_order;
|
||||
if(result)
|
||||
{
|
||||
if(r_neg)
|
||||
{
|
||||
if(pr[shift] > guess)
|
||||
pr[shift] -= guess;
|
||||
else
|
||||
{
|
||||
t.resize(shift + 1, shift + 1);
|
||||
t.limbs()[shift] = guess;
|
||||
for(unsigned i = 0; i < shift; ++i)
|
||||
t.limbs()[i] = 0;
|
||||
eval_subtract(*result, t);
|
||||
}
|
||||
}
|
||||
else if(CppInt1::max_limb_value - pr[shift] > guess)
|
||||
pr[shift] += guess;
|
||||
else
|
||||
{
|
||||
t.resize(shift + 1, shift + 1);
|
||||
t.limbs()[shift] = guess;
|
||||
for(unsigned i = 0; i < shift; ++i)
|
||||
t.limbs()[i] = 0;
|
||||
eval_add(*result, t);
|
||||
}
|
||||
}
|
||||
//
|
||||
// Calculate guess * y, we use a fused mutiply-shift O(N) for this
|
||||
// rather than a full O(N^2) multiply:
|
||||
//
|
||||
double_limb_type carry = 0;
|
||||
t.resize(y.size() + shift + 1, y.size() + shift);
|
||||
bool truncated_t = !CppInt1::variable && (t.size() != y.size() + shift + 1);
|
||||
typename CppInt1::limb_pointer pt = t.limbs();
|
||||
for(unsigned i = 0; i < shift; ++i)
|
||||
pt[i] = 0;
|
||||
for(unsigned i = 0; i < y.size(); ++i)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(py[i]) * static_cast<double_limb_type>(guess);
|
||||
pt[i + shift] = static_cast<limb_type>(carry);
|
||||
carry >>= CppInt1::limb_bits;
|
||||
}
|
||||
if(carry && !truncated_t)
|
||||
{
|
||||
pt[t.size() - 1] = static_cast<limb_type>(carry);
|
||||
}
|
||||
else if(!truncated_t)
|
||||
{
|
||||
t.resize(t.size() - 1, t.size() - 1);
|
||||
}
|
||||
//
|
||||
// Update r in a way that won't actually produce a negative result
|
||||
// in case the argument types are unsigned:
|
||||
//
|
||||
if(r.compare(t) > 0)
|
||||
{
|
||||
eval_subtract(r, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
r.swap(t);
|
||||
eval_subtract(r, t);
|
||||
prem = r.limbs();
|
||||
r_neg = !r_neg;
|
||||
}
|
||||
//
|
||||
// First time through we need to strip any leading zero, otherwise
|
||||
// the termination condition goes belly-up:
|
||||
//
|
||||
if(result && first_pass)
|
||||
{
|
||||
first_pass = false;
|
||||
while(pr[result->size() - 1] == 0)
|
||||
result->resize(result->size() - 1, result->size() - 1);
|
||||
}
|
||||
//
|
||||
// Update r_order:
|
||||
//
|
||||
r_order = r.size() - 1;
|
||||
if(r_order < y_order)
|
||||
break;
|
||||
}
|
||||
// Termination condition is really just a check that r > y, but with a common
|
||||
// short-circuit case handled first:
|
||||
while((r_order > y_order) || (r.compare_unsigned(y) >= 0));
|
||||
|
||||
//
|
||||
// We now just have to normalise the result:
|
||||
//
|
||||
if(r_neg && eval_get_sign(r))
|
||||
{
|
||||
// We have one too many in the result:
|
||||
if(result)
|
||||
eval_decrement(*result);
|
||||
if(y.sign())
|
||||
{
|
||||
r.negate();
|
||||
eval_subtract(r, y);
|
||||
}
|
||||
else
|
||||
eval_subtract(r, y, r);
|
||||
}
|
||||
|
||||
BOOST_ASSERT(r.compare_unsigned(y) < 0); // remainder must be less than the divisor or our code has failed
|
||||
}
|
||||
|
||||
template <class CppInt1, class CppInt2>
|
||||
void divide_unsigned_helper(
|
||||
CppInt1* result,
|
||||
const CppInt2& x,
|
||||
limb_type y,
|
||||
CppInt1& r)
|
||||
{
|
||||
if(((void*)result == (void*)&x) || ((void*)&r == (void*)&x))
|
||||
{
|
||||
CppInt2 t(x);
|
||||
divide_unsigned_helper(result, t, y, r);
|
||||
return;
|
||||
}
|
||||
|
||||
if(result == &r)
|
||||
{
|
||||
CppInt1 rem;
|
||||
divide_unsigned_helper(result, x, y, rem);
|
||||
r = rem;
|
||||
return;
|
||||
}
|
||||
|
||||
// As above, but simplified for integer divisor:
|
||||
|
||||
using default_ops::eval_subtract;
|
||||
|
||||
if(y == 0)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Integer Division by zero."));
|
||||
}
|
||||
//
|
||||
// Find the most significant word of numerator.
|
||||
//
|
||||
limb_type r_order = x.size() - 1;
|
||||
|
||||
//
|
||||
// Set remainder and result to their initial values:
|
||||
//
|
||||
r = x;
|
||||
r.sign(false);
|
||||
typename CppInt1::limb_pointer pr = r.limbs();
|
||||
|
||||
if((r_order == 0) && (*pr == 0))
|
||||
{
|
||||
// All the limbs in x are zero, so is the result:
|
||||
return;
|
||||
}
|
||||
//
|
||||
// check for x < y, try to do this without actually having to
|
||||
// do a full comparison:
|
||||
//
|
||||
if((r_order == 0) && (*pr < y))
|
||||
{
|
||||
if(result)
|
||||
*result = static_cast<limb_type>(0u);
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// See if we can short-circuit long division, and use basic arithmetic instead:
|
||||
//
|
||||
if(r_order == 0)
|
||||
{
|
||||
if(result)
|
||||
{
|
||||
*result = *pr / y;
|
||||
result->sign(x.sign());
|
||||
}
|
||||
*pr %= y;
|
||||
r.sign(x.sign());
|
||||
return;
|
||||
}
|
||||
else if(r_order == 1)
|
||||
{
|
||||
double_limb_type a;
|
||||
a = (static_cast<double_limb_type>(pr[r_order]) << CppInt1::limb_bits) | pr[0];
|
||||
if(result)
|
||||
{
|
||||
*result = a / y;
|
||||
result->sign(x.sign());
|
||||
}
|
||||
r = a % y;
|
||||
r.sign(x.sign());
|
||||
return;
|
||||
}
|
||||
|
||||
// This is initialised just to keep the compiler from emitting useless warnings later on:
|
||||
typename CppInt1::limb_pointer pres = typename CppInt1::limb_pointer();
|
||||
if(result)
|
||||
{
|
||||
result->resize(r_order + 1, r_order + 1);
|
||||
pres = result->limbs();
|
||||
if(result->size() > r_order)
|
||||
pres[r_order] = 0; // just in case we don't set the most significant limb below.
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
//
|
||||
// Calculate our best guess for how many times y divides into r:
|
||||
//
|
||||
if((pr[r_order] < y) && r_order)
|
||||
{
|
||||
double_limb_type a, b;
|
||||
a = (static_cast<double_limb_type>(pr[r_order]) << CppInt1::limb_bits) | pr[r_order - 1];
|
||||
b = a % y;
|
||||
r.resize(r.size() - 1, r.size() - 1);
|
||||
--r_order;
|
||||
pr[r_order] = static_cast<limb_type>(b);
|
||||
if(result)
|
||||
pres[r_order] = static_cast<limb_type>(a / y);
|
||||
if(r_order && pr[r_order] == 0)
|
||||
{
|
||||
--r_order; // No remainder, division was exact.
|
||||
r.resize(r.size() - 1, r.size() - 1);
|
||||
if(result)
|
||||
pres[r_order] = static_cast<limb_type>(0u);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(result)
|
||||
pres[r_order] = pr[r_order] / y;
|
||||
pr[r_order] %= y;
|
||||
if(r_order && pr[r_order] == 0)
|
||||
{
|
||||
--r_order; // No remainder, division was exact.
|
||||
r.resize(r.size() - 1, r.size() - 1);
|
||||
if(result)
|
||||
pres[r_order] = static_cast<limb_type>(0u);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Termination condition is really just a check that r > y, but with two common
|
||||
// short-circuit cases handled first:
|
||||
while(r_order || (pr[r_order] > y));
|
||||
|
||||
if(result)
|
||||
{
|
||||
result->normalize();
|
||||
result->sign(x.sign());
|
||||
}
|
||||
r.normalize();
|
||||
r.sign(x.sign());
|
||||
|
||||
BOOST_ASSERT(r.compare(y) < 0); // remainder must be less than the divisor or our code has failed
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2, unsigned MinBits3, unsigned MaxBits3, cpp_integer_type SignType3, cpp_int_check_type Checked3, class Allocator3>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3> >::value >::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b)
|
||||
{
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> r;
|
||||
divide_unsigned_helper(&result, a, b, r);
|
||||
result.sign(a.sign() != b.sign());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
limb_type& b)
|
||||
{
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> r;
|
||||
divide_unsigned_helper(&result, a, b, r);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
signed_limb_type& b)
|
||||
{
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> r;
|
||||
divide_unsigned_helper(&result, a, static_cast<limb_type>(std::abs(b)), r);
|
||||
if(b < 0)
|
||||
result.negate();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& b)
|
||||
{
|
||||
// There is no in place divide:
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> a(result);
|
||||
eval_divide(result, a, b);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
limb_type b)
|
||||
{
|
||||
// There is no in place divide:
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> a(result);
|
||||
eval_divide(result, a, b);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
signed_limb_type b)
|
||||
{
|
||||
// There is no in place divide:
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> a(result);
|
||||
eval_divide(result, a, b);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2, unsigned MinBits3, unsigned MaxBits3, cpp_integer_type SignType3, cpp_int_check_type Checked3, class Allocator3>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3> >::value >::type
|
||||
eval_modulus(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b)
|
||||
{
|
||||
divide_unsigned_helper(static_cast<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>* >(0), a, b, result);
|
||||
result.sign(a.sign());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_modulus(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a, limb_type b)
|
||||
{
|
||||
divide_unsigned_helper(static_cast<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>* >(0), a, b, result);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_modulus(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
signed_limb_type b)
|
||||
{
|
||||
divide_unsigned_helper(static_cast<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>* >(0), a, static_cast<limb_type>(std::abs(b)), result);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_modulus(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& b)
|
||||
{
|
||||
// There is no in place divide:
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> a(result);
|
||||
eval_modulus(result, a, b);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_modulus(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
limb_type b)
|
||||
{
|
||||
// There is no in place divide:
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> a(result);
|
||||
eval_modulus(result, a, b);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_modulus(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
signed_limb_type b)
|
||||
{
|
||||
// There is no in place divide:
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> a(result);
|
||||
eval_modulus(result, a, b);
|
||||
}
|
||||
|
||||
//
|
||||
// Over again for trivial cpp_int's:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
|| is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
|
||||
>::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o)
|
||||
{
|
||||
if(!*o.limbs())
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Division by zero."));
|
||||
*result.limbs() /= *o.limbs();
|
||||
result.sign(result.sign() != o.sign());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_divide(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o)
|
||||
{
|
||||
if(!*o.limbs())
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Division by zero."));
|
||||
*result.limbs() /= *o.limbs();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_modulus(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o)
|
||||
{
|
||||
if(!*o.limbs())
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Division by zero."));
|
||||
*result.limbs() %= *o.limbs();
|
||||
result.sign(result.sign());
|
||||
}
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,216 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
//
|
||||
// Comparison operators for cpp_int_backend:
|
||||
//
|
||||
#ifndef BOOST_MP_CPP_INT_LIM_HPP
|
||||
#define BOOST_MP_CPP_INT_LIM_HPP
|
||||
|
||||
namespace std{
|
||||
|
||||
namespace detail{
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_min(const boost::mpl::true_&, const boost::mpl::true_&)
|
||||
{
|
||||
// Bounded and signed.
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> result_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, Allocator>, ExpressionTemplates> ui_type;
|
||||
static const result_type val = -result_type(~ui_type(0));
|
||||
return val;
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_min(const boost::mpl::true_&, const boost::mpl::false_&)
|
||||
{
|
||||
// Bounded and unsigned:
|
||||
static const boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> val(0u);
|
||||
return val;
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_min(const boost::mpl::false_&, const boost::mpl::true_&)
|
||||
{
|
||||
// Unbounded and signed.
|
||||
// There is no minimum value, just return 0:
|
||||
static const boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> val(0u);
|
||||
return val;
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_min(const boost::mpl::false_&, const boost::mpl::false_&)
|
||||
{
|
||||
// Unbound and unsigned:
|
||||
static const boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> val(0u);
|
||||
return val;
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_max(const boost::mpl::true_&, const boost::mpl::true_&)
|
||||
{
|
||||
// Bounded and signed.
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> result_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, Allocator>, ExpressionTemplates> ui_type;
|
||||
static const result_type val = ~ui_type(0);
|
||||
return val;
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_max(const boost::mpl::true_&, const boost::mpl::false_&)
|
||||
{
|
||||
// Bound and unsigned:
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> result_type;
|
||||
typedef boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, Allocator>, ExpressionTemplates> ui_type;
|
||||
static const result_type val = ~ui_type(0);
|
||||
return val;
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_max(const boost::mpl::false_&, const boost::mpl::true_&)
|
||||
{
|
||||
// Unbounded and signed.
|
||||
// There is no maximum value, just return 0:
|
||||
static const boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> val(0u);
|
||||
return val;
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
inline boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates>
|
||||
get_max(const boost::mpl::false_&, const boost::mpl::false_&)
|
||||
{
|
||||
// Unbound and unsigned:
|
||||
static const boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> val(0u);
|
||||
return val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
class numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >
|
||||
{
|
||||
typedef boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator> backend_type;
|
||||
typedef boost::multiprecision::number<backend_type, ExpressionTemplates> number_type;
|
||||
|
||||
struct inititializer
|
||||
{
|
||||
inititializer()
|
||||
{
|
||||
(std::numeric_limits<number_type>::max)();
|
||||
(std::numeric_limits<number_type>::min)();
|
||||
}
|
||||
void do_nothing()const{}
|
||||
};
|
||||
|
||||
static const inititializer init;
|
||||
|
||||
public:
|
||||
BOOST_STATIC_CONSTEXPR bool is_specialized = true;
|
||||
//
|
||||
// Largest and smallest numbers are bounded only by available memory, set
|
||||
// to zero:
|
||||
//
|
||||
static number_type (min)() BOOST_NOEXCEPT
|
||||
{
|
||||
init.do_nothing();
|
||||
return detail::get_min<MinBits, MaxBits, SignType, Checked, Allocator, ExpressionTemplates>(boost::multiprecision::backends::is_fixed_precision<backend_type>(), boost::multiprecision::is_signed_number<backend_type>());
|
||||
}
|
||||
static number_type (max)() BOOST_NOEXCEPT
|
||||
{
|
||||
init.do_nothing();
|
||||
return detail::get_max<MinBits, MaxBits, SignType, Checked, Allocator, ExpressionTemplates>(boost::multiprecision::backends::is_fixed_precision<backend_type>(), boost::multiprecision::is_signed_number<backend_type>());
|
||||
}
|
||||
static number_type lowest() BOOST_NOEXCEPT { return (min)(); }
|
||||
BOOST_STATIC_CONSTEXPR int digits = boost::multiprecision::backends::max_precision<backend_type>::value == UINT_MAX ? INT_MAX : boost::multiprecision::backends::max_precision<backend_type>::value;
|
||||
BOOST_STATIC_CONSTEXPR int digits10 = (INT_MAX / 1000) * 301L;
|
||||
BOOST_STATIC_CONSTEXPR int max_digits10 = digits10 + 2;
|
||||
BOOST_STATIC_CONSTEXPR bool is_signed = boost::multiprecision::is_signed_number<backend_type>::value;
|
||||
BOOST_STATIC_CONSTEXPR bool is_integer = true;
|
||||
BOOST_STATIC_CONSTEXPR bool is_exact = true;
|
||||
BOOST_STATIC_CONSTEXPR int radix = 2;
|
||||
static number_type epsilon() BOOST_NOEXCEPT { return 0; }
|
||||
static number_type round_error() BOOST_NOEXCEPT { return 0; }
|
||||
BOOST_STATIC_CONSTEXPR int min_exponent = 0;
|
||||
BOOST_STATIC_CONSTEXPR int min_exponent10 = 0;
|
||||
BOOST_STATIC_CONSTEXPR int max_exponent = 0;
|
||||
BOOST_STATIC_CONSTEXPR int max_exponent10 = 0;
|
||||
BOOST_STATIC_CONSTEXPR bool has_infinity = false;
|
||||
BOOST_STATIC_CONSTEXPR bool has_quiet_NaN = false;
|
||||
BOOST_STATIC_CONSTEXPR bool has_signaling_NaN = false;
|
||||
BOOST_STATIC_CONSTEXPR float_denorm_style has_denorm = denorm_absent;
|
||||
BOOST_STATIC_CONSTEXPR bool has_denorm_loss = false;
|
||||
static number_type infinity() BOOST_NOEXCEPT { return 0; }
|
||||
static number_type quiet_NaN() BOOST_NOEXCEPT { return 0; }
|
||||
static number_type signaling_NaN() BOOST_NOEXCEPT { return 0; }
|
||||
static number_type denorm_min() BOOST_NOEXCEPT { return 0; }
|
||||
BOOST_STATIC_CONSTEXPR bool is_iec559 = false;
|
||||
BOOST_STATIC_CONSTEXPR bool is_bounded = boost::multiprecision::backends::is_fixed_precision<backend_type>::value;
|
||||
BOOST_STATIC_CONSTEXPR bool is_modulo = (boost::multiprecision::backends::is_fixed_precision<backend_type>::value && (Checked == boost::multiprecision::unchecked));
|
||||
BOOST_STATIC_CONSTEXPR bool traps = false;
|
||||
BOOST_STATIC_CONSTEXPR bool tinyness_before = false;
|
||||
BOOST_STATIC_CONSTEXPR float_round_style round_style = round_toward_zero;
|
||||
};
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
const typename numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::inititializer numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::init;
|
||||
|
||||
#ifndef BOOST_NO_INCLASS_MEMBER_INITIALIZATION
|
||||
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::digits;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::digits10;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::max_digits10;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::is_signed;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::is_integer;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::is_exact;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::radix;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::min_exponent;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::min_exponent10;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::max_exponent;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST int numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::max_exponent10;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::has_infinity;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::has_quiet_NaN;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::has_signaling_NaN;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST float_denorm_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::has_denorm;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::has_denorm_loss;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::is_iec559;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::is_bounded;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::is_modulo;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::traps;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST bool numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::tinyness_before;
|
||||
template <unsigned MinBits, unsigned MaxBits, boost::multiprecision::cpp_integer_type SignType, boost::multiprecision::cpp_int_check_type Checked, class Allocator, boost::multiprecision::expression_template_option ExpressionTemplates>
|
||||
BOOST_CONSTEXPR_OR_CONST float_round_style numeric_limits<boost::multiprecision::number<boost::multiprecision::cpp_int_backend<MinBits, MaxBits, SignType, Checked, Allocator>, ExpressionTemplates> >::round_style;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace std
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,317 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
//
|
||||
// Comparison operators for cpp_int_backend:
|
||||
//
|
||||
#ifndef BOOST_MP_CPP_INT_MISC_HPP
|
||||
#define BOOST_MP_CPP_INT_MISC_HPP
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4702)
|
||||
#endif
|
||||
|
||||
namespace boost{ namespace multiprecision{ namespace backends{
|
||||
|
||||
template <class R, class CppInt>
|
||||
void check_in_range(const CppInt& val, const mpl::int_<checked>&)
|
||||
{
|
||||
typedef typename boost::multiprecision::detail::canonical<R, CppInt>::type cast_type;
|
||||
if(val.sign())
|
||||
{
|
||||
if(val.compare(static_cast<cast_type>((std::numeric_limits<R>::min)())) < 0)
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Could not convert to the target type - -value is out of range."));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(val.compare(static_cast<cast_type>((std::numeric_limits<R>::max)())) > 0)
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Could not convert to the target type - -value is out of range."));
|
||||
}
|
||||
}
|
||||
template <class R, class CppInt>
|
||||
void check_in_range(const CppInt& /*val*/, const mpl::int_<unchecked>&) BOOST_NOEXCEPT {}
|
||||
|
||||
void check_is_negative(const mpl::true_&) BOOST_NOEXCEPT {}
|
||||
void check_is_negative(const mpl::false_&)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::range_error("Attempt to assign a negative value to an unsigned type."));
|
||||
}
|
||||
|
||||
template <class Integer>
|
||||
inline Integer negate_integer(Integer i, const mpl::true_&) BOOST_NOEXCEPT
|
||||
{
|
||||
return -i;
|
||||
}
|
||||
template <class Integer>
|
||||
inline Integer negate_integer(Integer i, const mpl::false_&) BOOST_NOEXCEPT
|
||||
{
|
||||
return ~(i-1);
|
||||
}
|
||||
|
||||
template <class R, unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<is_integral<R>::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, void>::type
|
||||
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& backend) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
typedef mpl::int_<Checked1> checked_type;
|
||||
check_in_range<R>(backend, checked_type());
|
||||
|
||||
*result = static_cast<R>(backend.limbs()[0]);
|
||||
unsigned shift = cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
for(unsigned i = 1; (i < backend.size()) && (shift < static_cast<unsigned>(std::numeric_limits<R>::digits)); ++i)
|
||||
{
|
||||
*result += static_cast<R>(backend.limbs()[i]) << shift;
|
||||
shift += cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
}
|
||||
if(backend.sign())
|
||||
{
|
||||
check_is_negative(boost::is_signed<R>());
|
||||
*result = negate_integer(*result, boost::is_signed<R>());
|
||||
}
|
||||
}
|
||||
|
||||
template <class R, unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<is_floating_point<R>::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, void>::type
|
||||
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& backend) BOOST_NOEXCEPT
|
||||
{
|
||||
typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::const_limb_pointer p = backend.limbs();
|
||||
unsigned shift = cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
*result = static_cast<R>(*p);
|
||||
for(unsigned i = 1; i < backend.size(); ++i)
|
||||
{
|
||||
*result += static_cast<R>(std::ldexp(static_cast<long double>(p[i]), shift));
|
||||
shift += cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
}
|
||||
if(backend.sign())
|
||||
*result = -*result;
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, bool>::type
|
||||
eval_is_zero(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val) BOOST_NOEXCEPT
|
||||
{
|
||||
return (val.size() == 1) && (val.limbs()[0] == 0);
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, int>::type
|
||||
eval_get_sign(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val) BOOST_NOEXCEPT
|
||||
{
|
||||
return eval_is_zero(val) ? 0 : val.sign() ? -1 : 1;
|
||||
}
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_abs(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
result = val;
|
||||
result.sign(false);
|
||||
}
|
||||
|
||||
//
|
||||
// Get the location of the least-significant-bit:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, unsigned>::type
|
||||
eval_lsb(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& a) BOOST_NOEXCEPT
|
||||
{
|
||||
using default_ops::eval_get_sign;
|
||||
if(eval_get_sign(a) == 0)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::range_error("No bits were set in the operand."));
|
||||
}
|
||||
if(a.sign())
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::range_error("Testing individual bits in negative values is not supported - results are undefined."));
|
||||
}
|
||||
|
||||
unsigned result = 0;
|
||||
//
|
||||
// Find the index of the least significant limb that is non-zero:
|
||||
//
|
||||
unsigned index = 0;
|
||||
while(!a.limbs()[index] && (index < a.size()))
|
||||
++index;
|
||||
//
|
||||
// Find the index of the least significant bit within that limb:
|
||||
//
|
||||
limb_type l = a.limbs()[index];
|
||||
while(!(l & 1u))
|
||||
{
|
||||
l >>= 1;
|
||||
++result;
|
||||
}
|
||||
|
||||
return result + index * cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, bool>::type
|
||||
eval_bit_test(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val, unsigned index) BOOST_NOEXCEPT
|
||||
{
|
||||
unsigned offset = index / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
unsigned shift = index % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u);
|
||||
if(offset >= val.size())
|
||||
return false;
|
||||
return val.limbs()[offset] & mask ? true : false;
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_bit_set(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val, unsigned index)
|
||||
{
|
||||
unsigned offset = index / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
unsigned shift = index % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u);
|
||||
if(offset >= val.size())
|
||||
{
|
||||
unsigned os = val.size();
|
||||
val.resize(offset + 1, offset + 1);
|
||||
if(offset >= val.size())
|
||||
return; // fixed precision overflow
|
||||
for(unsigned i = os; i <= offset; ++i)
|
||||
val.limbs()[i] = 0;
|
||||
}
|
||||
val.limbs()[offset] |= mask;
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_bit_unset(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val, unsigned index) BOOST_NOEXCEPT
|
||||
{
|
||||
unsigned offset = index / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
unsigned shift = index % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u);
|
||||
if(offset >= val.size())
|
||||
return;
|
||||
val.limbs()[offset] &= ~mask;
|
||||
val.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_bit_flip(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val, unsigned index)
|
||||
{
|
||||
unsigned offset = index / cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
unsigned shift = index % cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
limb_type mask = shift ? limb_type(1u) << shift : limb_type(1u);
|
||||
if(offset >= val.size())
|
||||
{
|
||||
unsigned os = val.size();
|
||||
val.resize(offset + 1, offset + 1);
|
||||
if(offset >= val.size())
|
||||
return; // fixed precision overflow
|
||||
for(unsigned i = os; i <= offset; ++i)
|
||||
val.limbs()[i] = 0;
|
||||
}
|
||||
val.limbs()[offset] ^= mask;
|
||||
val.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_qr(
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& x,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& y,
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& q,
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& r) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
divide_unsigned_helper(&q, x, y, r);
|
||||
q.sign(x.sign() != y.sign());
|
||||
r.sign(x.sign());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, class Integer>
|
||||
inline typename enable_if_c<is_unsigned<Integer>::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, Integer>::type
|
||||
eval_integer_modulus(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& x, Integer val)
|
||||
{
|
||||
if((sizeof(Integer) <= sizeof(limb_type)) || (val <= (std::numeric_limits<limb_type>::max)()))
|
||||
{
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> d;
|
||||
divide_unsigned_helper(static_cast<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>*>(0), x, static_cast<limb_type>(val), d);
|
||||
return d.limbs()[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
return default_ops::eval_integer_modulus(x, val);
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, class Integer>
|
||||
BOOST_FORCEINLINE typename enable_if_c<is_signed<Integer>::value && !is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value, Integer>::type
|
||||
eval_integer_modulus(const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& x, Integer val)
|
||||
{
|
||||
typedef typename make_unsigned<Integer>::type unsigned_type;
|
||||
return eval_integer_modulus(x, static_cast<unsigned_type>(std::abs(val)));
|
||||
}
|
||||
|
||||
//
|
||||
// Now again for trivial backends:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_gcd(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& a, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& b) BOOST_NOEXCEPT
|
||||
{
|
||||
*result.limbs() = boost::math::gcd(*a.limbs(), *b.limbs());
|
||||
}
|
||||
// This one is only enabled for unchecked cpp_int's, for checked int's we need the checking in the default version:
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && (Checked1 == unchecked)>::type
|
||||
eval_lcm(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& a, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = boost::math::lcm(*a.limbs(), *b.limbs());
|
||||
result.normalize(); // result may overflow the specified number of bits
|
||||
}
|
||||
|
||||
inline void conversion_overflow(const mpl::int_<checked>&)
|
||||
{
|
||||
BOOST_THROW_EXCEPTION(std::overflow_error("Overflow in conversion to narrower type"));
|
||||
}
|
||||
inline void conversion_overflow(const mpl::int_<unchecked>&){}
|
||||
|
||||
template <class R, unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val)
|
||||
{
|
||||
typedef typename common_type<R, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::local_limb_type>::type common_type;
|
||||
if(std::numeric_limits<R>::is_specialized && (static_cast<common_type>(*val.limbs()) > static_cast<common_type>((std::numeric_limits<R>::max)())))
|
||||
{
|
||||
conversion_overflow(typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
*result = (std::numeric_limits<R>::max)();
|
||||
}
|
||||
else
|
||||
*result = static_cast<R>(*val.limbs());
|
||||
if(val.isneg())
|
||||
{
|
||||
check_is_negative(mpl::bool_<boost::is_signed<R>::value || boost::is_floating_point<R>::value>());
|
||||
*result = negate_integer(*result, mpl::bool_<boost::is_signed<R>::value || boost::is_floating_point<R>::value>());
|
||||
}
|
||||
}
|
||||
|
||||
template <class R, unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_convert_to(R* result, const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& val)
|
||||
{
|
||||
typedef typename common_type<R, typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::local_limb_type>::type common_type;
|
||||
if(std::numeric_limits<R>::is_specialized && (static_cast<common_type>(*val.limbs()) > static_cast<common_type>((std::numeric_limits<R>::max)())))
|
||||
{
|
||||
conversion_overflow(typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
*result = (std::numeric_limits<R>::max)();
|
||||
}
|
||||
else
|
||||
*result = static_cast<R>(*val.limbs());
|
||||
}
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,437 @@
|
||||
///////////////////////////////////////////////////////////////
|
||||
// Copyright 2012 John Maddock. 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_
|
||||
//
|
||||
// Comparison operators for cpp_int_backend:
|
||||
//
|
||||
#ifndef BOOST_MP_CPP_INT_MUL_HPP
|
||||
#define BOOST_MP_CPP_INT_MUL_HPP
|
||||
|
||||
namespace boost{ namespace multiprecision{ namespace backends{
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(!val)
|
||||
{
|
||||
result = static_cast<limb_type>(0);
|
||||
return;
|
||||
}
|
||||
if((void*)&a != (void*)&result)
|
||||
result.resize(a.size(), a.size());
|
||||
double_limb_type carry = 0;
|
||||
typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_pointer p = result.limbs();
|
||||
typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_pointer pe = result.limbs() + result.size();
|
||||
typename cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>::const_limb_pointer pa = a.limbs();
|
||||
while(p != pe)
|
||||
{
|
||||
carry += static_cast<double_limb_type>(*pa) * static_cast<double_limb_type>(val);
|
||||
*p = static_cast<limb_type>(carry);
|
||||
carry >>= cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
++p, ++pa;
|
||||
}
|
||||
if(carry)
|
||||
{
|
||||
unsigned i = result.size();
|
||||
result.resize(i + 1, i + 1);
|
||||
if(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::variable || (result.size() > i))
|
||||
result.limbs()[i] = static_cast<limb_type>(carry);
|
||||
}
|
||||
result.sign(a.sign());
|
||||
if(!cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::variable)
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
//
|
||||
// resize_for_carry forces a resize of the underlying buffer only if a previous request
|
||||
// for "required" elements could possibly have failed, *and* we have checking enabled.
|
||||
// This will cause an overflow error inside resize():
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline void resize_for_carry(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& /*result*/, unsigned /*required*/){}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
inline void resize_for_carry(cpp_int_backend<MinBits1, MaxBits1, SignType1, checked, void>& result, unsigned required)
|
||||
{
|
||||
if(result.size() != required)
|
||||
result.resize(required, required);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2, unsigned MinBits3, unsigned MaxBits3, cpp_integer_type SignType3, cpp_int_check_type Checked3, class Allocator3>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3> >::value >::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
// Very simple long multiplication, only usable for small numbers of limb_type's
|
||||
// but that's the typical use case for this type anyway:
|
||||
//
|
||||
// Special cases first:
|
||||
//
|
||||
unsigned as = a.size();
|
||||
unsigned bs = b.size();
|
||||
typename cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>::const_limb_pointer pa = a.limbs();
|
||||
typename cpp_int_backend<MinBits3, MaxBits3, SignType3, Checked3, Allocator3>::const_limb_pointer pb = b.limbs();
|
||||
if(as == 1)
|
||||
{
|
||||
bool s = b.sign() != a.sign();
|
||||
if(bs == 1)
|
||||
{
|
||||
result = static_cast<double_limb_type>(*pa) * static_cast<double_limb_type>(*pb);
|
||||
}
|
||||
else
|
||||
{
|
||||
limb_type l = *pa;
|
||||
eval_multiply(result, b, l);
|
||||
}
|
||||
result.sign(s);
|
||||
return;
|
||||
}
|
||||
if(bs == 1)
|
||||
{
|
||||
bool s = b.sign() != a.sign();
|
||||
limb_type l = *pb;
|
||||
eval_multiply(result, a, l);
|
||||
result.sign(s);
|
||||
return;
|
||||
}
|
||||
|
||||
if((void*)&result == (void*)&a)
|
||||
{
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t(a);
|
||||
eval_multiply(result, t, b);
|
||||
return;
|
||||
}
|
||||
if((void*)&result == (void*)&b)
|
||||
{
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t(b);
|
||||
eval_multiply(result, a, t);
|
||||
return;
|
||||
}
|
||||
|
||||
result.resize(as + bs, as + bs - 1);
|
||||
typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_pointer pr = result.limbs();
|
||||
|
||||
static const double_limb_type limb_max = ~static_cast<limb_type>(0u);
|
||||
static const double_limb_type double_limb_max = ~static_cast<double_limb_type>(0u);
|
||||
BOOST_STATIC_ASSERT(double_limb_max - 2 * limb_max >= limb_max * limb_max);
|
||||
|
||||
double_limb_type carry = 0;
|
||||
std::memset(pr, 0, result.size() * sizeof(limb_type));
|
||||
for(unsigned i = 0; i < as; ++i)
|
||||
{
|
||||
unsigned inner_limit = cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::variable ? bs : (std::min)(result.size() - i, bs);
|
||||
for(unsigned j = 0; j < inner_limit; ++j)
|
||||
{
|
||||
BOOST_ASSERT(i+j < result.size());
|
||||
BOOST_ASSERT(!std::numeric_limits<double_limb_type>::is_specialized
|
||||
|| ((std::numeric_limits<double_limb_type>::max)() - carry
|
||||
>
|
||||
static_cast<double_limb_type>(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value) * static_cast<double_limb_type>(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value)));
|
||||
carry += static_cast<double_limb_type>(pa[i]) * static_cast<double_limb_type>(pb[j]);
|
||||
BOOST_ASSERT(!std::numeric_limits<double_limb_type>::is_specialized || ((std::numeric_limits<double_limb_type>::max)() - carry >= pr[i+j]));
|
||||
carry += pr[i + j];
|
||||
pr[i + j] = static_cast<limb_type>(carry);
|
||||
carry >>= cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::limb_bits;
|
||||
BOOST_ASSERT(carry <= (cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::max_limb_value));
|
||||
}
|
||||
resize_for_carry(result, as + bs); // May throw if checking is enabled
|
||||
if(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::variable || (i + bs < result.size()))
|
||||
pr[i + bs] = static_cast<limb_type>(carry);
|
||||
carry = 0;
|
||||
}
|
||||
result.normalize();
|
||||
//
|
||||
// Set the sign of the result:
|
||||
//
|
||||
result.sign(a.sign() != b.sign());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
eval_multiply(result, result, a);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_multiply(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
eval_multiply(result, result, val);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const double_limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(val <= (std::numeric_limits<limb_type>::max)())
|
||||
{
|
||||
eval_multiply(result, a, static_cast<limb_type>(val));
|
||||
}
|
||||
else
|
||||
{
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t(val);
|
||||
eval_multiply(result, a, t);
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_multiply(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const double_limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
eval_multiply(result, result, val);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const signed_limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(val > 0)
|
||||
eval_multiply(result, a, static_cast<limb_type>(val));
|
||||
else
|
||||
{
|
||||
eval_multiply(result, a, static_cast<limb_type>(-val));
|
||||
result.negate();
|
||||
}
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_multiply(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const signed_limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
eval_multiply(result, result, val);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
inline typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value && !is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value >::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>& a,
|
||||
const signed_double_limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
if(val > 0)
|
||||
{
|
||||
if(val <= (std::numeric_limits<limb_type>::max)())
|
||||
{
|
||||
eval_multiply(result, a, static_cast<limb_type>(val));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if(val >= -static_cast<signed_double_limb_type>((std::numeric_limits<limb_type>::max)()))
|
||||
{
|
||||
eval_multiply(result, a, static_cast<limb_type>(-val));
|
||||
result.negate();
|
||||
return;
|
||||
}
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> t(val);
|
||||
eval_multiply(result, a, t);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value>::type
|
||||
eval_multiply(cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result, const signed_double_limb_type& val) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
eval_multiply(result, result, val);
|
||||
}
|
||||
|
||||
//
|
||||
// Now over again for trivial cpp_int's:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
|| is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
|
||||
>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = detail::checked_multiply(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.sign(result.sign() != o.sign());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& o) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = detail::checked_multiply(*result.limbs(), *o.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& (is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
|| is_signed_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value)
|
||||
>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& a,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = detail::checked_multiply(*a.limbs(), *b.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.sign(a.sign() != b.sign());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_unsigned_number<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& a,
|
||||
const cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& b) BOOST_NOEXCEPT_IF((is_non_throwing_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value))
|
||||
{
|
||||
*result.limbs() = detail::checked_multiply(*a.limbs(), *b.limbs(), typename cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>::checked_type());
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
//
|
||||
// Special routines for multiplying two integers to obtain a multiprecision result:
|
||||
//
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
signed_double_limb_type a, signed_double_limb_type b)
|
||||
{
|
||||
static const signed_double_limb_type mask = ~static_cast<limb_type>(0);
|
||||
static const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT;
|
||||
bool s = false;
|
||||
double_limb_type w, x, y, z;
|
||||
if(a < 0)
|
||||
{
|
||||
a = -a;
|
||||
s = true;
|
||||
}
|
||||
if(b < 0)
|
||||
{
|
||||
b = -b;
|
||||
s = !s;
|
||||
}
|
||||
w = a & mask;
|
||||
x = a >> limb_bits;
|
||||
y = b & mask;
|
||||
z = b >> limb_bits;
|
||||
|
||||
result.resize(4, 4);
|
||||
limb_type* pr = result.limbs();
|
||||
|
||||
double_limb_type carry = w * y;
|
||||
pr[0] = static_cast<limb_type>(carry);
|
||||
carry >>= limb_bits;
|
||||
carry += w * z + x * y;
|
||||
pr[1] = static_cast<limb_type>(carry);
|
||||
carry >>= limb_bits;
|
||||
carry += x * z;
|
||||
pr[2] = static_cast<limb_type>(carry);
|
||||
pr[3] = static_cast<limb_type>(carry >> limb_bits);
|
||||
|
||||
result.sign(s);
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
double_limb_type a, double_limb_type b)
|
||||
{
|
||||
static const signed_double_limb_type mask = ~static_cast<limb_type>(0);
|
||||
static const unsigned limb_bits = sizeof(limb_type) * CHAR_BIT;
|
||||
|
||||
double_limb_type w, x, y, z;
|
||||
w = a & mask;
|
||||
x = a >> limb_bits;
|
||||
y = b & mask;
|
||||
z = b >> limb_bits;
|
||||
|
||||
result.resize(4, 4);
|
||||
limb_type* pr = result.limbs();
|
||||
|
||||
double_limb_type carry = w * y;
|
||||
pr[0] = static_cast<limb_type>(carry);
|
||||
carry >>= limb_bits;
|
||||
carry += w * z;
|
||||
pr[1] = static_cast<limb_type>(carry);
|
||||
carry >>= limb_bits;
|
||||
pr[2] = static_cast<limb_type>(carry);
|
||||
carry = x * y + pr[1];
|
||||
pr[1] = static_cast<limb_type>(carry);
|
||||
carry >>= limb_bits;
|
||||
carry += pr[2] + x * z;
|
||||
pr[2] = static_cast<limb_type>(carry);
|
||||
pr[3] = static_cast<limb_type>(carry >> limb_bits);
|
||||
|
||||
result.sign(false);
|
||||
result.normalize();
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1,
|
||||
unsigned MinBits2, unsigned MaxBits2, cpp_integer_type SignType2, cpp_int_check_type Checked2, class Allocator2>
|
||||
BOOST_FORCEINLINE typename enable_if_c<
|
||||
!is_trivial_cpp_int<cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
&& is_trivial_cpp_int<cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> >::value
|
||||
>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> const& a,
|
||||
cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2> const& b)
|
||||
{
|
||||
typedef typename boost::multiprecision::detail::canonical<typename cpp_int_backend<MinBits2, MaxBits2, SignType2, Checked2, Allocator2>::local_limb_type, cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1> >::type canonical_type;
|
||||
eval_multiply(result, static_cast<canonical_type>(*a.limbs()), static_cast<canonical_type>(*b.limbs()));
|
||||
result.sign(a.sign() != b.sign());
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, class SI>
|
||||
BOOST_FORCEINLINE typename enable_if_c<is_signed<SI>::value && (sizeof(SI) <= sizeof(signed_double_limb_type) / 2)>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
SI a, SI b)
|
||||
{
|
||||
result = static_cast<signed_double_limb_type>(a) * static_cast<signed_double_limb_type>(b);
|
||||
}
|
||||
|
||||
template <unsigned MinBits1, unsigned MaxBits1, cpp_integer_type SignType1, cpp_int_check_type Checked1, class Allocator1, class UI>
|
||||
BOOST_FORCEINLINE typename enable_if_c<is_unsigned<UI>::value && (sizeof(UI) <= sizeof(signed_double_limb_type) / 2)>::type
|
||||
eval_multiply(
|
||||
cpp_int_backend<MinBits1, MaxBits1, SignType1, Checked1, Allocator1>& result,
|
||||
UI a, UI b)
|
||||
{
|
||||
result = static_cast<double_limb_type>(a) * static_cast<double_limb_type>(b);
|
||||
}
|
||||
|
||||
}}} // namespaces
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user