diff --git a/doc/html/boost_multiprecision/intro.html b/doc/html/boost_multiprecision/intro.html index 59d5fc82..25367098 100644 --- a/doc/html/boost_multiprecision/intro.html +++ b/doc/html/boost_multiprecision/intro.html @@ -55,6 +55,19 @@ typedef mp::mp_number<mp::mpfr_float_backend<300> > my_float; +my_float a, b, c; // These variables have 300 decimal digits precision + +

+ 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 mp_number: +

+
#include <boost/multiprecision/mpfr.hpp>  // Defines the Backend type that wraps MPFR
+
+namespace mp = boost::multiprecision;     // Reduce the typing a bit later...
+
+typedef mp::mp_number<mp::mpfr_float_backend<300>, false>  my_float;
+
 my_float a, b, c; // These variables have 300 decimal digits precision
 
@@ -303,6 +316,12 @@ as one would hope. +

+ Finally, note that mp_number + takes a second template argument, which, when set to false + disables all the expression template machinary. The result is much faster to + compile, but slower at runtime. +

We'll conclude this section by providing some more performance comparisons between these three libraries, again, all are using MPFR diff --git a/doc/html/boost_multiprecision/ref/backendconc.html b/doc/html/boost_multiprecision/ref/backendconc.html index 95fe4403..d9633266 100644 --- a/doc/html/boost_multiprecision/ref/backendconc.html +++ b/doc/html/boost_multiprecision/ref/backendconc.html @@ -330,7 +330,7 @@

