00001 00002 /* 00003 The Extended Integer (XInt) Library 00004 A fast, portable C++ library for multi-precision integer math 00005 Copyright 2010 by Chad Nelson 00006 00007 Distributed under the Boost Software License, Version 1.0. 00008 See accompanying file LICENSE_1_0.txt or copy at 00009 http://www.boost.org/LICENSE_1_0.txt 00010 00011 See http://www.boost.org/libs/xint for library home page. 00012 */ 00013 00020 #ifndef BOOST_INCLUDED_XINT_INTERNALS_HPP 00021 #define BOOST_INCLUDED_XINT_INTERNALS_HPP 00022 00023 #ifdef BOOST_XINT_NO_EXCEPTIONS 00024 #define BOOST_XINT_TRY if (1) 00025 #define BOOST_XINT_CATCH_BADALLOC else if (0) 00026 #define BOOST_XINT_CATCH else 00027 #define BOOST_XINT_CATCH_E else 00028 #else 00029 #define BOOST_XINT_TRY try 00030 #define BOOST_XINT_CATCH_BADALLOC catch (std::bad_alloc&) 00031 #define BOOST_XINT_CATCH catch (std::exception&) 00032 #define BOOST_XINT_CATCH_E catch (std::exception& e) 00033 #endif 00034 00035 #include "../exceptions.hpp" 00036 #include "../random.hpp" 00037 00038 #include "basic_types_and_includes.hpp" 00039 #include "bitqueue.hpp" 00040 #include "policies.hpp" 00041 #include "magnitude_manager.hpp" 00042 #include "raw_integer.hpp" 00043 00044 #include "log2.hpp" 00045 #include "shift.hpp" 00046 #include "bitfunctions.hpp" 00047 #include "andorxor.hpp" 00048 #include "randomgen.hpp" 00049 #include "random_by_size.hpp" 00050 #include "compare.hpp" 00051 00052 #include "addsubtract.hpp" 00053 #include "multiply.hpp" 00054 #include "divide.hpp" 00055 00056 #include "convert.hpp" 00057 #include "streams.hpp" 00058 00059 #include "roots.hpp" 00060 #include "powers.hpp" 00061 #include "gcd.hpp" 00062 #include "monty.hpp" 00063 #include "modular.hpp" 00064 #include "prime.hpp" 00065 00068 00071 00072 namespace boost { 00073 namespace xint { 00074 namespace detail { 00076 00077 inline std::size_t log10_bits(std::size_t bits) { 00078 // large_step and count_per_large_step are based on a minimum-32-bit integer 00079 assert(std::numeric_limits<boost::intmax_t>::digits >= 32); 00080 00081 typedef raw_integer_t<0, false, std::allocator<digit_t> > T; 00082 const T large_step(1000000000), small_step(10); 00083 const std::size_t count_per_large_step = 9, count_per_small_step = 1; 00084 00085 T n; 00086 pow2(n, bits); 00087 --n; 00088 00089 std::size_t r = 0; 00090 while (n >= large_step) { n /= large_step; r += count_per_large_step; } 00091 while (n >= small_step) { n /= small_step; r += count_per_small_step; } 00092 return r; 00093 } 00094 00095 template <typename charT> 00096 const std::basic_string<charT>& nan_text() { 00097 static std::basic_string<charT> r; 00098 if (r.empty()) { 00099 std::basic_ostringstream<charT> out; 00100 out << "#NaN#"; 00101 r = out.str(); 00102 } 00103 return r; 00104 } 00105 00106 template <typename charT> 00107 bool is_nan_text(const std::basic_string<charT> str) { 00108 return (str == nan_text<charT>()); 00109 } 00110 00111 template <typename T> 00112 T get_nan() { 00113 static T r; 00114 static bool init = false; 00115 00116 if (!init) { 00117 init = true; 00118 r._data().make_nan(); 00119 } 00120 00121 return BOOST_XINT_MOVE(r); 00122 } 00123 00125 } // namespace detail 00126 } // namespace xint 00127 } // namespace boost 00128 00129 #include "options.hpp" 00130 00131 #endif // BOOST_INCLUDED_XINT_INTERNALS_HPP
© Copyright Chad Nelson, 2010-2011. 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)