def _areareduceA(area, area0, crossings, reverse, sign):
    """Reduce accumulator area to allowed range."""
    area.Remainder(area0)
    if crossings & 1:
        area.Add((1 if area.Sum() < 0 else -1) * area0 / 2)
    if not reverse:
        area.Negate()
    if sign:
        if area.Sum() > area0 / 2:
            area.Add(-area0)
        elif area.Sum() <= -area0 / 2:
            area.Add(area0)
    elif area.Sum() >= area0:
        area.Add(-area0)
    elif area.Sum() < 0:
        area.Add(area0)
    return 0.0 + area.Sum()
