1 # /* Copyright (C) 2001
3 # * http://www.housemarque.com
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)
10 # /* Revised by Paul Mensonides (2002) */
11 # /* Revised by Edward Diener (2020) */
13 # /* See http://www.boost.org for most recent version. */
15 # ifndef BOOST_PREPROCESSOR_ARITHMETIC_MUL_HPP
16 # define BOOST_PREPROCESSOR_ARITHMETIC_MUL_HPP
18 # include <boost/preprocessor/config/config.hpp>
20 # if ~BOOST_PP_CONFIG_FLAGS() & BOOST_PP_CONFIG_STRICT()
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>
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)))
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)))
37 # define BOOST_PP_MUL_P(d, rxy) BOOST_PP_TUPLE_ELEM(3, 2, rxy)
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)
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))
46 # define BOOST_PP_MUL_O_I(d, r, x, y) (BOOST_PP_ADD_D(d, r, x), x, BOOST_PP_DEC(y))
48 # /* BOOST_PP_MUL_D */
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)))
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)))
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>
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)
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)
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)))
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)))
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))))
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)
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))
95 # define BOOST_PP_MUL_O_I(d, r, x, y) (BOOST_PP_ADD_D(d, r, x), x, BOOST_PP_DEC(y))
97 # /* BOOST_PP_MUL_D */
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)
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)
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)))
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)))