- add(b, + eval_add(b, cb)

@@ -348,7 +348,7 @@

- subtract(b, + eval_subtract(b, cb)

@@ -367,7 +367,7 @@

- multiply(b, + eval_multiply(b, cb)

@@ -386,7 +386,7 @@

- divide(b, + eval_divide(b, cb)

@@ -404,7 +404,7 @@

- modulus(b, + eval_modulus(b, cb)

@@ -425,8 +425,7 @@

- bitwise_and(b, - cb) + eval_bitwise_and(b, cb)

@@ -446,8 +445,7 @@

- bitwise_or(b, - cb) + eval_bitwise_or(b, cb)

@@ -467,8 +465,7 @@

- bitwise_xor(b, - cb) + eval_bitwise_xor(b, cb)

@@ -488,8 +485,7 @@

- complement(b, - cb) + eval_complement(b, cb)

@@ -509,8 +505,7 @@

- left_shift(b, - ui) + eval_left_shift(b, ui)

@@ -530,8 +525,7 @@

- right_shift(b, - ui) + eval_right_shift(b, ui)

@@ -551,8 +545,7 @@

- convert_to(pa, - cb) + eval_convert_to(pa, cb)

@@ -807,7 +800,7 @@

- add(b, + eval_add(b, a)

@@ -827,7 +820,7 @@

- subtract(b, + eval_subtract(b, a)

@@ -849,7 +842,7 @@

- multiply(b, + eval_multiply(b, a)

@@ -871,7 +864,7 @@

- divide(b, + eval_divide(b, a)

@@ -891,7 +884,7 @@

- modulus(b, + eval_modulus(b, a)

@@ -914,8 +907,7 @@

- bitwise_and(b, - a) + eval_bitwise_and(b, a)

@@ -937,8 +929,7 @@

- bitwise_or(b, - a) + eval_bitwise_or(b, a)

@@ -960,8 +951,7 @@

- bitwise_xor(b, - a) + eval_bitwise_xor(b, a)

@@ -983,7 +973,7 @@

- add(b, + eval_add(b, cb, cb2)

@@ -1003,7 +993,7 @@

- subtract(b, + eval_subtract(b, cb, cb2)

@@ -1024,7 +1014,7 @@

- multiply(b, + eval_multiply(b, cb, cb2)

@@ -1045,7 +1035,7 @@

- divide(b, + eval_divide(b, cb, cb2)

@@ -1066,7 +1056,7 @@

- add(b, + eval_add(b, cb, a)

@@ -1087,7 +1077,7 @@

- subtract(b, + eval_subtract(b, cb, a)

@@ -1111,7 +1101,7 @@

- multiply(b, + eval_multiply(b, cb, a)

@@ -1135,7 +1125,7 @@

- divide(b, + eval_divide(b, cb, a)

@@ -1159,7 +1149,7 @@

- modulus(b, + eval_modulus(b, cb, cb2)

@@ -1182,9 +1172,7 @@

- bitwise_and(b, - cb, - cb2) + eval_bitwise_and(b, cb, cb2)

@@ -1205,9 +1193,7 @@

- bitwise_or(b, - cb, - cb2) + eval_bitwise_or(b, cb, cb2)

@@ -1228,9 +1214,7 @@

- bitwise_xor(b, - cb, - cb2) + eval_bitwise_xor(b, cb, cb2)

@@ -1251,7 +1235,7 @@

- add(b, + eval_add(b, a, cb)

@@ -1274,7 +1258,7 @@

- subtract(b, + eval_subtract(b, a, cb)

@@ -1298,7 +1282,7 @@

- multiply(b, + eval_multiply(b, a, cb)

@@ -1322,7 +1306,7 @@

- divide(b, + eval_divide(b, a, cb)

@@ -1345,7 +1329,7 @@

- modulus(b, + eval_modulus(b, cb, a)

@@ -1370,9 +1354,7 @@

- bitwise_and(b, - cb, - a) + eval_bitwise_and(b, cb, a)

@@ -1395,9 +1377,7 @@

- bitwise_or(b, - cb, - a) + eval_bitwise_or(b, cb, a)

@@ -1420,9 +1400,7 @@

- bitwise_xor(b, - cb, - a) + eval_bitwise_xor(b, cb, a)

@@ -1445,7 +1423,7 @@

- modulus(b, + eval_modulus(b, a, cb)

@@ -1470,9 +1448,7 @@

- bitwise_and(b, - a, - cb) + eval_bitwise_and(b, a, cb)

@@ -1495,9 +1471,7 @@

- bitwise_or(b, - a, - cb) + eval_bitwise_or(b, a, cb)

@@ -1520,9 +1494,7 @@

- bitwise_xor(b, - a, - cb) + eval_bitwise_xor(b, a, cb)

@@ -1545,9 +1517,7 @@

- left_shift(b, - cb, - ui) + eval_left_shift(b, cb, ui)

@@ -1568,9 +1538,7 @@

- right_shift(b, - cb, - ui) + eval_right_shift(b, cb, ui)

@@ -1591,7 +1559,7 @@

- increment(b) + eval_increment(b)

@@ -1609,7 +1577,7 @@

- decrement(b) + eval_decrement(b)

@@ -1627,7 +1595,7 @@

- is_zero(cb) + eval_is_zero(cb)

@@ -1644,7 +1612,7 @@

- get_sign(cb) + eval_get_sign(cb)

@@ -2102,7 +2070,18 @@ -
+
+ + + + + +
[Note]Note

+ The non-member functions are all named with an "eval_" prefix + to avoid conflicts with template classes of the same name - in point of + fact this naming convension shouldn't be necessary, but rather works around + some compiler bugs. +

diff --git a/doc/html/boost_multiprecision/ref/mp_number.html b/doc/html/boost_multiprecision/ref/mp_number.html index f039c147..a68c1649 100644 --- a/doc/html/boost_multiprecision/ref/mp_number.html +++ b/doc/html/boost_multiprecision/ref/mp_number.html @@ -23,7 +23,7 @@
namespace boost{ namespace multiprecision{
 
-template <class Backend>
+template <class Backend, bool ExpressionTemplates = true>
 class mp_number
 {
    mp_number();
@@ -94,15 +94,15 @@
 bool operator>=(const see-below&, const see-below&);
 
 // Swap:
-template <class Backend>
-void swap(mp_number<Backend>& a, mp_number<Backend>& b);
+template <class Backend, bool ExpressionTemplates>
+void swap(mp_number<Backend, ExpressionTemplates>& a, mp_number<Backend, ExpressionTemplates>& b);
 
 // iostream support:
-template <class Backend>
-std::ostream& operator << (std::ostream& os, const mp_number<Backend>& r);
+template <class Backend, bool ExpressionTemplates>
+std::ostream& operator << (std::ostream& os, const mp_number<Backend, ExpressionTemplates>& r);
 std::ostream& operator << (std::ostream& os, const unmentionable-expression-template-type& r);
-template <class Backend>
-std::istream& operator >> (std::istream& is, mp_number<Backend>& r);
+template <class Backend, bool ExpressionTemplates>
+std::istream& operator >> (std::istream& is, mp_number<Backend, ExpressionTemplates>& r);
 
 // Non-member function standard library support:
 unmentionable-expression-template-type    abs    (const mp_number-or-expression-template-type&);
@@ -163,8 +163,8 @@
 // numeric_limits support:
 namespace std{
 
-template <class Backend>
-struct numeric_limits<boost::multiprecision<Backend> >
+template <class Backend, bool ExpressionTemplates>
+struct numeric_limits<boost::multiprecision<Backend, ExpressionTemplates> >
 {
    /* Usual members here */
 };
@@ -175,6 +175,27 @@
 
         Description
       
+
template <class Backend, bool ExpressionTemplates = true>
+class mp_number;
+
+

+ Class mp_number has two template + arguments: +

+
+

+
+
Backend
+

+ The actual arithmetic backend that does all the work. +

+
ExpressionTemplates
+

+ A boolean value: when true, then expression templates are enabled, + otherwise they are disabled. +

+
+
mp_number();
 mp_number(see-below);
 mp_number& operator=(see-below);
@@ -235,7 +256,8 @@
       

  • - Another mp_number<Backend>. + Another mp_number<Backend, + ExpressionTemplates>.
  • A builtin arithmetic type. @@ -309,7 +331,7 @@ the precision of *this respectively.

    -
    int compare(const mp_number<Backend>& o)const;
    +
    int compare(const mp_number<Backend, ExpressionTemplates>& o)const;
     template <class V>
     typename enable_if<is_arithmetic<V>, int>::type compare(const V& other)const;
     
    @@ -377,12 +399,25 @@ In addition, one of the two arguments may be a builtin arithmetic type.

    - With the exception of the comparison operators (which always evaluate their - arguments and return a bool - result), these operators return an "unmentionable" expression template - type which defers evaluation of the operator until the result is actually - required. + The return type of these operators is either:

    +
      +
    • + An unmentionable-type expression template type when + ExpressionTemplates is + true. +
    • +
    • + Type mp_number<Backend, + false> + when ExpressionTemplates + is false. +
    • +
    • + Type bool if the operator + is a comparison operator. +
    • +

    Finally note that the second argument to the left and right shift operations must be a builtin integer type, and that the argument must be positive (negative @@ -393,8 +428,8 @@ swap -

    template <class Backend>
    -void swap(mp_number<Backend>& a, mp_number<Backend>& b);
    +
    template <class Backend, ExpressionTemplates>
    +void swap(mp_number<Backend, ExpressionTemplates>& a, mp_number<Backend, ExpressionTemplates>& b);
     

    Swaps a and b. @@ -404,12 +439,12 @@ Iostream Support -

    template <class Backend>
    -std::ostream& operator << (std::ostream& os, const mp_number<Backend>& r);
    -template <class Backend>
    +
    template <class Backend, bool ExpressionTemplates>
    +std::ostream& operator << (std::ostream& os, const mp_number<Backend, ExpressionTemplates>& r);
    +template <class Unspecified...>
     std::ostream& operator << (std::ostream& os, const unmentionable-expression-template& r);
    -template <class Backend>
    -inline std::istream& operator >> (std::istream& is, mp_number<Backend>& r)
    +template <class Backend, bool ExpressionTemplates>
    +inline std::istream& operator >> (std::istream& is, mp_number<Backend, ExpressionTemplates>& r)
     

    These operators provided formatted input-output operations on mp_number types, and expression templates @@ -460,8 +495,9 @@

    These functions all behave exactly as their standard library counterparts do: their argument is either an instance of mp_number - or an expression template derived from it; their return value is always an - expression template. + or an expression template derived from it; If the argument is of type mp_number<Backend, false> + then that is also the return type, otherwise the return type is an expression + template.

    These functions are normally implemented by the Backend type. However, default @@ -541,8 +577,8 @@

    namespace std{
     
    -template <class Backend>
    -struct numeric_limits<boost::multiprecision<Backend> >
    +template <class Backend, ExpressionTemplates>
    +struct numeric_limits<boost::multiprecision<Backend, ExpressionTemplates> >
     {
        /* Usual members here */
     };
    diff --git a/doc/html/boost_multiprecision/tut.html b/doc/html/boost_multiprecision/tut.html
    index 896c5a8d..cb05f329 100644
    --- a/doc/html/boost_multiprecision/tut.html
    +++ b/doc/html/boost_multiprecision/tut.html
    @@ -19,7 +19,7 @@
     

diff --git a/doc/html/boost_multiprecision/tut/ints.html b/doc/html/boost_multiprecision/tut/ints.html index c59d3f9a..e0b55bd3 100644 --- a/doc/html/boost_multiprecision/tut/ints.html +++ b/doc/html/boost_multiprecision/tut/ints.html @@ -7,7 +7,7 @@ - +

@@ -130,12 +130,12 @@
+ + + + + + + +

- fixed_int + cpp_int

- boost/multiprecision/fixed_int.hpp + boost/multiprecision/cpp_int.hpp

@@ -150,7 +150,8 @@

- Boost licenced fixed precision modular arithmetic integer. + Very versatile, Boost licenced, all C++ integer type which support + both arbitrary precision and fixed precision integer types.

@@ -336,47 +337,83 @@ { std::cout << e.what() << std::endl; } -

- fixed_int + cpp_int
namespace boost{ namespace multiprecision{
 
-template <unsigned Digits, bool Signed>
-class fixed_int;
+typedef unspecified-type limb_type;
 
-typedef mp_number<fixed_int<128, false> > mp_uint128_t;
-typedef mp_number<fixed_int<256, false> > mp_uint256_t;
-typedef mp_number<fixed_int<512, false> > mp_uint512_t;
+template <unsigned MinDigits = 0, bool Signed = true, class Allocator = std::allocator<limb_type> >
+class cpp_int_backend;
 
-typedef mp_number<fixed_int<128, true> > mp_int128_t;
-typedef mp_number<fixed_int<256, true> > mp_int256_t;
-typedef mp_number<fixed_int<512, true> > mp_int512_t;
+typedef mp_number<cpp_int_backend<> >           cpp_int;    // arbitrary precision integer
+typedef rational_adapter<cpp_int_backend<> >    cpp_rational_backend;
+typedef mp_number<cpp_rational_backend>         cpp_rational; // arbitrary precision rational number
+
+// Fixed precision unsigned types:
+typedef mp_number<cpp_int_backend<128, false, void> >   mp_uint128_t;
+typedef mp_number<cpp_int_backend<256, false, void> >   mp_uint256_t;
+typedef mp_number<cpp_int_backend<512, false, void> >   mp_uint512_t;
+
+// Fixed precision signed types:
+typedef mp_number<cpp_int_backend<128, true, void> >    mp_int128_t;
+typedef mp_number<cpp_int_backend<256, true, void> >    mp_int256_t;
+typedef mp_number<cpp_int_backend<512, true, void> >    mp_int512_t;
 
 }} // namespaces
 

- The fixed_int backend is - used via one of the typedefs boost::multiprecision::mp_uint128_t, - boost::multiprecision::mp_uint256_t, boost::multiprecision::mp_uint512_t, - boost::multiprecision::mp_int128_t, boost::multiprecision::mp_int256_t - or boost::multiprecision::mp_int512_t. It provides both signed and - unsigned integer types with a fixed precision and modular arithmetic with - a 2's complement representation for negative values. In other words it's - designed to work just like a typical built in integer type, but with larger - precision. + The cpp_int_backend type + is used via one of the typedefs boost::multiprecision::cpp_int, + boost::multiprecision::mp_uint128_t, boost::multiprecision::mp_uint256_t, + boost::multiprecision::mp_uint512_t, boost::multiprecision::mp_int128_t, + boost::multiprecision::mp_int256_t or boost::multiprecision::mp_int512_t.

+

+ This backend is the "Swiss Army Knife" of integer types as it can + represent both fixed and arbitrary precision integer types, and both signed + and unsigned types. There are three template arguments: +

+
+

+
+
MinBits
+

+ 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. When the Allocator parameter is type void, + then this field determines the total number of bits in the resulting + fixed precision type. +

+
Signed
+

+ Determines whether the resulting type is signed or not. Note that for + arbitrary precision types (where the Allocator parameter is non-void), + then this parameter must be true. + For fixed precision types then this type may be either true (type is signed), or false (type is unsigned). +

+
Allocator
+

+ The allocator to use for dymamic memory allocation, or type void if this is to be a fixed precision + type. +

+
+

Things you should know when using this type:

  • - Default constructed fixed_int's - have indeterminate value - just like normal built in integers. + Default constructed cpp_int_backend's + have the value zero.
  • Division by zero results in a std::runtime_error @@ -387,9 +424,26 @@ results in a std::runtime_error being thrown.
  • - Since the precision of fixed_int - is necessarily limited, care should be taken to avoid numeric overflow - when using this type unless you actually want modulo-arithmetic behavior. + Since the precision of cpp_int_backend + 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. +
  • +
  • + The type uses a sign-magnitude representation internally, so type mp_int128_t 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. +
  • +
  • + Attempting to print negative values as either an Octal or Hexadecimal + string results in a std::runtime_error + being thrown, this is a direct consequence of the sign-magnitude representation.
@@ -398,20 +452,24 @@

-
#include <boost/multiprecision/fixed_int.hpp>
+
#include <boost/multiprecision/cpp_int.hpp>
 
 using namespace boost::multiprecision;
 
 mp_int128_t v = 1;
 
-// Do some arithmetic:
+// Do some fixed precision arithmetic:
 for(unsigned i = 1; i <= 20; ++i)
    v *= i;
 
 std::cout << v << std::endl; // prints 20!
-v = -v;
-std::cout << std::hex << v << std::endl; // prints 2's complement representation
 
+// Try again at arbitrary precision:
+cpp_int u = 1;
+for(unsigned i = 1; i <= 100; ++i)
+   u *= i;
+
+std::cout << u << std::endl; // prints 100!
 

diff --git a/doc/html/boost_multiprecision/tut/rational.html b/doc/html/boost_multiprecision/tut/rational.html index 13d4cbb0..505e9393 100644 --- a/doc/html/boost_multiprecision/tut/rational.html +++ b/doc/html/boost_multiprecision/tut/rational.html @@ -6,7 +6,7 @@ - + @@ -96,6 +96,38 @@
+

+ cpp_rational +

+
+

+ boost/multiprecision/cpp_int.hpp +

+
+

+ 2 +

+
+

+ None +

+
+

+ An all C++ Boost-licenced implementation. +

+
+

+ Slower than GMP. +

+

tommath_rational @@ -229,6 +261,10 @@ mp_number<gmp_int>. +

+ There is also a two-argument constructor that accepts a numerator and denominator + (both of type mp_number<gmp_int>). +

There are also non-member functions:

@@ -298,6 +334,81 @@

+ cpp_rational +
+
namespace boost{ namespace multiprecision{
+
+typedef rational_adapter<cpp_int_backend<> >    cpp_rational_backend;
+
+typedef mp_number<cpp_rational_backend>         cpp_rational;
+
+}} // namespaces
+
+

+ The cpp_rational_backend + type is used via the typedef boost::multiprecision::cpp_rational. + It provides a rational number type that is a drop-in replacement for the + native C++ number types, but with unlimited precision. +

+

+ As well as the usual conversions from arithmetic and string types, instances + of cpp_rational are copy + constructible and assignable from type cpp_int. +

+

+ There is also a two argument constructor that accepts a numerator and denominator: + both of type cpp_int. +

+

+ There are also non-member functions: +

+
cpp_int numerator(const cpp_rational&);
+cpp_int denominator(const cpp_rational&);
+
+

+ which return the numerator and denominator of the number. +

+

+ Things you should know when using this type: +

+
    +
  • + Default constructed cpp_rational's + have the value zero. +
  • +
  • + Division by zero results in a std::rumtime_error + being thrown. +
  • +
+
+ + Example: +
+

+

+
#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
+
+

+

+
+ tommath_rational
namespace boost{ namespace multiprecision{
@@ -351,8 +462,8 @@
           
 
 
- - Example: + + Example:

@@ -373,12 +484,11 @@ mp_rational w(2, 3); // Component wise constructor std::cout << w << std::endl; // prints 2/3 -

- + Use With Boost.Rational
@@ -391,7 +501,7 @@ expression templates in mp_number.

- + rational_adapter
namespace boost{ namespace multiprecision{
diff --git a/doc/html/boost_multiprecision/tut/reals.html b/doc/html/boost_multiprecision/tut/reals.html
index fee37a92..fe118cb9 100644
--- a/doc/html/boost_multiprecision/tut/reals.html
+++ b/doc/html/boost_multiprecision/tut/reals.html
@@ -1,7 +1,7 @@
 
 
 
-Real Numbers
+Floating Point Numbers
 
 
 
@@ -15,10 +15,10 @@
 
 

- The following backends provide real number arithmetic: + The following backends provide floating point arithmetic:

diff --git a/doc/html/index.html b/doc/html/index.html index 19da3604..1d74c1b0 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -31,7 +31,7 @@
Tutorial
Integer Types
-
Real Numbers
+
Floating Point Numbers
Rational Number Types
Reference
@@ -56,7 +56,7 @@
- +

Last revised: February 15, 2012 at 18:08:37 GMT

Last revised: March 13, 2012 at 19:12:03 GMT


diff --git a/doc/multiprecision.qbk b/doc/multiprecision.qbk index 52f85764..7b7ee9ff 100644 --- a/doc/multiprecision.qbk +++ b/doc/multiprecision.qbk @@ -306,14 +306,14 @@ as a result performing formatted output on this type when the argument is negati typedef mp_number cpp_rational; // arbitrary precision rational number // Fixed precision unsigned types: - typedef mp_number > mp_uint128_t; - typedef mp_number > mp_uint256_t; - typedef mp_number > mp_uint512_t; + typedef mp_number > mp_uint128_t; + typedef mp_number > mp_uint256_t; + typedef mp_number > mp_uint512_t; // Fixed precision signed types: - typedef mp_number > mp_int128_t; - typedef mp_number > mp_int256_t; - typedef mp_number > mp_int512_t; + typedef mp_number > mp_int128_t; + typedef mp_number > mp_int256_t; + typedef mp_number > mp_int512_t; }} // namespaces @@ -352,6 +352,8 @@ In this respect the behaviour of these types differs from built-in 2's complemen 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. +* Attempting to print negative values as either an Octal or Hexadecimal string results in a `std::runtime_error` being thrown, +this is a direct consequence of the sign-magnitude representation. [h5 Example:] @@ -516,8 +518,8 @@ The following backends provide rational number arithmetic: [table [[Backend Type][Header][Radix][Dependencies][Pros][Cons]] [[`gmp_rational`][boost/multiprecision/gmp.hpp][2][[gmp]][Very fast and efficient backend.][Dependency on GNU licenced [gmp] library.]] -[[`cpp_rational`][boost/multiprecision/cpp_int.hpp][2][None][An all C++ Boost-licenced implementation.][[Slower than [gmp].]] -[[`tommath_rational`][boost/multiprecision/tommath.hpp][2][libtommath][All C/C++ implementation that's Boost Software Licence compatible.] +[[`cpp_rational`][boost/multiprecision/cpp_int.hpp][2][None][An all C++ Boost-licenced implementation.][Slower than [gmp].]] +[[`tommath_rational`][boost/multiprecision/tommath.hpp][2][libtommath][All C/C++ implementation that's Boost Software Licence compatible.][Slower than [gmp].]] [[`rational_adapter`][boost/multiprecision/rational_adapter.hpp][N/A][none][All C++ adapter that allows any inetger backend type to be used as a rational type.][Requires an underlying integer backend type.]] [[`boost::rational`][boost/rational.hpp][N/A][None][A C++ rational number type that can used with any `mp_number` integer type.][The expression templates used by `mp_number` end up being "hidden" inside `boost::rational`: performance may well suffer as a result.]] ] @@ -541,6 +543,8 @@ and assignable from: * The [gmp] native types: `mpz_t`, `mpq_t`. * `mp_number`. +There is also a two-argument constructor that accepts a numerator and denominator (both of type `mp_number`). + There are also non-member functions: mpz_int numerator(const mpq_rational&); @@ -578,6 +582,8 @@ a rational number type that is a drop-in replacement for the native C++ number t As well as the usual conversions from arithmetic and string types, instances of `cpp_rational` are copy constructible and assignable from type `cpp_int`. +There is also a two argument constructor that accepts a numerator and denominator: both of type `cpp_int`. + There are also non-member functions: cpp_int numerator(const cpp_rational&); @@ -1029,7 +1035,7 @@ this library support all of the iostream formatting flags, field width and preci ``['unmentionable-expression-template-type]`` atan2 (const ``['mp_number-or-expression-template-type]``&, const ``['mp_number-or-expression-template-type]``&); These functions all behave exactly as their standard library counterparts do: their argument is either an instance of `mp_number` or -an expression template derived from it; If the argument is of type `mp_number,Backend, false>` then that is also the return type, +an expression template derived from it; If the argument is of type `mp_number` then that is also the return type, otherwise the return type is an expression template. These functions are normally implemented by the Backend type. However, default versions are provided for Backend types that diff --git a/example/cpp_int_snips.cpp b/example/cpp_int_snips.cpp index eb2827c7..942f27d6 100644 --- a/example/cpp_int_snips.cpp +++ b/example/cpp_int_snips.cpp @@ -33,7 +33,7 @@ void t1() void t3() { - //[cpp_rat_eg + //[cpp_rational_eg //=#include using namespace boost::multiprecision; diff --git a/include/boost/multiprecision/cpp_int.hpp b/include/boost/multiprecision/cpp_int.hpp index b087fe5f..60d9cc50 100644 --- a/include/boost/multiprecision/cpp_int.hpp +++ b/include/boost/multiprecision/cpp_int.hpp @@ -2141,6 +2141,17 @@ typedef mp_number > cpp_int; typedef rational_adapter > cpp_rational_backend; typedef mp_number cpp_rational; +// Fixed precision unsigned types: +typedef mp_number > mp_uint128_t; +typedef mp_number > mp_uint256_t; +typedef mp_number > mp_uint512_t; + +// Fixed precision signed types: +typedef mp_number > mp_int128_t; +typedef mp_number > mp_int256_t; +typedef mp_number > mp_int512_t; + + }} // namespaces diff --git a/performance/Jamfile.v2 b/performance/Jamfile.v2 index 37c1017c..54fd7e52 100644 --- a/performance/Jamfile.v2 +++ b/performance/Jamfile.v2 @@ -50,7 +50,7 @@ exe performance_test : performance_test.cpp /boost/system//boost_system [ check-target-builds ../config//has_mpfr : TEST_MPFR mpfr : ] [ check-target-builds ../config//has_tommath : TEST_TOMMATH $(TOMMATH) : ] TEST_CPP_DEC_FLOAT - TEST_FIXED_INT + TEST_CPP_INT ; exe sf_performance : sf_performance.cpp /boost/system//boost_system diff --git a/performance/performance_test.cpp b/performance/performance_test.cpp index 7a541b02..6fc2d9cf 100644 --- a/performance/performance_test.cpp +++ b/performance/performance_test.cpp @@ -12,7 +12,7 @@ #if !defined(TEST_MPF) && !defined(TEST_MPZ) && \ !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPQ) \ && !defined(TEST_TOMMATH) && !defined(TEST_TOMMATH_BOOST_RATIONAL) && !defined(TEST_MPZ_BOOST_RATIONAL)\ - && !defined(TEST_FIXED_INT) && !defined(TEST_CPP_INT) && !defined(TEST_CPP_INT_RATIONAL) + && !defined(TEST_CPP_INT) && !defined(TEST_CPP_INT_RATIONAL) # define TEST_MPF # define TEST_MPZ # define TEST_MPQ @@ -20,7 +20,6 @@ # define TEST_CPP_DEC_FLOAT # define TEST_MPQ # define TEST_TOMMATH -# define TEST_FIXED_INT # define TEST_CPP_INT # define TEST_CPP_INT_RATIONAL @@ -47,9 +46,6 @@ #include #include #endif -#if defined(TEST_FIXED_INT) -#include -#endif #if defined(TEST_CPP_INT) #include #endif @@ -619,12 +615,6 @@ int main() test("mp_rational", 1024); */ #endif -#ifdef TEST_FIXED_INT - test("fixed_int", 128); - test("fixed_int", 256); - test("fixed_int", 512); - test > >("fixed_int", 1024); -#endif #ifdef TEST_CPP_DEC_FLOAT test("cpp_dec_float", 50); test("cpp_dec_float", 100); diff --git a/test/test_arithmetic.cpp b/test/test_arithmetic.cpp index ea66d0cf..e22c8a1c 100644 --- a/test/test_arithmetic.cpp +++ b/test/test_arithmetic.cpp @@ -18,7 +18,7 @@ #if !defined(TEST_MPF_50) && !defined(TEST_MPF) && !defined(TEST_BACKEND) && !defined(TEST_MPZ) && \ !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPFR_50) && !defined(TEST_MPQ) \ && !defined(TEST_TOMMATH) && !defined(TEST_TOMMATH_BOOST_RATIONAL) && !defined(TEST_MPZ_BOOST_RATIONAL)\ - && !defined(TEST_FIXED_INT1) && !defined(TEST_FIXED_INT2) && !defined(TEST_CPP_INT) && !defined(TEST_CPP_INT_BR) + && !defined(TEST_CPP_INT) && !defined(TEST_CPP_INT_BR) # define TEST_MPF_50 # define TEST_MPF # define TEST_BACKEND @@ -28,8 +28,6 @@ # define TEST_CPP_DEC_FLOAT # define TEST_MPQ # define TEST_TOMMATH -# define TEST_FIXED_INT1 -# define TEST_FIXED_INT2 # define TEST_CPP_INT # define TEST_CPP_INT_BR @@ -59,9 +57,6 @@ #include #include #endif -#if defined(TEST_FIXED_INT1) || defined(TEST_FIXED_INT2) -#include -#endif #if defined(TEST_CPP_INT) || defined(TEST_CPP_INT_BR) #include #endif @@ -1030,26 +1025,10 @@ int main() #ifdef TEST_MPZ_BOOST_RATIONAL test >(); #endif -#ifdef TEST_FIXED_INT1 - test > >(); - test(); - test(); - test > >(); -#endif -#ifdef TEST_FIXED_INT2 - // - // Can't test 64-bit signed ints - they don't have enough bits - // to interoperate with uint64_t without loss: - // - //test(); - test(); - test(); - test > >(); -#endif #ifdef TEST_CPP_INT test(); - test > >(); - test > >(); + test(); + test(); test(); test, false> >(); #endif diff --git a/test/test_int_io.cpp b/test/test_int_io.cpp index 704ec26c..9fac176d 100644 --- a/test/test_int_io.cpp +++ b/test/test_int_io.cpp @@ -9,11 +9,9 @@ # define _SCL_SECURE_NO_WARNINGS #endif -#if !defined(TEST_MPZ) && !defined(TEST_TOMMATH) && !defined(TEST_FIXED_INT1) && !defined(TEST_FIXED_INT2) && !defined(TEST_CPP_INT) +#if !defined(TEST_MPZ) && !defined(TEST_TOMMATH) && !defined(TEST_CPP_INT) # define TEST_TOMMATH # define TEST_MPZ -# define TEST_FIXED_INT1 -# define TEST_FIXED_INT2 # define TEST_CPP_INT #ifdef _MSC_VER @@ -31,9 +29,6 @@ #if defined(TEST_TOMMATH) #include #endif -#if defined(TEST_FIXED_INT1) || defined(TEST_FIXED_INT2) -#include -#endif #ifdef TEST_CPP_INT #include #endif @@ -127,20 +122,6 @@ int main() #ifdef TEST_TOMMATH test_round_trip(); #endif -#ifdef TEST_FIXED_INT1 - test_round_trip > >(); - test_round_trip(); - test_round_trip(); - test_round_trip > >(); - test_round_trip > >(); -#endif -#ifdef TEST_FIXED_INT2 - test_round_trip > >(); - test_round_trip(); - test_round_trip(); - test_round_trip > >(); - test_round_trip > >(); -#endif #ifdef TEST_CPP_INT test_round_trip > >(); test_round_trip > >(); diff --git a/test/test_numeric_limits.cpp b/test/test_numeric_limits.cpp index 3d988fc1..bb2d64c6 100644 --- a/test/test_numeric_limits.cpp +++ b/test/test_numeric_limits.cpp @@ -11,7 +11,7 @@ #if !defined(TEST_MPF_50) && !defined(TEST_MPF) && !defined(TEST_BACKEND) && !defined(TEST_MPZ) && \ !defined(TEST_CPP_DEC_FLOAT) && !defined(TEST_MPFR) && !defined(TEST_MPFR_50) && !defined(TEST_MPQ) && \ - !defined(TEST_TOMMATH) && !defined(TEST_CPP_INT) && !defined(TEST_FIXED_INT) + !defined(TEST_TOMMATH) && !defined(TEST_CPP_INT) # define TEST_MPF_50 # define TEST_MPF # define TEST_BACKEND @@ -21,7 +21,6 @@ # define TEST_CPP_DEC_FLOAT # define TEST_MPQ # define TEST_TOMMATH -# define TEST_FIXED_INT # define TEST_CPP_INT #ifdef _MSC_VER @@ -48,9 +47,6 @@ #ifdef TEST_TOMMATH #include #endif -#ifdef TEST_FIXED_INT -#include -#endif #ifdef TEST_CPP_INT #include #endif @@ -226,16 +222,10 @@ int main() #ifdef TEST_TOMMATH test(); #endif -#ifdef TEST_FIXED_INT - test(); - test(); - test(); - test(); -#endif #ifdef TEST_CPP_INT test(); - test > >(); - test > >(); + test(); + test(); #endif return boost::report_errors(); }