1 #ifndef BOOST_PREPROCESSOR_ARITHMETIC_MOD_HPP
2 #define BOOST_PREPROCESSOR_ARITHMETIC_MOD_HPP
6 * http://www.housemarque.com
8 * Permission to copy, use, modify, sell and distribute this software is
9 * granted provided this copyright notice appears in all copies. This
10 * software is provided "as is" without express or implied warranty, and
11 * with no claim as to its suitability for any purpose.
13 * See http://www.boost.org for most recent version.
16 #include <boost/preprocessor/comparison/less_equal.hpp>
18 /** <p>Expands to the remainder of <code>X</code> and <code>Y</code>.</p>
20 <p>Both <code>X</code> and <code>Y</code> must expand to integer literals
21 in the range [0, BOOST_PP_LIMIT_MAG].</p>
23 <p>For example, <code>BOOST_PP_MOD(4,3)</code> expands to <code>1</code> (a
28 <li><a href="../../test/arithmetic_test.cpp">arithmetic_test.cpp</a></li>
31 #define BOOST_PP_MOD(X,Y) BOOST_PP_MOD_D(0,X,Y)
33 /** <p>Can be used inside BOOST_PP_WHILE() (see for an explanation of the D parameter).</p> */
34 #define BOOST_PP_MOD_D(D,X,Y) BOOST_PP_TUPLE_ELEM(2,0,BOOST_PP_WHILE##D(BOOST_PP_MOD_C,BOOST_PP_MOD_F,(X,Y)))
35 #define BOOST_PP_MOD_C(D,RY) BOOST_PP_LESS_EQUAL_D(D,BOOST_PP_TUPLE_ELEM(2,1,RY),BOOST_PP_TUPLE_ELEM(2,0,RY))
36 #define BOOST_PP_MOD_F(D,RY) (BOOST_PP_SUB_D(D,BOOST_PP_TUPLE_ELEM(2,0,RY),BOOST_PP_TUPLE_ELEM(2,1,RY)),BOOST_PP_TUPLE_ELEM(2,1,RY))