mul.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # /* Copyright (C) 2001
  2. # * Housemarque Oy
  3. # * http://www.housemarque.com
  4. # *
  5. # * Distributed under the Boost Software License, Version 1.0. (See
  6. # * accompanying file LICENSE_1_0.txt or copy at
  7. # * http://www.boost.org/LICENSE_1_0.txt)
  8. # */
  9. #
  10. # /* Revised by Paul Mensonides (2002) */
  11. # /* Revised by Edward Diener (2020) */
  12. #
  13. # /* See http://www.boost.org for most recent version. */
  14. #
  15. # ifndef BOOST_PREPROCESSOR_ARITHMETIC_MUL_HPP
  16. # define BOOST_PREPROCESSOR_ARITHMETIC_MUL_HPP
  17. #
  18. # include <boost/preprocessor/config/config.hpp>
  19. #
  20. # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT()
  21. #
  22. # include <boost/preprocessor/arithmetic/add.hpp>
  23. # include <boost/preprocessor/arithmetic/dec.hpp>
  24. # include <boost/preprocessor/control/while.hpp>
  25. # include <boost/preprocessor/tuple/elem.hpp>
  26. # include <boost/preprocessor/tuple/rem.hpp>
  27. #
  28. # /* BOOST_PP_MUL */
  29. #
  30. # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG()
  31. # define BOOST_PP_MUL(x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  32. # else
  33. # define BOOST_PP_MUL(x, y) BOOST_PP_MUL_I(x, y)
  34. # define BOOST_PP_MUL_I(x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  35. # endif
  36. #
  37. # define BOOST_PP_MUL_P(d, rxy) BOOST_PP_TUPLE_ELEM(3, 2, rxy)
  38. #
  39. # if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT()
  40. # define BOOST_PP_MUL_O(d, rxy) BOOST_PP_MUL_O_IM(d, BOOST_PP_TUPLE_REM_3 rxy)
  41. # define BOOST_PP_MUL_O_IM(d, im) BOOST_PP_MUL_O_I(d, im)
  42. # else
  43. # define BOOST_PP_MUL_O(d, rxy) BOOST_PP_MUL_O_I(d, BOOST_PP_TUPLE_ELEM(3, 0, rxy), BOOST_PP_TUPLE_ELEM(3, 1, rxy), BOOST_PP_TUPLE_ELEM(3, 2, rxy))
  44. # endif
  45. #
  46. # define BOOST_PP_MUL_O_I(d, r, x, y) (BOOST_PP_ADD_D(d, r, x), x, BOOST_PP_DEC(y))
  47. #
  48. # /* BOOST_PP_MUL_D */
  49. #
  50. # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG()
  51. # define BOOST_PP_MUL_D(d, x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  52. # else
  53. # define BOOST_PP_MUL_D(d, x, y) BOOST_PP_MUL_D_I(d, x, y)
  54. # define BOOST_PP_MUL_D_I(d, x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  55. # endif
  56. #
  57. # else
  58. #
  59. # include <boost/preprocessor/arithmetic/add.hpp>
  60. # include <boost/preprocessor/arithmetic/dec.hpp>
  61. # include <boost/preprocessor/control/iif.hpp>
  62. # include <boost/preprocessor/control/while.hpp>
  63. # include <boost/preprocessor/facilities/identity.hpp>
  64. # include <boost/preprocessor/logical/bitand.hpp>
  65. # include <boost/preprocessor/logical/bool.hpp>
  66. # include <boost/preprocessor/logical/compl.hpp>
  67. # include <boost/preprocessor/tuple/elem.hpp>
  68. # include <boost/preprocessor/tuple/rem.hpp>
  69. # include <boost/preprocessor/arithmetic/detail/is_minimum_number.hpp>
  70. # include <boost/preprocessor/arithmetic/detail/is_maximum_number.hpp>
  71. # include <boost/preprocessor/arithmetic/detail/is_1_number.hpp>
  72. #
  73. # /* BOOST_PP_MUL */
  74. #
  75. # define BOOST_PP_MUL(x, y) BOOST_PP_IIF(BOOST_PP_DETAIL_IS_MINIMUM_NUMBER(x),BOOST_PP_IDENTITY_N(x,2),BOOST_PP_MUL_CHECK_1X)(x,y)
  76. #
  77. # define BOOST_PP_MUL_CHECK_1X(x, y) BOOST_PP_IIF(BOOST_PP_DETAIL_IS_1_NUMBER(x),BOOST_PP_IDENTITY_N(y,2),BOOST_PP_MUL_DO)(x,y)
  78. #
  79. # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG()
  80. # define BOOST_PP_MUL_DO(x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  81. # else
  82. # define BOOST_PP_MUL_DO(x, y) BOOST_PP_MUL_I(x, y)
  83. # define BOOST_PP_MUL_I(x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  84. # endif
  85. #
  86. # define BOOST_PP_MUL_P(d, rxy) BOOST_PP_BITAND(BOOST_PP_BOOL(BOOST_PP_TUPLE_ELEM(3, 2, rxy)),BOOST_PP_COMPL(BOOST_PP_DETAIL_IS_MAXIMUM_NUMBER(BOOST_PP_TUPLE_ELEM(3, 0, rxy))))
  87. #
  88. # if BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT()
  89. # define BOOST_PP_MUL_O(d, rxy) BOOST_PP_MUL_O_IM(d, BOOST_PP_TUPLE_REM_3 rxy)
  90. # define BOOST_PP_MUL_O_IM(d, im) BOOST_PP_MUL_O_I(d, im)
  91. # else
  92. # define BOOST_PP_MUL_O(d, rxy) BOOST_PP_MUL_O_I(d, BOOST_PP_TUPLE_ELEM(3, 0, rxy), BOOST_PP_TUPLE_ELEM(3, 1, rxy), BOOST_PP_TUPLE_ELEM(3, 2, rxy))
  93. # endif
  94. #
  95. # define BOOST_PP_MUL_O_I(d, r, x, y) (BOOST_PP_ADD_D(d, r, x), x, BOOST_PP_DEC(y))
  96. #
  97. # /* BOOST_PP_MUL_D */
  98. #
  99. # define BOOST_PP_MUL_D(d, x, y) BOOST_PP_IIF(BOOST_PP_DETAIL_IS_MINIMUM_NUMBER(x),BOOST_PP_IDENTITY_N(x,3),BOOST_PP_MUL_CHECK_1X_D)(d,x,y)
  100. #
  101. # define BOOST_PP_MUL_CHECK_1X_D(d, x, y) BOOST_PP_IIF(BOOST_PP_DETAIL_IS_1_NUMBER(x),BOOST_PP_IDENTITY_N(y,3),BOOST_PP_MUL_DO_D)(d,x,y)
  102. #
  103. # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_EDG()
  104. # define BOOST_PP_MUL_DO_D(d, x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  105. # else
  106. # define BOOST_PP_MUL_DO_D(d, x, y) BOOST_PP_MUL_D_I(d, x, y)
  107. # define BOOST_PP_MUL_D_I(d, x, y) BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_WHILE_ ## d(BOOST_PP_MUL_P, BOOST_PP_MUL_O, (0, x, y)))
  108. # endif
  109. #
  110. # endif
  111. #
  112. # endif