I am trying to understand the getPayout() in Roulette game code in solidity. Can anyone explain me the calculation here? And what does POPCNT_MULT, POPCNT_MASK and POPCNT_MODULO variable mean?
contract Roulette is Game {
uint8 private constant MODULO = 37;
uint256 private constant POPCNT_MULT =
0x0000000000002000000000100000000008000000000400000000020000000001;
uint256 private constant POPCNT_MASK =
0x0001041041041041041041041041041041041041041041041041041041041041;
uint256 private constant POPCNT_MODULO = 0x3F;
/// @notice Calculates the target payout amount.
/// @param betAmount Bet amount.
/// @param numbers The chosen numbers.
/// @return The target payout amount.
function _getPayout(uint256 betAmount, uint40 numbers)
private
pure
returns (uint256)
{
return
(betAmount * MODULO) /
(((numbers * POPCNT_MULT) & POPCNT_MASK) % POPCNT_MODULO);
}
}