# /* **************************************************************************
#  *                                                                          *
#  *     (C) Copyright Paul Mensonides 2002.
#  *     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)
#  *                                                                          *
#  ************************************************************************** */
#
# /* See http://www.boost.org for most recent version. */
#
# include <boost/preprocessor/config/limits.hpp>
# include <boost/preprocessor/arithmetic.hpp>
# include <libs/preprocessor/test/test.h>

/* addition */

BEGIN BOOST_PP_ADD(2, 3) == 5 END

BEGIN BOOST_PP_ADD(BOOST_PP_ADD(2, 2), 2) == 6 END
BEGIN BOOST_PP_ADD(2, BOOST_PP_ADD(1, 4)) == 7 END
BEGIN BOOST_PP_ADD(BOOST_PP_ADD(2, 2), BOOST_PP_ADD(2, 2)) == 8 END

#if BOOST_PP_LIMIT_MAG == 256

BEGIN BOOST_PP_ADD(1, 256) == 256 END
BEGIN BOOST_PP_ADD(256, 1) == 256 END
BEGIN BOOST_PP_ADD(2, 255) == 256 END
BEGIN BOOST_PP_ADD(255, 2) == 256 END
BEGIN BOOST_PP_ADD(1, 255) == 256 END
BEGIN BOOST_PP_ADD(255, 1) == 256 END

#endif

#if BOOST_PP_LIMIT_MAG == 512

BEGIN BOOST_PP_ADD(374, 129) == 503 END

BEGIN BOOST_PP_ADD(1, 512) == 512 END
BEGIN BOOST_PP_ADD(512, 1) == 512 END
BEGIN BOOST_PP_ADD(2, 511) == 512 END
BEGIN BOOST_PP_ADD(511, 2) == 512 END

BEGIN BOOST_PP_ADD(BOOST_PP_ADD(134, 187), 95) == 416 END
BEGIN BOOST_PP_ADD(BOOST_PP_ADD(83, 120), BOOST_PP_ADD(204, 51)) == 458 END
BEGIN BOOST_PP_ADD(149, BOOST_PP_ADD(102, 137)) == 388 END
BEGIN BOOST_PP_ADD(357, BOOST_PP_ADD(102, 137)) == 512 END

#endif

/* subtraction */

BEGIN BOOST_PP_SUB(11, 0) == 11 END
BEGIN BOOST_PP_SUB(12, 1) == 11 END
BEGIN BOOST_PP_SUB(3, 4) == 0 END

BEGIN BOOST_PP_SUB(5, BOOST_PP_SUB(3, 2)) == 4 END
BEGIN BOOST_PP_SUB(BOOST_PP_SUB(10, 5), 2) == 3 END
BEGIN BOOST_PP_SUB(BOOST_PP_SUB(7, 3), BOOST_PP_SUB(10, 8)) == 2 END

#if BOOST_PP_LIMIT_MAG == 256

BEGIN BOOST_PP_SUB(1, 256) == 0 END
BEGIN BOOST_PP_SUB(256, 255) == 1 END

#endif

#if BOOST_PP_LIMIT_MAG == 512

BEGIN BOOST_PP_SUB(315, 412) == 0 END
BEGIN BOOST_PP_SUB(511, 510) == 1 END
BEGIN BOOST_PP_SUB(463, 317) == 146 END
BEGIN BOOST_PP_SUB(272, 195) == 77 END

BEGIN BOOST_PP_SUB(1, 512) == 0 END
BEGIN BOOST_PP_SUB(512, 511) == 1 END

BEGIN BOOST_PP_SUB(371, BOOST_PP_SUB(3, 2)) == 370 END
BEGIN BOOST_PP_SUB(BOOST_PP_SUB(478, 211), 58) == 209 END
BEGIN BOOST_PP_SUB(BOOST_PP_SUB(395, 277), BOOST_PP_SUB(10, 7)) == 115 END
BEGIN BOOST_PP_SUB(BOOST_PP_SUB(412, 383), BOOST_PP_SUB(512, 506)) == 23 END

#endif

/* multiplication */

BEGIN BOOST_PP_MUL(0, 1) == 0 END
BEGIN BOOST_PP_MUL(1, 0) == 0 END
BEGIN BOOST_PP_MUL(1, 1) == 1 END
BEGIN BOOST_PP_MUL(4, 3) == 12 END

BEGIN BOOST_PP_MUL(BOOST_PP_MUL(2, 2), 2) == 8 END
BEGIN BOOST_PP_MUL(2, BOOST_PP_MUL(2, 2)) == 8 END
BEGIN BOOST_PP_MUL(BOOST_PP_MUL(2, 2), BOOST_PP_MUL(2, 2)) == 16 END

BEGIN BOOST_PP_MUL(0, BOOST_PP_LIMIT_MAG) == 0 END
BEGIN BOOST_PP_MUL(1, BOOST_PP_LIMIT_MAG) == BOOST_PP_LIMIT_MAG END
BEGIN BOOST_PP_MUL(2, BOOST_PP_LIMIT_MAG) == BOOST_PP_LIMIT_MAG END
BEGIN BOOST_PP_MUL(BOOST_PP_LIMIT_MAG, 0) == 0 END
BEGIN BOOST_PP_MUL(BOOST_PP_LIMIT_MAG, 1) == BOOST_PP_LIMIT_MAG END
BEGIN BOOST_PP_MUL(BOOST_PP_LIMIT_MAG, 2) == BOOST_PP_LIMIT_MAG END

#if BOOST_PP_LIMIT_MAG == 256

