1 <?xml version="1.0" encoding="UTF-8"?>
3 <!-- **************************************************************************
5 * (C) Copyright Paul Mensonides 2003-2005. *
7 * Distributed under the Boost Software License, Version 1.0. *
8 * (See accompanying file LICENSE). *
10 * See http://chaos-pp.sourceforge.net for the most recent version. *
12 ************************************************************************** -->
14 <document id="Arbitrary-Precision Arithmetic" author="Paul Mensonides" date="2003-2005">
17 The <link id="arbitrary-precision arithmetic"/> component supports arithmetic, relational, and equality operations on signed integers of any precision.
20 <section id="Representation">
22 Positive <link id="arbitrary-precision values"/> are represented as a <link id="sequence"/> of base-10 digits.
23 For example, the value +123 is represented as <code>(1)(2)(3)</code>.
24 Negative values are represented as a parenthesized <link id="sequence"/> of base-10 digits.
25 For example, the value -123 is represented as <code>((1)(2)(3))</code>.
28 <section id="Conversion">
30 The library supplies primitives that convert between various formats.
31 The first of these is <ARBITRARY_PROMOTE/> which converts a simple integer range from <code>0</code> to <LIMIT_MAG/> to an <link id="arbitrary-precision value"/> (e.g. <code><ARBITRARY_PROMOTE/>(123)</code>).
32 Negative values can be specified by prefixing the number with a parenthesized negation operator (e.g. <code><ARBITRARY_PROMOTE/>((-)123)</code>).
35 The second conversion primitive is <ARBITRARY_LITERAL/> which converts a <link id="string"/> of digits to a <link id="arbitrary-precision value"/> (e.g. <code><ARBITRARY_LITERAL/>(1 2 3)</code>).
36 Negative values can be specified by again prefixing the digits with a parenthesized negation operator (e.g. <code><ARBITRARY_LITERAL/>((-)1 2 3)</code>).
39 The third conversion primitive is <ARBITRARY_BOOL/> which converts a <link id="arbitrary-precision value"/> to a Boolean value (i.e. either <code>0</code> or <code>1</code>).
42 The last conversion primitive is <ARBITRARY_DEMOTE/> which converts an <link id="arbitrary-precision value"/> to a simple integer (e.g. <code><ARBITRARY_DEMOTE/>((1)(2)(3))</code>).
43 If the <link id="arbitrary-precision value"/> is negative, the result is prefixed with a negation operator (e.g. <code><ARBITRARY_DEMOTE/>(((1)(2)(3)))</code> expands to <code>-123</code>).
46 <section id="Arithmetic Operators">
48 The basic arithmetic operations are all available on <link id="arbitrary-precision values"/>.
49 The following table summarizes these operations and their equivalents in C or C++:
52 <column><code><ARBITRARY_ADD/>(x, y)</code></column>
53 <column type="expression"><code>x + y</code></column>
56 <column><code><ARBITRARY_DEC/>(x)</code></column>
57 <column type="expression"><code>x - 1</code></column>
60 <column><code><ARBITRARY_DIV/>(x, y)</code></column>
61 <column type="expression"><code>x / y</code></column>
64 <column><code><ARBITRARY_INC/>(x)</code></column>
65 <column type="expression"><code>x + 1</code></column>
68 <column><code><ARBITRARY_MUL/>(x, y)</code></column>
69 <column type="expression"><code>x * y</code></column>
72 <column><code><ARBITRARY_MOD/>(x, y)</code></column>
73 <column type="expression"><code>x % y</code></column>
76 <column><code><ARBITRARY_NEG/>(x)</code></column>
77 <column type="expression"><code>-x</code></column>
80 <column><code><ARBITRARY_SUB/>(x, y)</code></column>
81 <column type="expression"><code>x - y</code></column>
86 <section id="Equality & Relational Operators">
88 The basic equality and relation operators are provided as well.
89 The following table summarizes these operations and their equivalents in C or C++.
92 <column><code><ARBITRARY_EQUAL/>(x, y)</code></column>
93 <column type="expression"><code>x == y</code></column>
96 <column><code><ARBITRARY_GREATER/>(x, y)</code></column>
97 <column type="expression"><code>x > y</code></column>
100 <column><code><ARBITRARY_GREATER_EQUAL/>(x, y)</code></column>
101 <column type="expression"><code>x >= y</code></column>
104 <column><code><ARBITRARY_LESS/>(x, y)</code></column>
105 <column type="expression"><code>x < y</code></column>
108 <column><code><ARBITRARY_LESS_EQUAL/>(x, y)</code></column>
109 <column type="expression"><code>x <= y</code></column>
112 <column><code><ARBITRARY_NOT_EQUAL/>(x, y)</code></column>
113 <column type="expression"><code>x != y</code></column>