fwd.hpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Copyright 2023 John Maddock. Distributed under the Boost
  3. // Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_MP_FWD_HPP
  6. #define BOOST_MP_FWD_HPP
  7. #include <boost/multiprecision/cpp_int/cpp_int_config.hpp>
  8. namespace boost {
  9. namespace multiprecision {
  10. enum expression_template_option
  11. {
  12. et_off = 0,
  13. et_on = 1
  14. };
  15. template <class Backend>
  16. struct expression_template_default
  17. {
  18. static constexpr expression_template_option value = et_on;
  19. };
  20. template <class Backend, expression_template_option ExpressionTemplates = expression_template_default<Backend>::value>
  21. class number;
  22. template <class T>
  23. struct is_number : public std::integral_constant<bool, false>
  24. {};
  25. template <class Backend, expression_template_option ExpressionTemplates>
  26. struct is_number<number<Backend, ExpressionTemplates> > : public std::integral_constant<bool, true>
  27. {};
  28. namespace detail {
  29. // Forward-declare an expression wrapper
  30. template <class tag, class Arg1 = void, class Arg2 = void, class Arg3 = void, class Arg4 = void>
  31. struct expression;
  32. } // namespace detail
  33. enum cpp_integer_type
  34. {
  35. signed_magnitude = 1,
  36. unsigned_magnitude = 0,
  37. signed_packed = 3,
  38. unsigned_packed = 2
  39. };
  40. enum cpp_int_check_type
  41. {
  42. checked = 1,
  43. unchecked = 0
  44. };
  45. enum mpfr_allocation_type
  46. {
  47. allocate_stack,
  48. allocate_dynamic
  49. };
  50. template <class Backend>
  51. void log_postfix_event(const Backend&, const char* /*event_description*/);
  52. template <class Backend, class T>
  53. void log_postfix_event(const Backend&, const T&, const char* /*event_description*/);
  54. template <class Backend>
  55. void log_prefix_event(const Backend&, const char* /*event_description*/);
  56. template <class Backend, class T>
  57. void log_prefix_event(const Backend&, const T&, const char* /*event_description*/);
  58. template <class Backend, class T, class U>
  59. void log_prefix_event(const Backend&, const T&, const U&, const char* /*event_description*/);
  60. template <class Backend, class T, class U, class V>
  61. void log_prefix_event(const Backend&, const T&, const U&, const V&, const char* /*event_description*/);
  62. namespace backends {
  63. template <class Backend>
  64. struct debug_adaptor;
  65. template <class Backend>
  66. struct logged_adaptor;
  67. template <class Backend>
  68. struct complex_adaptor;
  69. enum digit_base_type
  70. {
  71. digit_base_2 = 2,
  72. digit_base_10 = 10
  73. };
  74. template <unsigned Digits, digit_base_type DigitBase = digit_base_10, class Allocator = void, class Exponent = int, Exponent MinExponent = 0, Exponent MaxExponent = 0>
  75. class cpp_bin_float;
  76. template <unsigned Digits10, class ExponentType = std::int32_t, class Allocator = void>
  77. class cpp_dec_float;
  78. template <std::size_t MinBits = 0, std::size_t MaxBits = 0, boost::multiprecision::cpp_integer_type SignType = signed_magnitude, cpp_int_check_type Checked = unchecked, class Allocator = typename std::conditional<MinBits && (MinBits == MaxBits), void, std::allocator<limb_type> >::type>
  79. struct cpp_int_backend;
  80. struct float128_backend;
  81. struct gmp_int;
  82. struct gmp_rational;
  83. template <unsigned digits10>
  84. struct gmp_float;
  85. template <unsigned digits10>
  86. struct mpc_complex_backend;
  87. template <unsigned digits10>
  88. struct mpfi_float_backend;
  89. template <unsigned digits10, mpfr_allocation_type AllocationType = allocate_dynamic>
  90. struct mpfr_float_backend;
  91. template <>
  92. struct mpfr_float_backend<0, allocate_stack>;
  93. template <class Backend>
  94. struct rational_adaptor;
  95. struct tommath_int;
  96. }
  97. using boost::multiprecision::backends::complex_adaptor;
  98. using boost::multiprecision::backends::debug_adaptor;
  99. using boost::multiprecision::backends::logged_adaptor;
  100. using backends::cpp_bin_float;
  101. using backends::digit_base_10;
  102. using backends::digit_base_2;
  103. using boost::multiprecision::backends::cpp_dec_float;
  104. using boost::multiprecision::backends::cpp_int_backend;
  105. using boost::multiprecision::backends::float128_backend;
  106. using boost::multiprecision::backends::gmp_float;
  107. using boost::multiprecision::backends::gmp_int;
  108. using boost::multiprecision::backends::gmp_rational;
  109. using boost::multiprecision::backends::mpc_complex_backend;
  110. using boost::multiprecision::backends::mpfi_float_backend;
  111. using boost::multiprecision::backends::mpfr_float_backend;
  112. using boost::multiprecision::backends::rational_adaptor;
  113. using boost::multiprecision::backends::tommath_int;
  114. template <unsigned Digits, backends::digit_base_type DigitBase, class Allocator, class Exponent, Exponent MinE, Exponent MaxE>
  115. struct expression_template_default<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinE, MaxE> >
  116. {
  117. static constexpr expression_template_option value = std::is_void<Allocator>::value ? et_off : et_on;
  118. };
  119. template <std::size_t MinBits, std::size_t MaxBits, cpp_integer_type SignType, cpp_int_check_type Checked>
  120. struct expression_template_default<backends::cpp_int_backend<MinBits, MaxBits, SignType, Checked, void> >
  121. {
  122. static constexpr expression_template_option value = et_off;
  123. };
  124. template <class IntBackend>
  125. struct expression_template_default<backends::rational_adaptor<IntBackend> > : public expression_template_default<IntBackend>
  126. {};
  127. using complex128 = number<complex_adaptor<float128_backend>, et_off>;
  128. using cpp_bin_float_50 = number<backends::cpp_bin_float<50> >;
  129. using cpp_bin_float_100 = number<backends::cpp_bin_float<100> >;
  130. using cpp_bin_float_single = number<backends::cpp_bin_float<24, backends::digit_base_2, void, std::int16_t, -126, 127>, et_off>;
  131. using cpp_bin_float_double = number<backends::cpp_bin_float<53, backends::digit_base_2, void, std::int16_t, -1022, 1023>, et_off>;
  132. using cpp_bin_float_double_extended = number<backends::cpp_bin_float<64, backends::digit_base_2, void, std::int16_t, -16382, 16383>, et_off>;
  133. using cpp_bin_float_quad = number<backends::cpp_bin_float<113, backends::digit_base_2, void, std::int16_t, -16382, 16383>, et_off>;
  134. using cpp_bin_float_oct = number<backends::cpp_bin_float<237, backends::digit_base_2, void, std::int32_t, -262142, 262143>, et_off>;
  135. template <unsigned Digits, backends::digit_base_type DigitBase = backends::digit_base_10, class Allocator = void, class Exponent = int, Exponent MinExponent = 0, Exponent MaxExponent = 0>
  136. using cpp_complex_backend = complex_adaptor<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinExponent, MaxExponent> >;
  137. template <unsigned Digits, backends::digit_base_type DigitBase = digit_base_10, class Allocator = void, class Exponent = int, Exponent MinExponent = 0, Exponent MaxExponent = 0, expression_template_option ExpressionTemplates = et_off>
  138. using cpp_complex = number<complex_adaptor<cpp_bin_float<Digits, DigitBase, Allocator, Exponent, MinExponent, MaxExponent> >, ExpressionTemplates>;
  139. using cpp_complex_50 = cpp_complex<50>;
  140. using cpp_complex_100 = cpp_complex<100>;
  141. using cpp_complex_single = cpp_complex<24, backends::digit_base_2, void, std::int16_t, -126, 127>;
  142. using cpp_complex_double = cpp_complex<53, backends::digit_base_2, void, std::int16_t, -1022, 1023>;
  143. using cpp_complex_extended = cpp_complex<64, backends::digit_base_2, void, std::int16_t, -16382, 16383>;
  144. using cpp_complex_quad = cpp_complex<113, backends::digit_base_2, void, std::int16_t, -16382, 16383>;
  145. using cpp_complex_oct = cpp_complex<237, backends::digit_base_2, void, std::int32_t, -262142, 262143>;
  146. using cpp_dec_float_50 = number<cpp_dec_float<50> >;
  147. using cpp_dec_float_100 = number<cpp_dec_float<100> >;
  148. using cpp_int = number<cpp_int_backend<> >;
  149. using cpp_rational_backend = rational_adaptor<cpp_int_backend<> >;
  150. using cpp_rational = number<cpp_rational_backend>;
  151. // Fixed precision unsigned types:
  152. using uint128_t = number<cpp_int_backend<128, 128, unsigned_magnitude, unchecked, void> >;
  153. using uint256_t = number<cpp_int_backend<256, 256, unsigned_magnitude, unchecked, void> >;
  154. using uint512_t = number<cpp_int_backend<512, 512, unsigned_magnitude, unchecked, void> >;
  155. using uint1024_t = number<cpp_int_backend<1024, 1024, unsigned_magnitude, unchecked, void> >;
  156. // Fixed precision signed types:
  157. using int128_t = number<cpp_int_backend<128, 128, signed_magnitude, unchecked, void> >;
  158. using int256_t = number<cpp_int_backend<256, 256, signed_magnitude, unchecked, void> >;
  159. using int512_t = number<cpp_int_backend<512, 512, signed_magnitude, unchecked, void> >;
  160. using int1024_t = number<cpp_int_backend<1024, 1024, signed_magnitude, unchecked, void> >;
  161. // Over again, but with checking enabled this time:
  162. using checked_cpp_int = number<cpp_int_backend<0, 0, signed_magnitude, checked> >;
  163. using checked_cpp_rational_backend = rational_adaptor<cpp_int_backend<0, 0, signed_magnitude, checked> >;
  164. using checked_cpp_rational = number<checked_cpp_rational_backend>;
  165. // Fixed precision unsigned types:
  166. using checked_uint128_t = number<cpp_int_backend<128, 128, unsigned_magnitude, checked, void> >;
  167. using checked_uint256_t = number<cpp_int_backend<256, 256, unsigned_magnitude, checked, void> >;
  168. using checked_uint512_t = number<cpp_int_backend<512, 512, unsigned_magnitude, checked, void> >;
  169. using checked_uint1024_t = number<cpp_int_backend<1024, 1024, unsigned_magnitude, checked, void> >;
  170. // Fixed precision signed types:
  171. using checked_int128_t = number<cpp_int_backend<128, 128, signed_magnitude, checked, void> >;
  172. using checked_int256_t = number<cpp_int_backend<256, 256, signed_magnitude, checked, void> >;
  173. using checked_int512_t = number<cpp_int_backend<512, 512, signed_magnitude, checked, void> >;
  174. using checked_int1024_t = number<cpp_int_backend<1024, 1024, signed_magnitude, checked, void> >;
  175. template <class Number>
  176. using debug_adaptor_t = number<debug_adaptor<typename Number::backend_type>, Number::et>;
  177. template <class Number>
  178. using logged_adaptor_t = number<logged_adaptor<typename Number::backend_type>, Number::et>;
  179. using float128 = number<float128_backend, et_off>;
  180. using mpf_float_50 = number<gmp_float<50> >;
  181. using mpf_float_100 = number<gmp_float<100> >;
  182. using mpf_float_500 = number<gmp_float<500> >;
  183. using mpf_float_1000 = number<gmp_float<1000> >;
  184. using mpf_float = number<gmp_float<0> >;
  185. using mpz_int = number<gmp_int>;
  186. using mpq_rational = number<gmp_rational>;
  187. using mpc_complex_50 = number<mpc_complex_backend<50> >;
  188. using mpc_complex_100 = number<mpc_complex_backend<100> >;
  189. using mpc_complex_500 = number<mpc_complex_backend<500> >;
  190. using mpc_complex_1000 = number<mpc_complex_backend<1000> >;
  191. using mpc_complex = number<mpc_complex_backend<0> >;
  192. using mpfi_float_50 = number<mpfi_float_backend<50> >;
  193. using mpfi_float_100 = number<mpfi_float_backend<100> >;
  194. using mpfi_float_500 = number<mpfi_float_backend<500> >;
  195. using mpfi_float_1000 = number<mpfi_float_backend<1000> >;
  196. using mpfi_float = number<mpfi_float_backend<0> >;
  197. using mpfr_float_50 = number<mpfr_float_backend<50> >;
  198. using mpfr_float_100 = number<mpfr_float_backend<100> >;
  199. using mpfr_float_500 = number<mpfr_float_backend<500> >;
  200. using mpfr_float_1000 = number<mpfr_float_backend<1000> >;
  201. using mpfr_float = number<mpfr_float_backend<0> >;
  202. using static_mpfr_float_50 = number<mpfr_float_backend<50, allocate_stack> >;
  203. using static_mpfr_float_100 = number<mpfr_float_backend<100, allocate_stack> >;
  204. using tom_int = number<tommath_int>;
  205. using tommath_rational = rational_adaptor<tommath_int>;
  206. using tom_rational = number<tommath_rational>;
  207. } }
  208. #endif