<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def calc_piece_size(total_size, max_pieces, min_piece_size, max_piece_size):
 """Calculate piece size"""

    ps = 1 << max(0, math.ceil(math.log(total_size / max_pieces, 2)))
    if ps < min_piece_size:
        ps = min_piece_size
    if ps > max_piece_size:
        ps = max_piece_size
    return ps