BEGIN BOOST_PP_MUL(17, 17) == 256 END
BEGIN BOOST_PP_MUL(1, 255) == 255 END
BEGIN BOOST_PP_MUL(2, 255) == 256 END
BEGIN BOOST_PP_MUL(255, 1) == 255 END
BEGIN BOOST_PP_MUL(255, 2) == 256 END

#endif

#if BOOST_PP_LIMIT_MAG == 512

BEGIN BOOST_PP_MUL(0, 351) == 0 END
BEGIN BOOST_PP_MUL(489, 0) == 0 END
BEGIN BOOST_PP_MUL(1, 272) == 272 END
BEGIN BOOST_PP_MUL(34, 11) == 374 END

BEGIN BOOST_PP_MUL(BOOST_PP_MUL(7, 7), 7) == 343 END
BEGIN BOOST_PP_MUL(7, BOOST_PP_MUL(7, 7)) == 343 END
BEGIN BOOST_PP_MUL(BOOST_PP_MUL(5, 5), BOOST_PP_MUL(4, 4)) == 400 END

BEGIN BOOST_PP_MUL(2, 511) == 512 END
BEGIN BOOST_PP_MUL(511, 2) == 512 END
BEGIN BOOST_PP_MUL(24, 24) == 512 END
BEGIN BOOST_PP_MUL(1, 511) == 511 END

#endif

/* division */

BEGIN BOOST_PP_DIV(2, 1) == 2 END
BEGIN BOOST_PP_DIV(0, 5) == 0 END
BEGIN BOOST_PP_DIV(7, 3) == 2 END

BEGIN BOOST_PP_DIV(BOOST_PP_DIV(4, 2), 2) == 1 END
BEGIN BOOST_PP_DIV(10, BOOST_PP_DIV(10, 2)) == 2 END
BEGIN BOOST_PP_DIV(BOOST_PP_DIV(10, 2), BOOST_PP_DIV(4, 2)) == 2 END

#if BOOST_PP_LIMIT_MAG == 512

BEGIN BOOST_PP_DIV(468, 3) == 156 END
BEGIN BOOST_PP_DIV(0, 272) == 0 END
BEGIN BOOST_PP_DIV(335, 6) == 55 END

BEGIN BOOST_PP_DIV(BOOST_PP_DIV(498, 2), 2) == 124 END
BEGIN BOOST_PP_DIV(375, BOOST_PP_DIV(279, 3)) == 4 END
BEGIN BOOST_PP_DIV(BOOST_PP_DIV(486, 2), BOOST_PP_DIV(17, 4)) == 60 END

#endif

/* modulus */

BEGIN BOOST_PP_MOD(5, 5) == 0 END
BEGIN BOOST_PP_MOD(9, 5) == 4 END
BEGIN BOOST_PP_MOD(7, 4) == 3 END

BEGIN BOOST_PP_MOD(BOOST_PP_MOD(5, 3), 3) == 2 END
BEGIN BOOST_PP_MOD(5, BOOST_PP_MOD(4, 3)) == 0 END

#if BOOST_PP_LIMIT_MAG == 512

BEGIN BOOST_PP_MOD(473, 473) == 0 END
BEGIN BOOST_PP_MOD(381, 126) == 3 END
BEGIN BOOST_PP_MOD(262, 27) == 19 END

BEGIN BOOST_PP_MOD(BOOST_PP_MOD(368, 65), 7) == 1 END
BEGIN BOOST_PP_MOD(194, BOOST_PP_MOD(411, 205)) == 0 END

#endif

/* increment */

BEGIN BOOST_PP_INC(0) == 1 END
BEGIN BOOST_PP_INC(22) == 23 END
BEGIN BOOST_PP_INC(BOOST_PP_INC(0)) == 2 END
BEGIN BOOST_PP_INC(BOOST_PP_INC(17)) == 19 END

#if BOOST_PP_LIMIT_MAG == 256

BEGIN BOOST_PP_INC(256) == 256 END
BEGIN BOOST_PP_INC(BOOST_PP_INC(255)) == 256 END

#endif

#if BOOST_PP_LIMIT_MAG == 512

BEGIN BOOST_PP_INC(349) == 350 END
BEGIN BOOST_PP_INC(426) == 427 END
BEGIN BOOST_PP_INC(256) == 257 END
BEGIN BOOST_PP_INC(BOOST_PP_INC(505)) == 507 END
BEGIN BOOST_PP_INC(BOOST_PP_INC(272)) == 274 END
BEGIN BOOST_PP_INC(BOOST_PP_INC(255)) == 257 END

#endif

/* decrement */

BEGIN BOOST_PP_DEC(256) == 255 END
BEGIN BOOST_PP_DEC(47) == 46 END
BEGIN BOOST_PP_DEC(0) == 0 END

BEGIN BOOST_PP_DEC(BOOST_PP_DEC(256)) == 254 END
BEGIN BOOST_PP_DEC(BOOST_PP_DEC(85)) == 83 END
BEGIN BOOST_PP_DEC(BOOST_PP_DEC(1)) == 0 END

#if BOOST_PP_LIMIT_MAG == 512

BEGIN BOOST_PP_DEC(257) == 256 END
BEGIN BOOST_PP_DEC(473) == 472 END
BEGIN BOOST_PP_DEC(512) == 511 END

BEGIN BOOST_PP_DEC(BOOST_PP_DEC(257)) == 255 END
BEGIN BOOST_PP_DEC(BOOST_PP_DEC(329)) == 327 END
BEGIN BOOST_PP_DEC(BOOST_PP_DEC(512)) == 510 END

#endif

